Commit 12967813 authored by Tiziano Munaro's avatar Tiziano Munaro

Fix line strokes and colors shift

Issue-Ref: 3452
Issue-Url: https://af3-developer.fortiss.org/issues/3452Signed-off-by: Tiziano Munaro's avatarTiziano Munaro <munaro@fortiss.org>
parent 82111f09
ColorStyleBase.java ca05f515764870da3d814f0ac38b32186f582132 YELLOW ColorStyleBase.java ca05f515764870da3d814f0ac38b32186f582132 YELLOW
FillStyle.java 523ca463b908d5075d32d3a66dc377d4583372b3 YELLOW FillStyle.java 198ea42987a2f02a07ed7d855b34a09e1deba28e YELLOW
FontStyle.java ab25b918bfee12eccbaad941b00adbc0bba29228 YELLOW FontStyle.java ab25b918bfee12eccbaad941b00adbc0bba29228 YELLOW
LineStyle.java 16084082302cbb9149e6a6f1f26503a982539e88 YELLOW LineStyle.java 65165ab9e4c8a913669251e16e2cfd3f0c8e5dc1 YELLOW
StrokeStyle.java 703b573d91c469f064e146b683e744eda6f3d8ed YELLOW StrokeStyle.java 703b573d91c469f064e146b683e744eda6f3d8ed YELLOW
...@@ -25,7 +25,7 @@ public final class FillStyle extends ColorStyleBase { ...@@ -25,7 +25,7 @@ public final class FillStyle extends ColorStyleBase {
/** Constructor */ /** Constructor */
public FillStyle(Color c, double alpha) { public FillStyle(Color c, double alpha) {
super(new Color(c.getRed(), c.getBlue(), c.getGreen(), alpha)); super(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha));
this.alpha = alpha; this.alpha = alpha;
} }
......
...@@ -51,6 +51,7 @@ public final class LineStyle extends ColorStyleBase { ...@@ -51,6 +51,7 @@ public final class LineStyle extends ColorStyleBase {
applyStyle(gc); applyStyle(gc);
gc.moveTo(x1, y1); gc.moveTo(x1, y1);
gc.lineTo(x2, y2); gc.lineTo(x2, y2);
gc.stroke();
gc.restore(); gc.restore();
} }
} }
SpiderChartCanvas.java fd348bdd520fbab08b4c910ec0b76fc6512ea408 YELLOW SpiderChartCanvas.java fd348bdd520fbab08b4c910ec0b76fc6512ea408 YELLOW
SpiderChartControl.java 15417ba85f751c306802ab1d64c5481071f0ad5b YELLOW SpiderChartControl.java 40459f05b754423a6017dcc1769ba85b6f5ede6a YELLOW
SpiderChartControlBase.java 12e98b77abfe0eeb6de22964b33bdfce056f157d YELLOW SpiderChartControlBase.java 12e98b77abfe0eeb6de22964b33bdfce056f157d YELLOW
SpiderChartLegendControl.java c2ef64fa4bbeb18cd02dc1a855532e241fd1ef69 YELLOW SpiderChartLegendControl.java 43e526425f2b2e19f1d9ea3de46cf0fd1ce9e261 YELLOW
SpiderChartTitleControl.java 64f026ea79a39c0e82d840e1920f1873a367e6ce YELLOW SpiderChartTitleControl.java 64f026ea79a39c0e82d840e1920f1873a367e6ce YELLOW
SpiderChartViewer.java 72f2db133eec606fd9e993fca3f6a0f03b6f528c YELLOW SpiderChartViewer.java 72f2db133eec606fd9e993fca3f6a0f03b6f528c YELLOW
...@@ -16,6 +16,7 @@ import java.util.HashMap; ...@@ -16,6 +16,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.AxisBase;
import org.fortiss.tooling.spiderchart.model.DataSeries; import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.DoubleAxis; import org.fortiss.tooling.spiderchart.model.DoubleAxis;
...@@ -24,7 +25,6 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart; ...@@ -24,7 +25,6 @@ import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.AxisStyle; import org.fortiss.tooling.spiderchart.style.AxisStyle;
import org.fortiss.tooling.spiderchart.style.ChartStyle; import org.fortiss.tooling.spiderchart.style.ChartStyle;
import org.fortiss.tooling.spiderchart.style.DataSeriesStyle; import org.fortiss.tooling.spiderchart.style.DataSeriesStyle;
import org.fortiss.tooling.common.ui.javafx.style.FontStyle;
import javafx.geometry.Dimension2D; import javafx.geometry.Dimension2D;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
...@@ -94,6 +94,7 @@ public final class SpiderChartControl extends SpiderChartControlBase { ...@@ -94,6 +94,7 @@ public final class SpiderChartControl extends SpiderChartControlBase {
/** Draws the background if style requires all axes to have equal number of segments. */ /** Draws the background if style requires all axes to have equal number of segments. */
private void drawBackground(GraphicsContext gc) { private void drawBackground(GraphicsContext gc) {
gc.save();
if(chart.getAxes().isEmpty()) { if(chart.getAxes().isEmpty()) {
return; return;
} }
...@@ -111,6 +112,7 @@ public final class SpiderChartControl extends SpiderChartControlBase { ...@@ -111,6 +112,7 @@ public final class SpiderChartControl extends SpiderChartControlBase {
gc.closePath(); gc.closePath();
style.getBackgroundFillStyle().applyStyle(gc); style.getBackgroundFillStyle().applyStyle(gc);
gc.fill(); gc.fill();
gc.restore();
} }
/** Draws the web lines of the background if all axes have equal number of segments. */ /** Draws the web lines of the background if all axes have equal number of segments. */
...@@ -125,6 +127,7 @@ public final class SpiderChartControl extends SpiderChartControlBase { ...@@ -125,6 +127,7 @@ public final class SpiderChartControl extends SpiderChartControlBase {
private void computeAndDrawPath(int i, GraphicsContext gc) { private void computeAndDrawPath(int i, GraphicsContext gc) {
double ratio = (double)i / (double)style.getAxisSegments(); double ratio = (double)i / (double)style.getAxisSegments();
boolean first = true; boolean first = true;
gc.save();
gc.beginPath(); gc.beginPath();
for(AxisBase axis : chart.getAxes()) { for(AxisBase axis : chart.getAxes()) {
Point2D outer = axesEnds.get(axis); Point2D outer = axesEnds.get(axis);
...@@ -140,12 +143,14 @@ public final class SpiderChartControl extends SpiderChartControlBase { ...@@ -140,12 +143,14 @@ public final class SpiderChartControl extends SpiderChartControlBase {
} }
} }
gc.closePath(); gc.closePath();
gc.restore();
} }
/** Draws the data series. */ /** Draws the data series. */
private void drawDataSeries(GraphicsContext gc, DataSeries data) { private void drawDataSeries(GraphicsContext gc, DataSeries data) {
DataSeriesStyle dStyle = style.getDataSeriesStyle(data); DataSeriesStyle dStyle = style.getDataSeriesStyle(data);
boolean first = true; boolean first = true;
gc.save();
gc.beginPath(); gc.beginPath();
for(AxisBase axis : chart.getAxes()) { for(AxisBase axis : chart.getAxes()) {
Point2D p = computeDataPoint(axis, data); Point2D p = computeDataPoint(axis, data);
...@@ -167,6 +172,7 @@ public final class SpiderChartControl extends SpiderChartControlBase { ...@@ -167,6 +172,7 @@ public final class SpiderChartControl extends SpiderChartControlBase {
gc.fill(); gc.fill();
dStyle.getLineStyle().applyStyle(gc); dStyle.getLineStyle().applyStyle(gc);
gc.stroke(); gc.stroke();
gc.restore();
} }
/** Draws the indicator labels next to the chart point. */ /** Draws the indicator labels next to the chart point. */
......
...@@ -10,18 +10,14 @@ ...@@ -10,18 +10,14 @@
*******************************************************************************/ *******************************************************************************/
package org.fortiss.tooling.spiderchart.control; package org.fortiss.tooling.spiderchart.control;
import java.util.HashMap; import org.fortiss.tooling.common.ui.javafx.style.FontStyle;
import java.util.Map; import org.fortiss.tooling.common.ui.javafx.style.LineStyle;
import org.fortiss.tooling.spiderchart.model.DataSeries; import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.SpiderChart; import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle; import org.fortiss.tooling.spiderchart.style.ChartStyle;
import org.fortiss.tooling.spiderchart.style.LegendStyle; import org.fortiss.tooling.spiderchart.style.LegendStyle;
import org.fortiss.tooling.common.ui.javafx.style.FontStyle;
import org.fortiss.tooling.common.ui.javafx.style.LineStyle;
import javafx.geometry.Dimension2D; import javafx.geometry.Dimension2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
/** Class used for drawing the the spider chart legend. */ /** Class used for drawing the the spider chart legend. */
...@@ -29,10 +25,7 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase { ...@@ -29,10 +25,7 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase {
/** The length of the line for each data series. */ /** The length of the line for each data series. */
private static final double LINE_SIZE = 20; private static final double LINE_SIZE = 20;
/** The space between line and text. */ /** The space between line and text. */
private static final double LINE_SPACE = 3; private static final double LINE_SPACE = 5;
/** Click areas of the legend entries. */
private final Map<DataSeries, Rectangle2D> clickAreas = new HashMap<>();
/** Constructor. */ /** Constructor. */
public SpiderChartLegendControl(SpiderChart chart, ChartStyle style) { public SpiderChartLegendControl(SpiderChart chart, ChartStyle style) {
...@@ -68,15 +61,12 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase { ...@@ -68,15 +61,12 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase {
LineStyle l = style.getDataSeriesStyle(data).getLineStyle(); LineStyle l = style.getDataSeriesStyle(data).getLineStyle();
double xl = getX() + xDelta; double xl = getX() + xDelta;
l.drawLine(gc, xl, y + extent.getHeight() / 2, xl + LINE_SIZE, l.drawLine(gc, xl, y - extent.getHeight() / 4, xl + LINE_SIZE,
y + extent.getHeight() / 2); y - extent.getHeight() / 4);
xDelta = xDelta + LINE_SIZE + LINE_SPACE; xDelta = xDelta + LINE_SIZE + LINE_SPACE;
double xs = getX() + xDelta; double xs = getX() + xDelta;
fontStyle.drawText(gc, text, xs, y); fontStyle.drawText(gc, text, xs, y);
xDelta = xDelta + extent.getWidth() + margin; xDelta = xDelta + extent.getWidth() + margin;
Rectangle2D clickArea = new Rectangle2D(xl, y, xDelta - xl, extent.getHeight());
clickAreas.put(data, clickArea);
} }
} }
...@@ -122,9 +112,6 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase { ...@@ -122,9 +112,6 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase {
style.getDataSeriesStyle(data).getIndicatorLabelStyle().drawText(gc, data.getName(), style.getDataSeriesStyle(data).getIndicatorLabelStyle().drawText(gc, data.getName(),
getX() + dX, getY() + dY); getX() + dX, getY() + dY);
cnt++; cnt++;
double totalWidth = margin + LINE_SIZE + textWidth;
Rectangle2D clickArea = new Rectangle2D(getX(), getY() + dY, totalWidth, textHeight);
clickAreas.put(data, clickArea);
} }
} }
...@@ -139,18 +126,4 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase { ...@@ -139,18 +126,4 @@ public final class SpiderChartLegendControl extends SpiderChartControlBase {
labelStyle.drawText(gc, labelText, x, getY() + margin); labelStyle.drawText(gc, labelText, x, getY() + margin);
return textExtent.getHeight() + margin; return textExtent.getHeight() + margin;
} }
/**
* Scans the legend entries for a hit at the given point and returns the corresponding
* {@link DataSeries}.
*/
public DataSeries legendEntryHitScan(double x, double y) {
for(DataSeries d : clickAreas.keySet()) {
Rectangle2D a = clickAreas.get(d);
if(a != null && a.contains(x, y)) {
return d;
}
}
return null;
}
} }
...@@ -19,7 +19,7 @@ import static javafx.scene.paint.Color.BLUE; ...@@ -19,7 +19,7 @@ import static javafx.scene.paint.Color.BLUE;
import static javafx.scene.paint.Color.DARKGRAY; import static javafx.scene.paint.Color.DARKGRAY;
import static javafx.scene.paint.Color.LIGHTGRAY; import static javafx.scene.paint.Color.LIGHTGRAY;
import static javafx.scene.paint.Color.NAVY; import static javafx.scene.paint.Color.NAVY;
import static javafx.scene.paint.Color.OLIVE; import static javafx.scene.paint.Color.YELLOW;
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_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_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_14PT;
...@@ -46,6 +46,7 @@ import org.fortiss.tooling.spiderchart.style.LegendStyle; ...@@ -46,6 +46,7 @@ import org.fortiss.tooling.spiderchart.style.LegendStyle;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
/** /**
...@@ -53,11 +54,14 @@ import javafx.scene.layout.Pane; ...@@ -53,11 +54,14 @@ import javafx.scene.layout.Pane;
* *
* @author hoelzl * @author hoelzl
*/ */
public final class SpiderChartExampleFXController extends CompositeFXControllerBase<Node, Node> { @SuppressWarnings("unchecked")
public class SpiderChartExampleFXController extends CompositeFXControllerBase<AnchorPane, Node> {
/** Pane containing the spider chart's canvas. */
@FXML @FXML
Pane pane; Pane pane;
/** Anchor pane on which the spider chart is drawn. */
@FXML @FXML
Pane anchorPane; Pane anchorPane;
...@@ -90,7 +94,7 @@ public final class SpiderChartExampleFXController extends CompositeFXControllerB ...@@ -90,7 +94,7 @@ public final class SpiderChartExampleFXController extends CompositeFXControllerB
spiderChart.addAxis(brand); spiderChart.addAxis(brand);
spiderChart.addAxis(screen); spiderChart.addAxis(screen);
DataSeries iPhoneData = new DataSeries("I phone 6"); DataSeries iPhoneData = new DataSeries("iPhone 6");
iPhoneData.setPoint(battery, 4.0); iPhoneData.setPoint(battery, 4.0);
iPhoneData.setPoint(camera, 3.5); iPhoneData.setPoint(camera, 3.5);
iPhoneData.setPoint(display, 4.0); iPhoneData.setPoint(display, 4.0);
...@@ -99,7 +103,7 @@ public final class SpiderChartExampleFXController extends CompositeFXControllerB ...@@ -99,7 +103,7 @@ public final class SpiderChartExampleFXController extends CompositeFXControllerB
iPhoneData.setPoint(screen, sc240); iPhoneData.setPoint(screen, sc240);
spiderChart.addData(iPhoneData); spiderChart.addData(iPhoneData);
DataSeries nexusData = new DataSeries("Nex US 6"); DataSeries nexusData = new DataSeries("Nexus 6");
nexusData.setPoint(battery, 3.0); nexusData.setPoint(battery, 3.0);
nexusData.setPoint(camera, 4.5); nexusData.setPoint(camera, 4.5);
nexusData.setPoint(display, 3.0); nexusData.setPoint(display, 3.0);
...@@ -132,14 +136,14 @@ public final class SpiderChartExampleFXController extends CompositeFXControllerB ...@@ -132,14 +136,14 @@ public final class SpiderChartExampleFXController extends CompositeFXControllerB
chartStyle.setBackgroundFillStyle(new FillStyle(LIGHTGRAY)); chartStyle.setBackgroundFillStyle(new FillStyle(LIGHTGRAY));
chartStyle.setBackgroundLineStyle(new LineStyle(DARKGRAY)); chartStyle.setBackgroundLineStyle(new LineStyle(DARKGRAY));
LineStyle olive1pt = new LineStyle(OLIVE); LineStyle olive1pt = new LineStyle(NAVY);
FillStyle oliveFill = new FillStyle(OLIVE, 0.5); FillStyle oliveFill = new FillStyle(NAVY, 0.25);
DataSeriesStyle iphoneStyle = new DataSeriesStyle(olive1pt, oliveFill, true, true, DataSeriesStyle iphoneStyle = new DataSeriesStyle(olive1pt, oliveFill, true, true,
BLACK_VERDANA_10PT, 7, new DecimalFormat("#.#")); BLACK_VERDANA_10PT, 7, new DecimalFormat("#.#"));
chartStyle.setDataSeriesStyle(iPhoneData, iphoneStyle); chartStyle.setDataSeriesStyle(iPhoneData, iphoneStyle);
LineStyle navy1pt = new LineStyle(NAVY); LineStyle navy1pt = new LineStyle(YELLOW);
FillStyle navyFill = new FillStyle(NAVY, 0.5); FillStyle navyFill = new FillStyle(YELLOW, 0.25);
DataSeriesStyle nexusStyle = new DataSeriesStyle(navy1pt, navyFill, true, true, DataSeriesStyle nexusStyle = new DataSeriesStyle(navy1pt, navyFill, true, true,
BLACK_VERDANA_10PT, 7, new DecimalFormat("#.#")); BLACK_VERDANA_10PT, 7, new DecimalFormat("#.#"));
chartStyle.setDataSeriesStyle(nexusData, nexusStyle); chartStyle.setDataSeriesStyle(nexusData, nexusStyle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment