Skip to content
Snippets Groups Projects
Commit 71b139ad authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Rework of spider chart except drawing of data series is completed.

refs 2589
parent 190c454a
No related branches found
No related tags found
No related merge requests found
Showing
with 797 additions and 2926 deletions
......@@ -8,20 +8,15 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Developer: Amit Kumar Mondal (admin@amitinside.com)
Github-Project-Url: https://github.com/amitjoy/Spider-Chart-SWT.git
Export-Package: org.fortiss.tooling.spiderchart,
org.fortiss.tooling.spiderchart.builder,
org.fortiss.tooling.spiderchart.builder.model,
org.fortiss.tooling.spiderchart.gc,
org.fortiss.tooling.spiderchart.gc.swt,
org.fortiss.tooling.spiderchart.label,
org.fortiss.tooling.spiderchart.label.api,
org.fortiss.tooling.spiderchart.listener,
org.fortiss.tooling.spiderchart.model,
org.fortiss.tooling.spiderchart.plotter,
org.fortiss.tooling.spiderchart.scale,
org.fortiss.tooling.spiderchart.sequence,
org.fortiss.tooling.spiderchart.style,
org.fortiss.tooling.spiderchart.swt,
org.fortiss.tooling.spiderchart.util
org.fortiss.tooling.spiderchart.util,
org.fortiss.tooling.spiderchart.widget
Require-Bundle: org.eclipse.swt;bundle-version="3.102.1",
org.fortiss.tooling.base;bundle-version="2.9.0"
Bundle-ActivationPolicy: lazy
......@@ -15,24 +15,18 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.builder;
package org.fortiss.tooling.spiderchart;
import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.spiderchart.style.FillStyle.GRADIENT_VERTICAL;
import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.WHITE;
import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.YELLOW;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.spiderchart.SpiderChartOld;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartLegend;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlotter;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartTitle;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
import org.fortiss.tooling.spiderchart.style.FillStyle;
import org.fortiss.tooling.spiderchart.swt.SpiderChartViewer;
import org.fortiss.tooling.spiderchart.widget.SpiderChartLegendWidget;
import org.fortiss.tooling.spiderchart.widget.SpiderChartTitleWidget;
import org.fortiss.tooling.spiderchart.widget.SpiderChartViewer;
import org.fortiss.tooling.spiderchart.widget.SpiderChartWidget;
/**
* Used to build the complete spider chart
......@@ -44,47 +38,38 @@ import org.fortiss.tooling.spiderchart.swt.SpiderChartViewer;
*/
public final class SpiderChartBuilder {
/** The Legend */
private SpiderChartLegend legend;
private SpiderChartLegendWidget legend;
/** The plotter */
private SpiderChartPlotter plotter;
private SpiderChartWidget plotter;
/** The title */
private SpiderChartTitle title;
private SpiderChartTitleWidget title;
private SpiderChart chart;
private ChartStyle style;
/** Prepares the legend */
public SpiderChartBuilder(SpiderChart chart, ChartStyle style, SpiderChartTitle title,
SpiderChartLegend legend, SpiderChartPlotter plotter) {
public SpiderChartBuilder(SpiderChart chart, ChartStyle style, SpiderChartTitleWidget title,
SpiderChartLegendWidget legend, SpiderChartWidget plotter) {
this.chart = requireNonNull(chart);
this.title = requireNonNull(title);
this.legend = legend;
this.style = style;
this.style = requireNonNull(style);
this.plotter = requireNonNull(plotter);
}
/** Builds the viewer */
// FIXME: make viewer instantiation in SCViewer class directly
public SpiderChartViewer createViewer(Composite parent) {
requireNonNull(parent);
// Some chart related default configurations
SpiderChartOld chartOld = new SpiderChartOld(chart, style, title, plotter);
chartOld.setBackStyle(new FillStyle(YELLOW));
chartOld.setBackgroundCanvasColor(WHITE);
chartOld.getBackStyle().setGradientType(GRADIENT_VERTICAL);
chartOld.setLegend(legend);
chartOld.setActivateSelection(true);
SpiderChartViewer chartViewer = new SpiderChartViewer(parent, SWT.NONE);
SpiderChartViewer chartViewer = new SpiderChartViewer(parent, chart, style);
chartViewer.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
chartViewer.setBounds(parent.getShell().getClientArea().x, parent.getShell()
.getClientArea().y, parent.getShell().getClientArea().width, parent.getShell()
.getClientArea().height - 10);
chartViewer.setChart(chartOld);
chartOld.setBounds(chartViewer.getBounds());
chartOld.layoutChartComponents();
return chartViewer;
}
......
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.builder;
import static org.fortiss.tooling.spiderchart.util.ChartUtil.toDoublePrimitiveArray;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Used to configure the axes for the spider chart diagram
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class AxesConfigurer {
/**
* Builder class to prepare axis
*
* @author AMIT
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public static class Builder {
/** Maximum Scales */
private final List<Double> maxScales;
/** Minimum Scales */
private final List<Double> minScales;
/** Scaling Labels */
private final List<String> scalesNames;
/** Scaling Label Formats */
private final List<Object> scalingLabelFormats;
/** Constructor */
public Builder() {
this.maxScales = new ArrayList<>();
this.minScales = new ArrayList<>();
this.scalesNames = new ArrayList<>();
this.scalingLabelFormats = new ArrayList<>();
}
/**
* Adds a new Axis to the Spider Chart
*
* @param name
* Name of the axis
* @param value
* Currently only Enum class object needs to be provided to
* use its constants as labels
* @return the Builder object for method chaining
*/
public <E extends Enum<E>> Builder addAxis(final String name, final Class<E> value) {
final double[] doubleValues = new double[value.getEnumConstants().length];
int i = 0;
for(final Enum<E> enumVal : value.getEnumConstants()) {
doubleValues[i++] = enumVal.ordinal();
}
Arrays.sort(doubleValues);
this.maxScales.add(doubleValues[doubleValues.length - 1] + 1);
this.minScales.add(doubleValues[0]);
this.scalesNames.add(name);
this.scalingLabelFormats.add(value);
return this;
}
/**
* Adds a new Axis to the Spider Chart
*
* @param name
* name of the axis
* @param maxScale
* maximum scale of axis
* @param minScale
* minimum scale of axis
* @return the Builder object for method chaining
*/
public Builder addAxis(final String name, final double maxScale, final double minScale) {
this.maxScales.add(maxScale);
this.minScales.add(minScale);
this.scalesNames.add(name);
this.scalingLabelFormats.add("#.#");
return this;
}
/**
* Adds a new Axis to the Spider Chart
*
* @param name
* name of the axis
* @param maxScale
* maximum scale of axis
* @param minScale
* minimum scale of axis
* @param scalingLabelFormat
* the scaling label format
* @return the Builder object for method chaining
*/
public Builder addAxis(final String name, final double maxScale, final double minScale,
final Object scalingLabelFormat) {
this.scalingLabelFormats.add(scalingLabelFormat);
this.maxScales.add(maxScale);
this.minScales.add(minScale);
this.scalesNames.add(name);
return this;
}
/** Builder */
public AxesConfigurer build() {
return new AxesConfigurer(this.maxScales, this.minScales, this.scalesNames,
this.scalingLabelFormats);
}
}
/** */
private final List<Double> maxScales;
/** */
private final List<Double> minScales;
/** */
private final List<String> scalesNames;
/** */
private final List<Object> scalingLabelFormats;
/** Constructor */
private AxesConfigurer(final List<Double> maxScales, final List<Double> minScales,
final List<String> scalesNames, final List<Object> scalingLabelFormats) {
super();
this.maxScales = maxScales;
this.minScales = minScales;
this.scalesNames = scalesNames;
this.scalingLabelFormats = scalingLabelFormats;
}
/** getter for the axes names */
public String[] axesNames() {
final String[] axesNames = new String[this.scalesNames.size()];
return this.scalesNames.toArray(axesNames);
}
/** getter for the scaling label formats */
public Object[] axesScalingLabelFormats() {
return this.scalingLabelFormats.toArray();
}
/** getter for the max scales */
public double[] maxScales() {
final Double[] maxScales = new Double[this.maxScales.size()];
return toDoublePrimitiveArray(this.maxScales.toArray(maxScales));
}
/** getter for min scales */
public double[] minScales() {
final Double[] minScales = new Double[this.minScales.size()];
return toDoublePrimitiveArray(this.minScales.toArray(minScales));
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.builder.model;
import static org.fortiss.tooling.spiderchart.gc.Fonts.VERDANA;
import static org.fortiss.tooling.spiderchart.style.LineStyle.NORMAL_LINE;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlot;
import org.fortiss.tooling.spiderchart.sequence.LineDataSequence;
import org.fortiss.tooling.spiderchart.style.FillStyle;
import org.fortiss.tooling.spiderchart.style.LineStyle;
/**
* Axis Pojo
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class AxisData {
/** Line Sequence to be used for the axis */
private final LineDataSequence data;
/** getter for the axis sequence */
public LineDataSequence getData() {
return data;
}
/** Constructor. */
public AxisData(SpiderChartPlot plot) {
this.data =
new LineDataSequence(plot.dataPoints(), new LineStyle(plot.areaColor(), 2,
NORMAL_LINE));
this.data.setDrawPoint(true);
this.data.setValueFontData(new FontData(VERDANA.getFontName(), SWT.BOLD, 12));
this.data.setFillStyle(new FillStyle(plot.areaColor(), 0.5f));
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.example;
import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.OLIVE;
import org.eclipse.swt.graphics.RGB;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlot;
/**
* IPhone test class.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public final class IPhone implements SpiderChartPlot {
/** {@inheritDoc} */
@Override
public double[] dataPoints() {
final double[] data = {4, 3.5, 4, 4.6, 5};
return data;
}
/** {@inheritDoc} */
@Override
public RGB areaColor() {
return OLIVE;
}
/** {@inheritDoc} */
@Override
public String name() {
return "iPhone 6";
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.example;
import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.NAVY;
import org.eclipse.swt.graphics.RGB;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlot;
@SuppressWarnings("javadoc")
public final class Nexus implements SpiderChartPlot {
/** {@inheritDoc} */
@Override
public double[] dataPoints() {
final double[] data = {4, 3, 3, 4.1, 3};
return data;
}
/** {@inheritDoc} */
@Override
public RGB areaColor() {
return NAVY;
}
/** {@inheritDoc} */
@Override
public String name() {
return "Nexus 6";
}
}
......@@ -29,22 +29,20 @@ import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.OLIVE;
import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.getDarkerColor;
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.spiderchart.builder.SpiderChartBuilder;
import org.fortiss.tooling.spiderchart.model.Axis;
import org.fortiss.tooling.spiderchart.model.DataSeries;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartLegend;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlotter;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartTitle;
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.FontStyle;
import org.fortiss.tooling.spiderchart.style.LegendStyle;
import org.fortiss.tooling.spiderchart.style.LineStyle;
import org.fortiss.tooling.spiderchart.swt.SpiderChartViewer;
import org.fortiss.tooling.spiderchart.widget.SpiderChartViewer;
/**
* Example application for the spider chart widget.
......@@ -123,14 +121,10 @@ public final class Sample {
chartStyle.setDataSeriesStyle(iPhoneData, iphoneStyle);
chartStyle.setDataSeriesStyle(nexusData, nexusStyle);
SpiderChartLegend legend = new SpiderChartLegend(spiderChart, chartStyle);
SpiderChartTitle title = new SpiderChartTitle(spiderChart, chartStyle);
SpiderChartPlotter plotter = new SpiderChartPlotter(spiderChart, chartStyle);
SpiderChartBuilder scBuilder =
new SpiderChartBuilder(spiderChart, chartStyle, title, legend, plotter);
viewer = scBuilder.createViewer(shell);
viewer.getChart().addSeq(iPhoneData);
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);
// Updating the chart with new parameters
// Display.getDefault().asyncExec(() -> {
......@@ -171,9 +165,7 @@ public final class Sample {
display.sleep();
}
}
viewer.getChart().dispose();
viewer.dispose();
display.dispose();
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.listener;
import org.fortiss.tooling.spiderchart.SpiderChartOld;
import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics;
/**
* Spider Chart Listener Events
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public interface ISpiderChartListener {
/** To be fired on clicking on chart canvas */
public static final int EVENT_CHART_CLICKED = 6;
/** To be fired on selecting data point */
public static final int EVENT_ENTER_POINT = 2;
/** To be fired on leaving data point */
public static final int EVENT_LEAVE_POINT = 3;
/** To be fired on clicking on data point */
public static final int EVENT_POINT_CLICKED = 5;
/** To be fired on tip shell update */
public static final int EVENT_TIP_UPDATE = 4;
/** */
public abstract void onChartEvent(SpiderChartOld paramChart, int paramInt);
/** */
public abstract void onPaintUserExit(SpiderChartOld paramChart,
SpiderChartSwtGraphics paramChartGraphics);
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.plotter;
import org.eclipse.swt.graphics.RGB;
/**
* Interface for Spider Chart Data
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public interface SpiderChartPlot {
/**
* Spider Chart Area Color
*
* @return SWT color constant of the color
*/
public RGB areaColor();
/**
* Spider Chart Legend Text
*
* @return name name of the legend to be used
*/
public String name();
public double[] dataPoints();
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.sequence;
import static java.text.NumberFormat.getNumberInstance;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.fortiss.tooling.spiderchart.SpiderChartOld;
/**
* Class representing sequence of points to be used for plotting
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public abstract class DataSequence {
/** Data Point Labels */
private String[] dataLabels;
/** Areas to be used for finding the points in the chart */
private List<Object> hotAreas = new ArrayList<>();
/** Label Template */
private String labelTemplate = "";
/** Descriptive Name for the Data Sequence */
private String name = "";
/** Tips to be used on the Data Sequence */
private String[] tips = new String[0];
/** Values to be formatted for the Data Sequence */
private String valueFormat = "######.##";
/** x-axis data points */
private List<Double> xData = new ArrayList<>();
/** y-axis data points */
private List<Double> yData = new ArrayList<>();
/**
* Constructor
*/
public DataSequence() {
}
/** Constructor */
public DataSequence(final double[] y) {
if(y == null) {
return;
}
for(int i = 0; i < y.length; i++) {
this.addData(new Double(i), new Double(y[i]));
}
}
/** Constructor */
public DataSequence(final double[] x, final double[] y) {
for(int i = 0; i < x.length; i++) {
this.addData(new Double(x[i]), new Double(y[i]));
}
}
/** Constructor */
public DataSequence(final double[] y, final int startingXValue) {
for(int i = 0; i < y.length; i++) {
this.addData(new Double(startingXValue + i), new Double(y[i]));
}
}
/** Constructor */
public DataSequence(final Double[] y) {
if(y == null) {
return;
}
for(int i = 0; i < y.length; i++) {
this.addData(new Double(i), y[i]);
}
}
/** Constructor */
public DataSequence(final Double[] x, final Double[] y) {
for(int i = 0; i < x.length; i++) {
this.addData(x[i], y[i]);
}
}
/** Constructor */
public DataSequence(final Double[] y, final int startingXValue) {
for(int i = 0; i < y.length; i++) {
this.addData(new Double(startingXValue + i), y[i]);
}
}
/** Constructor */
public void addData(final Object x, final Object y) {
this.xData.add((Double)x);
this.yData.add((Double)y);
}
/** Converts double values to string conforming to the provided template */
public String doubleToString(final Double d) {
if(this.valueFormat.compareTo("") == 0) {
return d.toString();
}
DecimalFormat df = null;
if(SpiderChartOld.getNumberLocale() == null) {
df = new DecimalFormat(this.valueFormat);
} else {
final NumberFormat nf =
getNumberInstance(new Locale(SpiderChartOld.getNumberLocale(), ""));
df = (DecimalFormat)nf;
df.applyPattern(this.valueFormat);
}
df = new DecimalFormat(this.valueFormat);
return df.format(d.doubleValue());
}
/** Returns the Data Point labels */
public String[] getDataLabels() {
return this.dataLabels;
}
/** Get element at X as provided */
public Object getElementX(final int i) {
return this.xData.get(i);
}
/** Get element at Y as provided */
public Object getElementY(final int i) {
return this.yData.get(i);
}
/** Getter for the hot areas */
public List<Object> getHotAreas() {
return this.hotAreas;
}
/** Getter for the Label Template */
public String getLabelTemplate() {
return this.labelTemplate;
}
/** Getter for the descriptive name */
public String getName() {
return this.name;
}
/** Getter for the size */
public int getSize() {
return this.xData.size();
}
/** Getter for the tips */
public String[] getTips() {
return this.tips;
}
/** Getter for the value label format */
public String getValueFormat() {
return this.valueFormat;
}
/** Getter for the x data */
public List<Double> getxData() {
return this.xData;
}
/** Getter for the y Data */
public List<Double> getyData() {
return this.yData;
}
/** Setter for data labels */
public void setDataLabels(final String[] dataLabels) {
this.dataLabels = dataLabels;
}
/** Setter for hot areas */
public void setHotAreas(final List<Object> hotAreas) {
this.hotAreas = hotAreas;
}
/** Setter for label template */
public void setLabelTemplate(final String labelTemplate) {
this.labelTemplate = labelTemplate;
}
/** Setter for the descriptive name */
public void setName(final String name) {
this.name = name;
}
/** Setter for the tips */
public void setTips(final String[] tips) {
this.tips = tips;
}
/** Setter for the value label format */
public void setValueFormat(final String valueFormat) {
this.valueFormat = valueFormat;
}
/** Setter for the x data */
public void setxData(final List<Double> xData) {
this.xData = xData;
}
/** Setter for the y Data */
public void setyData(final List<Double> yData) {
this.yData = yData;
}
/** Disposes this data object's resources. */
public void dispose() {
// nothing to do
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.sequence;
import static org.fortiss.tooling.spiderchart.gc.Fonts.VERDANA;
import static org.fortiss.tooling.spiderchart.style.LineStyle.NORMAL_LINE;
import static org.fortiss.tooling.spiderchart.util.ChartUtil.wrapValues;
import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.BLACK;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.fortiss.tooling.base.model.visualization.DataPoint;
import org.fortiss.tooling.base.model.visualization.DataSet;
import org.fortiss.tooling.spiderchart.gc.AbstractChartImage;
import org.fortiss.tooling.spiderchart.plotter.SpiderChartPlot;
import org.fortiss.tooling.spiderchart.style.FillStyle;
import org.fortiss.tooling.spiderchart.style.LineStyle;
/**
* Represents spider chart data sequence of points for plotting
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class LineDataSequence extends DataSequence {
/** */
private static final int STARTING_X_VALUE = 0;
/**
* Static Factory to create instance of {@link LineDataSequence}
*/
public static LineDataSequence of(final LineStyle style, final double... values) {
return new LineDataSequence(values, style);
}
/**
* Static Factory to create instance of {@link LineDataSequence}
*/
public static <E extends Enum<E>> LineDataSequence of(SpiderChartPlot oldObjectToCopyData,
final Object... values) {
final double[] wrappedValues = wrapValues(values);
final LineDataSequence seq =
new LineDataSequence(wrappedValues, new LineStyle(oldObjectToCopyData.areaColor(),
2, NORMAL_LINE));
seq.valueFont = new FontData(VERDANA.getFontName(), SWT.BOLD, 12);
seq.fillStyle = new FillStyle(oldObjectToCopyData.areaColor(), 0.5f);
seq.drawPoint = true;
return seq;
}
/**
* Static Factory to create instance of {@link LineDataSequence}
*/
public static <E extends Enum<E>> LineDataSequence of(RGB swtColor, final Object... values) {
final double[] wrappedValues = wrapValues(values);
final LineDataSequence seq =
new LineDataSequence(wrappedValues, new LineStyle(swtColor, 2, NORMAL_LINE));
seq.valueFont = new FontData(VERDANA.getFontName(), SWT.BOLD, 12);
seq.fillStyle = new FillStyle(swtColor, 0.5f);
seq.drawPoint = true;
return seq;
}
/**
* Static Factory to create instance of {@link LineDataSequence}
*/
public static <E extends Enum<E>> LineDataSequence of(RGB swtColor, final DataSet dataSet) {
List<DataPoint<?>> datapoints = dataSet.getPoints();
List<Object> values =
datapoints.stream().map(datapoint -> datapoint.getStart())
.collect(Collectors.toList());
final double[] wrappedValues = wrapValues(values.toArray());
final LineDataSequence seq =
new LineDataSequence(wrappedValues, new LineStyle(swtColor, 2, NORMAL_LINE));
seq.valueFont = new FontData(VERDANA.getFontName(), SWT.BOLD, 12);
seq.fillStyle = new FillStyle(swtColor, 0.5f);
seq.drawPoint = true;
return seq;
}
/** Draw Point Configuration */
private boolean drawPoint = false;
/** Fillstyle to be used */
private FillStyle fillStyle = null;
/** Icon to be used */
private AbstractChartImage icon = null;
/** Line Type */
private int lineType = 0;
/** Data Point Color */
private RGB swtPointColor = BLACK;
/** Line Style */
private LineStyle style = null;
/** value Color */
private RGB swtValueColor = BLACK;
/** value font */
private FontData valueFont = null;
/** */
private LineStyle vstyle = null;
/** Constructor */
public LineDataSequence(final double[] x, final double[] y, final LineStyle s) {
super(x, y);
this.style = s;
}
/** Constructor */
public LineDataSequence(final double[] y, final LineStyle s) {
super(y, STARTING_X_VALUE);
this.style = s;
}
/** Constructor */
public LineDataSequence(final Double[] x, final Double[] y, final LineStyle s) {
super(x, y);
this.style = s;
}
/** Constructor */
public LineDataSequence(final Double[] y, final LineStyle s) {
super(y, STARTING_X_VALUE);
this.style = s;
}
/** Constructor */
public LineDataSequence(final LineStyle s) {
this.style = s;
}
/**
* @return the fillStyle
*/
public FillStyle getFillStyle() {
return this.fillStyle;
}
/**
* @return the icon
*/
public AbstractChartImage getIcon() {
return this.icon;
}
/**
* @return the lineType
*/
public int getLineType() {
return this.lineType;
}
/**
* @return the pointColor
*/
public RGB getPointColor() {
return swtPointColor;
}
/**
* @return the style
*/
public LineStyle getStyle() {
return this.style;
}
/**
* @return the valueColor
*/
public RGB getValueColor() {
return swtValueColor;
}
/**
* @return the valueFont
*/
public FontData getValueFontData() {
return this.valueFont;
}
/**
* @return the vstyle
*/
public LineStyle getVstyle() {
return this.vstyle;
}
/**
* @return the drawPoint
*/
public boolean isDrawPoint() {
return this.drawPoint;
}
/**
* @param drawPoint
* the drawPoint to set
*/
public void setDrawPoint(final boolean drawPoint) {
this.drawPoint = drawPoint;
}
/**
* @param fillStyle
* the fillStyle to set
*/
public void setFillStyle(final FillStyle fillStyle) {
this.fillStyle = fillStyle;
}
/**
* @param icon
* the icon to set
*/
public void setIcon(final AbstractChartImage icon) {
this.icon = icon;
}
/**
* @param lineType
* the lineType to set
*/
public void setLineType(final int lineType) {
this.lineType = lineType;
}
/**
* @param pointColor
* the pointColor to set
*/
public void setPointColor(RGB pointColor) {
this.swtPointColor = pointColor;
}
/**
* @param style
* the style to set
*/
public void setStyle(final LineStyle style) {
this.style = style;
}
/**
* @param valueColor
* the valueColor to set
*/
public void setValueColor(RGB valueColor) {
this.swtValueColor = valueColor;
}
/**
* @param valueFont
* the valueFont to set
*/
public void setValueFontData(FontData valueFont) {
this.valueFont = valueFont;
}
/**
* @param vstyle
* the vstyle to set
*/
public void setVstyle(final LineStyle vstyle) {
this.vstyle = vstyle;
}
/** {@inheritDoc} */
@Override
public void dispose() {
if(icon != null) {
icon.dispose();
}
}
}
......@@ -46,6 +46,11 @@ public final class ChartStyle {
private boolean showLegend = true;
/** The style for the legend. */
private LegendStyle legendStyle;
/** The relative chart margin. The default is 10%. */
private double relativeMargin = 0.1;
/** The start angle of the first axis (default is 90 degree). */
private double startAngleDegree = 90.0;
/**
* The flag for using individual segments on each axis. No background spider web will be drawn
* if this is <code>true</code>.
......@@ -64,6 +69,29 @@ public final class ChartStyle {
this.useIndividualAxisSegments = useIndividualAxisSegments;
}
/** Returns the start angle in degree. */
public double getStartAngleDegree() {
return startAngleDegree;
}
/** Sets the start angle in degree. */
public void setStartAngleDegree(double startAngleDegree) {
this.startAngleDegree = startAngleDegree;
}
/**
* Sets the relative margin of the chart area. Specify <code>0.1</code> for a margin of 10
* percent.
*/
public void setRelativeMargin(double relativeMargin) {
this.relativeMargin = relativeMargin;
}
/** Returns the relative margin. */
public double getRelativeMargin() {
return relativeMargin;
}
/** Returns whether to show the title. */
public boolean isShowTitle() {
return showTitle;
......
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.swt;
import static org.eclipse.swt.SWT.CURSOR_ARROW;
import static org.eclipse.swt.SWT.CURSOR_HAND;
import static org.eclipse.swt.SWT.NONE;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.spiderchart.SpiderChartOld;
import org.fortiss.tooling.spiderchart.listener.SpiderChartAdapter;
/**
* Represents a viewer on the canvas to display the chart
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartViewer extends Composite {
/** the actual canvas to be used */
private SpiderChartCanvas canvas = null;
/** allows to change pointer on hovering data points */
private boolean changePointer = true;
/** Default Chart Listeners for hovering behaviors */
private final SpiderChartAdapter chartAdapter = new SpiderChartAdapter() {
/** {@inheritDoc} */
@Override
public void onChartEvent(final SpiderChartOld c, final int type) {
if(type == 2) {
SpiderChartViewer.this.canvas.setCursor(SpiderChartViewer.this.pointCursor);
}
if(type == 3) {
SpiderChartViewer.this.canvas.setCursor(SpiderChartViewer.this.defaultCursor);
}
}
};
/** Active Zoom Percentage */
private int currentZoom = 100;
/** Default cursor object */
private Cursor defaultCursor = null;
/** height of the canvas (used to restore from zoom) */
private int lastHeight = 0;
/** width of the canvas (used to restore from zoom) */
private int lastWidth = 0;
/** Actual height of the canvas */
private int originalHeight = -1;
/** Actual width of the canvas */
private int originalWidth = -1;
/** Cursor object in use */
private Cursor pointCursor = null;
/** Constructor */
public SpiderChartViewer(Composite parent, final int style) {
super(parent, style);
canvas = new SpiderChartCanvas(this, NONE);
canvas.setFocus();
this.addControlListener(new ControlListener() {
/** {@inheritDoc} */
@Override
public void controlMoved(ControlEvent e) {
// Not used
}
/** {@inheritDoc} */
@Override
public void controlResized(ControlEvent e) {
if(SpiderChartViewer.this.canvas.getChart() == null) {
return;
}
setCanvasSize();
}
});
this.defaultCursor = new Cursor(parent.getDisplay(), CURSOR_ARROW);
this.pointCursor = new Cursor(parent.getDisplay(), CURSOR_HAND);
}
/** {@inheritDoc} */
@Override
public void dispose() {
super.dispose();
if(this.pointCursor != null && !this.pointCursor.isDisposed()) {
this.pointCursor.dispose();
}
if(this.defaultCursor != null && !this.defaultCursor.isDisposed()) {
this.defaultCursor.dispose();
}
}
/** getter for the canvas in use */
public SpiderChartCanvas getCanvas() {
return this.canvas;
}
/** getter for the chart in use */
public SpiderChartOld getChart() {
return this.canvas.getChart();
}
/** getter for the chart listener in use */
public SpiderChartAdapter getChartAdapter() {
return this.chartAdapter;
}
/** getter for the current zoom percentage */
public int getCurrentZoom() {
return this.currentZoom;
}
/** getter for the default cursor */
public Cursor getDefaultCursor() {
return this.defaultCursor;
}
/** getter for height after zoom */
public int getLastHeight() {
return this.lastHeight;
}
/** getter for width after zoom */
public int getLastWidth() {
return this.lastWidth;
}
/** getter for original canvas height */
public int getOriginalHeight() {
return this.originalHeight;
}
/** getter for original canvas width */
public int getOriginalWidth() {
return this.originalWidth;
}
/** getter for cursor in use */
public Cursor getPointCursor() {
return this.pointCursor;
}
/**
* getter for configuration of changing pointer on data point mouse hover
*/
public boolean isChangePointer() {
return this.changePointer;
}
/** Redraws the chart */
public void redrawChart() {
this.canvas.redraw();
}
/** Resets the chart */
private void resetChart() {
this.lastWidth = 0;
this.lastHeight = 0;
}
/** setter for chart canvas */
public void setCanvas(final SpiderChartCanvas canvas) {
this.canvas = canvas;
}
/** setter for changing pointer */
public void setChangePointer(final boolean changePointer) {
this.changePointer = changePointer;
}
/** setter for chart instance */
public void setChart(final SpiderChartOld c) {
if(this.canvas.getChart() != null) {
this.canvas.getChart().removeChartListener(this.chartAdapter);
}
this.canvas.setChart(c);
this.originalHeight = this.canvas.getChart().getHeight();
this.originalWidth = this.canvas.getChart().getWidth();
this.resetChart();
setCanvasSize();
if(this.changePointer) {
this.canvas.getChart().addChartListener(this.chartAdapter);
}
}
/**
*
*/
private void setCanvasSize() {
this.canvas.setSize(this.getSize().x, this.getSize().y);
this.canvas.setLocation(0, 0);
}
/** setter for current zoom percentage */
public void setCurrentZoom(final int currentZoom) {
this.currentZoom = currentZoom;
}
/** setter for default cursor */
public void setDefaultCursor(final Cursor defaultCursor) {
this.defaultCursor = defaultCursor;
}
/** setter for last height after zoom */
public void setLastHeight(final int lastHeight) {
this.lastHeight = lastHeight;
}
/** setter for last width after zoom */
public void setLastWidth(final int lastWidth) {
this.lastWidth = lastWidth;
}
/** setter for original height of the canvas */
public void setOriginalHeight(final int originalHeight) {
this.originalHeight = originalHeight;
}
/** setter for original width of the canvas */
public void setOriginalWidth(final int originalWidth) {
this.originalWidth = originalWidth;
}
/** setter for the cursor instance in use */
public void setPointCursor(final Cursor pointCursor) {
this.pointCursor = pointCursor;
}
}
......@@ -15,7 +15,7 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.plotter;
package org.fortiss.tooling.spiderchart.widget;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
......@@ -38,7 +38,7 @@ import org.fortiss.tooling.spiderchart.style.LineStyle;
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartLegend extends SpiderChartComponentBase {
public final class SpiderChartLegendWidget extends SpiderChartWidgetBase {
/** The size of the color icon of data series. */
private static final int ICON_SIZE = 10;
......@@ -46,7 +46,7 @@ public final class SpiderChartLegend extends SpiderChartComponentBase {
private static final int ICON_SPACE = 3;
/** Constructor. */
public SpiderChartLegend(SpiderChart chart, ChartStyle style) {
public SpiderChartLegendWidget(SpiderChart chart, ChartStyle style) {
super(chart, style);
}
......
......@@ -15,23 +15,20 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.swt;
import static org.eclipse.swt.SWT.CTRL;
import static org.fortiss.tooling.spiderchart.gc.AbstractGraphicsSupplier.getGraphics;
import static org.fortiss.tooling.spiderchart.gc.AbstractGraphicsSupplier.startUiThread;
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.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
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.spiderchart.SpiderChartOld;
import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics;
import org.fortiss.tooling.spiderchart.listener.ISpiderChartListener;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
/**
* Represents a canvas on which chart will be displayed
......@@ -41,107 +38,115 @@ import org.fortiss.tooling.spiderchart.listener.ISpiderChartListener;
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartCanvas extends Canvas implements ISpiderChartListener {
/** Actual Spider Chart Ref */
private SpiderChartOld chart = null;
public final class SpiderChartSWTCanvas extends Canvas {
/** The chart data. */
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 SpiderChartCanvas(final Composite parent, final int style) {
super(parent, style | CTRL);
this.addPaintListener(e -> SpiderChartCanvas.this.paintChart(e));
final MouseMoveListener mouseMove = e -> SpiderChartCanvas.this.mouseMoved(e);
this.addMouseMoveListener(mouseMove);
final MouseAdapter mouseAdapter = new MouseAdapter() {
/** {@inheritDoc} */
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 -> SpiderChartSWTCanvas.this.paintChart(e));
addMouseMoveListener(e -> SpiderChartSWTCanvas.this.mouseMoved(e));
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(final MouseEvent e) {
SpiderChartCanvas.this.mouseClick();
public void mouseDown(MouseEvent e) {
SpiderChartSWTCanvas.this.mouseClick();
}
};
this.addMouseListener(mouseAdapter);
});
this.addControlListener(new ControlListener() {
/** {@inheritDoc} */
@Override
public void controlMoved(final ControlEvent e) {
public void controlMoved(ControlEvent e) {
// Not used
}
/** {@inheritDoc} */
@Override
public void controlResized(final ControlEvent e) {
SpiderChartCanvas.this.resizeChart();
public void controlResized(ControlEvent e) {
SpiderChartSWTCanvas.this.resizeChart();
}
});
}
/** Returns the spider chart */
public SpiderChartOld getChart() {
return this.chart;
/** Resizes the chart. */
protected void resizeChart() {
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.setX(0);
titleWidget.setY(0);
titleWidget.setHeight(heightMargin - 1);
titleWidget.setWidth(bounds.width - 1);
heightRemaining -= heightMargin;
chartY = heightMargin;
}
if(style.isShowLegend()) {
if(style.getLegendStyle().isVerticalLayout()) {
legendWidget.setX(bounds.width - widthMargin);
legendWidget.setY(bounds.height - heightRemaining);
legendWidget.setWidth(widthMargin - 1);
legendWidget.setHeight(heightRemaining - 1);
widthRemaining -= widthMargin;
} else {
legendWidget.setX(0);
legendWidget.setY(bounds.height - heightMargin);
legendWidget.setWidth(bounds.width - 1);
legendWidget.setHeight(heightMargin - 1);
heightRemaining -= heightMargin;
}
}
chartWidget.setX(0);
chartWidget.setWidth(widthRemaining);
chartWidget.setY(chartY);
chartWidget.setHeight(heightRemaining);
}
/** Mouse Click event */
private void mouseClick() {
if(this.chart != null) {
this.chart.mouseClick();
}
// feature currently disabled
}
/** Mouse Moved Event */
private void mouseMoved(final MouseEvent e) {
if(this.chart != null) {
this.chart.mouseMoved(e.x, e.y);
}
}
/** {@inheritDoc} */
@Override
public void onChartEvent(final SpiderChartOld c, final int type) {
if(type == 4) {
this.redraw();
}
if(type == 1) {
startUiThread(() -> {
if(!SpiderChartCanvas.this.isDisposed()) {
SpiderChartCanvas.this.redraw();
}
});
}
}
/** {@inheritDoc} */
@Override
public void onPaintUserExit(SpiderChartOld c, SpiderChartSwtGraphics g) {
// Not used
private void mouseMoved(MouseEvent e) {
// feature currently disabled
}
/** Draws the Spider Chart */
protected void paintChart(final PaintEvent e) {
protected void paintChart(PaintEvent e) {
try {
this.resizeChart();
SpiderChartSwtGraphics g = getGraphics(e.gc);
this.chart.paint(g);
g.dispose();
} catch(final Exception err) {
SpiderChartSwtGraphics graphics = new SpiderChartSwtGraphics(e.gc);
if(style.isShowTitle()) {
titleWidget.draw(graphics);
}
chartWidget.draw(graphics);
if(style.isShowLegend()) {
legendWidget.draw(graphics);
}
} catch(Exception err) {
err.printStackTrace();
}
}
/** Resizes the spider chart */
protected void resizeChart() {
this.chart.setWidth(this.getSize().x + 1);
this.chart.setHeight(this.getSize().y + 1);
}
/** Setter for Spider Chart */
public void setChart(final SpiderChartOld c) {
if(this.chart != null) {
this.chart.removeChartListener(this);
}
this.chart = c;
this.chart.addChartListener(this);
}
}
......@@ -15,7 +15,7 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.plotter;
package org.fortiss.tooling.spiderchart.widget;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
......@@ -35,10 +35,10 @@ import org.fortiss.tooling.spiderchart.style.FontStyle;
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: D822418216774A7766E735ECD40429CA
*/
public final class SpiderChartTitle extends SpiderChartComponentBase {
public final class SpiderChartTitleWidget extends SpiderChartWidgetBase {
/** Constructor */
public SpiderChartTitle(SpiderChart chart, ChartStyle style) {
public SpiderChartTitleWidget(SpiderChart chart, ChartStyle style) {
super(chart, style);
}
......
......@@ -15,30 +15,74 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.spiderchart.listener;
package org.fortiss.tooling.spiderchart.widget;
import org.fortiss.tooling.spiderchart.SpiderChartOld;
import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.spiderchart.model.SpiderChart;
import org.fortiss.tooling.spiderchart.style.ChartStyle;
/**
* Default Listener Implementation
* Represents a viewer on the canvas to display the spider chart.
*
* @author mondal
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public class SpiderChartAdapter implements ISpiderChartListener {
public final class SpiderChartViewer extends Composite {
/** the actual canvas to be used */
private SpiderChartSWTCanvas canvas = null;
/** Constructor */
public SpiderChartViewer(Composite parent, SpiderChart chart, ChartStyle style) {
super(parent, SWT.NONE);
canvas = new SpiderChartSWTCanvas(this, chart, style);
this.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
// Not used
}
@Override
public void controlResized(ControlEvent e) {
setCanvasSize();
}
});
}
/** getter for the canvas in use */
public SpiderChartSWTCanvas getCanvas() {
return this.canvas;
}
/** {@inheritDoc} */
@Override
public void onChartEvent(SpiderChartOld c, int type) {
//
public boolean setFocus() {
return canvas.setFocus();
}
/** Redraws the chart */
public void redrawChart() {
canvas.redraw();
}
/** Sets the size of the canvas. */
private void setCanvasSize() {
canvas.setLocation(0, 0);
canvas.setSize(this.getSize().x, this.getSize().y);
}
/** {@inheritDoc} */
@Override
public void onPaintUserExit(SpiderChartOld c, SpiderChartSwtGraphics g) {
//
public void dispose() {
canvas.dispose();
super.dispose();
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics;
import org.fortiss.tooling.spiderchart.model.Axis;
import org.fortiss.tooling.spiderchart.model.DataSeries;
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.FontStyle;
/**
* Class for drawing the spider chart.
*
* @author mondal
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603
*/
public final class SpiderChartWidget extends SpiderChartWidgetBase {
/** Constructor. */
public SpiderChartWidget(SpiderChart chart, ChartStyle style) {
super(chart, style);
}
@SuppressWarnings({"unchecked", "rawtypes"})
protected void
plotSequence(SpiderChartSwtGraphics graphics, DataSeries seq, int sequenceNumber) {
// int count = line.getyData().size();
// int[] xs = new int[count];
// int[] ys = new int[count];
//
// int radi = width;
// if(height < radi) {
// radi = height;
// }
// radi = (int)(radi * chartRadius);
//
// int toCenterX = (width - radi) / 2;
// int toCenterY = (height - radi) / 2;
//
// int PieCenterX = toCenterX + x + radi / 2;
// int PieCenterY = toCenterY + y + radi / 2;
// double angle;
// if(sequenceNumber == 0 || sequenceNumber >= data.size() - 1) {
// if(sequenceNumber == 0 && backStyle != null && drawCircle) {
// backStyle.drawArc(graphics, toCenterX + x, toCenterY + y, radi, radi, 0, 360);
// }
// if(sequenceNumber == 0 && backStyle != null && !drawCircle) {
// for(int i = 0; i < count; i++) {
// angle = 360.0D / count * i;
//
// angle += 90.0D;
// if(angle > 360.0D) {
// angle -= 360.0D;
// }
// double radian = 0.01745277777777778D * angle;
// double Sin = Math.sin(radian);
// double Cos = Math.cos(radian);
// int relativeY = (int)(Sin * (radi / 2));
// int relativeX = (int)(Cos * (radi / 2));
// relativeY *= -1;
//
// xs[i] = PieCenterX + relativeX;
// ys[i] = PieCenterY + relativeY;
// }
// backStyle.drawPolygon(graphics, xs, ys, (int)count);
// }
// if(sequenceNumber == data.size() - 1 && border != null) {
// if(drawCircle) {
// border.drawArc(graphics, toCenterX + x, toCenterY + y, radi, radi, 0, 360);
// }
// for(int i = 0; i < count; i++) {
// angle = 360.0D / count * i;
//
// angle += 90.0D;
// if(angle > 360.0D) {
// angle -= 360.0D;
// }
// double radian = 0.01745277777777778D * angle;
// double Sin = Math.sin(radian);
// double Cos = Math.cos(radian);
// int relativeY = (int)(Sin * (radi / 2));
// int relativeX = (int)(Cos * (radi / 2));
// relativeY *= -1;
//
// border.draw(graphics, PieCenterX, PieCenterY, PieCenterX + relativeX,
// PieCenterY + relativeY);
// }
// }
// if(sequenceNumber == 0 && axisFactorFontData != null) {
// Font ontheflyFont = new Font(Display.getCurrent(), axisFactorFontData);
// for(int i = 0; i < count; i++) {
// RGB rgb = swtAxisFactorColor;
// if(swtAxisFactorColors != null && swtAxisFactorColors.length > i) {
// rgb = swtAxisFactorColors[i];
// }
// angle = 360.0D / count * i;
//
// angle += 90.0D;
// if(angle > 360.0D) {
// angle -= 360.0D;
// }
// int tmpradi = (int)(radi * 1.1D / 2.0D);
// int correction = 0;
// if(angle > 120.0D && angle < 240.0D) {
// correction = graphics.getFontWidth(axesFactors[i]);
// }
// double radian = 0.01745277777777778D * angle;
// double sin = Math.sin(radian);
// double cos = Math.cos(radian);
// int relativeY = (int)(sin * tmpradi);
// int relativeX = (int)(cos * tmpradi);
// relativeY *= -1;
// if(axesFactors.length > i) {
// graphics.drawText(axesFactors[i], PieCenterX + relativeX - correction,
// PieCenterY + relativeY, rgb, ontheflyFont);
// }
// }
// }
// }
// for(int i = 0; i < count; i++) {
// angle = 360.0D / count * i;
//
// angle += 90.0D;
// if(angle > 360.0D) {
// angle -= 360.0D;
// }
// int tmpradi = 0;
//
// double min = 0.0D;
// double max = 100.0D;
// if(minScaleFactors.length >= i + 1) {
// min = minScaleFactors[i];
// }
// if(maxScaleFactors.length >= i + 1) {
// max = maxScaleFactors[i];
// }
// tmpradi =
// (int)((((Double)line.getElementY(i)).doubleValue() - min) * 100.0D / (max - min));
// tmpradi = tmpradi * radi / 100;
//
// double radian = 0.01745277777777778D * angle;
// double Sin = Math.sin(radian);
// double Cos = Math.cos(radian);
// int relativeY = (int)(Sin * (tmpradi / 2));
// int relativeX = (int)(Cos * (tmpradi / 2));
// relativeY *= -1;
// xs[i] = PieCenterX + relativeX;
// ys[i] = PieCenterY + relativeY;
// }
// if(line.getStyle() != null) {
// line.getStyle().drawPolygon(graphics, xs, ys, (int)count);
// }
// if(line.getFillStyle() != null) {
// line.getFillStyle().drawPolygon(graphics, xs, ys, (int)count);
// }
// int kl = 0;
// for(int i = 0; i < count; i++) {
// Polygon po = new Polygon();
// po.addPoint(xs[i] - 3, ys[i] - 3);
// po.addPoint(xs[i] - 3, ys[i] + 3);
// po.addPoint(xs[i] + 3, ys[i] + 3);
// po.addPoint(xs[i] + 3, ys[i] - 3);
// seq.getHotAreas().add(po);
// double YValue;
// if(line.isDrawPoint()) {
// RGB rgb = line.getPointColor();
// YValue = ((Double)line.getElementY(i)).doubleValue();
// if(pointColors != null && pointColorScale != null) {
// if(pointColors.length > 0) {
// rgb = pointColors[0];
// }
// for(int j = 1; j < pointColors.length; j++) {
// if(pointColorScale.length >= j) {
// if(pointColorScale[j - 1] > YValue) {
// break;
// }
// rgb = pointColors[j];
// }
// }
// }
// if(line.getIcon() == null) {
// graphics.fillRect(xs[i] - 3, ys[i] - 3, 6, 6, rgb);
// } else {
// graphics.drawImage(line.getIcon(), xs[i] - 4, ys[i] - 4);
// }
// }
// if(line.getValueFontData() != null) {
// YValue = ((Double)line.getElementY(i)).doubleValue();
// String txt = line.doubleToString(new Double(YValue));
//
// if(YValue == (int)YValue) {
// txt = new Integer((int)YValue).toString();
// }
// if(line.getLabelTemplate().length() > 0) {
// txt = line.getLabelTemplate();
// }
// if(line.getDataLabels() != null && line.getDataLabels().length > i) {
// txt = line.getDataLabels()[i];
// }
//
// Font ontheflyFont = new Font(Display.getCurrent(), line.getValueFontData());
// graphics.drawText(txt, xs[i] + 7, ys[i], line.getValueColor(), ontheflyFont);
// ontheflyFont.dispose();
// }
// }
// if(gridStyle != null) {
// double maxValues[] = new double[xs.length];
// double minValues[] = new double[20];
// if(minScaleFactors.length >= 1) {
// for(int j = 0; j < xs.length; j++) {
// minValues[j] = minScaleFactors[j];
// }
// }
// if(maxScaleFactors.length >= 1) {
// for(int j = 0; j < xs.length; j++) {
// maxValues[j] = maxScaleFactors[j];
// }
// }
// int tickInterval = 100 / scalingDivisions;
// double[] tickIntervalAbsValues = new double[xs.length];
//
// for(int j = 0; j < xs.length; j++) {
// tickIntervalAbsValues[j] = (maxValues[j] - minValues[j]) / scalingDivisions;
// }
//
// int tickAt = 0;
// double[] tickAtAbsValues = new double[xs.length];
// for(int j = 0; j < scalingDivisions; j++) {
// tickAt += tickInterval;
// for(int k = 0; k < xs.length; k++) {
// tickAtAbsValues[k] += tickIntervalAbsValues[k];
// }
// for(int i = 0; i < count; i++) {
// angle = 360.0D / count * i;
//
// angle += 90.0D;
// if(angle > 360.0D) {
// angle -= 360.0D;
// }
// int tmpradi = radi * tickAt / 100;
// double radian = 0.01745277777777778D * angle;
// double Sin = Math.sin(radian);
// double Cos = Math.cos(radian);
// int relativeY = (int)(Sin * (tmpradi / 2));
// int relativeX = (int)(Cos * (tmpradi / 2));
// relativeY *= -1;
//
// xs[i] = PieCenterX + relativeX;
// ys[i] = PieCenterY + relativeY;
// }
// if(sequenceNumber >= data.size() - 1) {
// gridStyle.drawPolygon(graphics, xs, ys, count);
// }
// if(sequenceNumber >= data.size() - 1 && gridFontData != null) {
// double[] tickValues = new double[xs.length];
// String[] values = new String[xs.length];
//
// for(int i = 0; i < tickValues.length; i++) {
// tickValues[i] = tickAtAbsValues[i];
// values[i] = "" + tickValues[i];
//
// if(scalingLabelFormat.length > 0) {
// Object scalingLabel = scalingLabelFormat[i];
// DecimalFormat df = null;
// if(scalingLabel instanceof String) {
// df = new DecimalFormat((String)scalingLabelFormat[i]);
// values[i] = df.format(new Double(tickValues[i]));
// }
// if(scalingLabel instanceof Class<?>) {
// if(((Class<?>)scalingLabel).isEnum()) {
// try {
// values[i] =
// (String)enumConstants((Class<Enum>)scalingLabel)
// .get(kl++);
// } catch(Exception e) {
// e.printStackTrace();
// }
// }
// }
// }
// }
//
// Font ontheflyFont = new Font(Display.getCurrent(), gridFontData);
// if(markScalesOnEveryAxis) {
// for(int k = 0; k < xs.length; k++) {
// graphics.drawText("" + values[k],
// xs[k] - 3 - graphics.getFontWidth("" + values[k]), ys[k],
// swtGridFontColor, ontheflyFont);
// }
// } else {
// graphics.drawText("" + values[0],
// xs[0] - 3 - graphics.getFontWidth("" + values[0]), ys[0],
// swtGridFontColor, ontheflyFont);
// }
// ontheflyFont.dispose();
// }
// }
// }
}
/** Disposes the plotter's resources. */
public void dispose() {
// FIXME: needed?
}
/** Draws the spider chart. */
public void draw(SpiderChartSwtGraphics g) {
// FIXME: remove debug rectangle
g.getGraphics().drawRectangle(getX(), getY(), getWidth(), getHeight());
compute();
drawAxes(g);
for(DataSeries data : chart.getDataSeries()) {
drawDataSeries(g, data);
}
}
/** The center point of the chart. */
private Point center = new Point(0, 0);
/** The extent in pixels from the center point. */
private int extent = 0;
/** The end points of the axes. */
private Map<Axis, Point> axesEnds = new HashMap<Axis, Point>();
/** The angle in degree between two axes. */
private double segmentDegree = 0.0;
/** Computes the end point for each axis. */
// FIXME: do not call this during draw, but when widget size changes.
private void compute() {
List<Axis> 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);
extent = Math.min(wExtent, hExtent);
for(int i = 0; i < size; i++) {
Axis 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 data series. */
private void drawDataSeries(SpiderChartSwtGraphics g, DataSeries data) {
// TODO: implement
}
/** Draws the axes of the spider chart. */
private Map<Axis, Point> drawAxes(SpiderChartSwtGraphics graphics) {
List<Axis> 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;
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++) {
Axis axis = axes.get(i);
Point outer = axesEnds.get(axis);
// draw line
AxisStyle aStyle = style.getAxisStyle(axis);
aStyle.getLineStyle().draw(graphics, centerX, centerY, outer.x, outer.y);
// draw label
drawAxisLabel(graphics, axis, aStyle, centerX, centerY, outer.x, outer.y);
// draw segment indicators
int segments = aStyle.getSegments();
for(int s = 1; s <= segments; s++) {
double ratio = (double)s / (double)segments;
// FIXME: use locale info here
String lbl = axis.getAxisRatio(ratio).toString();
Point segmentPoint =
getSegmentPoint(aStyle, s, outer.x - center.x, outer.y - center.y);
drawSegmentIndicator(graphics, lbl, aStyle, centerX, centerY, segmentPoint);
}
angleDegree = (angleDegree + segmentDegree) % 360.0;
}
return axesEnds;
}
/** Draws the indicator on the axis. */
private void drawSegmentIndicator(SpiderChartSwtGraphics graphics, String lbl,
AxisStyle axisStyle, int centerX, int centerY, Point segment) {
GC gc = graphics.getGraphics();
FontStyle segmentStyle = axisStyle.getSegmentStyle();
Font oldFont = gc.getFont();
Font font = segmentStyle.createSWTFont();
gc.setFont(font);
Color oldColor = gc.getForeground();
Color color = segmentStyle.createSWTColor();
gc.setForeground(color);
int posX = centerX + segment.x;
if(posX == centerX) {
posX += 5;
}
int posY = centerY + segment.y;
if(posY == centerY) {
posY += 5;
}
gc.drawText(lbl, posX, posY, true);
gc.setForeground(oldColor);
color.dispose();
gc.setFont(oldFont);
font.dispose();
}
/** Draws the axis label at the correct position. */
private void drawAxisLabel(SpiderChartSwtGraphics graphics, Axis axis, AxisStyle style,
int centerX, int centerY, int outerX, int outerY) {
String axisLabel = axis.getName();
FontData fontData = style.getLabelStyle().getFontData();
GC gc = graphics.getGraphics();
Font oldFont = gc.getFont();
Font font = new Font(Display.getCurrent(), fontData);
gc.setFont(font);
Color oldColor = gc.getForeground();
Color color = style.getLabelStyle().createSWTColor();
gc.setForeground(color);
int textExtent = graphics.getGraphics().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;
}
gc.drawString(axisLabel, outerX, outerY, true);
gc.setFont(oldFont);
font.dispose();
gc.setForeground(oldColor);
color.dispose();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment