diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF index 40b70377e69e0bbdafcbc08c48aa302c1cbb0a99..a283933c57fe83c5057375207f757c3affd6e95f 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.spiderchart.ui/trunk/META-INF/MANIFEST.MF @@ -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 diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/SpiderChartBuilder.java similarity index 66% rename from org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java rename to org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/SpiderChartBuilder.java index 6a220f9c9a722fbdc78b2fb96b23240a68f2c324..927360f77a3f2a0d1eebc1d1df8e595e5a5b89a5 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/SpiderChartBuilder.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/SpiderChartBuilder.java @@ -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; } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/SpiderChartOld.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/SpiderChartOld.java deleted file mode 100644 index 6e29429e43c8645206f5f8c3cf7bae7297a464d4..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/SpiderChartOld.java +++ /dev/null @@ -1,698 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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; - -import static org.fortiss.tooling.spiderchart.gc.AbstractGraphicsSupplier.createImage; -import static org.fortiss.tooling.spiderchart.listener.ISpiderChartListener.EVENT_CHART_CLICKED; -import static org.fortiss.tooling.spiderchart.listener.ISpiderChartListener.EVENT_POINT_CLICKED; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.GRAY; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.RED; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.graphics.Rectangle; -import org.fortiss.tooling.spiderchart.gc.AbstractChartImage; -import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics; -import org.fortiss.tooling.spiderchart.label.SpiderChartLabel; -import org.fortiss.tooling.spiderchart.label.api.IFloatingObject; -import org.fortiss.tooling.spiderchart.listener.ISpiderChartListener; -import org.fortiss.tooling.spiderchart.model.DataSeries; -import org.fortiss.tooling.spiderchart.model.SpiderChart; -import org.fortiss.tooling.spiderchart.plotter.SpiderChartComponentBase; -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.sequence.DataSequence; -import org.fortiss.tooling.spiderchart.style.ChartStyle; -import org.fortiss.tooling.spiderchart.style.FillStyle; -import org.fortiss.tooling.spiderchart.style.LineStyle; - -/** - * Actual Spider Chart Diagram - * - * @author mondal - * @author hoelzl - * @author $Author$ - * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603 - */ -public final class SpiderChartOld extends SpiderChartComponentBase { - /** Margin for the spider chart from all sides. */ - private static final double MARGIN_PERCENT = 0.125; - /** Margin for axes. */ - private static final double AXIS_MARGIN = MARGIN_PERCENT / 2.0; - - /** the localized string for numbers */ - private static String numberLocale; - - /** Getter for number locale */ - public static String getNumberLocale() { - return numberLocale; - } - - /** Setter for number locale */ - public static void setNumberLocale(final String numberLocale) { - SpiderChartOld.numberLocale = numberLocale; - } - - /** The flag to be used to enable selection of data points */ - private boolean activateSelection = false; - - /** Background Canvas Color */ - private RGB swtBackgroundCanvasColor = GRAY; - - /** Background Styling Theme */ - private FillStyle backStyle = new FillStyle(GRAY); - - /** Temporary Background Image */ - private AbstractChartImage backTmpImage = null; - - /** Border Style */ - private LineStyle border = null; - - /** Spider Chart Image */ - private AbstractChartImage chartImage = null; - - /** List of action listeners */ - private final List<ISpiderChartListener> chartListeners = new CopyOnWriteArrayList<>(); - - /** Current X Coordinate of the cursor */ - private int currentX; - - /** Current Y Coordinate of the cursor */ - private int currentY; - - /** Previous X Coordinate of the cursor */ - private int cursorLastX = 0; - - /** Previous Y Coordinate of the cursor */ - private int cursorLastY = 0; - - /** the rendered spider chart image */ - private AbstractChartImage finalImage = null; - - /** Container for list of Spider Chart Elements such as Labels */ - private final List<IFloatingObject> floatingObjects = new ArrayList<>(); - - /** configuration if X-Axis Screen Margin will be set */ - private final boolean fullXAxis = false; - - /** Spider Chart Legend */ - private SpiderChartLegend legend; - - /** minimum height */ - private int minimumHeight = 0; - - /** minimum width */ - private int minimumWidth = 0; - - /** microseconds to wait before a chart refresh */ - private long msecs = 2000L; - - /** X-offset for data points */ - private int offsetX = 0; - - /** Y-offset for data points */ - private int offsetY = 0; - - /** The plotters to be used for spider chart plotting. */ - private SpiderChartPlotter plotter; - - /** Spider Chart Label */ - private SpiderChartLabel selectedLabel = null; - - /** The data sequence to be used */ - private DataSequence selectedSeq = null; - - /** Data point as selected */ - private int selectedSeqPoint = -1; - - /** Show Tips on the Spider Chart Points */ - private boolean showTips = true; - - /** Check refresh thread status */ - private boolean stopped = false; - - /** Spider Chart Title */ - private SpiderChartTitle title; - - /** Constructor */ - public SpiderChartOld(SpiderChart chart, ChartStyle style, SpiderChartTitle t, - SpiderChartPlotter p) { - super(chart, style); - this.resetChart(t, p); - } - - /** Registers the selected chart listener */ - public void addChartListener(final ISpiderChartListener cl) { - this.chartListeners.add(cl); - } - - /** Adds the selected floating object */ - public void addFloationgObject(final IFloatingObject obj) { - this.floatingObjects.add(obj); - } - - /** Adds the plotter */ - public void setPlotter(SpiderChartPlotter p) { - plotter = p; - } - - /** Adds the sequence */ - public void addSeq(DataSeries data) { - plotter.addSeq(data); - } - - /** Disposes the spider chart */ - public void dispose() { - if(plotter != null) { - plotter.dispose(); - } - if(this.chartImage != null) { - this.chartImage.dispose(); - } - if(this.finalImage != null) { - this.finalImage.dispose(); - } - if(this.backTmpImage != null) { - this.backTmpImage.dispose(); - } - } - - /** Getter for Background Fill Style */ - public FillStyle getBackStyle() { - return this.backStyle; - } - - /** Getter for Background Temporary Image */ - public AbstractChartImage getBackTmpImage() { - return this.backTmpImage; - } - - /** Getter for Border */ - public LineStyle getBorder() { - return this.border; - } - - /** Getter for Chart Image */ - public AbstractChartImage getChartImage() { - return this.chartImage; - } - - /** Getter for all registered chart listeners */ - public List<ISpiderChartListener> getChartListeners() { - return this.chartListeners; - } - - /** Getter for current X coordinate of the cursor */ - public int getCurrentX() { - return this.currentX; - } - - /** Getter for current Y coordinate of the cursor */ - public int getCurrentY() { - return this.currentY; - } - - /** Getter for last cursor X coordinate of the cursor */ - public int getCursorLastX() { - return this.cursorLastX; - } - - /** Getter for last cursor Y coordinate of the cursor */ - public int getCursorLastY() { - return this.cursorLastY; - } - - /** Getter for the last image to be shown as a background to the chart */ - public AbstractChartImage getFinalImage() { - return this.finalImage; - } - - /** Getter for all floating objects to be used in the chart */ - public List<IFloatingObject> getFloatingObjects() { - return this.floatingObjects; - } - - /** Getter for the spider chart legend */ - public SpiderChartLegend getLegend() { - return this.legend; - } - - /** Getter for minimum height */ - public int getMinimumHeight() { - return this.minimumHeight; - } - - /** Getter for minimum width */ - public int getMinimumWidth() { - return this.minimumWidth; - } - - /** Getter for the microseconds to wait before the chart to be refreshed */ - public long getMsecs() { - return this.msecs; - } - - /** Getter for X-coordinate offset */ - public int getOffsetX() { - return this.offsetX; - } - - /** Getter for Y-coordinate offset */ - public int getOffsetY() { - return this.offsetY; - } - - /** Returns the plotter. */ - public SpiderChartPlotter getPlotter() { - return plotter; - } - - /** Getter for spider chart label */ - public SpiderChartLabel getSelectedLabel() { - return this.selectedLabel; - } - - /** Getter for the sequence to be used */ - public DataSequence getSelectedSeq() { - return this.selectedSeq; - } - - /** Getter for selected sequence point */ - public int getSelectedSeqPoint() { - return this.selectedSeqPoint; - } - - /** Getter for the first plotter to be used */ - public SpiderChartPlotter getSpiderPlotter() { - return plotter; - } - - /** Getter for the spider chart title */ - public SpiderChartTitle getTitle() { - return this.title; - } - - /** - * Getter for the configuration to check if it is a active sequence - * selection - */ - public boolean isActivateSelection() { - return this.activateSelection; - } - - /** - * Getter for the configuration to check if X-axis screen margin will be set - */ - public boolean isFullXAxis() { - return this.fullXAxis; - } - - /** Getter for the configuration to check if tips to be shown */ - public boolean isShowTips() { - return this.showTips; - } - - /** - * Getter to check if the thread responsible to refresh the chart is stopped - */ - public boolean isStopped() { - return this.stopped; - } - - /** Mouse Click Functionality */ - public void mouseClick() { - if(this.selectedSeq != null && this.selectedSeqPoint >= 0 || this.selectedLabel != null) { - this.triggerChartEvent(EVENT_POINT_CLICKED); - return; - } - this.triggerChartEvent(EVENT_CHART_CLICKED); - } - - /** Mouse Move Functionality */ - public void mouseMoved(final int eX, final int eY) { - // FIXME: mouse motion feature currently disabled - // if(plotter == null) { - // return; - // } - // - // this.currentX = eX; - // this.currentY = eY; - // - // Object previousSelectedObject = this.selectedSeq; - // final int previousPoint = this.selectedSeqPoint; - // - // if(this.selectedSeq == null && this.selectedLabel != null) { - // previousSelectedObject = this.selectedLabel; - // } - // this.selectedSeq = null; - // this.selectedLabel = null; - // this.selectedSeqPoint = -1; - // if(this.activateSelection) { - // List<DataSequence> sList = plotter.getData(); - // for(DataSequence d : sList) { - // for(int i = 0; i < d.getHotAreas().size(); i++) { - // if(((Polygon)d.getHotAreas().get(i)).contains(this.currentX + this.offsetX, - // this.currentY + this.offsetY)) { - // boolean triggerEnter = false; - // if(previousSelectedObject == null) { - // triggerEnter = true; - // } else if(previousSelectedObject != d || previousPoint != i) { - // this.triggerChartEvent(EVENT_LEAVE_POINT); - // triggerEnter = true; - // } - // this.selectedSeq = d; - // this.selectedSeqPoint = i; - // if(!triggerEnter) { - // break; - // } - // this.triggerChartEvent(EVENT_ENTER_POINT); - // break; - // } - // } - // } - // } - // if(Math.abs(this.currentX - this.cursorLastX) > 2 || - // Math.abs(this.currentY - this.cursorLastY) > 2) { - // this.cursorLastX = this.currentX; - // this.cursorLastY = this.currentY; - // this.triggerChartEvent(EVENT_TIP_UPDATE); - // } - // if(previousSelectedObject != null && this.selectedSeq == null && this.selectedLabel == - // null) { - // this.triggerChartEvent(EVENT_LEAVE_POINT); - // } - } - - /** Paints the chart */ - public void paint(SpiderChartSwtGraphics graphics) { - this.floatingObjects.clear(); - - if(plotter == null) { - graphics.drawText("No plotters have been found", 30, 30, RED); - return; - } - - if(plotter != null) { - plotter.drawAxes(graphics); - plotter.plot(graphics); - // FIXME: break out - // return; - } - - if(title != null) { - title.draw(graphics); - } - - if(legend != null) { - legend.draw(graphics); - // FIXME: break out - return; - } - - // FIXME: untested parts follow - SpiderChartSwtGraphics gScroll = graphics; - SpiderChartSwtGraphics gBack = graphics; - SpiderChartSwtGraphics g = graphics; - if(this.finalImage != null) { - this.finalImage.dispose(); - } - this.finalImage = createImage(this.getWidth(), this.getHeight()); - g = this.finalImage.getGraphics(); - gScroll = g; - gBack = g; - if(this.backStyle != null) { - this.backStyle.draw(gBack, swtBackgroundCanvasColor, 0, 0, getWidth(), getHeight()); - } - // FIXME: scale feature disabled - // if(plotter.getxScale() != null) { - // plotter.getxScale().setScreenMax(plotter.getX() + plotter.getWidth()); - // plotter.getxScale().setScreenMaxMargin( - // (int)(plotter.getxScale().getScreenMax() * (1.0D - this.axisMargin))); - // if(this.fullXAxis) { - // plotter.getxScale().setScreenMaxMargin(plotter.getxScale().getScreenMax()); - // } - // plotter.getxScale().setScreenMin(plotter.getX()); - // } - // if(plotter.getyScale() != null) { - // plotter.getyScale().setScreenMax(plotter.getY() + plotter.getHeight()); - // plotter.getyScale().setScreenMaxMargin( - // (int)(plotter.getyScale().getScreenMax() * (1.0D - this.axisMargin))); - // plotter.getyScale().setScreenMin(plotter.getY()); - // } - plotter.plot(gScroll); - if(this.border != null) { - this.border.drawRect(g, 0, 0, this.getWidth() - 1, this.getHeight() - 1); - } - if(this.chartImage != null) { - final int x1 = plotter.getX(); - final int x2 = plotter.getX() + plotter.getWidth(); - final int y1 = plotter.getY() - plotter.getDepth(); - final int y2 = plotter.getY() - plotter.getDepth() + plotter.getHeight(); - - g.drawImage(this.chartImage, x1, y1, x2, y2, x1 + this.offsetX, y1 + this.offsetY, x2 + - this.offsetX, y2 + this.offsetY); - } - if(this.chartListeners != null) { - for(int i = 0; i < this.chartListeners.size(); i++) { - this.chartListeners.get(i).onPaintUserExit(this, g); - } - } - - if(this.finalImage != null) { - graphics.drawImage(this.finalImage, 0, 0, this.getWidth(), this.getHeight(), 0, 0, - this.getWidth(), this.getHeight()); - } - if(gScroll != graphics) { - gScroll.dispose(); - } - if(gBack != graphics) { - gBack.dispose(); - } - if(g != graphics) { - g.dispose(); - } - } - - /** - * Places the defined floating object - * - * @param obj - * the floating object to place - */ - public void placeFloatingObject(final IFloatingObject obj) { - // To be implemented - } - - /** Removes all registered listeners */ - public void removeAllChartListener() { - this.chartListeners.clear(); - } - - /** Removes the specified chart listener */ - public void removeChartListener(final ISpiderChartListener cl) { - this.chartListeners.remove(cl); - } - - /** Release the used resources */ - protected void resetChart(final SpiderChartTitle t, final SpiderChartPlotter p) { - this.legend = null; - this.title = null; - this.border = null; - this.backStyle = null; - this.selectedSeq = null; - this.selectedSeqPoint = -1; - this.floatingObjects.clear(); - plotter = p; - this.title = t; - } - - /** Resizes the chart */ - public void layoutChartComponents() { - int width = getWidth(); - int widthMargin = (int)(width * MARGIN_PERCENT); - int height = getHeight(); - int heightMargin = (int)(height * MARGIN_PERCENT); - - plotter.setX(widthMargin); - plotter.setWidth(width - 2 * widthMargin - 1); - plotter.setY(heightMargin); - plotter.setHeight(height - 2 * heightMargin - 1); - - title.setX(0); - title.setY(0); - title.setHeight(heightMargin - 1); - title.setWidth(width - 1); - - if(legend != null && style.isShowLegend()) { - if(style.getLegendStyle().isVerticalLayout()) { - legend.setX(width - widthMargin); - legend.setY(heightMargin); - legend.setWidth(widthMargin - 1); - legend.setHeight(height - heightMargin - 1); - } else { - legend.setX(0); - legend.setY(height - heightMargin); - legend.setWidth(width - 1); - legend.setHeight(heightMargin - 1); - } - } - } - - /** Setter for the active sequence selection */ - public void setActivateSelection(final boolean activateSelection) { - this.activateSelection = activateSelection; - } - - /** Setter for the background canvas color */ - public void setBackgroundCanvasColor(RGB swtBackgroundCanvasColor) { - this.swtBackgroundCanvasColor = swtBackgroundCanvasColor; - } - - /** Setter for the background fill style */ - public void setBackStyle(final FillStyle backStyle) { - this.backStyle = backStyle; - } - - /** Setter for background temporary image */ - public void setBackTmpImage(final AbstractChartImage backTmpImage) { - this.backTmpImage = backTmpImage; - } - - /** Setter for the border */ - public void setBorder(final LineStyle border) { - this.border = border; - } - - /** Setter for the chart image */ - public void setChartImage(final AbstractChartImage chartImage) { - this.chartImage = chartImage; - } - - /** Setter for the current X Coordinate of the cursor */ - public void setCurrentX(final int currentX) { - this.currentX = currentX; - } - - /** Setter for the current Y Coordinate of the cursor */ - public void setCurrentY(final int currentY) { - this.currentY = currentY; - } - - /** Setter for previous X Coordinate of the cursor */ - public void setCursorLastX(final int cursorLastX) { - this.cursorLastX = cursorLastX; - } - - /** Setter for previous Y Coordinate of the cursor */ - public void setCursorLastY(final int cursorLastY) { - this.cursorLastY = cursorLastY; - } - - /** Setter for final image to be used on the chart */ - public void setFinalImage(final AbstractChartImage finalImage) { - this.finalImage = finalImage; - } - - /** Setter for the legend */ - public void setLegend(final SpiderChartLegend legend) { - this.legend = legend; - } - - /** Setter for the minimum height */ - public void setMinimumHeight(final int minimumHeight) { - this.minimumHeight = minimumHeight; - } - - /** Setter for the minimum size */ - public void setMinimumSize(final int w, final int h) { - this.minimumWidth = w; - this.minimumHeight = h; - } - - /** Setter for the minimum width */ - public void setMinimumWidth(final int minimumWidth) { - this.minimumWidth = minimumWidth; - } - - /** Setter for the miliseconds to wait before the chart gets refreshed */ - public void setMsecs(final long msecs) { - this.msecs = msecs; - } - - /** Setter for the offset to use in X-axis */ - public void setOffsetX(final int offsetX) { - this.offsetX = offsetX; - } - - /** Setter for the offset to use in Y-axis */ - public void setOffsetY(final int offsetY) { - this.offsetY = offsetY; - } - - /** Setter for the spider chart label */ - public void setSelectedLabel(final SpiderChartLabel selectedLabel) { - this.selectedLabel = selectedLabel; - } - - /** Setter for the selected data points sequence */ - public void setSelectedSeq(final DataSequence selectedSeq) { - this.selectedSeq = selectedSeq; - } - - /** */ - public void setSelectedSeqPoint(final int selectedSeqPoint) { - this.selectedSeqPoint = selectedSeqPoint; - } - - /** Setter for the configuration to show tips */ - public void setShowTips(final boolean showTips) { - this.showTips = showTips; - } - - /** Setter for the configuration to mark the stop as stopped */ - public void setStopped(final boolean stopped) { - this.stopped = stopped; - } - - /** Setter for the spider chart title */ - public void setTitle(final SpiderChartTitle title) { - this.title = title; - } - - /** Triggers the chart event */ - private void triggerChartEvent(final int event) { - for(int i = 0; i < this.chartListeners.size(); i++) { - this.chartListeners.get(i).onChartEvent(this, event); - } - } - - /** - * @param bounds - */ - public void setBounds(Rectangle bounds) { - setX(bounds.x); - setY(bounds.y); - setWidth(bounds.width); - setHeight(bounds.height); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/AxesConfigurer.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/AxesConfigurer.java deleted file mode 100644 index 52ed8f5a79bce31ab6779ce46b097117a9e6b189..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/AxesConfigurer.java +++ /dev/null @@ -1,182 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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)); - } - -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/model/AxisData.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/model/AxisData.java deleted file mode 100644 index 09929157ec5117b0d6b8939b9ed2d31555a97fda..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/builder/model/AxisData.java +++ /dev/null @@ -1,57 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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)); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/IPhone.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/IPhone.java deleted file mode 100644 index 73f3102cca336dcfa703766ee67e5822d4e349c4..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/IPhone.java +++ /dev/null @@ -1,53 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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"; - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Nexus.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Nexus.java deleted file mode 100644 index 242dc9eafeaeb2faa0cc24dd0f662f611bb2376e..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Nexus.java +++ /dev/null @@ -1,46 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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"; - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Sample.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Sample.java index 04f01ddf5877c44760abe43e8b7a0a21f8ed1d35..ab110438e0b3ae0116a46a7fd574a627b7ac5fc8 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Sample.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/example/Sample.java @@ -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(); } } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/listener/ISpiderChartListener.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/listener/ISpiderChartListener.java deleted file mode 100644 index 6913549834025a6db8f7c707a338c6369b50d509..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/listener/ISpiderChartListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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); -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/listener/SpiderChartAdapter.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/listener/SpiderChartAdapter.java deleted file mode 100644 index e5bcb3bc8cf388dc8956239c6c87af70e039453c..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/listener/SpiderChartAdapter.java +++ /dev/null @@ -1,44 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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; - -/** - * Default Listener Implementation - * - * @author mondal - * @author $Author$ - * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603 - */ -public class SpiderChartAdapter implements ISpiderChartListener { - - /** {@inheritDoc} */ - @Override - public void onChartEvent(SpiderChartOld c, int type) { - // - } - - /** {@inheritDoc} */ - @Override - public void onPaintUserExit(SpiderChartOld c, SpiderChartSwtGraphics g) { - // - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartPlot.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartPlot.java deleted file mode 100644 index a027d274756be8bde6165780140eb1576fe04d4f..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartPlot.java +++ /dev/null @@ -1,47 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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(); -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartPlotter.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartPlotter.java deleted file mode 100644 index f795e61b14d825e66b54bc1e33ca3ed4e7834405..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartPlotter.java +++ /dev/null @@ -1,931 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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 static java.util.Objects.requireNonNull; -import static org.fortiss.tooling.spiderchart.gc.Fonts.VERDANA; -import static org.fortiss.tooling.spiderchart.util.AxisUtils.getSegmentPoint; -import static org.fortiss.tooling.spiderchart.util.ChartUtil.enumConstants; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.BLACK; -import static org.fortiss.tooling.spiderchart.util.RGBColorUtils.DARK_GRAY; - -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.swt.SWT; -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.graphics.RGB; -import org.eclipse.swt.widgets.Display; -import org.fortiss.tooling.spiderchart.gc.Polygon; -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.scale.SpiderChartScale; -import org.fortiss.tooling.spiderchart.sequence.DataSequence; -import org.fortiss.tooling.spiderchart.sequence.LineDataSequence; -import org.fortiss.tooling.spiderchart.style.AxisStyle; -import org.fortiss.tooling.spiderchart.style.ChartStyle; -import org.fortiss.tooling.spiderchart.style.FillStyle; -import org.fortiss.tooling.spiderchart.style.FontStyle; -import org.fortiss.tooling.spiderchart.style.LineStyle; - -/** - * Class for drawing the spider chart. - * - * @author mondal - * @author $Author$ - * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603 - */ -public final class SpiderChartPlotter extends SpiderChartComponentBase { - - /** The relative chart margin. The default is 10%. */ - private double relativeMargin = 0.9; - - /** depth of the component */ - private int depth = 0; - - /** The list of data sequences. */ - protected List<DataSequence> data = new ArrayList<DataSequence>(); - - /** Adds sequence to the plotter */ - public void addSeq(DataSeries data) { - replaceSeq(-1, data); - } - - /** calculates the max values in the provided scale */ - private void calculateMax(final SpiderChartScale s, final double m) { - if(!s.isExactMaxValue()) { - s.setMax(m); - return; - } - final double[] value = s.getPreferred_MaxMin_values(); - if(value != null && value.length > 0) { - for(final double preferred_MaxMin_value : value) { - if(preferred_MaxMin_value >= m) { - s.setMax(preferred_MaxMin_value); - - break; - } - } - } - } - - /** calculates the min values in the provided scale */ - private void calculateMin(final SpiderChartScale s, final double m) { - if(!s.isExactMinValue()) { - s.setMin(m); - return; - } - final double[] value = s.getPreferred_MaxMin_values(); - if(value != null && value.length > 0) { - for(int j = value.length - 1; j > 0; j--) { - if(value[j] <= m) { - s.setMin(value[j]); - - break; - } - } - } - } - - /** replaces a sequence with the provided one */ - @SuppressWarnings("cast") - public void replaceSeq(int p, DataSeries d) { - SpiderChartScale tmpScaleX = xScale; - // FIXME: ??? - // getActiveYScale(); - if(p >= data.size()) { - return; - } - if(data.size() > 3) { - return; - } - // FIXME: below - // if(p == -1) { - // data.add(new LineDataSequence(d.get, s)); - // } else { - // data.set(p, s); - // } - // final boolean fixedLimits = false; - // final boolean cumulative = false; - // if(!(this instanceof SpiderChartPlotter)) { - // for(int i = 0; i < s.getSize(); i++) { - // if(s.getElementY(i) != null) { - // final double XValue = ((Double)s.getElementX(i)).doubleValue(); - // double YValue = ((Double)s.getElementY(i)).doubleValue(); - // if(cumulative) { - // YValue = 0.0D; - // for(int si = 0; si < data.size(); si++) { - // final DataSequence ser = data.get(si); - // } - // } - // if(XValue >= tmpScaleX.getMax()) { - // calculateMax(tmpScaleX, XValue); - // } - // if(XValue < tmpScaleX.getMin()) { - // calculateMin(tmpScaleX, XValue); - // } - // if(!fixedLimits) { - // if(YValue > yScale.getMax()) { - // calculateMax(yScale, YValue); - // } - // if(YValue < yScale.getMin()) { - // calculateMin(yScale, YValue); - // } - // } - // } - // } - // } - } - - /** x-axis scaling */ - private SpiderChartScale xScale; - - /** y-axis scaling */ - private SpiderChartScale yScale; - /** - * axes names - */ - private String[] axesFactors; - - /** - * Axes Factor Color - */ - private RGB swtAxisFactorColor = BLACK; - - /** - * Axis Factor Colors (in case you need to set different colors - * for different axes) - */ - private RGB[] swtAxisFactorColors; - - /** - * Axes Factor Text Font - */ - private FontData axisFactorFontData = new FontData(VERDANA.getFontName(), SWT.NORMAL, 11); - - /** - * Polygon Area Background Style - */ - private FillStyle backStyle; - - /** - * Border Style - */ - private LineStyle border = new LineStyle(BLACK, 0.2F, 1); - - /** - * Radius - */ - private double chartRadius = 0.9D; - - /** - * would be surrounded by an enclosing circle - */ - private boolean drawCircle = false; - - /** - * Font for Grid Label - */ - private FontData gridFontData; - - /** - * Font Color for Grid Label - */ - private RGB swtGridFontColor = DARK_GRAY; - - /** - * Grid Style - */ - private LineStyle gridStyle; - - /** Mark Scales on Every Axis */ - private boolean markScalesOnEveryAxis = false; - - /** - * Scaling Factors (Maximum Values) - */ - private double[] maxScaleFactors; - - /** - * Scaling Factors (Minimum Values) - */ - private double[] minScaleFactors; - - /** */ - private RGB[] pointColors = null; - - /** */ - private double[] pointColorScale = null; - - /** - * Scaling Divisions - */ - private int scalingDivisions = 5; - - /** - * Scaling Label Format - */ - private Object[] scalingLabelFormat; - - /** Constructor. */ - public SpiderChartPlotter(SpiderChart chart, ChartStyle style) { - super(chart, style); - } - - /** - * @return the axesFactors - */ - public String[] getAxesFactors() { - return axesFactors; - } - - /** - * @return the axisFactorColor - */ - public RGB getAxisFactorColor() { - return swtAxisFactorColor; - } - - /** - * @return the axisFactorColors - */ - public RGB[] getAxisFactorColors() { - return swtAxisFactorColors; - } - - /** - * @return the backStyle - */ - public FillStyle getBackStyle() { - return backStyle; - } - - /** - * @return the border - */ - public LineStyle getBorder() { - return border; - } - - /** - * @return the chartRadius - */ - public double getChartRadius() { - return chartRadius; - } - - /** - * @return the gridStyle - */ - public LineStyle getGridStyle() { - return gridStyle; - } - - /** - * @return the maxScaleFactors - */ - public double[] getMaxScaleFactors() { - return maxScaleFactors; - } - - /** - * @return the minScaleFactors - */ - public double[] getMinScaleFactors() { - return minScaleFactors; - } - - /** - * @return the pointColors - */ - public RGB[] getPointColors() { - return pointColors; - } - - /** - * @return the pointColorScale - */ - public double[] getPointColorScale() { - return pointColorScale; - } - - /** - * @return the scalingDivisions - */ - public int getScalingDivisions() { - return scalingDivisions; - } - - /** - * @return the scalingLabelFormat - */ - public Object[] getScalingLabelFormat() { - return scalingLabelFormat; - } - - /** - * @return the drawCircle - */ - public boolean isDrawCircle() { - return drawCircle; - } - - /** - * @return the markScalesOnEveryAxis - */ - public boolean isMarkScalesOnEveryAxis() { - return markScalesOnEveryAxis; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - protected void plotSequence(SpiderChartSwtGraphics graphics, DataSequence seq, - int sequenceNumber) { - if(!(seq instanceof LineDataSequence)) { - return; - } - LineDataSequence line = (LineDataSequence)seq; - seq.getHotAreas().clear(); - 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(); - } - } - } - } - - /** - * @param axesFactors - * the axesFactors to set - */ - public void setAxesFactors(String[] axesFactors) { - this.axesFactors = axesFactors; - } - - /** - * @param axisFactorColor - * the axisFactorColor to set - */ - public void setAxisFactorColor(RGB swtAxisFactorColor) { - this.swtAxisFactorColor = swtAxisFactorColor; - } - - /** - * @param axisFactorColors - * the axisFactorColors to set - */ - public void setAxisFactorColors(RGB[] swtAxisFactorColors) { - this.swtAxisFactorColors = swtAxisFactorColors; - } - - /** - * @param axisFactorFont - * the axisFactorFont to set - */ - public void setAxisFactorFont(FontData axisFactorFontData) { - this.axisFactorFontData = axisFactorFontData; - } - - /** - * @param backStyle - * the backStyle to set - */ - public void setBackStyle(FillStyle backStyle) { - this.backStyle = backStyle; - } - - /** - * @param border - * the border to set - */ - public void setBorder(LineStyle border) { - this.border = border; - } - - /** - * @param chartRadius - * the chartRadius to set - */ - public void setChartRadius(double chartRadius) { - this.chartRadius = chartRadius; - } - - /** - * @param drawCircle - * the drawCircle to set - */ - public void setDrawCircle(boolean drawCircle) { - this.drawCircle = drawCircle; - } - - /** - * @param gridFont - * the gridFont to set - */ - public void setGridFontData(FontData gridFontData) { - this.gridFontData = gridFontData; - } - - /** - * @param gridFontColor - * the gridFontColor to set - */ - public void setGridFontColor(RGB swtGridFontColor) { - this.swtGridFontColor = swtGridFontColor; - } - - /** - * @param gridStyle - * the gridStyle to set - */ - public void setGridStyle(LineStyle gridStyle) { - this.gridStyle = gridStyle; - } - - /** - * @param markScalesOnEveryAxis - * the markScalesOnEveryAxis to set - */ - public void setMarkScalesOnEveryAxis(boolean markScalesOnEveryAxis) { - this.markScalesOnEveryAxis = markScalesOnEveryAxis; - } - - /** - * @param maxScaleFactors - * the maxScaleFactors to set - */ - public void setMaxScaleFactors(double[] maxScaleFactors) { - this.maxScaleFactors = maxScaleFactors; - } - - /** - * @param minScaleFactors - * the minScaleFactors to set - */ - public void setMinScaleFactors(double[] minScaleFactors) { - this.minScaleFactors = minScaleFactors; - } - - /** - * @param pointColors - * the pointColors to set - */ - public void setPointColors(RGB[] pointColors) { - this.pointColors = pointColors; - } - - /** - * @param pointColorScale - * the pointColorScale to set - */ - public void setPointColorScale(double[] pointColorScale) { - this.pointColorScale = pointColorScale; - } - - /** - * @param scalingDivisions - * the scalingDivisions to set - */ - public void setScalingDivisions(int scalingDivisions) { - this.scalingDivisions = scalingDivisions; - } - - /** - * @param scalingLabelFormat - * the scalingLabelFormat to set - */ - public void setScalingLabelFormat(Object... scalingLabelFormat) { - this.scalingLabelFormat = Arrays.asList(scalingLabelFormat).toArray(); - } - - /** */ - public void use(SpiderChart model) { - requireNonNull(model); - maxScaleFactors = model.maxScales(); - minScaleFactors = model.minScales(); - axesFactors = model.axesNames(); - scalingLabelFormat = model.axesScalingLabelFormats(); - } - - /** Disposes the plotter's resources. */ - public void dispose() { - for(DataSequence ds : data) { - ds.dispose(); - } - } - - /** plots the values */ - public void plot(SpiderChartSwtGraphics g) { - // FIXME: remove debug rectangle - g.getGraphics().drawRectangle(getX(), getY(), getWidth(), getHeight()); - - for(int i = 0; i < data.size(); i++) { - plotSequence(g, data.get(i), i); - } - } - - /** Returns depth. */ - public int getDepth() { - return depth; - } - - /** Plots the axes of the spider chart. */ - public void 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; - - 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); - - // draw line - double angleRad = Math.PI * angleDegree / 180.0; - int extentX = (int)(Math.cos(angleRad) * extent); - int outerX = centerX + extentX; - int extentY = (int)(Math.sin(angleRad) * extent); - int outerY = centerY + extentY; - AxisStyle aStyle = style.getAxisStyle(axis); - aStyle.getLineStyle().draw(graphics, centerX, centerY, outerX, outerY); - // draw label - drawAxisLabel(graphics, axis, aStyle, centerX, centerY, outerX, outerY); - // 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, extentX, extentY); - drawSegmentIndicator(graphics, lbl, aStyle, centerX, centerY, segmentPoint); - } - - angleDegree = (angleDegree + segmentDegree) % 360.0; - } - } - - /** 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(); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/DataSequence.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/DataSequence.java deleted file mode 100644 index e9f974baec0f23989b6bc8e6d1884df51746b059..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/DataSequence.java +++ /dev/null @@ -1,242 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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 - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSequence.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSequence.java deleted file mode 100644 index 8dc8853df0d3dfca5ccbf83e1419ebbee564cdc9..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/sequence/LineDataSequence.java +++ /dev/null @@ -1,301 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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(); - } - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java index e54d3c51f4b1e2c9f98d1366a417f29b18a204e2..0b5094051e5dfb33c2442843be4c4d3ac330a391 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/style/ChartStyle.java @@ -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; diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/swt/SpiderChartCanvas.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/swt/SpiderChartCanvas.java deleted file mode 100644 index 5df2796b569d0591c077a45799dbc7efb0ef474d..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/swt/SpiderChartCanvas.java +++ /dev/null @@ -1,147 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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.CTRL; -import static org.fortiss.tooling.spiderchart.gc.AbstractGraphicsSupplier.getGraphics; -import static org.fortiss.tooling.spiderchart.gc.AbstractGraphicsSupplier.startUiThread; - -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.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; - -/** - * Represents a canvas on which chart will be displayed - * - * @author mondal - * @author $Author$ - * @version $Rev$ - * @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603 - */ -public final class SpiderChartCanvas extends Canvas implements ISpiderChartListener { - - /** Actual Spider Chart Ref */ - private SpiderChartOld chart = null; - - /** 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} */ - @Override - public void mouseDown(final MouseEvent e) { - SpiderChartCanvas.this.mouseClick(); - } - }; - this.addMouseListener(mouseAdapter); - - this.addControlListener(new ControlListener() { - /** {@inheritDoc} */ - @Override - public void controlMoved(final ControlEvent e) { - // Not used - } - - /** {@inheritDoc} */ - @Override - public void controlResized(final ControlEvent e) { - SpiderChartCanvas.this.resizeChart(); - } - }); - } - - /** Returns the spider chart */ - public SpiderChartOld getChart() { - return this.chart; - } - - /** Mouse Click event */ - private void mouseClick() { - if(this.chart != null) { - this.chart.mouseClick(); - } - } - - /** 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 - } - - /** Draws the Spider Chart */ - protected void paintChart(final PaintEvent e) { - try { - this.resizeChart(); - SpiderChartSwtGraphics g = getGraphics(e.gc); - this.chart.paint(g); - g.dispose(); - } catch(final 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); - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/swt/SpiderChartViewer.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/swt/SpiderChartViewer.java deleted file mode 100644 index 0b320cd3aa7084a1333f76d2f4d326e805b07bfc..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/swt/SpiderChartViewer.java +++ /dev/null @@ -1,258 +0,0 @@ -/*--------------------------------------------------------------------------+ -$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; - } -} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartLegend.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java similarity index 97% rename from org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartLegend.java rename to org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java index 32f6ec7ad44f96789799fd7c56353ae2f69c21df..d35dd01a5508f41efa4d1b56dfa80a4050123fae 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartLegend.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartLegendWidget.java @@ -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); } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java new file mode 100644 index 0000000000000000000000000000000000000000..21a2b2e7a701966193a3b82f25b90fd1bef3c3a6 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartSWTCanvas.java @@ -0,0 +1,152 @@ +/*--------------------------------------------------------------------------+ +$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 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.PaintEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.fortiss.tooling.spiderchart.gc.swt.SpiderChartSwtGraphics; +import org.fortiss.tooling.spiderchart.model.SpiderChart; +import org.fortiss.tooling.spiderchart.style.ChartStyle; + +/** + * Represents a canvas on which chart will be displayed + * + * @author mondal + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603 + */ +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 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(MouseEvent e) { + SpiderChartSWTCanvas.this.mouseClick(); + } + }); + + this.addControlListener(new ControlListener() { + @Override + public void controlMoved(ControlEvent e) { + // Not used + } + + @Override + public void controlResized(ControlEvent e) { + SpiderChartSWTCanvas.this.resizeChart(); + } + }); + } + + /** 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() { + // feature currently disabled + } + + /** Mouse Moved Event */ + private void mouseMoved(MouseEvent e) { + // feature currently disabled + } + + /** Draws the Spider Chart */ + protected void paintChart(PaintEvent e) { + try { + 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(); + } + } + +} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartTitle.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java similarity index 93% rename from org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartTitle.java rename to org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java index ffc6f77a2c5fccbebeaeb605d5d8645b424cc381..89fdc6ac8a26eac948079b7080867d4f47bda3a9 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartTitle.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartTitleWidget.java @@ -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); } diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartViewer.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartViewer.java new file mode 100644 index 0000000000000000000000000000000000000000..9c3188bea55a9ad654b7e9d5cb880bcd22735488 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartViewer.java @@ -0,0 +1,88 @@ +/*--------------------------------------------------------------------------+ +$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 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; + +/** + * 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 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 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 dispose() { + canvas.dispose(); + super.dispose(); + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java new file mode 100644 index 0000000000000000000000000000000000000000..b18e76ca45cef262e54b26940298354057505719 --- /dev/null +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidget.java @@ -0,0 +1,500 @@ +/*--------------------------------------------------------------------------+ +$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(); + } +} diff --git a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartComponentBase.java b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidgetBase.java similarity index 93% rename from org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartComponentBase.java rename to org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidgetBase.java index d7b599fbcc59031a3e24d02ae85fcb84c4f5cc27..a98cdb5d782d8dd9f4905894973a5affe038141a 100644 --- a/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/plotter/SpiderChartComponentBase.java +++ b/org.fortiss.tooling.spiderchart.ui/trunk/src/org/fortiss/tooling/spiderchart/widget/SpiderChartWidgetBase.java @@ -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.fortiss.tooling.spiderchart.model.SpiderChart; import org.fortiss.tooling.spiderchart.style.ChartStyle; @@ -29,7 +29,7 @@ import org.fortiss.tooling.spiderchart.style.ChartStyle; * @version $Rev$ * @ConQAT.Rating GREEN Hash: 13207B1B51F8F60D2122999D2EDB0603 */ -public abstract class SpiderChartComponentBase { +public abstract class SpiderChartWidgetBase { /** The spider chart this component belongs to. */ protected final SpiderChart chart; @@ -49,7 +49,7 @@ public abstract class SpiderChartComponentBase { protected int y; /** Constructor. */ - public SpiderChartComponentBase(SpiderChart chart, ChartStyle style) { + public SpiderChartWidgetBase(SpiderChart chart, ChartStyle style) { this.chart = chart; this.style = style; }