diff --git a/org.fortiss.tooling.common.ui/META-INF/MANIFEST.MF b/org.fortiss.tooling.common.ui/META-INF/MANIFEST.MF index 136c94b88a7bb325a675fa04974adaea53f0ed1c..8904b24d996d445d452ec69850534811444df865 100644 --- a/org.fortiss.tooling.common.ui/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.common.ui/META-INF/MANIFEST.MF @@ -80,6 +80,7 @@ Export-Package: aerofx, org.fortiss.tooling.common.ui.javafx, org.fortiss.tooling.common.ui.javafx.control.treetableview, org.fortiss.tooling.common.ui.javafx.layout, + org.fortiss.tooling.common.ui.javafx.style, org.fortiss.tooling.common.ui.javafx.lwfxef, org.fortiss.tooling.common.ui.javafx.lwfxef.change, org.fortiss.tooling.common.ui.javafx.lwfxef.controller, diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..74625831a21ad679132a4b8270eff17589e0d83b --- /dev/null +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/.ratings @@ -0,0 +1,5 @@ +ColorStyleBase.java e9af86785db1e20ba812494f05eebc64205437b9 GREEN +FillStyle.java 6acb49d026b93145b32522dcb05e6e5410ae590e GREEN +FontStyle.java be4253fb2f2186d01e2de3faf26477efb634e137 GREEN +LineStyle.java f83241e40e434267876a26cebc1c9a8b131512d2 GREEN +StrokeStyle.java c30b6e901dbc8b853be659cfd411905ddb76da3c GREEN diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/ColorStyleBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/ColorStyleBase.java new file mode 100644 index 0000000000000000000000000000000000000000..e9af86785db1e20ba812494f05eebc64205437b9 --- /dev/null +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/ColorStyleBase.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.common.ui.javafx.style; + +import javafx.scene.paint.Color; + +/** + * Base class for styles with a single {@link Color}. + * + * @author hoelzl + */ +abstract class ColorStyleBase { + /** The RGBA color. */ + private final Color rgbaColor; + + /** Constructor. */ + public ColorStyleBase(Color rgbaColor) { + this.rgbaColor = rgbaColor; + } + + /** Returns the RGBA color. */ + public final Color getColor() { + return rgbaColor; + } +} diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/FillStyle.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/FillStyle.java new file mode 100644 index 0000000000000000000000000000000000000000..6acb49d026b93145b32522dcb05e6e5410ae590e --- /dev/null +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/FillStyle.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.common.ui.javafx.style; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +/** + * Represents a style to be used in for filling areas. + * + * @author hoelzl + */ +public final class FillStyle extends ColorStyleBase { + /** Alpha transparency value (default is opaque 1.0). */ + private final double alpha; + + /** Constructor */ + public FillStyle(Color rgbColor) { + this(rgbColor, 1); + } + + /** Constructor */ + public FillStyle(Color c, double alpha) { + super(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha)); + this.alpha = alpha; + } + + /** Returns alpha value. */ + public double getAlpha() { + return alpha; + } + + /** Applies the style to the given graphics context. */ + public void applyStyle(GraphicsContext gc) { + gc.setFill(getColor()); + } +} diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/FontStyle.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/FontStyle.java new file mode 100644 index 0000000000000000000000000000000000000000..be4253fb2f2186d01e2de3faf26477efb634e137 --- /dev/null +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/FontStyle.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.common.ui.javafx.style; + +import static javafx.scene.paint.Color.BLACK; +import static javafx.scene.text.Font.font; +import static javafx.scene.text.FontSmoothingType.LCD; + +import javafx.geometry.Bounds; +import javafx.geometry.Dimension2D; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.Text; + +/** + * Represents style attributes of fonts and provides a corresponding + * {@link #drawText(GraphicsContext, String, double, double) drawText} method. + * + * @author hoelzl + */ +public final class FontStyle extends ColorStyleBase { + /** Black Verdana 18 point. */ + public static final FontStyle BLACK_VERDANA_18PT = new FontStyle("Verdana", 18, BLACK); + /** Black Verdana 16 point. */ + public static final FontStyle BLACK_VERDANA_16PT = new FontStyle("Verdana", 16, BLACK); + /** Black Verdana 14 point. */ + public static final FontStyle BLACK_VERDANA_14PT = new FontStyle("Verdana", 14, BLACK); + /** Black Verdana 12 point. */ + public static final FontStyle BLACK_VERDANA_12PT = new FontStyle("Verdana", 12, BLACK); + /** Black Verdana 10 point. */ + public static final FontStyle BLACK_VERDANA_10PT = new FontStyle("Verdana", 10, BLACK); + /** Black Verdana 8 point. */ + public static final FontStyle BLACK_VERDANA_8PT = new FontStyle("Verdana", 8, BLACK); + /** The font data. */ + private final Font font; + + /** Constructor. */ + public FontStyle(String fontFamily, double size, Color rgbColor) { + super(rgbColor); + this.font = font(fontFamily, size); + } + + /** Applies the font style to the given graphics context. */ + public void applyStyle(GraphicsContext gc) { + gc.setStroke(getColor()); + gc.setFill(getColor()); + gc.setFont(font); + gc.setFontSmoothingType(LCD); + } + + /** Draws the given text at the given location. */ + public void drawText(GraphicsContext gc, String text, double x, double y) { + gc.save(); + applyStyle(gc); + gc.fillText(text, x, y); + gc.restore(); + } + + /** Returns the dimensions of the text when drawn with this style. */ + public Dimension2D getTextBounds(String text) { + Text t = new Text(text); + t.setFont(font); + Bounds b = t.getBoundsInLocal(); + Dimension2D dim = new Dimension2D(b.getWidth(), b.getHeight()); + return dim; + } +} diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/LineStyle.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/LineStyle.java new file mode 100644 index 0000000000000000000000000000000000000000..f83241e40e434267876a26cebc1c9a8b131512d2 --- /dev/null +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/LineStyle.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.common.ui.javafx.style; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +/** + * Represents a style to be used for lines and provides a corresponding + * {@link #drawLine(GraphicsContext, double, double, double, double) drawLine} method. + * + * @author hoelzl + */ +public final class LineStyle extends ColorStyleBase { + /** Solid, black line with width of one point. */ + public static final LineStyle SOLID_BLACK_1PT = + new LineStyle(Color.BLACK, 1, StrokeStyle.SOLID); + /** The style of the stroke of the line. */ + private final StrokeStyle strokeStyle; + /** The width of the line. */ + private final double width; + + /** Constructor. */ + public LineStyle(Color rgbColor, double width, StrokeStyle strokeStyle) { + super(rgbColor); + this.width = width; + this.strokeStyle = strokeStyle; + } + + /** Constructor. */ + public LineStyle(Color rgbColor) { + this(rgbColor, 1, StrokeStyle.SOLID); + } + + /** Applies the line style to the given graphics context. */ + public void applyStyle(GraphicsContext gc) { + gc.setStroke(getColor()); + gc.setLineWidth(width); + strokeStyle.applyStyle(gc); + } + + /** Draws a line */ + public void drawLine(GraphicsContext gc, double x1, double y1, double x2, double y2) { + applyStyle(gc); + gc.strokeLine(x1, y1, x2, y2); + } +} diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/StrokeStyle.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/StrokeStyle.java new file mode 100644 index 0000000000000000000000000000000000000000..c30b6e901dbc8b853be659cfd411905ddb76da3c --- /dev/null +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/style/StrokeStyle.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.common.ui.javafx.style; + +import javafx.scene.canvas.GraphicsContext; + +/** + * Represents the style of the stroke of a line. + * + * @author hoelzl + */ +public final class StrokeStyle { + /** Stroke style of the solid line. */ + public static final StrokeStyle SOLID = new StrokeStyle(0, null); + /** The line dash offset. */ + private final double offset; + /** The dashes array. */ + private final double[] dashes; + + /** Constructor. */ + public StrokeStyle(double offset, double[] dashes) { + this.offset = offset; + this.dashes = dashes; + } + + /** Set the stroke style for the given graphics context. */ + public void applyStyle(GraphicsContext gc) { + gc.setLineDashOffset(offset); + gc.setLineDashes(dashes); + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/.classpath b/org.fortiss.tooling.spiderchart.ui/.classpath index 5ec5c0d472425196dd61544159a97ce7c6d17d5a..7f27d63afa87bc2b54fd3de7b2b9d6ed921f82ea 100644 --- a/org.fortiss.tooling.spiderchart.ui/.classpath +++ b/org.fortiss.tooling.spiderchart.ui/.classpath @@ -8,5 +8,6 @@ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="test-src"/> + <classpathentry kind="src" path="res"/> <classpathentry kind="output" path="build"/> </classpath> diff --git a/org.fortiss.tooling.spiderchart.ui/META-INF/MANIFEST.MF b/org.fortiss.tooling.spiderchart.ui/META-INF/MANIFEST.MF index c89ba19a5107cb3016de7bf571720bb88fedc2c8..612048b1fc36a2fe01715a7c7f82420922fe10bf 100644 --- a/org.fortiss.tooling.spiderchart.ui/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.spiderchart.ui/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Spider Chart -Bundle-SymbolicName: org.fortiss.tooling.spiderchart.ui +Bundle-SymbolicName: org.fortiss.tooling.spiderchart.ui;singleton:=true Bundle-Version: 2.17.0.qualifier Bundle-Vendor: fortiss GmbH Bundle-RequiredExecutionEnvironment: JavaSE-11 @@ -10,8 +10,9 @@ Github-Project-Url: https://github.com/amitjoy/Spider-Chart-SWT.git Export-Package: org.fortiss.tooling.spiderchart.model, org.fortiss.tooling.spiderchart.style, org.fortiss.tooling.spiderchart.util, - org.fortiss.tooling.spiderchart.widget + org.fortiss.tooling.spiderchart.control Require-Bundle: org.eclipse.swt, - org.fortiss.tooling.base.ui;bundle-version="2.17.0";visibility:=reexport + org.fortiss.tooling.base.ui, + org.fortiss.tooling.common.ui Bundle-ActivationPolicy: lazy Automatic-Module-Name: org.fortiss.tooling.spiderchart.ui diff --git a/org.fortiss.tooling.spiderchart.ui/plugin.xml b/org.fortiss.tooling.spiderchart.ui/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..d7ce8aeabb6f1cfff885838fe9d0c17fd9572a12 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/plugin.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<!-- (c) 2017 fortiss GmbH --> + +<plugin> + <extension point="org.eclipse.ui.views"> + <view + class="test.org.fortiss.tooling.spiderchart.SpiderChartExampleFXViewPart" + id="test.org.fortiss.tooling.spiderchart.SpiderChartExampleFXViewPart" + name="SpiderChartExample" + restorable="true"> + </view> + </extension> +</plugin> diff --git a/org.fortiss.tooling.spiderchart.ui/res/test/org/fortiss/tooling/spiderchart/SpiderChartExample.fxml b/org.fortiss.tooling.spiderchart.ui/res/test/org/fortiss/tooling/spiderchart/SpiderChartExample.fxml new file mode 100644 index 0000000000000000000000000000000000000000..4153e709a4f198ca213eccc5e5dbfe7bf07674cb --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/res/test/org/fortiss/tooling/spiderchart/SpiderChartExample.fxml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.layout.AnchorPane?> + +<AnchorPane fx:id="anchorPane" prefHeight="216.0" prefWidth="345.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" /> diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/.ratings b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/.ratings new file mode 100644 index 0000000000000000000000000000000000000000..469ea7388b216300e34e1d0f12b25b85a3458068 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/.ratings @@ -0,0 +1,6 @@ +SpiderChartCanvas.java fcb6bf9c05b5e459de3282996f8d1fdc7dba919c GREEN +SpiderChartControl.java f8eab27397e782217754971ee7e54eab1931b82d GREEN +SpiderChartControlBase.java 83657aa8d923b6f8150b28a3f9f85d78b7435093 GREEN +SpiderChartLegendControl.java c77162dc8aa1233acc84ac042452755071b69076 GREEN +SpiderChartTitleControl.java ce3f7623c82e98e611de99fcc566c5363431f209 GREEN +SpiderChartViewer.java 9d697a5c19f93fe658bed5117ca4218ebc6660bc GREEN diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartCanvas.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartCanvas.java new file mode 100644 index 0000000000000000000000000000000000000000..fcb6bf9c05b5e459de3282996f8d1fdc7dba919c --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartCanvas.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.spiderchart.control; + +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.ChartStyle; + +import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; + +/** + * Represents a {@link Canvas} on which chart will be drawn. + * + * @author hoelzl + */ +final class SpiderChartCanvas { + /** The canvas. */ + private final Canvas canvas; + /** The chart style. */ + private final ChartStyle style; + /** The chart widget. */ + private final SpiderChartControl chartControl; + /** The title widget. */ + private final SpiderChartTitleControl titleControl; + /** The legend widget. */ + private final SpiderChartLegendControl legendControl; + + /** Constructor */ + public SpiderChartCanvas(SpiderChart chart, ChartStyle style) { + this.style = style; + this.chartControl = new SpiderChartControl(chart, style); + this.titleControl = new SpiderChartTitleControl(chart, style); + this.legendControl = new SpiderChartLegendControl(chart, style); + + this.canvas = new Canvas(); + canvas.widthProperty().addListener(evt -> { + layoutAndPaint(); + }); + canvas.heightProperty().addListener(evt -> { + layoutAndPaint(); + }); + } + + /** Returns canvas. */ + public Canvas getCanvasControl() { + return canvas; + } + + /** Paints the spider chart. */ + private void layoutAndPaint() { + double width = canvas.getWidth(); + double height = canvas.getHeight(); + layoutChart(width, height); + + GraphicsContext gc = canvas.getGraphicsContext2D(); + gc.clearRect(0, 0, width, height); + drawChart(gc); + } + + /** Computes the bounding boxes of the chart components. */ + private void layoutChart(double width, double height) { + double chartMarginPercent = style.getRelativeMargin(); + double widthMargin = width * chartMarginPercent; + double heightMargin = height * chartMarginPercent; + + double chartY = 0; + double widthRemaining = width; + double heightRemaining = height; + + if(style.isShowTitle()) { + titleControl.setBounds(0, 0, width - 1, heightMargin - 1); + heightRemaining -= heightMargin; + chartY = heightMargin; + } + if(style.isShowLegend()) { + if(style.getLegendStyle().isVerticalLayout()) { + legendControl.setBounds(width - widthMargin, height - heightRemaining, + widthMargin - 1, heightRemaining - 1); + widthRemaining -= widthMargin; + } else { + legendControl.setBounds(0, height - heightMargin, width - 1, heightMargin - 1); + heightRemaining -= heightMargin; + } + } + chartControl.setBounds(0, chartY, widthRemaining, heightRemaining); + } + + /** Draws the spider chart. */ + private void drawChart(GraphicsContext gc) { + if(style.isShowTitle()) { + titleControl.draw(gc); + } + chartControl.draw(gc); + if(style.isShowLegend()) { + legendControl.draw(gc); + } + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartControl.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartControl.java new file mode 100644 index 0000000000000000000000000000000000000000..f8eab27397e782217754971ee7e54eab1931b82d --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartControl.java @@ -0,0 +1,315 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.spiderchart.control; + +import static org.fortiss.tooling.spiderchart.util.AxisUtils.getSegmentPoint; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.spiderchart.model.AxisBase; +import org.fortiss.tooling.spiderchart.model.DataSeries; +import org.fortiss.tooling.spiderchart.model.DoubleAxis; +import org.fortiss.tooling.spiderchart.model.EnumerationAxis; +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.AxisStyle; +import org.fortiss.tooling.spiderchart.style.ChartStyle; +import org.fortiss.tooling.spiderchart.style.DataSeriesStyle; + +import javafx.geometry.Dimension2D; +import javafx.geometry.Point2D; +import javafx.scene.canvas.GraphicsContext; + +/** + * Class for drawing the spider chart. + * + * @author hoelzl + */ +public final class SpiderChartControl extends SpiderChartControlBase { + /** The center point of the chart. */ + private Point2D center = new Point2D(0, 0); + /** The end points of the axes. */ + private Map<AxisBase, Point2D> axesEnds = new HashMap<>(); + /** The angle in degree between two axes. */ + private double segmentDegree = 0.0; + + /** Constructor. */ + public SpiderChartControl(SpiderChart chart, ChartStyle style) { + super(chart, style); + } + + /** Draws the spider chart. */ + public void draw(GraphicsContext gc) { + if(!style.isUseIndividualAxisSegments()) { + drawBackground(gc); + drawWebLines(gc); + } + drawAxes(gc); + for(DataSeries data : chart.getDataSeries()) { + drawDataSeries(gc, data); + } + } + + /** {@inheritDoc} */ + @Override + public void setBounds(double x, double y, double w, double h) { + super.setBounds(x, y, w, h); + computeAxisEndPoints(); + } + + /** Computes the end points of the axes. */ + private void computeAxisEndPoints() { + // compute the axis points + List<AxisBase> axes = chart.getAxes(); + int size = axes.size(); + segmentDegree = 360.0 / size; + double currentAngleDegree = style.getStartAngleDegree(); + + double halfWidth = getWidth() / 2; + double halfHeight = getHeight() / 2; + center = new Point2D(getX() + halfWidth, getY() + halfHeight); + + double relativeMargin = 1.0 - style.getRelativeMargin(); + int wExtent = (int)(relativeMargin * halfWidth); + int hExtent = (int)(relativeMargin * halfHeight); + int extent = Math.min(wExtent, hExtent); + + for(int i = 0; i < size; i++) { + AxisBase axis = axes.get(i); + // compute end point + double startAngleRad = Math.PI * currentAngleDegree / 180.0; + int extentX = (int)(Math.cos(startAngleRad) * extent); + int extentY = (int)(Math.sin(startAngleRad) * extent); + Point2D outer = new Point2D(center.getX() + extentX, center.getY() + extentY); + axesEnds.put(axis, outer); + currentAngleDegree = (currentAngleDegree + segmentDegree) % 360.0; + } + } + + /** Draws the background if style requires all axes to have equal number of segments. */ + private void drawBackground(GraphicsContext gc) { + gc.save(); + if(chart.getAxes().isEmpty()) { + return; + } + + gc.beginPath(); + boolean first = true; + for(AxisBase axis : chart.getAxes()) { + Point2D p = axesEnds.get(axis); + if(first) { + gc.moveTo(p.getX(), p.getY()); + first = false; + } else { + gc.lineTo(p.getX(), p.getY()); + } + } + gc.closePath(); + style.getBackgroundFillStyle().applyStyle(gc); + gc.fill(); + gc.restore(); + } + + /** Draws the web lines of the background if all axes have equal number of segments. */ + private void drawWebLines(GraphicsContext gc) { + style.getBackgroundLineStyle().applyStyle(gc); + for(int i = 1; i <= style.getAxisSegments(); i++) { + computeAndDrawPath(i, gc); + } + } + + /** Computes the i-th web line path. */ + private void computeAndDrawPath(int i, GraphicsContext gc) { + double ratio = (double)i / (double)style.getAxisSegments(); + boolean first = true; + gc.save(); + gc.beginPath(); + for(AxisBase axis : chart.getAxes()) { + Point2D outer = axesEnds.get(axis); + double xExtent = outer.getX() - center.getX(); + double yExtent = outer.getY() - center.getY(); + double x = center.getX() + ratio * xExtent; + double y = center.getY() + ratio * yExtent; + if(first) { + gc.moveTo(x, y); + first = false; + } else { + gc.lineTo(x, y); + } + } + gc.closePath(); + gc.restore(); + } + + /** Draws the data series. */ + private void drawDataSeries(GraphicsContext gc, DataSeries data) { + DataSeriesStyle dStyle = style.getDataSeriesStyle(data); + boolean first = true; + gc.save(); + gc.beginPath(); + for(AxisBase axis : chart.getAxes()) { + Point2D p = computeDataPoint(axis, data); + if(first) { + gc.moveTo(p.getX(), p.getY()); + first = false; + } else { + gc.lineTo(p.getX(), p.getY()); + } + if(dStyle.isShowIndicators()) { + drawIndicator(gc, dStyle, p); + } + if(dStyle.isShowIndicatorLabels()) { + drawIndicatorLabel(gc, dStyle, p, axis, data.getAxisValue(axis)); + } + } + gc.closePath(); + dStyle.getFillStyle().applyStyle(gc); + gc.fill(); + dStyle.getLineStyle().applyStyle(gc); + gc.stroke(); + gc.restore(); + } + + /** Draws the indicator labels next to the chart point. */ + private void drawIndicatorLabel(GraphicsContext gc, DataSeriesStyle dStyle, Point2D p, + AxisBase axis, Object value) { + FontStyle fontStyle = dStyle.getIndicatorLabelStyle(); + String label = dStyle.getFormattedLabel(axis, value); + Dimension2D textExtent = fontStyle.getTextBounds(label); + // data series indicator labels are always to the right of the point + int offset = 5; + double x = p.getX() + offset; + double y = p.getY(); + if(y > center.getY()) { + y = y + offset + textExtent.getHeight() / 2; + } else if(y < center.getY()) { + y = y - offset; + } else { + y = y - textExtent.getHeight() / 2; + } + fontStyle.drawText(gc, label, x, y); + } + + /** Draws the filled indicator rectangle. */ + private void drawIndicator(GraphicsContext gc, DataSeriesStyle dStyle, Point2D p) { + double size = dStyle.getIndicatorSize(); + dStyle.getLineStyle().applyStyle(gc); + gc.fillRect(p.getX() - size / 2, p.getY() - size / 2, size, size); + } + + /** Computes the point on the given axis for the given data. */ + @SuppressWarnings("unchecked") + private Point2D computeDataPoint(AxisBase axis, DataSeries data) { + Double ratio = 0.0; + if(axis instanceof DoubleAxis) { + DoubleAxis da = (DoubleAxis)axis; + ratio = da.getAxisRatio((Double)data.getAxisValue(axis)); + } + if(axis instanceof EnumerationAxis) { + EnumerationAxis<Object> ea = (EnumerationAxis<Object>)axis; + int segments = style.isUseIndividualAxisSegments() + ? style.getAxisStyle(axis).getSegments() : style.getAxisSegments(); + int index = Math.max(0, ea.indexOfEnumerationMember(data.getAxisValue(ea))); + ratio = (double)index / (double)segments; + } + Point2D outer = axesEnds.get(axis); + int deltaX = (int)(ratio * (outer.getX() - center.getX())); + int deltaY = (int)(ratio * (outer.getY() - center.getY())); + return new Point2D(center.getX() + deltaX, center.getY() + deltaY); + } + + /** Draws the axes of the spider chart. */ + private Map<AxisBase, Point2D> drawAxes(GraphicsContext gc) { + List<AxisBase> axes = chart.getAxes(); + int size = axes.size(); + double segmentDegree = 360.0 / size; + double angleDegree = 90.0; + + double halfWidth = getWidth() / 2; + double halfHeight = getHeight() / 2; + double centerX = getX() + halfWidth; + double centerY = getY() + halfHeight; + + for(int i = 0; i < size; i++) { + AxisBase axis = axes.get(i); + Point2D outer = axesEnds.get(axis); + // draw line + AxisStyle aStyle = style.getAxisStyle(axis); + aStyle.getLineStyle().drawLine(gc, centerX, centerY, outer.getX(), outer.getY()); + // draw label + drawAxisLabel(gc, axis, aStyle, centerX, centerY, outer.getX(), outer.getY()); + + if(aStyle.isUseSegmentIndicators()) { + drawSegmentIndicators(gc, centerX, centerY, axis, outer, aStyle); + } + angleDegree = (angleDegree + segmentDegree) % 360.0; + } + return axesEnds; + } + + /** Draws the indicators of the given axis. */ + private void drawSegmentIndicators(GraphicsContext gc, double centerX, double centerY, + AxisBase axis, Point2D outer, AxisStyle aStyle) { + // draw segment indicators + int segments = style.isUseIndividualAxisSegments() ? aStyle.getSegments() + : style.getAxisSegments(); + for(int s = 1; s <= segments; s++) { + String lbl = ""; + if(axis instanceof DoubleAxis) { + double ratio = (double)s / (double)segments; + Double value = ((DoubleAxis)axis).getAxisValue(ratio); + lbl = aStyle.getDecimalFormat().format(value); + } else if(axis instanceof EnumerationAxis) { + Object value = ((EnumerationAxis<?>)axis).getEnumerationMemberAtIndex(s); + if(value != null) { + lbl = value.toString(); + } + } + Point2D segmentPoint = getSegmentPoint(segments, s, outer.getX() - center.getX(), + outer.getY() - center.getY()); + drawSegmentIndicator(gc, lbl, aStyle, centerX, centerY, segmentPoint); + } + } + + /** Draws the indicator on the axis. */ + private void drawSegmentIndicator(GraphicsContext gc, String lbl, AxisStyle axisStyle, + double centerX, double centerY, Point2D segment) { + FontStyle segmentStyle = axisStyle.getSegmentStyle(); + // segment indicator labels are always to the left of the axis + double textWidth = segmentStyle.getTextBounds(lbl).getWidth(); + double posX = centerX + segment.getX() - textWidth - 4; + double posY = centerY + segment.getY() + 4; + segmentStyle.drawText(gc, lbl, posX, posY); + } + + /** Draws the axis label at the correct position. */ + private void drawAxisLabel(GraphicsContext gc, AxisBase axis, AxisStyle style, double centerX, + double centerY, double outerX, double outerY) { + String axisLabel = axis.getName(); + FontStyle labelStyle = style.getLabelStyle(); + Dimension2D tb = labelStyle.getTextBounds(axisLabel); + int offset = 20; + if(outerX > centerX) { + outerX += offset; + } else if(outerX < centerX) { + outerX = outerX - offset - tb.getWidth(); + } else { + outerX = outerX - tb.getWidth() / 2; + } + if(outerY > centerY) { + outerY = outerY + offset + tb.getHeight() / 2; + } else if(outerY < centerY) { + outerY = outerY - offset; + } + labelStyle.drawText(gc, axisLabel, outerX, outerY); + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartControlBase.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartControlBase.java new file mode 100644 index 0000000000000000000000000000000000000000..83657aa8d923b6f8150b28a3f9f85d78b7435093 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartControlBase.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.spiderchart.control; + +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.ChartStyle; + +import javafx.geometry.Rectangle2D; + +/** + * Base class for elements of the spider chart. + * + * @author hoelzl + */ +public abstract class SpiderChartControlBase { + /** The spider chart this component belongs to. */ + protected final SpiderChart chart; + /** The spider chart style information. */ + protected final ChartStyle style; + /** The height of the component. */ + protected double height; + /** The width of the component. */ + protected double width; + /** The x location. */ + protected double x; + /** The y location. */ + protected double y; + + /** Constructor. */ + public SpiderChartControlBase(SpiderChart chart, ChartStyle style) { + this.chart = chart; + this.style = style; + } + + /** Sets the bounding rectangle area of this widget. */ + public void setBounds(double x, double y, double width, double height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + /** Returns x. */ + public final double getX() { + return x; + } + + /** Returns y. */ + public final double getY() { + return y; + } + + /** Returns width. */ + public final double getWidth() { + return width; + } + + /** Returns height. */ + public final double getHeight() { + return height; + } + + /** Returns the bounding rectangle. */ + public final Rectangle2D getBounds() { + return new Rectangle2D(x, y, width, height); + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartLegendControl.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartLegendControl.java new file mode 100644 index 0000000000000000000000000000000000000000..c77162dc8aa1233acc84ac042452755071b69076 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartLegendControl.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.spiderchart.control; + +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.common.ui.javafx.style.LineStyle; +import org.fortiss.tooling.spiderchart.model.DataSeries; +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.ChartStyle; +import org.fortiss.tooling.spiderchart.style.LegendStyle; + +import javafx.geometry.Dimension2D; +import javafx.scene.canvas.GraphicsContext; + +/** + * Class used for drawing the the spider chart legend. + * + * @author hoelzl + */ +public final class SpiderChartLegendControl extends SpiderChartControlBase { + /** The length of the line for each data series. */ + private static final double LINE_SIZE = 20; + /** The space between line and text. */ + private static final double LINE_SPACE = 5; + + /** Constructor. */ + public SpiderChartLegendControl(SpiderChart chart, ChartStyle style) { + super(chart, style); + } + + /** Draws the provided graphics */ + public void draw(GraphicsContext gc) { + if(!style.isShowLegend()) { + return; + } + + if(style.getLegendStyle().isVerticalLayout()) { + drawVertical(gc); + } else { + drawHorizontal(gc); + } + } + + /** Draws the graphics horizontally. */ + public void drawHorizontal(GraphicsContext gc) { + String labelText = chart.getLegendLabel(); + double margin = style.getLegendStyle().getMargin(); + + double xDelta = 0; + if(labelText != null && labelText.trim().length() > 0) { + xDelta = drawHorizontalLabel(gc); + } + double y = getY() + margin; + for(DataSeries data : chart.getDataSeries()) { + String text = data.getName(); + FontStyle fontStyle = style.getDataSeriesStyle(data).getIndicatorLabelStyle(); + Dimension2D extent = fontStyle.getTextBounds(text); + + LineStyle l = style.getDataSeriesStyle(data).getLineStyle(); + double xl = getX() + xDelta; + l.drawLine(gc, xl, y - extent.getHeight() / 4, xl + LINE_SIZE, + y - extent.getHeight() / 4); + xDelta = xDelta + LINE_SIZE + LINE_SPACE; + double xs = getX() + xDelta; + fontStyle.drawText(gc, text, xs, y); + xDelta = xDelta + extent.getWidth() + margin; + } + } + + /** Draws the horizontal legend label and returns the offset. */ + private double drawHorizontalLabel(GraphicsContext gc) { + String labelText = chart.getLegendLabel(); + LegendStyle legendStyle = style.getLegendStyle(); + FontStyle labelStyle = legendStyle.getLabelStyle(); + double margin = legendStyle.getMargin(); + + double textExtent = labelStyle.getTextBounds(labelText).getWidth(); + labelStyle.drawText(gc, labelText, getX() + margin, getY() + margin); + return textExtent + 2 * margin; + } + + /** Draws the graphics vertically. */ + public void drawVertical(GraphicsContext gc) { + String labelText = chart.getLegendLabel(); + LegendStyle legendStyle = style.getLegendStyle(); + double margin = legendStyle.getMargin(); + + double yDelta = 0; + if(labelText != null && labelText.trim().length() > 0) { + yDelta = drawVerticalLabel(gc); + } + + double textWidth = 0; + double textHeight = 0; + + for(DataSeries data : chart.getDataSeries()) { + Dimension2D extent = legendStyle.getLabelStyle().getTextBounds(data.getName()); + textWidth = Math.max(textWidth, extent.getWidth()); + textHeight = Math.max(textHeight, extent.getHeight()); + } + + int cnt = 0; + for(DataSeries data : chart.getDataSeries()) { + double dY = yDelta + cnt * (textHeight + margin); + double dX = LINE_SIZE + 2 * margin; + LineStyle l = style.getDataSeriesStyle(data).getLineStyle(); + double lY = dY + textHeight / 2; + l.drawLine(gc, getX() + margin, getY() + lY, getX() + margin + LINE_SIZE, getY() + lY); + style.getDataSeriesStyle(data).getIndicatorLabelStyle().drawText(gc, data.getName(), + getX() + dX, getY() + dY); + cnt++; + } + } + + /** Draws the header label for the vertical legend layout and returns the offset. */ + private double drawVerticalLabel(GraphicsContext gc) { + String labelText = chart.getLegendLabel(); + LegendStyle legendStyle = style.getLegendStyle(); + FontStyle labelStyle = legendStyle.getLabelStyle(); + double margin = legendStyle.getMargin(); + Dimension2D textExtent = labelStyle.getTextBounds(labelText); + double x = getX() + margin + (getWidth() - margin - textExtent.getWidth()) / 2; + labelStyle.drawText(gc, labelText, x, getY() + margin); + return textExtent.getHeight() + margin; + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartTitleControl.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartTitleControl.java new file mode 100644 index 0000000000000000000000000000000000000000..ce3f7623c82e98e611de99fcc566c5363431f209 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartTitleControl.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.spiderchart.control; + +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.ChartStyle; + +import javafx.geometry.Dimension2D; +import javafx.scene.canvas.GraphicsContext; + +/** + * Class used for drawing the spider chart title. + * + * @author hoelzl + */ +public final class SpiderChartTitleControl extends SpiderChartControlBase { + /** Constructor */ + public SpiderChartTitleControl(SpiderChart chart, ChartStyle style) { + super(chart, style); + } + + /** Used to draw the title */ + public void draw(GraphicsContext gc) { + if(!style.isShowTitle()) { + return; + } + + String text = chart.getTitle(); + if(text == null || text.trim().length() == 0) { + return; + } + + gc.save(); + FontStyle fontStyle = style.getTitleStyle(); + Dimension2D extent = fontStyle.getTextBounds(text); + double x = getX() + getWidth() / 2 - extent.getWidth() / 2; + double y = getY() + getHeight() / 2 - extent.getHeight() / 2; + fontStyle.drawText(gc, text, x, y); + gc.restore(); + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartViewer.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartViewer.java new file mode 100644 index 0000000000000000000000000000000000000000..9d697a5c19f93fe658bed5117ca4218ebc6660bc --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/control/SpiderChartViewer.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ +package org.fortiss.tooling.spiderchart.control; + +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.ChartStyle; + +import javafx.geometry.Bounds; +import javafx.scene.canvas.Canvas; +import javafx.scene.layout.Pane; + +/** + * Represents a viewer on the canvas to display the spider chart. + * + * @author hoelzl + */ +public final class SpiderChartViewer { + /** The viewer main pane. */ + private final Pane viewerPane; + /** The actual canvas to be used for drawing. */ + private final SpiderChartCanvas canvas; + + /** Constructor */ + public SpiderChartViewer(SpiderChart chart, ChartStyle style) { + canvas = new SpiderChartCanvas(chart, style); + viewerPane = new Pane(); + viewerPane.getChildren().add(canvas.getCanvasControl()); + viewerPane.widthProperty().addListener(evt -> { + updateCanvasSize(); + }); + viewerPane.heightProperty().addListener(evt -> { + updateCanvasSize(); + }); + } + + /** Updates the canvas size after viewer size changed. */ + protected void updateCanvasSize() { + Bounds b = viewerPane.getLayoutBounds(); + Canvas c = canvas.getCanvasControl(); + c.setWidth(b.getWidth()); + c.setHeight(b.getHeight()); + } + + /** Returns the viewer pane. */ + public Pane getViewerPane() { + return viewerPane; + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/.ratings b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/.ratings index 62d10887df0766c239cf71c1431f42c963b4283b..f9bb881fae63a86579390fbc3c2c06c755b2eeb6 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/.ratings +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/.ratings @@ -1,5 +1,5 @@ -AxisBase.java 59936f17099d2262635e872efa232d717d6ca4d4 GREEN -DataSeries.java 85831f58bec44db8b42d00b86b74c3a572b65bd8 GREEN -DoubleAxis.java fe58c07ebc364d939346048173bcbd493dbac347 GREEN -EnumerationAxis.java 0ec318d6394c20d4dc779bb9736a96d3f8f04263 GREEN -SpiderChart.java 5a61c43903b9f6cc3ebc07ed2c14f1f1ef60da08 GREEN +AxisBase.java 201e1e5fbd8d672ddf05e3bccf464eafe0850991 GREEN +DataSeries.java ca210729107a39adf3e27fffb620694ebe2e0ee1 GREEN +DoubleAxis.java 4fc73d9fb1d19fbb4f2e68e417af0376dce61c23 GREEN +EnumerationAxis.java b61bcfdaed2e3d4cc2172d9289496f711e92723c GREEN +SpiderChart.java 84df851b06832707a40f66dfde4b43f523ee5ea5 GREEN diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/AxisBase.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/AxisBase.java index 59936f17099d2262635e872efa232d717d6ca4d4..201e1e5fbd8d672ddf05e3bccf464eafe0850991 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/AxisBase.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/AxisBase.java @@ -1,18 +1,12 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.model; import static java.util.Objects.requireNonNull; diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DataSeries.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DataSeries.java index 85831f58bec44db8b42d00b86b74c3a572b65bd8..ca210729107a39adf3e27fffb620694ebe2e0ee1 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DataSeries.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DataSeries.java @@ -1,18 +1,12 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.model; import static java.util.Objects.requireNonNull; diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DoubleAxis.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DoubleAxis.java index fe58c07ebc364d939346048173bcbd493dbac347..4fc73d9fb1d19fbb4f2e68e417af0376dce61c23 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DoubleAxis.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/DoubleAxis.java @@ -1,24 +1,18 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.model; import java.util.Comparator; /** - * Class representing an axis of the spider chart. + * Class representing an axis of the spider chart displaying double values. * * @author hoelzl */ diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/EnumerationAxis.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/EnumerationAxis.java index 0ec318d6394c20d4dc779bb9736a96d3f8f04263..b61bcfdaed2e3d4cc2172d9289496f711e92723c 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/EnumerationAxis.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/EnumerationAxis.java @@ -1,18 +1,12 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.model; import static java.util.Collections.sort; @@ -21,7 +15,7 @@ import java.util.Comparator; import java.util.List; /** - * An axis that represents an enumeration. + * Class representing an axis of the spider chart that displays enumeration values. * * @author hoelzl */ diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/SpiderChart.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/SpiderChart.java index 5a61c43903b9f6cc3ebc07ed2c14f1f1ef60da08..84df851b06832707a40f66dfde4b43f523ee5ea5 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/SpiderChart.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/model/SpiderChart.java @@ -1,21 +1,15 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.model; -import static org.conqat.lib.commons.collections.CollectionUtils.asUnmodifiable; +import static java.util.Collections.unmodifiableList; import java.util.ArrayList; import java.util.List; @@ -75,12 +69,12 @@ public final class SpiderChart { /** Returns the unmodifiable list of axes. */ public List<AxisBase> getAxes() { - return asUnmodifiable(axes); + return unmodifiableList(axes); } /** Returns the unmodifiable list of data series. */ public List<DataSeries> getDataSeries() { - return asUnmodifiable(dataSeries); + return unmodifiableList(dataSeries); } /** Returns the legend label. */ diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/.ratings b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/.ratings index 8b725f3946a3802215aba1ebf833464dce5f5661..a6ee578b399d527b4d9be3b48dbaaa05a0f29eab 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/.ratings +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/.ratings @@ -1,8 +1,4 @@ -AxisStyle.java 7c106a32ed09f4674131c486956f84839bd5467c GREEN -ChartStyle.java b2c76a10141ebe9a083d5456bd9e5ef61f472500 GREEN -ColorStyleBase.java b8e824b55490b30507b8d38acf10bc61daf1fa00 GREEN -DataSeriesStyle.java a7bda5ba4e12133ea20edda627e41560b3679641 GREEN -FillStyle.java 36e54f1ecb31836a7c7a821ddf0432264349bd83 GREEN -FontStyle.java 012dfcddfd85159ba6045141df0762289fb70d6f GREEN -LegendStyle.java 39a10d789aeac41114b8b43e7e6790543cb2f618 GREEN -LineStyle.java bc3df608b46c9d2fa367cf75465961389ab4491f GREEN +AxisStyle.java 9e4fc8ad4e2fcaf4d7af87bc3b9d3422a7589dc8 GREEN +ChartStyle.java 308c56bcb1c7c4c1a1f76c02cc3f8d361ea06f7e GREEN +DataSeriesStyle.java 5c9ecf7e9b3f89759cefe309ab5e86fb5c246760 GREEN +LegendStyle.java b4dd4125b87d412a607e311593503206326d9b0a GREEN diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/AxisStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/AxisStyle.java index 7c106a32ed09f4674131c486956f84839bd5467c..9e4fc8ad4e2fcaf4d7af87bc3b9d3422a7589dc8 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/AxisStyle.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/AxisStyle.java @@ -1,31 +1,27 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.style; import static java.util.Objects.requireNonNull; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_12PT; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_8PT; -import static org.fortiss.tooling.spiderchart.style.LineStyle.SOLID_BLACK_1PT; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_12PT; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_8PT; +import static org.fortiss.tooling.common.ui.javafx.style.LineStyle.SOLID_BLACK_1PT; import java.text.DecimalFormat; +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.common.ui.javafx.style.LineStyle; import org.fortiss.tooling.spiderchart.model.DoubleAxis; /** - * Class for all style attributes for {@link DoubleAxis spider chart axes}. + * Class for all style attributes of {@link DoubleAxis spider chart axes}. * <P> * If {@link #segmentStyle} is non-null then indicators will be drawn. * diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java index b2c76a10141ebe9a083d5456bd9e5ef61f472500..308c56bcb1c7c4c1a1f76c02cc3f8d361ea06f7e 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java @@ -1,26 +1,22 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.style; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.GREEN; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.getBrighterColor; +import static javafx.scene.paint.Color.GREEN; import java.util.HashMap; import java.util.Map; +import org.fortiss.tooling.common.ui.javafx.style.FillStyle; +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.common.ui.javafx.style.LineStyle; import org.fortiss.tooling.spiderchart.model.AxisBase; import org.fortiss.tooling.spiderchart.model.DataSeries; import org.fortiss.tooling.spiderchart.model.SpiderChart; @@ -29,6 +25,7 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart; * Class for all style attributes of the {@link SpiderChart spider chart}. * * @author hoelzl + * @author munaro */ public final class ChartStyle { /** The map for style information of axes. */ @@ -62,7 +59,7 @@ public final class ChartStyle { * The {@link FillStyle} used for the background if {@link #useIndividualAxisSegments} is * <code>false</code>. */ - private FillStyle backgroundFillStyle = new FillStyle(getBrighterColor(GREEN)); + private FillStyle backgroundFillStyle = new FillStyle(GREEN.brighter()); /** * The {@link LineStyle} used for the background if {@link #useIndividualAxisSegments} is false. */ diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/DataSeriesStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/DataSeriesStyle.java index a7bda5ba4e12133ea20edda627e41560b3679641..5c9ecf7e9b3f89759cefe309ab5e86fb5c246760 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/DataSeriesStyle.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/DataSeriesStyle.java @@ -1,26 +1,23 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.style; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_10PT; -import static org.fortiss.tooling.spiderchart.style.LineStyle.SOLID_BLACK_1PT; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.LIGHT_GRAY; +import static javafx.scene.paint.Color.LIGHTGRAY; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_10PT; +import static org.fortiss.tooling.common.ui.javafx.style.LineStyle.SOLID_BLACK_1PT; import java.text.DecimalFormat; +import org.fortiss.tooling.common.ui.javafx.style.FillStyle; +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.common.ui.javafx.style.LineStyle; import org.fortiss.tooling.spiderchart.model.AxisBase; import org.fortiss.tooling.spiderchart.model.DataSeries; import org.fortiss.tooling.spiderchart.model.DoubleAxis; @@ -39,7 +36,7 @@ public final class DataSeriesStyle { /** The font style of the data series indicators. */ private final FontStyle indicatorLabelStyle; /** The size of the indicator box. Default is 7. */ - private final int indicatorSize; + private final double indicatorSize; /** The flag to show indicator boxes. */ private final boolean showIndicators; /** The flag to show indicator labels. */ @@ -49,7 +46,7 @@ public final class DataSeriesStyle { /** Constructor. */ public DataSeriesStyle(LineStyle lineStyle, FillStyle fillStyle, boolean withIndicators, - boolean withIndicatorLabels, FontStyle indicatorStyle, int indicatorSize, + boolean withIndicatorLabels, FontStyle indicatorStyle, double indicatorSize, DecimalFormat decimalFormat) { this.lineStyle = lineStyle; this.fillStyle = fillStyle; @@ -62,7 +59,7 @@ public final class DataSeriesStyle { /** Constructor. */ public DataSeriesStyle() { - this(SOLID_BLACK_1PT, new FillStyle(LIGHT_GRAY), true, true, BLACK_VERDANA_10PT, 7, + this(SOLID_BLACK_1PT, new FillStyle(LIGHTGRAY), true, true, BLACK_VERDANA_10PT, 7, new DecimalFormat("#.##")); } @@ -92,7 +89,7 @@ public final class DataSeriesStyle { } /** Returns the size of the indicator box. */ - public int getIndicatorSize() { + public double getIndicatorSize() { return indicatorSize; } diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/FillStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/FillStyle.java deleted file mode 100644 index 36e54f1ecb31836a7c7a821ddf0432264349bd83..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/FillStyle.java +++ /dev/null @@ -1,45 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.style; - -import org.eclipse.swt.graphics.RGB; - -/** - * Represents a style to be used in for filling areas. - * - * @author mondal - * @author hoelzl - */ -public final class FillStyle extends ColorStyleBase { - /** Alpha transparency value (default is opaque 255). */ - private final int alpha; - - /** Constructor */ - public FillStyle(RGB rgbColor) { - this(rgbColor, 255); - } - - /** Constructor */ - public FillStyle(RGB rgbColor, int alpha) { - super(rgbColor); - this.alpha = alpha; - } - - /** Returns alpha value. */ - public int getAlpha() { - return alpha; - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/FontStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/FontStyle.java deleted file mode 100644 index 012dfcddfd85159ba6045141df0762289fb70d6f..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/FontStyle.java +++ /dev/null @@ -1,62 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.style; - -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_10PT; -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_12PT; -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_14PT; -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_16PT; -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_18PT; -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_8PT; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.BLACK; - -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.RGB; - -/** - * Class for style attributes of fonts (FontData and SWT color). - * - * @author hoelzl - */ -public final class FontStyle extends ColorStyleBase { - - /** Black Verdana 18 point. */ - public static final FontStyle BLACK_VERDANA_18PT = new FontStyle(VERDANA_18PT, BLACK); - /** Black Verdana 16 point. */ - public static final FontStyle BLACK_VERDANA_16PT = new FontStyle(VERDANA_16PT, BLACK); - /** Black Verdana 14 point. */ - public static final FontStyle BLACK_VERDANA_14PT = new FontStyle(VERDANA_14PT, BLACK); - /** Black Verdana 12 point. */ - public static final FontStyle BLACK_VERDANA_12PT = new FontStyle(VERDANA_12PT, BLACK); - /** Black Verdana 10 point. */ - public static final FontStyle BLACK_VERDANA_10PT = new FontStyle(VERDANA_10PT, BLACK); - /** Black Verdana 8 point. */ - public static final FontStyle BLACK_VERDANA_8PT = new FontStyle(VERDANA_8PT, BLACK); - - /** The font data. */ - private final FontData fontData; - - /** Constructor. */ - public FontStyle(FontData fontData, RGB rgbColor) { - super(rgbColor); - this.fontData = fontData; - } - - /** Returns font data. */ - public final FontData getFontData() { - return fontData; - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LegendStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LegendStyle.java index 39a10d789aeac41114b8b43e7e6790543cb2f618..b4dd4125b87d412a607e311593503206326d9b0a 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LegendStyle.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LegendStyle.java @@ -1,38 +1,31 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.style; -import org.eclipse.swt.graphics.RGB; +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; /** * Class for all style attributes of the spider chart legend. * * @author hoelzl */ -public final class LegendStyle extends ColorStyleBase { +public final class LegendStyle { /** The vertical / horizontal layout flag. */ private boolean verticalLayout; /** The inner margins. */ - private int margin = 5; + private double margin = 5; /** The font style of the label. */ private FontStyle labelStyle; /** Constructor. */ - public LegendStyle(RGB rgbColor, boolean verticalLayout, int margin, FontStyle labelStyle) { - super(rgbColor); + public LegendStyle(boolean verticalLayout, double margin, FontStyle labelStyle) { this.margin = Math.max(5, margin); this.verticalLayout = verticalLayout; this.labelStyle = labelStyle; @@ -44,7 +37,7 @@ public final class LegendStyle extends ColorStyleBase { } /** Returns margin. */ - public int getMargin() { + public double getMargin() { return margin; } diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LineStyle.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LineStyle.java deleted file mode 100644 index bc3df608b46c9d2fa367cf75465961389ab4491f..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/LineStyle.java +++ /dev/null @@ -1,56 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.style; - -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.BLACK; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; -import org.fortiss.tooling.base.ui.utils.GCStateManager; - -/** - * Represents a style to be used in SWT spider chart graphics. - * - * @author mondal - */ -public final class LineStyle extends ColorStyleBase { - /** Solid, black line with width of one point. */ - public static final LineStyle SOLID_BLACK_1PT = new LineStyle(BLACK, 1, SWT.LINE_SOLID); - /** The type of the line. */ - private final int swtLineStyle; - /** The width of the line. */ - private final int width; - - /** Constructor */ - public LineStyle(RGB rgbColor, int width, int swtLineStyle) { - super(rgbColor); - this.width = width; - this.swtLineStyle = swtLineStyle; - } - - /** Constructor */ - public LineStyle(RGB rgbColor) { - this(rgbColor, 1, SWT.LINE_SOLID); - } - - /** Draws the line */ - public void draw(GCStateManager gcState, int x1, int y1, int x2, int y2) { - gcState.foregroundStoreAndCreate(getRGBColor()); - gcState.lineStoreAndSet(width, swtLineStyle); - gcState.GC().drawLine(x1, y1, x2, y2); - gcState.lineRestore().foregroundRestoreAndDispose(); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/.ratings b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/.ratings index c642a0e3c02646d53064605dcb87dda842a6c1ec..b0f4c4ec7a80b6b0fd9d77c707ae86ae554b454c 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/.ratings +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/.ratings @@ -1,2 +1 @@ -AxisUtils.java 6fc6928adad9955184284f56919193218d24f087 GREEN -RGBColorUtils.java 2fc319ab0bc3d898f7c68db324cded3ddcd45f70 GREEN +AxisUtils.java 728130b4956452cd0e0258489e4eda1cc1b9e259 GREEN diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/AxisUtils.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/AxisUtils.java index 6fc6928adad9955184284f56919193218d24f087..728130b4956452cd0e0258489e4eda1cc1b9e259 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/AxisUtils.java +++ b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/AxisUtils.java @@ -1,40 +1,36 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ +/******************************************************************************* + * Copyright (c) 2017, 2018 fortiss GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0, which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ package org.fortiss.tooling.spiderchart.util; -import org.eclipse.swt.graphics.Point; import org.fortiss.tooling.spiderchart.model.DoubleAxis; import org.fortiss.tooling.spiderchart.style.AxisStyle; +import javafx.geometry.Point2D; + /** * Utility methods related to {@link DoubleAxis} and {@link AxisStyle}. * * @author hoelzl + * @author munaro */ public class AxisUtils { /** Returns the segment point on the axis if the the axis displayed with the given extents. */ - public static Point getSegmentPoint(int numberOfSegments, int segment, int extentX, - int extentY) { - int segmentX = extentX / numberOfSegments; - int segmentY = extentY / numberOfSegments; - return new Point(segmentX * segment, segmentY * segment); + public static Point2D getSegmentPoint(int numberOfSegments, int segment, double extentX, + double extentY) { + double segmentX = extentX / numberOfSegments; + double segmentY = extentY / numberOfSegments; + return new Point2D(segmentX * segment, segmentY * segment); } /** Returns the segment point on the axis if the the axis displayed with the given extents. */ - public static Point getSegmentPoint(AxisStyle style, int segment, Point extent) { - return getSegmentPoint(style.getSegments(), segment, extent.x, extent.y); + public static Point2D getSegmentPoint(AxisStyle style, int segment, Point2D extent) { + return getSegmentPoint(style.getSegments(), segment, extent.getX(), extent.getY()); } } diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/RGBColorUtils.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/RGBColorUtils.java deleted file mode 100644 index 2fc319ab0bc3d898f7c68db324cded3ddcd45f70..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/util/RGBColorUtils.java +++ /dev/null @@ -1,93 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.util; - -import static java.lang.Math.max; -import static java.lang.Math.min; - -import org.eclipse.swt.graphics.RGB; - -/** - * Utility class for handling colors with a set of commonly used colors. - * - * @author mondal - * @author hoelzl - */ -public final class RGBColorUtils { - /** The RGB color black. */ - public static final RGB BLACK = new RGB(0, 0, 0); - /** The RGB color white. */ - public static final RGB WHITE = new RGB(255, 255, 255); - /** The RGB color red. */ - public static final RGB RED = new RGB(255, 0, 0); - /** The RGB color green. */ - public static final RGB GREEN = new RGB(0, 255, 0); - /** The RGB color blue. */ - public static final RGB BLUE = new RGB(0, 0, 255); - /** The RGB color cyan. */ - public static final RGB CYAN = new RGB(0, 255, 255); - /** The RGB color magenta. */ - public static final RGB MAGENTA = new RGB(255, 0, 128); - /** The RGB color yellow. */ - public static final RGB YELLOW = new RGB(255, 255, 255); - /** The RGB color light gray. */ - public static final RGB LIGHT_GRAY = new RGB(192, 192, 192); - /** The RGB color gray. */ - public static final RGB GRAY = new RGB(128, 128, 128); - /** The RGB color dark gry. */ - public static final RGB DARK_GRAY = new RGB(70, 70, 70); - /** The RGB color pink. */ - public static final RGB PINK = new RGB(255, 255, 255); - /** The RGB color lime. */ - public static final RGB LIME = convert(65280); - /** The RGB color olive. */ - public static final RGB OLIVE = convert(8421376); - /** The RGB color navy. */ - public static final RGB NAVY = new RGB(0, 0, 128); - - /** Returns the color, which is 10% brighter than the given color. */ - public static RGB getBrighterColor(RGB color) { - int percent = 10; - int rr = color.red; - int gg = color.green; - int bb = color.blue; - int r = rr + percent * (rr / 100); - int g = gg + percent * (gg / 100); - int b = bb + percent * (bb / 100); - return new RGB(min(r, 255), min(g, 255), min(b, 255)); - } - - /** Returns the color, which is 10% darker than the given color. */ - public static RGB getDarkerColor(RGB color) { - int percent = 10; - int rr = color.red; - int gg = color.green; - int bb = color.blue; - int r = rr - percent * (rr / 100); - int g = gg - percent * (gg / 100); - int b = bb - percent * (bb / 100); - - return new RGB(max(r, 0), max(g, 0), max(b, 0)); - } - - /** Converts from integer value to RGB instance. */ - private static RGB convert(int rgb) { - int red = rgb >> 16 & 0xFF; - int green = rgb >> 8 & 0xFF; - int blue = rgb & 0xFF; - return new RGB(red, green, blue); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/.ratings b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/.ratings deleted file mode 100644 index aea3e6d813177d037f4450e3bf2a4227c8ce8892..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/.ratings +++ /dev/null @@ -1,6 +0,0 @@ -SpiderChartLegendWidget.java 405f963218f164d04a02d626b653218d51450bb2 GREEN -SpiderChartSWTCanvas.java 3f65376b935086c8c43602b37121b0927529d6b9 GREEN -SpiderChartTitleWidget.java d822c18e47056ab57269d96c71fb504a8187667e GREEN -SpiderChartViewer.java af1f4c13f99bcb598c5f00e4a0b5ae192a6e235c GREEN -SpiderChartWidget.java f852e52bb73f7587de097ab214efb6bb2a8e25e2 GREEN -SpiderChartWidgetBase.java 8e83167f07c4ca2cbe7d130394db5ebc8968bb82 GREEN diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java deleted file mode 100644 index 405f963218f164d04a02d626b653218d51450bb2..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java +++ /dev/null @@ -1,194 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.widget; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.fortiss.tooling.base.ui.utils.GCStateManager; -import org.fortiss.tooling.spiderchart.model.DataSeries; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.style.ChartStyle; -import org.fortiss.tooling.spiderchart.style.FontStyle; -import org.fortiss.tooling.spiderchart.style.LegendStyle; -import org.fortiss.tooling.spiderchart.style.LineStyle; - -/** - * Class used for drawing the the spider chart legend. - * - * @author mondal - * @author hoelzl - */ -public final class SpiderChartLegendWidget extends SpiderChartWidgetBase { - /** The length of the line for each data series. */ - private static final int LINE_SIZE = 20; - /** The space between line and text. */ - private static final int LINE_SPACE = 3; - - /** Click areas of the legend entries. */ - private final Map<DataSeries, Rectangle> clickAreas = new HashMap<DataSeries, Rectangle>(); - - /** Constructor. */ - public SpiderChartLegendWidget(SpiderChart chart, ChartStyle style) { - super(chart, style); - } - - /** Draws the provided graphics */ - public void draw(GCStateManager gcState) { - if(!style.isShowLegend()) { - return; - } - if(style.getLegendStyle().isVerticalLayout()) { - drawVertical(gcState); - } else { - drawHorizontal(gcState); - } - } - - /** draws the graphics horizontally */ - public void drawHorizontal(GCStateManager gcState) { - String labelText = chart.getLegendLabel(); - int margin = style.getLegendStyle().getMargin(); - GC gc = gcState.GC(); - - int xDelta = 0; - if(labelText != null && labelText.trim().length() > 0) { - xDelta = drawHorizontalLabel(gcState); - } - int y = getY() + margin; - for(DataSeries data : chart.getDataSeries()) { - String text = data.getName(); - Point extent = gc.textExtent(text); - LineStyle l = style.getDataSeriesStyle(data).getLineStyle(); - gcState.foregroundStoreAndCreate(l.getRGBColor()); - - int xl = getX() + xDelta; - l.draw(gcState, xl, y + extent.y / 2, xl + LINE_SIZE, y + extent.y / 2); - xDelta = xDelta + LINE_SIZE + LINE_SPACE; - - int xs = getX() + xDelta; - gc.drawString(text, xs, y, true); - xDelta = xDelta + extent.x + margin; - gcState.foregroundRestoreAndDispose(); - - Rectangle clickArea = new Rectangle(xl, y, xDelta - xl, extent.y); - clickAreas.put(data, clickArea); - } - } - - /** Draws the horizontal legend label and returns the offset. */ - private int drawHorizontalLabel(GCStateManager gcState) { - String labelText = chart.getLegendLabel(); - LegendStyle legendStyle = style.getLegendStyle(); - FontStyle labelStyle = legendStyle.getLabelStyle(); - int margin = legendStyle.getMargin(); - GC gc = gcState.GC(); - - gcState.fontStoreAndCreate(labelStyle.getFontData()); - gcState.foregroundStoreAndCreate(labelStyle.getRGBColor()); - - gc.setClipping(getX(), getY(), getWidth(), getHeight()); - Point textExtent = gc.textExtent(labelText); - gc.drawString(labelText, getX() + margin, getY() + margin, true); - gc.setClipping((Rectangle)null); - - gcState.foregroundRestoreAndDispose(); - gcState.fontRestoreAndDispose(); - - return textExtent.x + 2 * margin; - } - - /** draws the graphics vertically */ - public void drawVertical(GCStateManager gcState) { - String labelText = chart.getLegendLabel(); - LegendStyle legendStyle = style.getLegendStyle(); - int margin = legendStyle.getMargin(); - GC gc = gcState.GC(); - - int yDelta = 0; - if(labelText != null && labelText.trim().length() > 0) { - yDelta = drawVerticalLabel(gcState); - } - - int textWidth = 0; - int textHeight = 0; - - for(DataSeries data : chart.getDataSeries()) { - Point extent = gc.textExtent(data.getName()); - textWidth = Math.max(textWidth, extent.x); - textHeight = Math.max(textHeight, extent.y); - } - - int cnt = 0; - for(DataSeries data : chart.getDataSeries()) { - int dY = yDelta + cnt * (textHeight + margin); - int dX = LINE_SIZE + 2 * margin; - LineStyle l = style.getDataSeriesStyle(data).getLineStyle(); - gcState.foregroundStoreAndCreate(l.getRGBColor()); - - int lY = dY + textHeight / 2; - l.draw(gcState, getX() + margin, getY() + lY, getX() + margin + LINE_SIZE, getY() + lY); - gc.drawText(data.getName(), getX() + dX, getY() + dY, true); - - gcState.foregroundRestoreAndDispose(); - cnt++; - - int totalWidth = margin + LINE_SIZE + textWidth; - Rectangle clickArea = new Rectangle(getX(), getY() + dY, totalWidth, textHeight); - clickAreas.put(data, clickArea); - } - } - - /** Draws the header label for the vertical legend layout and returns the offset. */ - private int drawVerticalLabel(GCStateManager gcState) { - String labelText = chart.getLegendLabel(); - LegendStyle legendStyle = style.getLegendStyle(); - FontStyle labelStyle = legendStyle.getLabelStyle(); - int margin = legendStyle.getMargin(); - GC gc = gcState.GC(); - - gcState.fontStoreAndCreate(labelStyle.getFontData()); - gcState.foregroundStoreAndCreate(labelStyle.getRGBColor()); - - gc.setClipping(getX(), getY(), getWidth(), getHeight()); - Point textExtent = gc.textExtent(labelText); - int x = getX() + margin + (getWidth() - margin - textExtent.x) / 2; - gc.drawString(labelText, x, getY() + margin, true); - gc.setClipping((Rectangle)null); - - gcState.foregroundRestoreAndDispose(); - gcState.fontRestoreAndDispose(); - - return textExtent.y + margin; - } - - /** - * Scans the legend entries for a hit at the given point and returns the corresponding - * {@link DataSeries}. - */ - public DataSeries legendEntryHitScan(int x, int y) { - for(DataSeries d : clickAreas.keySet()) { - Rectangle a = clickAreas.get(d); - if(a != null && a.contains(x, y)) { - return d; - } - } - return null; - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java deleted file mode 100644 index 3f65376b935086c8c43602b37121b0927529d6b9..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java +++ /dev/null @@ -1,125 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.widget; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.base.ui.utils.GCStateManager; -import org.fortiss.tooling.spiderchart.model.DataSeries; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.style.ChartStyle; - -/** - * Represents a {@link Canvas} on which chart will be drawn. - * - * @author mondal - * @author hoelzl - */ -final class SpiderChartSWTCanvas extends Canvas { - - /** The chart. */ - private final SpiderChart chart; - /** The chart style. */ - private final ChartStyle style; - /** The chart widget. */ - private final SpiderChartWidget chartWidget; - /** The title widget. */ - private final SpiderChartTitleWidget titleWidget; - /** The legend widget. */ - private final SpiderChartLegendWidget legendWidget; - - /** Constructor */ - public SpiderChartSWTCanvas(Composite parent, SpiderChart chart, ChartStyle style) { - super(parent, SWT.NONE); - this.chart = chart; - this.style = style; - this.chartWidget = new SpiderChartWidget(chart, style); - this.titleWidget = new SpiderChartTitleWidget(chart, style); - this.legendWidget = new SpiderChartLegendWidget(chart, style); - - addPaintListener(e -> drawChart(e)); - - addControlListener(new ControlListener() { - @Override - public void controlMoved(ControlEvent e) { - // not used - } - - @Override - public void controlResized(ControlEvent e) { - layoutChart(); - } - }); - } - - /** Computes the bounding boxes of the chart components. */ - private void layoutChart() { - double charMarginPercent = style.getRelativeMargin(); - Rectangle bounds = getBounds(); - int widthMargin = (int)(bounds.width * charMarginPercent); - int heightMargin = (int)(bounds.height * charMarginPercent); - - int chartY = 0; - int widthRemaining = bounds.width; - int heightRemaining = bounds.height; - - if(style.isShowTitle()) { - titleWidget.setBounds(0, 0, bounds.width - 1, heightMargin - 1); - heightRemaining -= heightMargin; - chartY = heightMargin; - } - if(style.isShowLegend()) { - if(style.getLegendStyle().isVerticalLayout()) { - legendWidget.setBounds(bounds.width - widthMargin, bounds.height - heightRemaining, - widthMargin - 1, heightRemaining - 1); - widthRemaining -= widthMargin; - } else { - legendWidget.setBounds(0, bounds.height - heightMargin, bounds.width - 1, - heightMargin - 1); - heightRemaining -= heightMargin; - } - } - chartWidget.setBounds(0, chartY, widthRemaining, heightRemaining); - } - - /** Draws the spider chart. */ - private void drawChart(PaintEvent e) { - GCStateManager gcState = new GCStateManager(e.gc); - if(style.isShowTitle()) { - titleWidget.draw(gcState); - } - chartWidget.draw(gcState); - if(style.isShowLegend()) { - legendWidget.draw(gcState); - } - } - - /** Handles mouse clicks on the canvas. */ - public void mouseClickedAt(int x, int y) { - if(legendWidget.getBounds().contains(x, y)) { - DataSeries ds = legendWidget.legendEntryHitScan(x, y); - if(ds != null) { - chart.moveSeriesToEnd(ds); - redraw(); - } - } - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java deleted file mode 100644 index d822c18e47056ab57269d96c71fb504a8187667e..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java +++ /dev/null @@ -1,56 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.widget; - -import org.eclipse.swt.graphics.Point; -import org.fortiss.tooling.base.ui.utils.GCStateManager; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.style.ChartStyle; - -/** - * Class used for drawing the spider chart title. - * - * @author mondal - * @author hoelzl - */ -public final class SpiderChartTitleWidget extends SpiderChartWidgetBase { - /** Constructor */ - public SpiderChartTitleWidget(SpiderChart chart, ChartStyle style) { - super(chart, style); - } - - /** Used to draw the title */ - public void draw(GCStateManager gcState) { - if(!style.isShowTitle()) { - return; - } - String text = chart.getTitle(); - if(text == null || text.trim().length() == 0) { - return; - } - - gcState.fontStoreAndCreate(style.getTitleStyle().getFontData()); - gcState.foregroundStoreAndCreate(style.getTitleStyle().getRGBColor()); - - Point extent = gcState.GC().textExtent(text); - int x = getX() + getWidth() / 2 - extent.x / 2; - int y = getY() + getHeight() / 2 - extent.y / 2; - gcState.GC().drawString(text, x, y, true); - - gcState.foregroundRestoreAndDispose(); - gcState.fontRestoreAndDispose(); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartViewer.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartViewer.java deleted file mode 100644 index af1f4c13f99bcb598c5f00e4a0b5ae192a6e235c..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartViewer.java +++ /dev/null @@ -1,95 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.widget; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Composite; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.style.ChartStyle; - -/** - * Represents a viewer on the canvas to display the spider chart. - * - * @author mondal - * @author hoelzl - */ -public final class SpiderChartViewer extends Composite implements MouseListener { - /** The actual canvas to be used for drawing. */ - private final SpiderChartSWTCanvas canvas; - - /** Constructor */ - public SpiderChartViewer(Composite parent, SpiderChart chart, ChartStyle style) { - super(parent, SWT.NONE); - - canvas = new SpiderChartSWTCanvas(this, chart, style); - canvas.addMouseListener(this); - - addControlListener(new ControlListener() { - @Override - public void controlMoved(ControlEvent e) { - // not used - } - - @Override - public void controlResized(ControlEvent e) { - Rectangle b = getBounds(); - canvas.setLocation(b.x, b.y); - canvas.setSize(b.width, b.height); - } - }); - } - - /** {@inheritDoc} */ - @Override - public boolean setFocus() { - return canvas.setFocus(); - } - - /** Redraws the chart */ - public void redrawChart() { - canvas.redraw(); - } - - /** {@inheritDoc} */ - @Override - public void dispose() { - canvas.dispose(); - super.dispose(); - } - - /** {@inheritDoc} */ - @Override - public void mouseDoubleClick(MouseEvent e) { - // nothing to do - } - - /** {@inheritDoc} */ - @Override - public void mouseDown(MouseEvent e) { - // nothing to do - } - - /** {@inheritDoc} */ - @Override - public void mouseUp(MouseEvent e) { - canvas.mouseClickedAt(e.x, e.y); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java deleted file mode 100644 index f852e52bb73f7587de097ab214efb6bb2a8e25e2..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java +++ /dev/null @@ -1,351 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.widget; - -import static org.fortiss.tooling.spiderchart.util.AxisUtils.getSegmentPoint; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Path; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Display; -import org.fortiss.tooling.base.ui.utils.GCStateManager; -import org.fortiss.tooling.spiderchart.model.AxisBase; -import org.fortiss.tooling.spiderchart.model.DataSeries; -import org.fortiss.tooling.spiderchart.model.DoubleAxis; -import org.fortiss.tooling.spiderchart.model.EnumerationAxis; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.style.AxisStyle; -import org.fortiss.tooling.spiderchart.style.ChartStyle; -import org.fortiss.tooling.spiderchart.style.DataSeriesStyle; -import org.fortiss.tooling.spiderchart.style.FillStyle; -import org.fortiss.tooling.spiderchart.style.FontStyle; - -/** - * Class for drawing the spider chart. - * - * @author mondal - * @author hoelzl - */ -public final class SpiderChartWidget extends SpiderChartWidgetBase { - /** The center point of the chart. */ - private Point center = new Point(0, 0); - /** The end points of the axes. */ - private Map<AxisBase, Point> axesEnds = new HashMap<AxisBase, Point>(); - /** The angle in degree between two axes. */ - private double segmentDegree = 0.0; - - /** Constructor. */ - public SpiderChartWidget(SpiderChart chart, ChartStyle style) { - super(chart, style); - } - - /** Draws the spider chart. */ - public void draw(GCStateManager gcState) { - if(!style.isUseIndividualAxisSegments()) { - drawBackground(gcState); - drawWebLines(gcState); - } - drawAxes(gcState); - for(DataSeries data : chart.getDataSeries()) { - drawDataSeries(gcState, data); - } - } - - /** {@inheritDoc} */ - @Override - public void setBounds(int x, int y, int w, int h) { - super.setBounds(x, y, w, h); - computeAxisEndPoints(); - } - - /** Computes the end points of the axes. */ - private void computeAxisEndPoints() { - // compute the axis points - List<AxisBase> axes = chart.getAxes(); - int size = axes.size(); - segmentDegree = 360.0 / size; - double currentAngleDegree = style.getStartAngleDegree(); - - int halfWidth = getWidth() / 2; - int halfHeight = getHeight() / 2; - center.x = getX() + halfWidth; - center.y = getY() + halfHeight; - - double relativeMargin = 1.0 - style.getRelativeMargin(); - int wExtent = (int)(relativeMargin * halfWidth); - int hExtent = (int)(relativeMargin * halfHeight); - int extent = Math.min(wExtent, hExtent); - - for(int i = 0; i < size; i++) { - AxisBase axis = axes.get(i); - // compute end point - double startAngleRad = Math.PI * currentAngleDegree / 180.0; - int extentX = (int)(Math.cos(startAngleRad) * extent); - int extentY = (int)(Math.sin(startAngleRad) * extent); - Point outer = new Point(center.x + extentX, center.y + extentY); - axesEnds.put(axis, outer); - currentAngleDegree = (currentAngleDegree + segmentDegree) % 360.0; - } - } - - /** Draws the background if style requires all axes to have equal number of segments. */ - private void drawBackground(GCStateManager gcState) { - Path path = new Path(Display.getCurrent()); - boolean first = true; - for(AxisBase axis : chart.getAxes()) { - Point p = axesEnds.get(axis); - if(first) { - path.moveTo(p.x, p.y); - first = false; - } else { - path.lineTo(p.x, p.y); - } - } - path.close(); - - gcState.backgroundStoreAndCreate(style.getBackgroundFillStyle().getRGBColor()); - gcState.GC().fillPath(path); - gcState.backgroundRestoreAndDispose(); - - path.dispose(); - } - - /** Draws the web lines of the background if all axes have equal number of segments. */ - private void drawWebLines(GCStateManager gcState) { - gcState.foregroundStoreAndCreate(style.getBackgroundLineStyle().getRGBColor()); - for(int i = 1; i <= style.getAxisSegments(); i++) { - Path p = computePath(i); - gcState.GC().drawPath(p); - p.dispose(); - } - gcState.foregroundRestoreAndDispose(); - } - - /** Computes the i-th web line path. */ - private Path computePath(int i) { - double ratio = (double)i / (double)style.getAxisSegments(); - boolean first = true; - Path p = new Path(Display.getCurrent()); - for(AxisBase axis : chart.getAxes()) { - Point outer = axesEnds.get(axis); - int xExtent = outer.x - center.x; - int yExtent = outer.y - center.y; - int x = center.x + (int)(ratio * xExtent); - int y = center.y + (int)(ratio * yExtent); - if(first) { - p.moveTo(x, y); - first = false; - } else { - p.lineTo(x, y); - } - } - p.close(); - return p; - } - - /** Draws the data series. */ - private void drawDataSeries(GCStateManager gcState, DataSeries data) { - DataSeriesStyle dStyle = style.getDataSeriesStyle(data); - Path path = new Path(Display.getCurrent()); - boolean first = true; - for(AxisBase axis : chart.getAxes()) { - Point p = computeDataPoint(axis, data); - if(first) { - path.moveTo(p.x, p.y); - first = false; - } else { - path.lineTo(p.x, p.y); - } - if(dStyle.isShowIndicators()) { - drawIndicator(gcState, dStyle, p); - } - if(dStyle.isShowIndicatorLabels()) { - drawIndicatorLabel(gcState, dStyle, p, axis, data.getAxisValue(axis)); - } - } - path.close(); - - // draw the filled area with alpha value. - FillStyle fStyle = dStyle.getFillStyle(); - gcState.alphaStoreAndSet(fStyle.getAlpha()); - gcState.backgroundStoreAndCreate(fStyle.getRGBColor()); - gcState.GC().fillPath(path); - gcState.backgroundRestoreAndDispose().alphaRestore(); - - // draw the outline without alpha value - gcState.foregroundStoreAndCreate(dStyle.getLineStyle().getRGBColor()); - gcState.GC().drawPath(path); - gcState.foregroundRestoreAndDispose(); - - path.dispose(); - } - - /** Draws the indicator labels next to the chart point. */ - private void drawIndicatorLabel(GCStateManager gcState, DataSeriesStyle dStyle, Point p, - AxisBase axis, Object value) { - gcState.fontStoreAndCreate(dStyle.getIndicatorLabelStyle().getFontData()); - gcState.foregroundStoreAndCreate(dStyle.getIndicatorLabelStyle().getRGBColor()); - - GC gc = gcState.GC(); - String label = dStyle.getFormattedLabel(axis, value); - Point textExtent = gc.textExtent(label); - // data series indicator labels are always to the right of the point - int x = p.x + 4; - int y = p.y; - if(y > center.y) { - y = y + 4; - } else if(y < center.y) { - y = y - 4 - textExtent.y; - } else { - y = y - textExtent.y / 2; - } - gc.drawString(label, x, y, true); - - gcState.foregroundRestoreAndDispose().fontRestoreAndDispose(); - } - - /** Draws the filled indicator rectangle. */ - private void drawIndicator(GCStateManager gcState, DataSeriesStyle dStyle, Point p) { - int size = dStyle.getIndicatorSize(); - gcState.backgroundStoreAndCreate(dStyle.getLineStyle().getRGBColor()); - gcState.GC().fillRectangle(p.x - size / 2, p.y - size / 2, size, size); - gcState.backgroundRestoreAndDispose(); - } - - /** Computes the point on the given axis for the given data. */ - @SuppressWarnings("unchecked") - private Point computeDataPoint(AxisBase axis, DataSeries data) { - Double ratio = 0.0; - if(axis instanceof DoubleAxis) { - DoubleAxis da = (DoubleAxis)axis; - ratio = da.getAxisRatio((Double)data.getAxisValue(axis)); - } - if(axis instanceof EnumerationAxis) { - EnumerationAxis<Object> ea = (EnumerationAxis<Object>)axis; - int segments = style.isUseIndividualAxisSegments() - ? style.getAxisStyle(axis).getSegments() : style.getAxisSegments(); - int index = Math.max(0, ea.indexOfEnumerationMember(data.getAxisValue(ea))); - ratio = (double)index / (double)segments; - } - Point outer = axesEnds.get(axis); - int deltaX = (int)(ratio * (outer.x - center.x)); - int deltaY = (int)(ratio * (outer.y - center.y)); - return new Point(center.x + deltaX, center.y + deltaY); - } - - /** Draws the axes of the spider chart. */ - private Map<AxisBase, Point> drawAxes(GCStateManager gcState) { - List<AxisBase> axes = chart.getAxes(); - int size = axes.size(); - double segmentDegree = 360.0 / size; - double angleDegree = 90.0; - - int halfWidth = getWidth() / 2; - int halfHeight = getHeight() / 2; - int centerX = getX() + halfWidth; - int centerY = getY() + halfHeight; - - for(int i = 0; i < size; i++) { - AxisBase axis = axes.get(i); - Point outer = axesEnds.get(axis); - // draw line - AxisStyle aStyle = style.getAxisStyle(axis); - aStyle.getLineStyle().draw(gcState, centerX, centerY, outer.x, outer.y); - // draw label - drawAxisLabel(gcState, axis, aStyle, centerX, centerY, outer.x, outer.y); - - if(aStyle.isUseSegmentIndicators()) { - drawSegmentIndicators(gcState, centerX, centerY, axis, outer, aStyle); - } - angleDegree = (angleDegree + segmentDegree) % 360.0; - } - return axesEnds; - } - - /** Draws the indicators of the given axis. */ - private void drawSegmentIndicators(GCStateManager gcState, int centerX, int centerY, - AxisBase axis, Point outer, AxisStyle aStyle) { - // draw segment indicators - int segments = style.isUseIndividualAxisSegments() ? aStyle.getSegments() - : style.getAxisSegments(); - for(int s = 1; s <= segments; s++) { - String lbl = ""; - if(axis instanceof DoubleAxis) { - double ratio = (double)s / (double)segments; - Double value = ((DoubleAxis)axis).getAxisValue(ratio); - lbl = aStyle.getDecimalFormat().format(value); - } else if(axis instanceof EnumerationAxis) { - Object value = ((EnumerationAxis<?>)axis).getEnumerationMemberAtIndex(s); - if(value != null) { - lbl = value.toString(); - } - } - Point segmentPoint = - getSegmentPoint(segments, s, outer.x - center.x, outer.y - center.y); - drawSegmentIndicator(gcState, lbl, aStyle, centerX, centerY, segmentPoint); - } - } - - /** Draws the indicator on the axis. */ - private void drawSegmentIndicator(GCStateManager gcState, String lbl, AxisStyle axisStyle, - int centerX, int centerY, Point segment) { - FontStyle segmentStyle = axisStyle.getSegmentStyle(); - gcState.fontStoreAndCreate(segmentStyle.getFontData()); - gcState.foregroundStoreAndCreate(segmentStyle.getRGBColor()); - - GC gc = gcState.GC(); - // segment indicator labels are always to the left of the axis - int posX = centerX + segment.x - gc.textExtent(lbl).x - 4; - int posY = centerY + segment.y + 4; - gc.drawText(lbl, posX, posY, true); - - gcState.foregroundRestoreAndDispose().fontRestoreAndDispose(); - } - - /** Draws the axis label at the correct position. */ - private void drawAxisLabel(GCStateManager gcState, AxisBase axis, AxisStyle style, int centerX, - int centerY, int outerX, int outerY) { - String axisLabel = axis.getName(); - FontData fontData = style.getLabelStyle().getFontData(); - - gcState.fontStoreAndCreate(fontData); - gcState.foregroundStoreAndCreate(style.getLabelStyle().getRGBColor()); - - int textExtent = gcState.GC().textExtent(axisLabel).x; - if(outerX > centerX) { - outerX += 5; - } else if(outerX < centerX) { - outerX = outerX - 5 - textExtent; - } else { - outerX = outerX - textExtent / 2; - } - if(outerY > centerY) { - outerY = outerY + 5; - } else if(outerY < centerY) { - outerY = outerY - 5 - fontData.getHeight(); - } else { - outerY = outerY - fontData.getHeight() / 2; - } - gcState.GC().drawString(axisLabel, outerX, outerY, true); - - gcState.foregroundRestoreAndDispose().fontRestoreAndDispose(); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidgetBase.java b/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidgetBase.java deleted file mode 100644 index 8e83167f07c4ca2cbe7d130394db5ebc8968bb82..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidgetBase.java +++ /dev/null @@ -1,80 +0,0 @@ -/*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.widget; - -import org.eclipse.swt.graphics.Rectangle; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.style.ChartStyle; - -/** - * Base class for elements of the spider chart. - * - * @author mondal - * @author hoelzl - */ -public abstract class SpiderChartWidgetBase { - /** The spider chart this component belongs to. */ - protected final SpiderChart chart; - /** The spider chart style information. */ - protected final ChartStyle style; - /** The height of the component. */ - protected int height; - /** The width of the component. */ - protected int width; - /** The x location. */ - protected int x; - /** The y location. */ - protected int y; - - /** Constructor. */ - public SpiderChartWidgetBase(SpiderChart chart, ChartStyle style) { - this.chart = chart; - this.style = style; - } - - /** Sets the bounding rectangle area of this widget. */ - public void setBounds(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - /** Returns x. */ - public final int getX() { - return x; - } - - /** Returns y. */ - public final int getY() { - return y; - } - - /** Returns width. */ - public final int getWidth() { - return width; - } - - /** Returns height. */ - public final int getHeight() { - return height; - } - - /** Returns the bounding rectangle. */ - public final Rectangle getBounds() { - return new Rectangle(x, y, width, height); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExample.java b/org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExampleFXController.java similarity index 62% rename from org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExample.java rename to org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExampleFXController.java index f98c574d5902e8bc90926dd7dabe2ae48c29649b..26170e941643307aa5353ad877cd8b245ee726be 100644 --- a/org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExample.java +++ b/org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExampleFXController.java @@ -15,28 +15,26 @@ +--------------------------------------------------------------------------*/ package test.org.fortiss.tooling.spiderchart; -import static org.fortiss.tooling.base.ui.utils.FontUtils.VERDANA_14PT; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_10PT; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_12PT; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_14PT; -import static org.fortiss.tooling.spiderchart.style.FontStyle.BLACK_VERDANA_8PT; -import static org.fortiss.tooling.spiderchart.style.LineStyle.SOLID_BLACK_1PT; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.BLUE; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.DARK_GRAY; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.LIGHT_GRAY; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.NAVY; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.OLIVE; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.getDarkerColor; +import static javafx.scene.paint.Color.BLUE; +import static javafx.scene.paint.Color.DARKGRAY; +import static javafx.scene.paint.Color.GREEN; +import static javafx.scene.paint.Color.LIGHTGRAY; +import static javafx.scene.paint.Color.RED; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_10PT; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_12PT; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_14PT; +import static org.fortiss.tooling.common.ui.javafx.style.FontStyle.BLACK_VERDANA_8PT; +import static org.fortiss.tooling.common.ui.javafx.style.LineStyle.SOLID_BLACK_1PT; import java.text.DecimalFormat; import java.util.Arrays; import java.util.Comparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; +import org.fortiss.tooling.common.ui.javafx.layout.CompositeFXControllerBase; +import org.fortiss.tooling.common.ui.javafx.style.FillStyle; +import org.fortiss.tooling.common.ui.javafx.style.FontStyle; +import org.fortiss.tooling.common.ui.javafx.style.LineStyle; +import org.fortiss.tooling.spiderchart.control.SpiderChartViewer; import org.fortiss.tooling.spiderchart.model.DataSeries; import org.fortiss.tooling.spiderchart.model.DoubleAxis; import org.fortiss.tooling.spiderchart.model.EnumerationAxis; @@ -44,21 +42,31 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart; import org.fortiss.tooling.spiderchart.style.AxisStyle; import org.fortiss.tooling.spiderchart.style.ChartStyle; import org.fortiss.tooling.spiderchart.style.DataSeriesStyle; -import org.fortiss.tooling.spiderchart.style.FillStyle; -import org.fortiss.tooling.spiderchart.style.FontStyle; import org.fortiss.tooling.spiderchart.style.LegendStyle; -import org.fortiss.tooling.spiderchart.style.LineStyle; -import org.fortiss.tooling.spiderchart.widget.SpiderChartViewer; + +import javafx.fxml.FXML; +import javafx.scene.Node; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Pane; /** - * Example application for the spider chart widget. + * Test view for the {@link SpiderChartViewer}. * - * @author mondal * @author hoelzl */ -public final class SpiderChartExample { // NO_UCD +@SuppressWarnings("unchecked") +public class SpiderChartExampleFXController extends CompositeFXControllerBase<AnchorPane, Node> { + + /** Pane containing the spider chart's canvas. */ + @FXML + Pane pane; + + /** Anchor pane on which the spider chart is drawn. */ + @FXML + Pane anchorPane; + /** Constructs the spider chart viewer. */ - private static SpiderChartViewer buildSpiderChart(final Shell shell) { + private static SpiderChartViewer buildSpiderChart() { SpiderChart spiderChart = new SpiderChart(); spiderChart.setTitle("Smartphone Comparison Scale"); spiderChart.setLegendLabel("Legend"); @@ -69,7 +77,7 @@ public final class SpiderChartExample { // NO_UCD DoubleAxis memory = new DoubleAxis("Memory", 0.0, 5.0); DoubleAxis brand = new DoubleAxis("Brand", 0.0, 5.0); - Screen sc0 = new Screen(0); // unused dummy element for spider chart center point + Screen sc0 = new Screen(0); // Unused dummy element for spider chart center point Screen sc100 = new Screen(100); Screen sc240 = new Screen(240); Screen sc320 = new Screen(320); @@ -86,7 +94,7 @@ public final class SpiderChartExample { // NO_UCD spiderChart.addAxis(brand); spiderChart.addAxis(screen); - DataSeries iPhoneData = new DataSeries("iPhone 6"); + DataSeries iPhoneData = new DataSeries("Phone 1"); iPhoneData.setPoint(battery, 4.0); iPhoneData.setPoint(camera, 3.5); iPhoneData.setPoint(display, 4.0); @@ -95,7 +103,7 @@ public final class SpiderChartExample { // NO_UCD iPhoneData.setPoint(screen, sc240); spiderChart.addData(iPhoneData); - DataSeries nexusData = new DataSeries("Nexus 6"); + DataSeries nexusData = new DataSeries("Phone 2"); nexusData.setPoint(battery, 3.0); nexusData.setPoint(camera, 4.5); nexusData.setPoint(display, 3.0); @@ -106,8 +114,9 @@ public final class SpiderChartExample { // NO_UCD ChartStyle chartStyle = new ChartStyle(true, true, true); chartStyle.setUseIndividualAxisSegments(false); - chartStyle.setTitleStyle(new FontStyle(VERDANA_14PT, getDarkerColor(BLUE))); - LegendStyle legendStyle = new LegendStyle(BLUE, false, 5, BLACK_VERDANA_12PT); + chartStyle.setTitleStyle(new FontStyle("Verdana", 14, BLUE.brighter())); + + LegendStyle legendStyle = new LegendStyle(false, 5, BLACK_VERDANA_12PT); chartStyle.setLegendStyle(legendStyle); AxisStyle aStyle3Segs = new AxisStyle(SOLID_BLACK_1PT, BLACK_VERDANA_14PT, 3, @@ -123,46 +132,26 @@ public final class SpiderChartExample { // NO_UCD chartStyle.setAxisStyle(brand, aStyle4Segs); chartStyle.setAxisStyle(screen, aStyle6Segs); chartStyle.setAxisSegments(4); - chartStyle.setBackgroundFillStyle(new FillStyle(LIGHT_GRAY)); - chartStyle.setBackgroundLineStyle(new LineStyle(DARK_GRAY)); - LineStyle olive1pt = new LineStyle(OLIVE); - FillStyle oliveFill = new FillStyle(OLIVE, 128); + chartStyle.setBackgroundFillStyle(new FillStyle(LIGHTGRAY)); + chartStyle.setBackgroundLineStyle(new LineStyle(DARKGRAY)); + + LineStyle olive1pt = new LineStyle(GREEN); + FillStyle oliveFill = new FillStyle(GREEN, 0.25); DataSeriesStyle iphoneStyle = new DataSeriesStyle(olive1pt, oliveFill, true, true, BLACK_VERDANA_10PT, 7, new DecimalFormat("#.#")); chartStyle.setDataSeriesStyle(iPhoneData, iphoneStyle); - LineStyle navy1pt = new LineStyle(NAVY); - FillStyle navyFill = new FillStyle(NAVY, 128); + LineStyle navy1pt = new LineStyle(RED); + FillStyle navyFill = new FillStyle(RED, 0.25); DataSeriesStyle nexusStyle = new DataSeriesStyle(navy1pt, navyFill, true, true, BLACK_VERDANA_10PT, 7, new DecimalFormat("#.#")); chartStyle.setDataSeriesStyle(nexusData, nexusStyle); - SpiderChartViewer viewer = new SpiderChartViewer(shell, spiderChart, chartStyle); - viewer.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); - Rectangle clientArea = shell.getClientArea(); - viewer.setBounds(clientArea.x, clientArea.y, clientArea.width, clientArea.height); + SpiderChartViewer viewer = new SpiderChartViewer(spiderChart, chartStyle); return viewer; } - /** Main method. */ - public static void main(final String[] args) { - final Display display = new Display(); - final Shell shell = new Shell(display, SWT.DIALOG_TRIM); - shell.setSize(800, 750); - - SpiderChartViewer viewer = buildSpiderChart(shell); - shell.open(); - - while(!shell.isDisposed()) { - if(!display.readAndDispatch()) { - display.sleep(); - } - } - viewer.dispose(); - display.dispose(); - } - /** Data class used to demonstrate enumeration data axes. */ private static class Screen implements Comparable<Screen> { /** Screen width in pixels. */ @@ -176,7 +165,7 @@ public final class SpiderChartExample { // NO_UCD /** {@inheritDoc} */ @Override public int compareTo(Screen o) { - return width - o.width; + return screenComparator.compare(this, o); } /** {@inheritDoc} */ @@ -187,11 +176,24 @@ public final class SpiderChartExample { // NO_UCD } /** {@link Comparator} implementation for {@link Screen}s . */ - private static Comparator<Screen> screenComparator = - new Comparator<SpiderChartExample.Screen>() { - @Override - public int compare(Screen o1, Screen o2) { - return o1.width - o2.width; - } - }; + private static Comparator<Screen> screenComparator = new Comparator<Screen>() { + @Override + public int compare(Screen o1, Screen o2) { + return o1.width - o2.width; + } + }; + + /** {@inheritDoc} */ + @Override + public String getFXMLLocation() { + return "SpiderChartExample.fxml"; + } + + /** {@inheritDoc} */ + @Override + public void initialize() { + Pane viewerPane = buildSpiderChart().getViewerPane(); + viewerPane.setPrefSize(500, 500); + anchorPane.getChildren().add(viewerPane); + } } diff --git a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ColorStyleBase.java b/org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExampleFXViewPart.java similarity index 69% rename from org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ColorStyleBase.java rename to org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExampleFXViewPart.java index b8e824b55490b30507b8d38acf10bc61daf1fa00..80a2c8751371a5b5e301549b1c96c5b2306f0b18 100644 --- a/org.fortiss.tooling.spiderchart.ui/src/org/fortiss/tooling/spiderchart/style/ColorStyleBase.java +++ b/org.fortiss.tooling.spiderchart.ui/test-src/test/org/fortiss/tooling/spiderchart/SpiderChartExampleFXViewPart.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2016 fortiss GmbH | +| Copyright 2020 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -13,26 +13,20 @@ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.spiderchart.style; +package test.org.fortiss.tooling.spiderchart; -import org.eclipse.swt.graphics.RGB; +import org.eclipse.fx.ui.workbench3.FXViewPart; +import org.fortiss.tooling.common.ui.javafx.AF3FXViewPart; /** - * Base class for styles with a single {@link RGB} color. + * {@link FXViewPart} for containing a {@link SpiderChartExampleFXController}. * - * @author hoelzl + * @author munaro */ -public abstract class ColorStyleBase { - /** The RGB color. */ - private final RGB rgbColor; +public class SpiderChartExampleFXViewPart extends AF3FXViewPart { /** Constructor. */ - public ColorStyleBase(RGB rgbColor) { - this.rgbColor = rgbColor; - } - - /** Returns the RGB color. */ - public final RGB getRGBColor() { - return rgbColor; + public SpiderChartExampleFXViewPart() throws Exception { + super(new SpiderChartExampleFXController(), null); } }