Skip to content
Snippets Groups Projects
Commit cc620dc4 authored by Amit Kumar Mondal's avatar Amit Kumar Mondal
Browse files

New Changes

parent bd3a9d95
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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;
}
......
......@@ -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);
}
}
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment