Commit 166b735c authored by Alexander Diewald's avatar Alexander Diewald

Merge branch '3452' into 'master'

[3452] Migrate the spiderchart visualization

See merge request !119
parents 433d5623 31e870bf
......@@ -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,
......
ColorStyleBase.java e9af86785db1e20ba812494f05eebc64205437b9 GREEN
FillStyle.java 6acb49d026b93145b32522dcb05e6e5410ae590e GREEN
FontStyle.java be4253fb2f2186d01e2de3faf26477efb634e137 GREEN
LineStyle.java f83241e40e434267876a26cebc1c9a8b131512d2 GREEN
StrokeStyle.java c30b6e901dbc8b853be659cfd411905ddb76da3c GREEN
/*******************************************************************************
* 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;
}
}
/*******************************************************************************
* 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());
}
}
/*******************************************************************************
* 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;
}
}
/*******************************************************************************
* 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);
}
}
/*******************************************************************************
* 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);
}
}
......@@ -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>
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
<?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>
<?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" />
SpiderChartCanvas.java fcb6bf9c05b5e459de3282996f8d1fdc7dba919c GREEN
SpiderChartControl.java f8eab27397e782217754971ee7e54eab1931b82d GREEN
SpiderChartControlBase.java 83657aa8d923b6f8150b28a3f9f85d78b7435093 GREEN
SpiderChartLegendControl.java c77162dc8aa1233acc84ac042452755071b69076 GREEN
SpiderChartTitleControl.java ce3f7623c82e98e611de99fcc566c5363431f209 GREEN
SpiderChartViewer.java 9d697a5c19f93fe658bed5117ca4218ebc6660bc GREEN
/*******************************************************************************
* 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);
}
}
}
/*-------------------------------------------------------------------------+
| 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;
/*******************************************************************************
* 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.eclipse.swt.graphics.Rectangle;
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 mondal
* @author hoelzl
*/
public abstract class SpiderChartWidgetBase {
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 int height;
protected double height;
/** The width of the component. */
protected int width;
protected double width;
/** The x location. */
protected int x;
protected double x;
/** The y location. */
protected int y;
protected double y;
/** Constructor. */
public SpiderChartWidgetBase(SpiderChart chart, ChartStyle style) {
public SpiderChartControlBase(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) {
public void setBounds(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
......@@ -54,27 +48,27 @@ public abstract class SpiderChartWidgetBase {
}
/** Returns x. */
public final int getX() {
public final double getX() {
return x;
}
/** Returns y. */
public final int getY() {
public final double getY() {
return y;
}
/** Returns width. */
public final int getWidth() {
public final double getWidth() {
return width;
}
/** Returns height. */
public final int getHeight() {
public final double getHeight() {
return height;
}
/** Returns the bounding rectangle. */
public final Rectangle getBounds() {
return new Rectangle(x, y, width, height);
public final Rectangle2D getBounds() {
return new Rectangle2D(x, y, width, height);
}
}
/*******************************************************************************
* 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 {