From cc620dc41e30ab0b99f740e2dd6ac82b88cae6d8 Mon Sep 17 00:00:00 2001 From: Amit Kumar Mondal <mondal@fortiss.org> Date: Fri, 18 Mar 2016 12:53:23 +0000 Subject: [PATCH] New Changes --- .../trunk/META-INF/MANIFEST.MF | 3 +- .../builder/SpiderChartBuilder.java | 1 + .../spiderchart/legend/SpiderChartLegend.java | 153 +++++++++--------- .../spiderchart/sequence/LineDataSeq.java | 42 +++-- 4 files changed, 109 insertions(+), 90 deletions(-) diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF index 60806ed34..a02b8e932 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF @@ -27,5 +27,6 @@ Export-Package: org.fortiss.tooling.spiderchart, org.fortiss.tooling.spiderchart.swt, org.fortiss.tooling.spiderchart.title, org.fortiss.tooling.spiderchart.util -Require-Bundle: org.eclipse.swt;bundle-version="3.102.1" +Require-Bundle: org.eclipse.swt;bundle-version="3.102.1", + org.fortiss.tooling.base;bundle-version="2.9.0" Bundle-ActivationPolicy: lazy diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java index 2196345f8..419f0434d 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java @@ -106,6 +106,7 @@ public final class SpiderChartBuilder { /** Builds the viewer if values are already provided to the plotter using line data sequence */ public SpiderChartViewer viewer() { + this.chartViewer.setChart(this.chart); return chartViewerBuilder.chartViewer; } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/legend/SpiderChartLegend.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/legend/SpiderChartLegend.java index bd08a005a..b27cd504a 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/legend/SpiderChartLegend.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/legend/SpiderChartLegend.java @@ -82,7 +82,7 @@ public final class SpiderChartLegend extends SpiderChartComponent { /** Constructor */ public SpiderChartLegend() { - if (this.title != null) { + if(this.title != null) { this.addItem(this.title, null); } } @@ -93,24 +93,28 @@ public final class SpiderChartLegend extends SpiderChartComponent { this.names.add(name); } + /** */ + public void addItem(final String name, final String colorName) { + final LineStyle ls = LineStyle.of(1, getColor(colorName), NORMAL_LINE); + this.addItem(name, ls); + } + /** */ public void addItem(final Supplier<Object> pojo) { final Object data = pojo.get(); - final LineStyle ls = LineStyle.of(1, getColor(getAreaColor(data)), - NORMAL_LINE); + final LineStyle ls = LineStyle.of(1, getColor(getAreaColor(data)), NORMAL_LINE); this.addItem(getLegend(data), ls); } /** Draws the provided graphics */ public void draw(final AbstractChartGraphics g) { - if (this.legendLabel != null && this.legendLabel.length() > 0) { - final SpiderChartLabel cl = new SpiderChartLabel(this.legendLabel, - "", false, true); + if(this.legendLabel != null && this.legendLabel.length() > 0) { + final SpiderChartLabel cl = new SpiderChartLabel(this.legendLabel, "", false, true); cl.initialize(g, this.chart); cl.paint(g, this.x, this.y, this.width, this.height); return; } - if (this.verticalLayout) { + if(this.verticalLayout) { this.drawVertical(g); } else { this.drawHorizontal(g); @@ -130,95 +134,90 @@ public final class SpiderChartLegend extends SpiderChartComponent { final int textHeight = g.getFontHeight(); final int iconSeparator = 3; final int textSeparator = 5; - for (final Object element : this.names) { - final String s = (String) element; + for(final Object element : this.names) { + final String s = (String)element; w = g.getFontWidth(s); - if (w > textWidth) { + if(w > textWidth) { textWidth = w; } } totalWidth = (textWidth + textSeparator) * this.names.size(); - for (final Object o : this.items) { + for(final Object o : this.items) { w = 0; h = 0; - if (o instanceof LineStyle) { + if(o instanceof LineStyle) { w = 10; h = 10; } - if (o instanceof FillStyle) { + if(o instanceof FillStyle) { w = 10; h = 10; } - if (o instanceof AbstractChartImage) { - w = ((AbstractChartImage) o).getWidth(); - h = ((AbstractChartImage) o).getHeight(); + if(o instanceof AbstractChartImage) { + w = ((AbstractChartImage)o).getWidth(); + h = ((AbstractChartImage)o).getHeight(); } - if (w > iconWidth) { + if(w > iconWidth) { iconWidth = w; } - if (h > iconHeight) { + if(h > iconHeight) { iconHeight = h; } } totalWidth += (iconWidth + iconSeparator) * this.names.size(); int itemHeight = textHeight; - if (iconHeight > itemHeight) { + if(iconHeight > itemHeight) { itemHeight = iconHeight; } int toCenterX = (this.width - totalWidth) / 2; int toCenterY = (this.height - itemHeight) / 2; - if (toCenterY < 0) { + if(toCenterY < 0) { toCenterY = 0; } - if (toCenterX < 0) { + if(toCenterX < 0) { toCenterX = 0; } final int legendX1 = this.x + toCenterX; final int legendY1 = this.y + toCenterY; final int legendX2 = this.x + toCenterX + totalWidth; final int legendY2 = this.y + toCenterY + itemHeight; - if (this.background != null) { - this.background.draw(g, legendX1 - this.legendMargin, legendY1 - - this.legendMargin, legendX2 + this.legendMargin, legendY2 - + this.legendMargin); + if(this.background != null) { + this.background.draw(g, legendX1 - this.legendMargin, legendY1 - this.legendMargin, + legendX2 + this.legendMargin, legendY2 + this.legendMargin); } - if (this.border != null) { - this.border.drawRect(g, legendX1 - this.legendMargin, legendY1 - - this.legendMargin, legendX2 + this.legendMargin, legendY2 - + this.legendMargin); + if(this.border != null) { + this.border.drawRect(g, legendX1 - this.legendMargin, legendY1 - this.legendMargin, + legendX2 + this.legendMargin, legendY2 + this.legendMargin); } int offset = 0; - for (int i = 1; i <= this.names.size(); i++) { + for(int i = 1; i <= this.names.size(); i++) { g.setColor(this.color); - g.drawText(this.names.get(i - 1), toCenterX + offset + iconWidth - + iconSeparator + this.x, toCenterY + this.y + itemHeight); - offset = offset + iconWidth + iconSeparator + textWidth - + textSeparator; + g.drawText(this.names.get(i - 1), toCenterX + offset + iconWidth + iconSeparator + + this.x, toCenterY + this.y + itemHeight); + offset = offset + iconWidth + iconSeparator + textWidth + textSeparator; } offset = 0; - for (int i = 1; i <= this.names.size(); i++) { + for(int i = 1; i <= this.names.size(); i++) { final Object icon = this.items.get(i - 1); - if (icon instanceof AbstractChartImage) { - g.drawImage((AbstractChartImage) icon, toCenterX + this.x - + offset, toCenterY + this.y); + if(icon instanceof AbstractChartImage) { + g.drawImage((AbstractChartImage)icon, toCenterX + this.x + offset, toCenterY + + this.y); } - if (icon instanceof LineStyle) { - final LineStyle l = (LineStyle) icon; - l.draw(g, toCenterX + this.x + offset, toCenterY + this.y - + iconHeight / 2, toCenterX + this.x + iconWidth - 2 - + offset, toCenterY + this.y + iconHeight / 2); + if(icon instanceof LineStyle) { + final LineStyle l = (LineStyle)icon; + l.draw(g, toCenterX + this.x + offset, toCenterY + this.y + iconHeight / 2, + toCenterX + this.x + iconWidth - 2 + offset, toCenterY + this.y + + iconHeight / 2); } - if (icon instanceof FillStyle) { + if(icon instanceof FillStyle) { final int sidelentgh = iconWidth / 2; - final FillStyle f = (FillStyle) icon; - f.draw(g, toCenterX + this.x + offset, toCenterY + this.y, - toCenterX + this.x + offset + sidelentgh, toCenterY - + this.y + sidelentgh); + final FillStyle f = (FillStyle)icon; + f.draw(g, toCenterX + this.x + offset, toCenterY + this.y, toCenterX + this.x + + offset + sidelentgh, toCenterY + this.y + sidelentgh); } - offset = offset + iconWidth + iconSeparator + textWidth - + textSeparator; + offset = offset + iconWidth + iconSeparator + textWidth + textSeparator; } } @@ -232,72 +231,68 @@ public final class SpiderChartLegend extends SpiderChartComponent { int w = 0; int h = 0; final int textHeight = g.getFontHeight(); - for (final Object element : this.names) { - final String s = (String) element; + for(final Object element : this.names) { + final String s = (String)element; w = g.getFontWidth(s); - if (w > textWidth) { + if(w > textWidth) { textWidth = w; } } - for (final Object o : this.items) { + for(final Object o : this.items) { w = 0; h = 0; - if (o instanceof LineStyle) { + if(o instanceof LineStyle) { w = 10; h = 10; } - if (w > iconWidth) { + if(w > iconWidth) { iconWidth = w; } - if (h > iconHeight) { + if(h > iconHeight) { iconHeight = h; } } int itemHeight = textHeight; - if (iconHeight > itemHeight) { + if(iconHeight > itemHeight) { itemHeight = iconHeight; } int toCenterX = (this.width - (iconWidth + textWidth)) / 2; int toCenterY = (this.height - this.names.size() * itemHeight) / 2; - if (toCenterY < 0) { + if(toCenterY < 0) { toCenterY = 0; } - if (toCenterX < 0) { + if(toCenterX < 0) { toCenterX = 0; } final int legendX1 = this.x + toCenterX; final int legendY1 = this.y + toCenterY; final int legendX2 = this.x + toCenterX + iconWidth + textWidth; - final int legendY2 = this.y + toCenterY + this.names.size() - * itemHeight; + final int legendY2 = this.y + toCenterY + this.names.size() * itemHeight; final int x1 = legendX1 - this.legendMargin; final int y1 = legendY1 - this.legendMargin; final int x2 = legendX2 + this.legendMargin; final int y2 = legendY2 + this.legendMargin; - if (this.background != null) { - this.background.draw(g, x1, y1 + this.legendOffset, x2, y2 - + this.legendOffset); + if(this.background != null) { + this.background.draw(g, x1, y1 + this.legendOffset, x2, y2 + this.legendOffset); } - if (this.border != null) { - this.border.drawRect(g, x1, y1 + this.legendOffset, x2, y2 - + this.legendOffset); + if(this.border != null) { + this.border.drawRect(g, x1, y1 + this.legendOffset, x2, y2 + this.legendOffset); } - for (int i = 1; i <= this.names.size(); i++) { + for(int i = 1; i <= this.names.size(); i++) { g.setColor(this.color); - g.drawText(this.names.get(i - 1), toCenterX + iconWidth + this.x, - toCenterY + this.y + i * itemHeight + this.legendOffset); + g.drawText(this.names.get(i - 1), toCenterX + iconWidth + this.x, toCenterY + this.y + + i * itemHeight + this.legendOffset); } - for (int i = 1; i <= this.names.size(); i++) { + for(int i = 1; i <= this.names.size(); i++) { final Object icon = this.items.get(i - 1); - if (icon instanceof LineStyle) { - final LineStyle l = (LineStyle) icon; + if(icon instanceof LineStyle) { + final LineStyle l = (LineStyle)icon; l.setWidth(10); - l.draw(g, toCenterX + this.x, toCenterY + this.y + iconHeight - / 2 + (i - 1) * itemHeight + this.legendOffset, - toCenterX + this.x + iconWidth - 2, toCenterY + this.y - + iconHeight / 2 + (i - 1) * itemHeight - + this.legendOffset); + l.draw(g, toCenterX + this.x, toCenterY + this.y + iconHeight / 2 + (i - 1) * + itemHeight + this.legendOffset, toCenterX + this.x + iconWidth - 2, + toCenterY + this.y + iconHeight / 2 + (i - 1) * itemHeight + + this.legendOffset); } } } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSeq.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSeq.java index 3e8ec23d5..52557d331 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSeq.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSeq.java @@ -26,6 +26,11 @@ import static org.fortiss.tooling.spiderchart.gc.Fonts.VERDANA; import static org.fortiss.tooling.spiderchart.style.LineStyle.NORMAL_LINE; import static org.fortiss.tooling.spiderchart.util.ChartUtil.wrapValues; +import java.util.List; +import java.util.stream.Collectors; + +import org.fortiss.tooling.base.model.visualization.DataPoint; +import org.fortiss.tooling.base.model.visualization.DataSet; import org.fortiss.tooling.spiderchart.gc.AbstractChartColor; import org.fortiss.tooling.spiderchart.gc.AbstractChartFont; import org.fortiss.tooling.spiderchart.gc.AbstractChartImage; @@ -53,14 +58,14 @@ public final class LineDataSeq extends DataSeq { /** * Static Factory to create instance of {@link LineDataSeq} */ - public static <E extends Enum<E>> LineDataSeq of( - final Object oldObjectToCopyData, final Object... values) { + public static <E extends Enum<E>> LineDataSeq of(final Object oldObjectToCopyData, + final Object... values) { final double[] wrappedValues = wrapValues(values); - final LineDataSeq seq = new LineDataSeq(wrappedValues, new LineStyle(2, - getColor(getAreaColor(oldObjectToCopyData)), NORMAL_LINE)); + final LineDataSeq seq = + new LineDataSeq(wrappedValues, new LineStyle(2, + getColor(getAreaColor(oldObjectToCopyData)), NORMAL_LINE)); seq.valueFont = getFont(VERDANA, BOLD, 12); - seq.fillStyle = new FillStyle( - getColor(getAreaColor(oldObjectToCopyData)), 0.5f); + seq.fillStyle = new FillStyle(getColor(getAreaColor(oldObjectToCopyData)), 0.5f); seq.drawPoint = true; return seq; } @@ -68,11 +73,28 @@ public final class LineDataSeq extends DataSeq { /** * Static Factory to create instance of {@link LineDataSeq} */ - public static <E extends Enum<E>> LineDataSeq of(final String colorName, - final Object... values) { + public static <E extends Enum<E>> LineDataSeq + of(final String colorName, final Object... values) { final double[] wrappedValues = wrapValues(values); - final LineDataSeq seq = new LineDataSeq(wrappedValues, new LineStyle(2, - getColor(colorName), NORMAL_LINE)); + final LineDataSeq seq = + new LineDataSeq(wrappedValues, new LineStyle(2, getColor(colorName), NORMAL_LINE)); + seq.valueFont = getFont(VERDANA, BOLD, 12); + seq.fillStyle = new FillStyle(getColor(colorName), 0.5f); + seq.drawPoint = true; + return seq; + } + + /** + * Static Factory to create instance of {@link LineDataSeq} + */ + public static <E extends Enum<E>> LineDataSeq of(final String colorName, final DataSet dataSet) { + List<DataPoint<?>> datapoints = dataSet.getPoints(); + List<Object> values = + datapoints.stream().map(datapoint -> datapoint.getStart()) + .collect(Collectors.toList()); + final double[] wrappedValues = wrapValues(values.toArray()); + final LineDataSeq seq = + new LineDataSeq(wrappedValues, new LineStyle(2, getColor(colorName), NORMAL_LINE)); seq.valueFont = getFont(VERDANA, BOLD, 12); seq.fillStyle = new FillStyle(getColor(colorName), 0.5f); seq.drawPoint = true; -- GitLab