From 992bb822486d5a47fd0211d21dbbcf8392cb8c7f Mon Sep 17 00:00:00 2001 From: timmolter <tim.molter@gmail.com> Date: Sat, 22 Sep 2012 21:13:13 +0200 Subject: [PATCH] deleted in conjunction with a refactor move --- src/main/java/com/xeiam/xchart/Axis.java | 234 --------------- src/main/java/com/xeiam/xchart/AxisPair.java | 155 ---------- src/main/java/com/xeiam/xchart/AxisTick.java | 280 ------------------ .../java/com/xeiam/xchart/AxisTickLabels.java | 118 -------- .../java/com/xeiam/xchart/AxisTickMarks.java | 113 ------- src/main/java/com/xeiam/xchart/AxisTitle.java | 150 ---------- .../java/com/xeiam/xchart/ChartTitle.java | 101 ------- src/main/java/com/xeiam/xchart/Legend.java | 153 ---------- src/main/java/com/xeiam/xchart/Plot.java | 72 ----- .../java/com/xeiam/xchart/PlotContent.java | 162 ---------- .../java/com/xeiam/xchart/PlotSurface.java | 129 -------- .../java/com/xeiam/xchart/XChartJPanel.java | 51 ---- .../xeiam/xchart/interfaces/IChartPart.java | 32 -- .../xeiam/xchart/interfaces/IHideable.java | 18 -- .../java/com/xeiam/xchart/series/Series.java | 267 ----------------- .../com/xeiam/xchart/series/SeriesColor.java | 116 -------- .../xeiam/xchart/series/SeriesLineStyle.java | 104 ------- .../com/xeiam/xchart/series/SeriesMarker.java | 100 ------- .../xeiam/xchart/series/markers/Circle.java | 33 --- .../xeiam/xchart/series/markers/Diamond.java | 52 ---- .../xeiam/xchart/series/markers/Marker.java | 34 --- .../xeiam/xchart/series/markers/Square.java | 34 --- .../xchart/series/markers/TriangleDown.java | 49 --- .../xchart/series/markers/TriangleUp.java | 49 --- 24 files changed, 2606 deletions(-) delete mode 100644 src/main/java/com/xeiam/xchart/Axis.java delete mode 100644 src/main/java/com/xeiam/xchart/AxisPair.java delete mode 100644 src/main/java/com/xeiam/xchart/AxisTick.java delete mode 100644 src/main/java/com/xeiam/xchart/AxisTickLabels.java delete mode 100644 src/main/java/com/xeiam/xchart/AxisTickMarks.java delete mode 100644 src/main/java/com/xeiam/xchart/AxisTitle.java delete mode 100644 src/main/java/com/xeiam/xchart/ChartTitle.java delete mode 100644 src/main/java/com/xeiam/xchart/Legend.java delete mode 100644 src/main/java/com/xeiam/xchart/Plot.java delete mode 100644 src/main/java/com/xeiam/xchart/PlotContent.java delete mode 100644 src/main/java/com/xeiam/xchart/PlotSurface.java delete mode 100644 src/main/java/com/xeiam/xchart/XChartJPanel.java delete mode 100644 src/main/java/com/xeiam/xchart/interfaces/IChartPart.java delete mode 100644 src/main/java/com/xeiam/xchart/interfaces/IHideable.java delete mode 100644 src/main/java/com/xeiam/xchart/series/Series.java delete mode 100644 src/main/java/com/xeiam/xchart/series/SeriesColor.java delete mode 100644 src/main/java/com/xeiam/xchart/series/SeriesLineStyle.java delete mode 100644 src/main/java/com/xeiam/xchart/series/SeriesMarker.java delete mode 100644 src/main/java/com/xeiam/xchart/series/markers/Circle.java delete mode 100644 src/main/java/com/xeiam/xchart/series/markers/Diamond.java delete mode 100644 src/main/java/com/xeiam/xchart/series/markers/Marker.java delete mode 100644 src/main/java/com/xeiam/xchart/series/markers/Square.java delete mode 100644 src/main/java/com/xeiam/xchart/series/markers/TriangleDown.java delete mode 100644 src/main/java/com/xeiam/xchart/series/markers/TriangleUp.java diff --git a/src/main/java/com/xeiam/xchart/Axis.java b/src/main/java/com/xeiam/xchart/Axis.java deleted file mode 100644 index 539a6e53..00000000 --- a/src/main/java/com/xeiam/xchart/Axis.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.font.FontRenderContext; -import java.awt.font.TextLayout; -import java.math.BigDecimal; - -import com.xeiam.xchart.interfaces.IChartPart; - -/** - * Axis - * - * @author timmolter - */ -public class Axis implements IChartPart { - - public enum AxisType { - - NUMBER, DATE; - } - - /** parent */ - protected AxisPair axisPair; - - /** the axisType */ - protected AxisType axisType; - - /** the axis title */ - protected AxisTitle axisTitle; - - /** the axis tick */ - protected AxisTick axisTick; - - /** the axis direction */ - protected Direction direction; - - protected BigDecimal min = null; - - protected BigDecimal max = null; - - /** the bounds */ - private Rectangle bounds; - - /** the paint zone */ - private Rectangle paintZone; - - /** An axis direction */ - protected enum Direction { - - /** the constant to represent X axis */ - X, - - /** the constant to represent Y axis */ - Y - } - - /** - * Constructor - * - * @param direction the axis direction (X or Y) - * @param chart the chart - */ - protected Axis(AxisPair axisPair, Direction direction) { - - this.axisPair = axisPair; - this.direction = direction; - - axisTitle = new AxisTitle(this); - axisTick = new AxisTick(this); - } - - /** - * @param min - * @param max - */ - protected void addMinMax(BigDecimal min, BigDecimal max) { - - // System.out.println(min); - // System.out.println(max); - if (this.min == null || min.compareTo(this.min) < 0) { - this.min = min; - } - if (this.max == null || max.compareTo(this.max) > 0) { - this.max = max; - } - - // System.out.println(this.min); - // System.out.println(this.max); - } - - protected void setAxisType(AxisType axisType) { - - if (this.axisType != null && this.axisType != axisType) { - throw new IllegalArgumentException("Date and Number Axes cannot be mixed on the same chart!! "); - } - this.axisType = axisType; - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - - protected Rectangle getPaintZone() { - - return paintZone; - } - - protected AxisTitle getAxisTitle() { - - return axisTitle; - } - - protected void setAxisTitle(String title) { - - this.axisTitle.setText(title); - } - - protected void setAxisTitle(AxisTitle axisTitle) { - - this.axisTitle = axisTitle; - } - - /** - * @return - */ - protected int getSizeHint() { - - if (direction == Direction.X) { // X-Axis - - // Axis title - double titleHeight = 0.0; - if (axisTitle.isVisible) { - TextLayout textLayout = new TextLayout(axisTitle.getText(), axisTitle.getFont(), new FontRenderContext(null, true, false)); - Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - titleHeight = rectangle.getHeight() + AxisTitle.AXIS_TITLE_PADDING; - } - - // Axis tick labels - double axisTickLabelsHeight = 0.0; - if (axisTick.isVisible) { - TextLayout textLayout = new TextLayout("0", axisTick.axisTickLabels.font, new FontRenderContext(null, true, false)); - Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - axisTickLabelsHeight = rectangle.getHeight() + AxisTick.AXIS_TICK_PADDING + AxisTickMarks.TICK_LENGTH + Plot.PLOT_PADDING; - } - return (int) (titleHeight + axisTickLabelsHeight); - } else { // Y-Axis - return 0; // We layout the yAxis first depending in the xAxis height hint. We don't care about the yAxis height hint - } - } - - @Override - public void paint(Graphics2D g) { - - paintZone = new Rectangle(); - bounds = new Rectangle(); - - // determine Axis bounds - if (direction == Direction.Y) { // Y-Axis - - // calculate paint zone - // ---- - // | - // | - // | - // | - // ---- - int xOffset = Chart.CHART_PADDING; - int yOffset = (int) (axisPair.getChartTitleBounds().getY() + axisPair.getChartTitleBounds().getHeight() + Chart.CHART_PADDING); - int width = 80; // arbitrary, final width depends on Axis tick labels - int height = axisPair.chart.height - yOffset - axisPair.xAxis.getSizeHint() - Chart.CHART_PADDING; - Rectangle yAxisRectangle = new Rectangle(xOffset, yOffset, width, height); - this.paintZone = yAxisRectangle; - // g.setColor(Color.green); - // g.draw(yAxisRectangle); - - // fill in Axis with sub-components - axisTitle.paint(g); - axisTick.paint(g); - - xOffset = (int) paintZone.getX(); - yOffset = (int) paintZone.getY(); - width = (int) (axisTitle.isVisible ? axisTitle.getBounds().getWidth() : 0) + (int) axisTick.getBounds().getWidth(); - height = (int) paintZone.getHeight(); - bounds = new Rectangle(xOffset, yOffset, width, height); - // g.setColor(Color.yellow); - // g.draw(bounds); - - } else { // X-Axis - - // calculate paint zone - // |____________________| - - int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (axisPair.yAxis.axisTick.isVisible ? Plot.PLOT_PADDING : 0) + Chart.CHART_PADDING); - int yOffset = (int) (axisPair.yAxis.getBounds().getY() + axisPair.yAxis.getBounds().getHeight()); - int width = (int) (axisPair.chart.width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (axisPair.chart.chartLegend.isVisible ? 3 : 2) * Chart.CHART_PADDING); - int height = this.getSizeHint(); - Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); - this.paintZone = xAxisRectangle; - // g.setColor(Color.green); - // g.draw(xAxisRectangle); - - axisTitle.paint(g); - axisTick.paint(g); - - xOffset = (int) paintZone.getX(); - yOffset = (int) paintZone.getY(); - width = (int) paintZone.getWidth(); - height = (int) ((axisTitle.isVisible ? axisTitle.getBounds().getHeight() : 0) + (int) axisTick.getBounds().getHeight()); - bounds = new Rectangle(xOffset, yOffset, width, height); - bounds = new Rectangle(xOffset, yOffset, width, height); - // g.setColor(Color.yellow); - // g.draw(bounds); - } - - } -} diff --git a/src/main/java/com/xeiam/xchart/AxisPair.java b/src/main/java/com/xeiam/xchart/AxisPair.java deleted file mode 100644 index 94e9c4d4..00000000 --- a/src/main/java/com/xeiam/xchart/AxisPair.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -import com.xeiam.xchart.Axis.AxisType; -import com.xeiam.xchart.interfaces.IChartPart; -import com.xeiam.xchart.series.Series; - -/** - * @author timmolter - */ -public class AxisPair implements IChartPart { - - /** parent */ - protected Chart chart; - - protected Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>(); - - private int seriesCount; - - protected Axis xAxis; - protected Axis yAxis; - - /** - * Constructor. - * - * @param chart the chart - */ - protected AxisPair(Chart chart) { - - this.chart = chart; - seriesCount = 0; - - // add axes - xAxis = new Axis(this, Axis.Direction.X); - yAxis = new Axis(this, Axis.Direction.Y); - } - - /** - * @param <T> - * @param xData - * @param yData - */ - protected <T> Series addSeries(String seriesName, Collection<T> xData, Collection<Number> yData, Collection<Number> errorBars) { - - // Sanity checks - if (seriesName == null) { - throw new IllegalArgumentException("Series Name cannot be null!!!"); - } - if (yData == null) { - throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); - } - if (yData.size() == 0) { - throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); - } - if (xData != null && xData.size() == 0) { - throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); - } - - Series series = null; - if (xData != null) { - // Check if xAxis series contains Number or Date data - Iterator<?> itr = xData.iterator(); - Object dataPoint = itr.next(); - if (dataPoint instanceof Number) { - xAxis.setAxisType(AxisType.NUMBER); - } else if (dataPoint instanceof Date) { - xAxis.setAxisType(AxisType.DATE); - } - yAxis.setAxisType(AxisType.NUMBER); - series = new Series(seriesName, xData, xAxis.axisType, yData, yAxis.axisType, errorBars); - } else { // generate xData - Collection<Number> generatedXData = new ArrayList<Number>(); - for (int i = 1; i < yData.size(); i++) { - generatedXData.add(i); - } - xAxis.setAxisType(AxisType.NUMBER); - yAxis.setAxisType(AxisType.NUMBER); - series = new Series(seriesName, generatedXData, xAxis.axisType, yData, yAxis.axisType, errorBars); - } - - // Sanity check - if (xData != null && xData.size() != yData.size()) { - throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!! "); - } - if (errorBars != null && errorBars.size() != yData.size()) { - throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!! "); - } - - seriesMap.put(seriesCount++, series); - - // add min/max to axis - xAxis.addMinMax(series.getxMin(), series.getxMax()); - yAxis.addMinMax(series.getyMin(), series.getyMax()); - - return series; - } - - protected Rectangle getChartTitleBounds() { - - return chart.chartTitle.getBounds(); - } - - protected Rectangle getChartLegendBounds() { - - return chart.chartLegend.getBounds(); - } - - protected static int getTickSpace(int workingSpace) { - - return (int) (workingSpace * 0.95); - } - - protected static int getMargin(int workingSpace, int tickSpace) { - - int marginSpace = workingSpace - tickSpace; - return (int) (marginSpace / 2.0); - } - - @Override - public void paint(Graphics2D g) { - - yAxis.paint(g); - xAxis.paint(g); - } - - @Override - public Rectangle getBounds() { - - return null; // should never be called - } - -} diff --git a/src/main/java/com/xeiam/xchart/AxisTick.java b/src/main/java/com/xeiam/xchart/AxisTick.java deleted file mode 100644 index 76a09f5b..00000000 --- a/src/main/java/com/xeiam/xchart/AxisTick.java +++ /dev/null @@ -1,280 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.text.SimpleDateFormat; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -import com.xeiam.xchart.Axis.AxisType; -import com.xeiam.xchart.interfaces.IChartPart; -import com.xeiam.xchart.interfaces.IHideable; - -/** - * An axis tick. - */ -public class AxisTick implements IChartPart, IHideable { - - /** the default tick mark step hint */ - private static final int DEFAULT_TICK_MARK_STEP_HINT = 64; - - /** the padding between the tick labels and the tick marks */ - protected final static int AXIS_TICK_PADDING = 4; - - /** parent */ - protected Axis axis; - - /** the axisticklabels */ - protected AxisTickLabels axisTickLabels; - - /** the axistickmarks */ - protected AxisTickMarks axisTickMarks; - - /** the arraylist of tick label position in pixels */ - protected List<Integer> tickLocations; - - /** the arraylist of tick label values */ - protected List<String> tickLabels; - - private int workingSpace; - - /** the Locale for Date tick labels */ - protected Locale locale; - - protected String normalDecimalPattern; - protected String scientificDecimalPattern; - protected String datePattern; - - /** the bounds */ - private Rectangle bounds; - - /** the visibility state of axistick */ - protected boolean isVisible = true; // default to true - - /** - * Constructor - * - * @param axis the axis - */ - protected AxisTick(Axis axis) { - - this.axis = axis; - axisTickLabels = new AxisTickLabels(this); - axisTickMarks = new AxisTickMarks(this); - - // formatting - locale = Locale.getDefault(); - normalDecimalPattern = "#.###"; - scientificDecimalPattern = "0.###E0"; - datePattern = "HHmmss"; - - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - if (axis.direction == Axis.Direction.Y) { - workingSpace = (int) axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks - // System.out.println("workingspace= " + workingSpace); - } else { - workingSpace = (int) axis.getPaintZone().getWidth(); // number of pixels the axis has to work with for drawing AxisTicks - // System.out.println("workingspace= " + workingSpace); - } - - determineAxisTick(); - - // for (Integer position : tickLocations) { - // System.out.println(position); - // } - // for (String label : tickLabels) { - // System.out.println(label); - // } - - if (isVisible) { - axisTickLabels.paint(g); - axisTickMarks.paint(g); - - if (axis.direction == Axis.Direction.Y) { - bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()), - (int) (axisTickLabels.getBounds().getWidth() + AXIS_TICK_PADDING + axisTickMarks.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight())); - // g.setColor(Color.red); - // g.draw(bounds); - } else { - bounds = new Rectangle((int) axisTickMarks.getBounds().getX(), (int) (axisTickMarks.getBounds().getY()), (int) axisTickLabels.getBounds().getWidth(), (int) (axisTickMarks.getBounds().getHeight() - + AXIS_TICK_PADDING + axisTickLabels.getBounds().getHeight())); - // g.setColor(Color.red); - // g.draw(bounds); - } - } - - } - - /** - * - */ - private void determineAxisTick() { - - tickLocations = new LinkedList<Integer>(); - tickLabels = new LinkedList<String>(); - - // System.out.println("workingSpace= " + workingSpace); - - int tickSpace = AxisPair.getTickSpace(workingSpace); - // System.out.println("tickSpace= " + tickSpace); - - int margin = AxisPair.getMargin(workingSpace, tickSpace); - - // a check if all axis data are the exact same values - if (axis.max == axis.min) { - tickLabels.add(format(axis.max)); - tickLocations.add((int) (margin + tickSpace / 2.0)); - } else { - - final BigDecimal min = new BigDecimal(axis.min.doubleValue()); - BigDecimal firstPosition; - BigDecimal gridStep = getGridStep(tickSpace); - - double xyz = min.remainder(gridStep).doubleValue(); - if (xyz <= 0.0) { - firstPosition = min.subtract(min.remainder(gridStep)); - } else { - firstPosition = min.subtract(min.remainder(gridStep)).add(gridStep); - } - - for (BigDecimal b = firstPosition; b.compareTo(axis.max) <= 0; b = b.add(gridStep)) { - - // System.out.println("b= " + b); - tickLabels.add(format(b)); - int tickLabelPosition = (int) (margin + ((b.subtract(axis.min)).doubleValue() / (axis.max.subtract(axis.min)).doubleValue() * tickSpace)); - // System.out.println("tickLabelPosition= " + tickLabelPosition); - - tickLocations.add(tickLabelPosition); - } - } - } - - private BigDecimal getGridStep(int tickSpace) { - - double length = Math.abs(axis.max.subtract(axis.min).doubleValue()); - // System.out.println(axis.getMax()); - // System.out.println(axis.min); - // System.out.println(length); - double gridStepHint = length / tickSpace * DEFAULT_TICK_MARK_STEP_HINT; - - // gridStepHint --> mantissa * 10 ** exponent - // e.g. 724.1 --> 7.241 * 10 ** 2 - double mantissa = gridStepHint; - int exponent = 0; - if (mantissa == 0) { - exponent = 1; - } else if (mantissa < 1) { - while (mantissa < 1) { - mantissa *= 10.0; - exponent--; - } - } else { - while (mantissa >= 10) { - mantissa /= 10.0; - exponent++; - } - } - - // calculate the grid step with hint. - BigDecimal gridStep; - if (mantissa > 7.5) { - // gridStep = 10.0 * 10 ** exponent - gridStep = BigDecimal.TEN.multiply(pow(10, exponent)); - } else if (mantissa > 3.5) { - // gridStep = 5.0 * 10 ** exponent - gridStep = new BigDecimal(new Double(5).toString()).multiply(pow(10, exponent)); - } else if (mantissa > 1.5) { - // gridStep = 2.0 * 10 ** exponent - gridStep = new BigDecimal(new Double(2).toString()).multiply(pow(10, exponent)); - } else { - // gridStep = 1.0 * 10 ** exponent - gridStep = pow(10, exponent); - } - return gridStep; - } - - /** - * Calculates the value of the first argument raised to the power of the second argument. - * - * @param base the base - * @param exponent the exponent - * @return the value <tt>a<sup>b</sup></tt> in <tt>BigDecimal</tt> - */ - private BigDecimal pow(double base, int exponent) { - - BigDecimal value; - if (exponent > 0) { - value = new BigDecimal(new Double(base).toString()).pow(exponent); - } else { - value = BigDecimal.ONE.divide(new BigDecimal(new Double(base).toString()).pow(-exponent)); - } - return value; - } - - private String format(BigDecimal value) { - - if (axis.axisType == AxisType.NUMBER) { - - NumberFormat nf = NumberFormat.getNumberInstance(locale); - - if (Math.abs(value.doubleValue()) <= 9999 && Math.abs(value.doubleValue()) > .0001 || value.doubleValue() == 0) { - - DecimalFormat normalFormat = (DecimalFormat) nf; - normalFormat.applyPattern(normalDecimalPattern); - return normalFormat.format(value.doubleValue()); - - } else { - - DecimalFormat scientificFormat = (DecimalFormat) nf; - scientificFormat.applyPattern(scientificDecimalPattern); - return scientificFormat.format(value.doubleValue()); - - } - } else { - - // TODO set this more intelligently - SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, locale); - simpleDateformat.applyPattern(datePattern); - return simpleDateformat.format(value.longValueExact()); - - } - - } - - @Override - public void setVisible(boolean isVisible) { - - this.isVisible = isVisible; - } -} diff --git a/src/main/java/com/xeiam/xchart/AxisTickLabels.java b/src/main/java/com/xeiam/xchart/AxisTickLabels.java deleted file mode 100644 index 2b8dbc2a..00000000 --- a/src/main/java/com/xeiam/xchart/AxisTickLabels.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.font.FontRenderContext; -import java.awt.font.TextLayout; - -import com.xeiam.xchart.interfaces.IChartPart; - -/** - * Axis tick labels - */ -public class AxisTickLabels implements IChartPart { - - /** parent */ - private AxisTick axisTick; - - /** the font */ - protected Font font; - - /** the bounds */ - private Rectangle bounds; - - /** - * Constructor - * - * @param axisTick - */ - protected AxisTickLabels(AxisTick axisTick) { - - this.axisTick = axisTick; - font = new Font(Font.SANS_SERIF, Font.BOLD, 12); // default font - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - g.setColor(axisTick.axis.axisPair.chart.fontColor); - - if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis - - int xOffset = (int) (axisTick.axis.getAxisTitle().getBounds().getX() + axisTick.axis.getAxisTitle().getBounds().getWidth()); - int yOffset = (int) (axisTick.axis.getPaintZone().getY()); - int maxTickLabelWidth = 0; - for (int i = 0; i < axisTick.tickLabels.size(); i++) { - - String tickLabel = axisTick.tickLabels.get(i); - int tickLocation = axisTick.tickLocations.get(i); - - FontRenderContext frc = g.getFontRenderContext(); - // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); - TextLayout layout = new TextLayout(tickLabel, font, frc); - Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); - layout.draw(g, xOffset, (int) (yOffset + axisTick.axis.getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); - - if (tickLabelBounds.getWidth() > maxTickLabelWidth) { - maxTickLabelWidth = (int) tickLabelBounds.getWidth(); - } - } - - // bounds - bounds = new Rectangle(xOffset, yOffset, maxTickLabelWidth, (int) axisTick.axis.getPaintZone().getHeight()); - // g.setColor(Color.blue); - // g.draw(bounds); - - } else { // X-Axis - - int xOffset = (int) (axisTick.axis.getPaintZone().getX()); - int yOffset = (int) (axisTick.axis.getAxisTitle().getBounds().getY()); - int maxTickLabelHeight = 0; - for (int i = 0; i < axisTick.tickLabels.size(); i++) { - - String tickLabel = axisTick.tickLabels.get(i); - int tickLocation = axisTick.tickLocations.get(i); - - FontRenderContext frc = g.getFontRenderContext(); - TextLayout layout = new TextLayout(tickLabel, font, frc); - Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); - layout.draw(g, (int) (xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0), yOffset); - - if (tickLabelBounds.getHeight() > maxTickLabelHeight) { - maxTickLabelHeight = (int) tickLabelBounds.getHeight(); - } - } - - // bounds - bounds = new Rectangle(xOffset, yOffset - maxTickLabelHeight, (int) axisTick.axis.getPaintZone().getWidth(), maxTickLabelHeight); - // g.setColor(Color.blue); - // g.draw(bounds); - - } - - } -} diff --git a/src/main/java/com/xeiam/xchart/AxisTickMarks.java b/src/main/java/com/xeiam/xchart/AxisTickMarks.java deleted file mode 100644 index 5f026221..00000000 --- a/src/main/java/com/xeiam/xchart/AxisTickMarks.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.BasicStroke; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.Stroke; - -import com.xeiam.xchart.interfaces.IChartPart; - -/** - * Axis tick marks. - */ -public class AxisTickMarks implements IChartPart { - - /** the tick length */ - public static final int TICK_LENGTH = 3; - - /** parent */ - private AxisTick axisTick; - - /** the line style */ - private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); - - /** the bounds */ - private Rectangle bounds; - - /** - * Constructor - * - * @param axisTick - */ - protected AxisTickMarks(AxisTick axisTick) { - - this.axisTick = axisTick; - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - g.setColor(axisTick.axis.axisPair.chart.bordersColor); - - if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis - - int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + AxisTick.AXIS_TICK_PADDING); - int yOffset = (int) (axisTick.axis.getPaintZone().getY()); - - // tick marks - for (int i = 0; i < axisTick.tickLabels.size(); i++) { - - int tickLocation = axisTick.tickLocations.get(i); - - g.setColor(axisTick.axis.axisPair.chart.bordersColor); - g.setStroke(stroke); - - g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + TICK_LENGTH, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation)); - - } - // Line - g.drawLine(xOffset + TICK_LENGTH, yOffset, xOffset + TICK_LENGTH, yOffset + (int) axisTick.axis.getPaintZone().getHeight()); - - // bounds - bounds = new Rectangle(xOffset, yOffset, TICK_LENGTH, (int) axisTick.axis.getPaintZone().getHeight()); - // g.setColor(Color.yellow); - // g.draw(bounds); - - } else { // X-Axis - - int xOffset = (int) (axisTick.axis.getPaintZone().getX()); - int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - AxisTick.AXIS_TICK_PADDING); - - // tick marks - for (int i = 0; i < axisTick.tickLabels.size(); i++) { - - int tickLocation = axisTick.tickLocations.get(i); - - g.setColor(axisTick.axis.axisPair.chart.bordersColor); - g.setStroke(stroke); - - g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - TICK_LENGTH); - } - // Line - g.drawLine(xOffset, yOffset - TICK_LENGTH, xOffset + (int) axisTick.axis.getPaintZone().getWidth(), yOffset - TICK_LENGTH); - - // bounds - bounds = new Rectangle(xOffset, yOffset - TICK_LENGTH, (int) axisTick.axis.getPaintZone().getWidth(), TICK_LENGTH); - // g.setColor(Color.yellow); - // g.draw(bounds); - } - } -} diff --git a/src/main/java/com/xeiam/xchart/AxisTitle.java b/src/main/java/com/xeiam/xchart/AxisTitle.java deleted file mode 100644 index dd8c94aa..00000000 --- a/src/main/java/com/xeiam/xchart/AxisTitle.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.font.FontRenderContext; -import java.awt.font.TextLayout; -import java.awt.geom.AffineTransform; - -import com.xeiam.xchart.interfaces.IHideable; - -/** - * AxisTitle - */ -public class AxisTitle implements IHideable { - - protected final static int AXIS_TITLE_PADDING = 10; - - /** parent */ - private Axis axis; - - /** the title text */ - protected String text = ""; // default to "" - - /** the visibility state of title */ - protected boolean isVisible = false; // default to false, set true if text is set - - /** the font */ - protected Font font; - - /** the bounds */ - private Rectangle bounds; - - /** - * Constructor. - * - * @param axis the axis - */ - protected AxisTitle(Axis axis) { - - this.axis = axis; - font = new Font(Font.SANS_SERIF, Font.BOLD, 12); // default font - } - - protected String getText() { - - return text; - } - - protected void setText(String text) { - - if (text.trim().equalsIgnoreCase("")) { - this.isVisible = false; - } else { - this.isVisible = true; - } - this.text = text; - } - - protected Font getFont() { - - return font; - } - - @Override - public void setVisible(boolean isVisible) { - - this.isVisible = isVisible; - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - g.setColor(axis.axisPair.chart.fontColor); - - if (axis.direction == Axis.Direction.Y) { - if (isVisible) { - - FontRenderContext frc = g.getFontRenderContext(); - TextLayout nonRotatedTextLayout = new TextLayout(text, font, frc); - Rectangle nonRotatedRectangle = nonRotatedTextLayout.getPixelBounds(null, 0, 0); - // System.out.println(nonRotatedRectangle); - - TextLayout rotatedTextLayout = new TextLayout(text, font.deriveFont(AffineTransform.getRotateInstance(Math.PI / -2.0, 0, 0)), frc); - // Rectangle rotatedRectangle = rotatedTextLayout.getPixelBounds(null, 0, 0); - // System.out.println(rotatedRectangle); - - int xOffset = (int) (axis.getPaintZone().getX() + nonRotatedRectangle.getHeight()); - int yOffset = (int) ((axis.getPaintZone().getHeight() + nonRotatedRectangle.getWidth()) / 2.0 + axis.getPaintZone().getY()); - rotatedTextLayout.draw(g, xOffset, yOffset); - - // bounds - bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight() + AXIS_TITLE_PADDING, - (int) nonRotatedRectangle.getWidth()); - // g.setColor(Color.blue); - // g.draw(bounds); - } else { - bounds = new Rectangle((int) axis.getPaintZone().getX(), (int) axis.getPaintZone().getY(), 0, (int) axis.getPaintZone().getHeight()); - } - - } else { - - if (isVisible) { - - FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, font, frc); - Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - // System.out.println(rectangle); - - int xOffset = (int) (axis.getPaintZone().getX() + (axis.getPaintZone().getWidth() - rectangle.getWidth()) / 2.0); - int yOffset = (int) (axis.getPaintZone().getY() + axis.getPaintZone().getHeight() - rectangle.getHeight()); - - textLayout.draw(g, xOffset, (float) (yOffset - rectangle.getY())); - - bounds = new Rectangle(xOffset, yOffset - AXIS_TITLE_PADDING, (int) rectangle.getWidth(), (int) rectangle.getHeight() + AXIS_TITLE_PADDING); - // g.setColor(Color.blue); - // g.draw(bounds); - - } else { - bounds = new Rectangle((int) axis.getPaintZone().getX(), (int) (axis.getPaintZone().getY() + axis.getPaintZone().getHeight()), (int) axis.getPaintZone().getWidth(), 0); - // g.setColor(Color.blue); - // g.draw(bounds); - - } - } - } -} diff --git a/src/main/java/com/xeiam/xchart/ChartTitle.java b/src/main/java/com/xeiam/xchart/ChartTitle.java deleted file mode 100644 index d85fb687..00000000 --- a/src/main/java/com/xeiam/xchart/ChartTitle.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.font.FontRenderContext; -import java.awt.font.TextLayout; - -import com.xeiam.xchart.interfaces.IHideable; - -/** - * Chart Title - */ -public class ChartTitle implements IHideable { - - /** parent */ - private Chart chart; - - /** the title text */ - protected String text = ""; // default to "" - - /** the visibility state of title */ - protected boolean isVisible = false; // default to false - - /** the font */ - protected Font font; - - /** the bounds */ - private Rectangle bounds; - - /** - * Constructor - * - * @param chart - */ - public ChartTitle(Chart chart) { - - this.chart = chart; - font = new Font(Font.SANS_SERIF, Font.BOLD, 14); // default font - } - - protected void setText(String text) { - - if (text.trim().equalsIgnoreCase("")) { - this.isVisible = false; - } else { - this.isVisible = true; - } - this.text = text; - } - - @Override - public void setVisible(boolean isVisible) { - - this.isVisible = isVisible; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - if (isVisible) { - - FontRenderContext frc = g.getFontRenderContext(); - TextLayout textLayout = new TextLayout(text, font, frc); - Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - int xOffset = (int) ((chart.width - rectangle.getWidth()) / 2.0); - int yOffset = (int) ((isVisible ? (Chart.CHART_PADDING - rectangle.getY()) : 0)); - - bounds = new Rectangle(xOffset, yOffset + (isVisible ? (int) rectangle.getY() : 0), (int) rectangle.getWidth(), (int) (isVisible ? rectangle.getHeight() : 0)); - // g.setColor(Color.green); - // g.draw(bounds); - - g.setColor(chart.fontColor); - textLayout.draw(g, xOffset, yOffset); - } - - } - - @Override - public Rectangle getBounds() { - - return bounds; - } -} \ No newline at end of file diff --git a/src/main/java/com/xeiam/xchart/Legend.java b/src/main/java/com/xeiam/xchart/Legend.java deleted file mode 100644 index 937cc616..00000000 --- a/src/main/java/com/xeiam/xchart/Legend.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Color; -import java.awt.Font; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.font.FontRenderContext; -import java.awt.font.TextLayout; -import java.util.Map; - -import com.xeiam.xchart.interfaces.IHideable; -import com.xeiam.xchart.series.Series; -import com.xeiam.xchart.series.markers.Marker; - -/** - * @author timmolter - */ -public class Legend implements IHideable { - - private static final int LEGEND_PADDING = 10; - - /** parent */ - private Chart chart; - - /** the visibility state of legend */ - protected boolean isVisible = true; // default to true - - /** the font */ - protected Font font; - - /** the background color */ - protected Color backgroundColor; - - /** the bounds */ - private Rectangle bounds; - - /** - * Constructor - * - * @param chart - */ - public Legend(Chart chart) { - - this.chart = chart; - backgroundColor = ChartColor.getAWTColor(ChartColor.LIGHT_GREY); // default background color - font = new Font(Font.SANS_SERIF, Font.PLAIN, 11); // default font - } - - @Override - public void setVisible(boolean isVisible) { - - this.isVisible = isVisible; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - if (isVisible) { - - Map<Integer, Series> seriesMap = chart.axisPair.seriesMap; - - // determine legend text content max width - int legendTextContentMaxWidth = 0; - int legendTextContentMaxHeight = 0; - - for (Integer seriesId : seriesMap.keySet()) { - Series series = seriesMap.get(seriesId); - TextLayout textLayout = new TextLayout(series.getName(), font, new FontRenderContext(null, true, false)); - Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - // System.out.println(rectangle); - if (rectangle.getWidth() > legendTextContentMaxWidth) { - legendTextContentMaxWidth = (int) rectangle.getWidth(); - } - if (rectangle.getHeight() > legendTextContentMaxHeight) { - legendTextContentMaxHeight = (int) rectangle.getHeight(); - } - } - - // determine legend content height - int legendContentHeight = 0; - int maxContentHeight = Math.max(legendTextContentMaxHeight, Marker.SIZE); - legendContentHeight = maxContentHeight * seriesMap.size() + LEGEND_PADDING * (seriesMap.size() - 1); - - // determine legend content width - int legendContentWidth = (int) (3.0 * Marker.SIZE + LEGEND_PADDING + legendTextContentMaxWidth); - - // Draw Legend Box - int legendBoxWidth = legendContentWidth + 2 * LEGEND_PADDING; - int legendBoxHeight = legendContentHeight + 2 * LEGEND_PADDING; - int xOffset = chart.width - legendBoxWidth - Chart.CHART_PADDING; - int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.chartTitle.getBounds().getY() + chart.chartTitle.getBounds().getHeight()); - - g.setColor(chart.bordersColor); - g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight); - g.setColor(backgroundColor); - g.fillRect(xOffset + 1, yOffset + 1, legendBoxWidth - 1, legendBoxHeight - 1); - - // Draw legend content inside legend box - int startx = xOffset + LEGEND_PADDING; - int starty = yOffset + LEGEND_PADDING; - for (Integer seriesId : seriesMap.keySet()) { - Series series = seriesMap.get(seriesId); - // paint line - if (series.getLineStyle() != null) { - g.setColor(series.getLineColor()); - g.setStroke(series.getLineStyle()); - g.drawLine(startx, starty - Marker.Y_OFFSET, (int) (startx + Marker.SIZE * 3.0), starty - Marker.Y_OFFSET); - } - // paint marker - if (series.getMarker() != null) { - g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, (int) (startx + (Marker.SIZE * 1.5)), starty - Marker.Y_OFFSET); - } - - // paint series name - g.setColor(chart.fontColor); - TextLayout layout = new TextLayout(series.getName(), font, new FontRenderContext(null, true, false)); - layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + LEGEND_PADDING), (starty + Marker.SIZE)); - starty = starty + legendTextContentMaxHeight + LEGEND_PADDING; - } - - // bounds - bounds = new Rectangle(xOffset, yOffset, legendBoxWidth, legendBoxHeight); - // g.setColor(Color.blue); - // g.draw(bounds); - } - - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - -} diff --git a/src/main/java/com/xeiam/xchart/Plot.java b/src/main/java/com/xeiam/xchart/Plot.java deleted file mode 100644 index 8ac0b03a..00000000 --- a/src/main/java/com/xeiam/xchart/Plot.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Graphics2D; -import java.awt.Rectangle; - -import com.xeiam.xchart.interfaces.IChartPart; - -/** - * @author timmolter - */ -public class Plot implements IChartPart { - - /** parent */ - protected Chart chart; - - protected PlotSurface plotSurface; - - protected PlotContent plotContent; - - public static final int PLOT_PADDING = 3; - - /** the bounds */ - private Rectangle bounds; - - protected Plot(Chart chart) { - - this.chart = chart; - this.plotSurface = new PlotSurface(this); - this.plotContent = new PlotContent(this); - } - - @Override - public Rectangle getBounds() { - - return bounds; - } - - @Override - public void paint(Graphics2D g) { - - bounds = new Rectangle(); - - // calculate bounds - int xOffset = (int) (chart.axisPair.yAxis.getBounds().getX() + chart.axisPair.yAxis.getBounds().getWidth() + (chart.axisPair.yAxis.axisTick.isVisible ? (Plot.PLOT_PADDING + 1) : 0)); - int yOffset = (int) (chart.axisPair.yAxis.getBounds().getY()); - int width = (int) chart.axisPair.xAxis.getBounds().getWidth(); - int height = (int) chart.axisPair.yAxis.getBounds().getHeight(); - bounds = new Rectangle(xOffset, yOffset, width, height); - // g.setColor(Color.green); - // g.draw(bounds); - - plotSurface.paint(g); - plotContent.paint(g); - - } - -} diff --git a/src/main/java/com/xeiam/xchart/PlotContent.java b/src/main/java/com/xeiam/xchart/PlotContent.java deleted file mode 100644 index 2ccb8c1c..00000000 --- a/src/main/java/com/xeiam/xchart/PlotContent.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.Map; - -import com.xeiam.xchart.Axis.AxisType; -import com.xeiam.xchart.interfaces.IChartPart; -import com.xeiam.xchart.series.Series; -import com.xeiam.xchart.series.SeriesLineStyle; - -/** - * @author timmolter - */ -public class PlotContent implements IChartPart { - - /** parent */ - private Plot plot; - - /** - * Constructor - * - * @param plot - */ - protected PlotContent(Plot plot) { - - this.plot = plot; - } - - @Override - public Rectangle getBounds() { - - return plot.getBounds(); - } - - @Override - public void paint(Graphics2D g) { - - Rectangle bounds = plot.getBounds(); - - Map<Integer, Series> seriesMap = plot.chart.axisPair.seriesMap; - for (Integer seriesId : seriesMap.keySet()) { - - Series series = seriesMap.get(seriesId); - - // X-Axis - int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth()); - int xLeftMargin = AxisPair.getMargin((int) bounds.getWidth(), xTickSpace); - - // Y-Axis - int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight()); - int yTopMargin = AxisPair.getMargin((int) bounds.getHeight(), yTickSpace); - - // data points - Collection<?> xData = series.getxData(); - BigDecimal xMin = plot.chart.axisPair.xAxis.min; - BigDecimal xMax = plot.chart.axisPair.xAxis.max; - Collection<Number> yData = series.getyData(); - BigDecimal yMin = plot.chart.axisPair.yAxis.min; - BigDecimal yMax = plot.chart.axisPair.yAxis.max; - Collection<Number> errorBars = series.getErrorBars(); - - int previousX = Integer.MIN_VALUE; - int previousY = Integer.MIN_VALUE; - - Iterator<?> xItr = xData.iterator(); - Iterator<Number> yItr = yData.iterator(); - Iterator<Number> ebItr = null; - if (errorBars != null) { - ebItr = errorBars.iterator(); - } - while (xItr.hasNext()) { - - BigDecimal x = null; - if (plot.chart.axisPair.xAxis.axisType == AxisType.NUMBER) { - x = new BigDecimal(((Number) xItr.next()).doubleValue()); - } - if (plot.chart.axisPair.xAxis.axisType == AxisType.DATE) { - x = new BigDecimal(((Date) xItr.next()).getTime()); - // System.out.println(x); - } - - BigDecimal y = new BigDecimal(yItr.next().doubleValue()); - // System.out.println(y); - double eb = 0.0; - if (errorBars != null) { - eb = ebItr.next().doubleValue(); - } - - // int xTransform = (int) (xLeftMargin + ((x - xMin) / (xMax - xMin) * xTickSpace)); - int xTransform = (int) (xLeftMargin + (x.subtract(xMin).doubleValue() / xMax.subtract(xMin).doubleValue() * xTickSpace)); - // int yTransform = (int) (bounds.getHeight() - (yTopMargin + (y - yMin) / (yMax - yMin) * yTickSpace)); - int yTransform = (int) (bounds.getHeight() - (yTopMargin + y.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); - - // a check if all y data are the exact same values - if (Math.abs(xMax.subtract(xMin).doubleValue()) / 5 == 0.0) { - xTransform = (int) (bounds.getWidth() / 2.0); - } - - // a check if all y data are the exact same values - if (Math.abs(yMax.subtract(yMin).doubleValue()) / 5 == 0.0) { - yTransform = (int) (bounds.getHeight() / 2.0); - } - - int xOffset = (int) (bounds.getX() + xTransform - 1); - int yOffset = (int) (bounds.getY() + yTransform); - // System.out.println(yOffset); - // System.out.println(yTransform); - - // paint line - if (series.getLineStyle() != null) { - if (previousX != Integer.MIN_VALUE && previousY != Integer.MIN_VALUE) { - g.setColor(series.getLineColor()); - g.setStroke(series.getLineStyle()); - g.drawLine(previousX, previousY, xOffset, yOffset); - } - previousX = xOffset; - previousY = yOffset; - } - - // paint marker - if (series.getMarker() != null) { - g.setColor(series.getMarkerColor()); - series.getMarker().paint(g, xOffset, yOffset); - } - - // paint errorbar - if (errorBars != null) { - g.setColor(plot.chart.bordersColor); - g.setStroke(SeriesLineStyle.getBasicStroke(SeriesLineStyle.SOLID)); - int bottom = (int) (-1 * bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); - int top = (int) (bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue())); - g.drawLine(xOffset, yOffset + bottom, xOffset, yOffset + top); - g.drawLine(xOffset - 3, yOffset + bottom, xOffset + 3, yOffset + bottom); - g.drawLine(xOffset - 3, yOffset + top, xOffset + 3, yOffset + top); - } - } - - } - - } - -} diff --git a/src/main/java/com/xeiam/xchart/PlotSurface.java b/src/main/java/com/xeiam/xchart/PlotSurface.java deleted file mode 100644 index ab6a53d0..00000000 --- a/src/main/java/com/xeiam/xchart/PlotSurface.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.util.List; - -import com.xeiam.xchart.interfaces.IChartPart; -import com.xeiam.xchart.interfaces.IHideable; - -/** - * @author timmolter - */ -public class PlotSurface implements IChartPart, IHideable { - - /** parent */ - private Plot plot; - - /** the gridLines Color */ - private Color gridLinesColor; - - /** the background color */ - private Color foregroundColor; - - /** the line style */ - private BasicStroke stroke; - - /** the visibility state of PlotSurface */ - protected boolean isVisible = true; // default to true - - /** - * Constructor - * - * @param plot - */ - protected PlotSurface(Plot plot) { - - this.plot = plot; - gridLinesColor = ChartColor.getAWTColor(ChartColor.GREY); // default gridLines color - foregroundColor = ChartColor.getAWTColor(ChartColor.LIGHT_GREY); // default foreground Color color - stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); - } - - @Override - public Rectangle getBounds() { - - return plot.getBounds(); - } - - @Override - public void paint(Graphics2D g) { - - Rectangle bounds = plot.getBounds(); - - // paint foreground - Rectangle backgroundRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); - g.setColor(foregroundColor); - g.fill(backgroundRectangle); - Rectangle borderRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight()); - g.setColor(plot.chart.bordersColor); - g.draw(borderRectangle); - - // paint grid lines - if (isVisible) { - // horizontal - List<Integer> yAxisTickLocations = plot.chart.axisPair.yAxis.axisTick.tickLocations; - for (int i = 0; i < yAxisTickLocations.size(); i++) { - - int tickLocation = yAxisTickLocations.get(i); - - g.setColor(gridLinesColor); - g.setStroke(stroke); - // System.out.println("bounds.getY()= " + bounds.getY()); - g.drawLine((int) bounds.getX(), (int) (bounds.getY() + bounds.getHeight() - tickLocation), (int) (bounds.getX() + bounds.getWidth() - 2), (int) (bounds.getY() + bounds.getHeight() - tickLocation)); - } - - // vertical - List<Integer> xAxisTickLocations = plot.chart.axisPair.xAxis.axisTick.tickLocations; - for (int i = 0; i < xAxisTickLocations.size(); i++) { - - int tickLocation = xAxisTickLocations.get(i); - - g.setColor(gridLinesColor); - g.setStroke(stroke); - - g.drawLine((int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + 1), (int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + bounds.getHeight() - 1)); - } - } - } - - @Override - public void setVisible(boolean isVisible) { - - this.isVisible = isVisible; - } - - /** - * @param gridLinesColor the gridLinesColor to set - */ - public void setGridLinesColor(Color gridLinesColor) { - - this.gridLinesColor = gridLinesColor; - } - - /** - * @param foregroundColor the foregroundColor to set - */ - public void setForegroundColor(Color foregroundColor) { - - this.foregroundColor = foregroundColor; - } - -} diff --git a/src/main/java/com/xeiam/xchart/XChartJPanel.java b/src/main/java/com/xeiam/xchart/XChartJPanel.java deleted file mode 100644 index bb8e69cc..00000000 --- a/src/main/java/com/xeiam/xchart/XChartJPanel.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2012 Xeiam LLC. - * - * 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 com.xeiam.xchart; - -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; - -import javax.swing.JPanel; - -/** - * @author timmolter - * @create Sep 9, 2012 - */ -public class XChartJPanel extends JPanel { - - private final Chart chart; - - public XChartJPanel(final Chart chart) { - - this.chart = chart; - - } - - @Override - protected void paintComponent(Graphics g) { - - super.paintComponent(g); - - chart.paint((Graphics2D) g, getWidth(), getHeight()); - } - - @Override - public Dimension getPreferredSize() { - - return new Dimension(chart.width, chart.height); - } -} diff --git a/src/main/java/com/xeiam/xchart/interfaces/IChartPart.java b/src/main/java/com/xeiam/xchart/interfaces/IChartPart.java deleted file mode 100644 index 2a87d89e..00000000 --- a/src/main/java/com/xeiam/xchart/interfaces/IChartPart.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.interfaces; - -import java.awt.Graphics2D; -import java.awt.Rectangle; - -/** - * All components of a chart that need to be painted should implement this interface - * - * @author timmolter - */ -public interface IChartPart { - - public Rectangle getBounds(); - - public void paint(final Graphics2D g); - -} diff --git a/src/main/java/com/xeiam/xchart/interfaces/IHideable.java b/src/main/java/com/xeiam/xchart/interfaces/IHideable.java deleted file mode 100644 index d4ef3265..00000000 --- a/src/main/java/com/xeiam/xchart/interfaces/IHideable.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2011 SWTChart project. All rights reserved. - * - * This code is distributed under the terms of the Eclipse Public License v1.0 - * which is available at http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ -package com.xeiam.xchart.interfaces; - -/** - * ChartParts that can be set visible or not should implement this interface - * - * @author timmolter - */ -public interface IHideable extends IChartPart { - - public void setVisible(boolean isVisible); - -} \ No newline at end of file diff --git a/src/main/java/com/xeiam/xchart/series/Series.java b/src/main/java/com/xeiam/xchart/series/Series.java deleted file mode 100644 index 95da82d5..00000000 --- a/src/main/java/com/xeiam/xchart/series/Series.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; - -import com.xeiam.xchart.Axis.AxisType; -import com.xeiam.xchart.series.markers.Marker; - -/** - * @author timmolter - */ -public class Series { - - private String name = ""; - - protected Collection<?> xData; - - protected Collection<Number> yData; - - protected Collection<Number> errorBars; - - /** the minimum value of axis range */ - private BigDecimal xMin; - - /** the maximum value of axis range */ - private BigDecimal xMax; - - /** the minimum value of axis range */ - private BigDecimal yMin; - - /** the maximum value of axis range */ - private BigDecimal yMax; - - /** Line Style */ - private BasicStroke stroke; - - /** Line Color */ - private Color strokeColor; - - /** Marker Style */ - private Marker marker; - - /** Marker Color */ - private Color markerColor; - - /** - * Constructor - * - * @param name - * @param xData - * @param xAxisType - * @param yData - * @param yAxisType - * @param errorBars - */ - public Series(String name, Collection<?> xData, AxisType xAxisType, Collection<Number> yData, AxisType yAxisType, Collection<Number> errorBars) { - - this.name = name; - this.xData = xData; - this.yData = yData; - this.errorBars = errorBars; - - // xData - BigDecimal[] xMinMax = findMinMax(xData, xAxisType); - xMin = xMinMax[0]; - xMax = xMinMax[1]; - - // yData - BigDecimal[] yMinMax = null; - if (errorBars == null) { - yMinMax = findMinMax(yData, yAxisType); - } else { - yMinMax = findMinMaxWithErrorBars(yData, errorBars); - } - yMin = yMinMax[0]; - yMax = yMinMax[1]; - // System.out.println(yMin); - // System.out.println(yMax); - - Color color = SeriesColor.getNextAWTColor(); - strokeColor = color; - markerColor = color; - - marker = SeriesMarker.getNextMarker(); - stroke = SeriesLineStyle.getNextBasicStroke(); - - } - - /** - * Finds the min and max of a dataset - * - * @param data - * @return - */ - private BigDecimal[] findMinMax(Collection<?> data, AxisType axisType) { - - BigDecimal min = null; - BigDecimal max = null; - - for (Object dataPoint : data) { - - BigDecimal bigDecimal = null; - - if (axisType == AxisType.NUMBER) { - bigDecimal = new BigDecimal(((Number) dataPoint).toString()); - - } else if (axisType == AxisType.DATE) { - Date date = (Date) dataPoint; - bigDecimal = new BigDecimal(date.getTime()); - } - if (min == null || bigDecimal.compareTo(min) < 0) { - min = bigDecimal; - } - if (max == null || bigDecimal.compareTo(max) > 0) { - max = bigDecimal; - } - } - - return new BigDecimal[] { min, max }; - } - - /** - * Finds the min and max of a dataset accounting for error bars - * - * @param data - * @return - */ - private BigDecimal[] findMinMaxWithErrorBars(Collection<Number> data, Collection<Number> errorBars) { - - BigDecimal min = null; - BigDecimal max = null; - - Iterator<Number> itr = data.iterator(); - Iterator<Number> ebItr = errorBars.iterator(); - while (itr.hasNext()) { - BigDecimal bigDecimal = new BigDecimal(itr.next().doubleValue()); - BigDecimal eb = new BigDecimal(ebItr.next().doubleValue()); - if (min == null || (bigDecimal.subtract(eb)).compareTo(min) < 0) { - min = bigDecimal.subtract(eb); - } - if (max == null || (bigDecimal.add(eb)).compareTo(max) > 0) { - max = bigDecimal.add(eb); - } - } - return new BigDecimal[] { min, max }; - } - - public String getName() { - - return name; - } - - public Collection<?> getxData() { - - return xData; - } - - public Collection<Number> getyData() { - - return yData; - } - - public Collection<Number> getErrorBars() { - - return errorBars; - } - - public BigDecimal getxMin() { - - return xMin; - } - - public BigDecimal getxMax() { - - return xMax; - } - - public BigDecimal getyMin() { - - return yMin; - } - - public BigDecimal getyMax() { - - return yMax; - } - - public BasicStroke getLineStyle() { - - return stroke; - } - - public void setLineStyle(SeriesLineStyle lineStyle) { - - stroke = SeriesLineStyle.getBasicStroke(lineStyle); - } - - public void setLineStyle(BasicStroke lineStyle) { - - stroke = lineStyle; - } - - public Color getLineColor() { - - return strokeColor; - } - - public void setLineColor(SeriesColor lineColor) { - - strokeColor = SeriesColor.getAWTColor(lineColor); - } - - public void setLineColor(java.awt.Color lineColor) { - - strokeColor = lineColor; - } - - public Marker getMarker() { - - return marker; - } - - public void setMarker(SeriesMarker marker) { - - this.marker = SeriesMarker.getMarker(marker); - } - - public void setMarker(Marker marker) { - - this.marker = marker; - } - - public Color getMarkerColor() { - - return markerColor; - } - - public void setMarkerColor(SeriesColor lineColor) { - - this.markerColor = SeriesColor.getAWTColor(lineColor); - } - - public void setMarkerColor(java.awt.Color lineColor) { - - this.markerColor = lineColor; - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/SeriesColor.java b/src/main/java/com/xeiam/xchart/series/SeriesColor.java deleted file mode 100644 index bbd00ec6..00000000 --- a/src/main/java/com/xeiam/xchart/series/SeriesColor.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series; - -import java.awt.Color; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -/** - * @author timmolter - */ -public enum SeriesColor { - - /** BLUE */ - BLUE(0, new Color(0, 55, 255)), - - /** ORANGE */ - ORANGE(1, new Color(255, 172, 0)), - - /** PURPLE */ - PURPLE(2, new Color(128, 0, 255)), - - /** GREEN */ - GREEN(3, new Color(0, 205, 0)), - - /** RED */ - RED(4, new Color(205, 0, 0)), - - /** YELLOW */ - YELLOW(5, new Color(255, 215, 0)), - - /** MAGENTA */ - MAGENTA(6, new Color(255, 0, 255)), - - /** PINK */ - PINK(7, new Color(255, 166, 201)), - - /** LIGHT_GREY */ - LIGHT_GREY(8, new Color(207, 207, 207)), - - /** CYAN */ - CYAN(9, new Color(0, 255, 255)), - - /** BROWN */ - BROWN(10, new Color(150, 74, 0)), - - /** BLACK */ - BLACK(11, new Color(0, 0, 0)), - - /** RANDOM */ - RANDOM(12, new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); - - int id; - Color color; - - private static int nextId = 0; - - private static final Map<Integer, SeriesColor> idLookup = new HashMap<Integer, SeriesColor>(); - static { - for (SeriesColor seriesColor : EnumSet.allOf(SeriesColor.class)) { - idLookup.put(seriesColor.getId(), seriesColor); - } - } - - private Integer getId() { - - return id; - } - - public static void resetId() { - - nextId = 0; - } - - protected static Color getAWTColor(SeriesColor seriesColor) { - - return seriesColor.color; - } - - protected static Color getNextAWTColor() { - - SeriesColor seriesColor = idLookup.get(nextId); - if (seriesColor == null) { - // rotate thru from beginning - resetId(); - } - return idLookup.get(nextId++).color; - } - - /** - * Constructor - * - * @param id - * @param color - */ - private SeriesColor(int id, Color color) { - - this.id = id; - this.color = color; - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/SeriesLineStyle.java b/src/main/java/com/xeiam/xchart/series/SeriesLineStyle.java deleted file mode 100644 index 5193c6b9..00000000 --- a/src/main/java/com/xeiam/xchart/series/SeriesLineStyle.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series; - -import java.awt.BasicStroke; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -/** - * @author timmolter - */ -public enum SeriesLineStyle { - - /** NONE */ - NONE(-1, null), - - /** SOLID */ - SOLID(0, new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)), - - /** DASH_DOT */ - DASH_DOT(1, new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f)), - - /** DASH_DASH */ - DASH_DASH(2, new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f)), - - /** DOT_DOT */ - DOT_DOT(3, new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f)); - - int id; - - BasicStroke basicStroke; - - private static int nextId = 0; - - /** - * Constructor - * - * @param id - * @param color - */ - private SeriesLineStyle(int id, BasicStroke basicStroke) { - - this.id = id; - this.basicStroke = basicStroke; - } - - private static final Map<Integer, SeriesLineStyle> idLookup = new HashMap<Integer, SeriesLineStyle>(); - static { - for (SeriesLineStyle seriesLineStyle : EnumSet.allOf(SeriesLineStyle.class)) { - idLookup.put(seriesLineStyle.getId(), seriesLineStyle); - } - } - - private Integer getId() { - - return id; - } - - public static void resetId() { - - nextId = 0; - } - - /** - * Get an AWT Stroke - * - * @param seriesMarker - * @return - */ - public static BasicStroke getBasicStroke(SeriesLineStyle seriesMarker) { - - return seriesMarker.basicStroke; - } - - /** - * Gets the next Stroke - * - * @return - */ - protected static BasicStroke getNextBasicStroke() { - - SeriesLineStyle seriesLineStyle = idLookup.get(nextId); - if (seriesLineStyle == null) { - // rotate thru from beginning - resetId(); - } - return idLookup.get(nextId++).basicStroke; - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/SeriesMarker.java b/src/main/java/com/xeiam/xchart/series/SeriesMarker.java deleted file mode 100644 index 0cd71300..00000000 --- a/src/main/java/com/xeiam/xchart/series/SeriesMarker.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -import com.xeiam.xchart.series.markers.Circle; -import com.xeiam.xchart.series.markers.Diamond; -import com.xeiam.xchart.series.markers.Marker; -import com.xeiam.xchart.series.markers.Square; -import com.xeiam.xchart.series.markers.TriangleDown; -import com.xeiam.xchart.series.markers.TriangleUp; - -/** - * @author timmolter - */ -public enum SeriesMarker { - - /** NONE */ - NONE(-1, null), - - /** CIRCLE */ - CIRCLE(0, new Circle()), - - /** DIAMOND */ - DIAMOND(1, new Diamond()), - - /** SQUARE */ - SQUARE(2, new Square()), - - /** TRIANGLE_DOWN */ - TRIANGLE_DOWN(3, new TriangleDown()), - - /** TRIANGLE_UP */ - TRIANGLE_UP(4, new TriangleUp()); - - int id; - Marker marker; - private static int nextId = 0; - - private static final Map<Integer, SeriesMarker> idLookup = new HashMap<Integer, SeriesMarker>(); - static { - for (SeriesMarker seriesMarker : EnumSet.allOf(SeriesMarker.class)) { - idLookup.put(seriesMarker.getId(), seriesMarker); - } - } - - private Integer getId() { - - return id; - } - - public static void resetId() { - - nextId = 0; - } - - protected static Marker getMarker(SeriesMarker seriesMarker) { - - return seriesMarker.marker; - } - - protected static Marker getNextMarker() { - - SeriesMarker seriesMarker = idLookup.get(nextId); - if (seriesMarker == null) { - // rotate thru from beginning - resetId(); - } - return idLookup.get(nextId++).marker; - } - - /** - * Constructor - * - * @param id - * @param color - */ - private SeriesMarker(int id, Marker marker) { - - this.id = id; - this.marker = marker; - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/markers/Circle.java b/src/main/java/com/xeiam/xchart/series/markers/Circle.java deleted file mode 100644 index 75ada143..00000000 --- a/src/main/java/com/xeiam/xchart/series/markers/Circle.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series.markers; - -import java.awt.Graphics2D; - -/** - * @author timmolter - */ -public class Circle extends Marker { - - @Override - public void paint(Graphics2D g, int xOffset, int yOffset) { - - g.setStroke(stroke); - g.fillOval(xOffset + Marker.X_OFFSET, yOffset + Marker.Y_OFFSET, Marker.SIZE, Marker.SIZE); - - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/markers/Diamond.java b/src/main/java/com/xeiam/xchart/series/markers/Diamond.java deleted file mode 100644 index b96a5a5f..00000000 --- a/src/main/java/com/xeiam/xchart/series/markers/Diamond.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series.markers; - -import java.awt.Graphics2D; -import java.awt.Polygon; - -/** - * @author timmolter - */ -public class Diamond extends Marker { - - @Override - public void paint(Graphics2D g, int xOffset, int yOffset) { - - g.setStroke(stroke); - - int[] x = new int[4]; - int[] y = new int[4]; - int n = 4; - - // Make a diamond - int halfSize = (int) (Math.ceil((Marker.SIZE + 3) / 2.0)); - x[0] = xOffset - halfSize + 0; - x[1] = xOffset - halfSize + halfSize; - x[2] = xOffset - halfSize + Marker.SIZE + 3; - x[3] = xOffset - halfSize + halfSize; - - y[0] = 1 + yOffset - halfSize + halfSize; - y[1] = 1 + yOffset - halfSize + Marker.SIZE + 3; - y[2] = 1 + yOffset - halfSize + halfSize; - y[3] = 1 + yOffset - halfSize + 0; - - Polygon diamond = new Polygon(x, y, n); - g.fillPolygon(diamond); - - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/markers/Marker.java b/src/main/java/com/xeiam/xchart/series/markers/Marker.java deleted file mode 100644 index cf5f59dc..00000000 --- a/src/main/java/com/xeiam/xchart/series/markers/Marker.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series.markers; - -import java.awt.BasicStroke; -import java.awt.Graphics2D; - -/** - * @author timmolter - */ -public abstract class Marker { - - protected BasicStroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); - - public static final int SIZE = 7; // make this an odd number! - - public static final int X_OFFSET = (int) (-1.0 * (SIZE / 2.0)); - public static final int Y_OFFSET = (int) (-1.0 * (SIZE / 2.0)); - - public abstract void paint(Graphics2D g, int xOffset, int yOffset); -} diff --git a/src/main/java/com/xeiam/xchart/series/markers/Square.java b/src/main/java/com/xeiam/xchart/series/markers/Square.java deleted file mode 100644 index e5e8ed13..00000000 --- a/src/main/java/com/xeiam/xchart/series/markers/Square.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series.markers; - -import java.awt.Graphics2D; -import java.awt.Rectangle; - -/** - * @author timmolter - */ -public class Square extends Marker { - - @Override - public void paint(Graphics2D g, int xOffset, int yOffset) { - - g.setStroke(stroke); - g.fill(new Rectangle(xOffset + Marker.X_OFFSET, yOffset + Marker.Y_OFFSET, Marker.SIZE, Marker.SIZE)); - - } - -} diff --git a/src/main/java/com/xeiam/xchart/series/markers/TriangleDown.java b/src/main/java/com/xeiam/xchart/series/markers/TriangleDown.java deleted file mode 100644 index c19ba4d9..00000000 --- a/src/main/java/com/xeiam/xchart/series/markers/TriangleDown.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series.markers; - -import java.awt.Graphics2D; -import java.awt.Polygon; - -/** - * @author timmolter - */ -public class TriangleDown extends Marker { - - @Override - public void paint(Graphics2D g, int xOffset, int yOffset) { - - g.setStroke(stroke); - - int[] x = new int[3]; - int[] y = new int[3]; - int n = 3; - - // Make a triangle - int halfSize = (int) (Math.ceil((Marker.SIZE + 1) / 2.0)); - x[0] = xOffset - halfSize + 0; - x[1] = xOffset - halfSize + halfSize; - x[2] = xOffset - halfSize + Marker.SIZE + 1; - - y[0] = 1 + yOffset - halfSize + 0; - y[1] = 1 + yOffset - halfSize + Marker.SIZE + 1; - y[2] = 1 + yOffset - halfSize + 0; - - Polygon triangle = new Polygon(x, y, n); - g.fillPolygon(triangle); - - } -} diff --git a/src/main/java/com/xeiam/xchart/series/markers/TriangleUp.java b/src/main/java/com/xeiam/xchart/series/markers/TriangleUp.java deleted file mode 100644 index 098abdd5..00000000 --- a/src/main/java/com/xeiam/xchart/series/markers/TriangleUp.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2011-2012 Xeiam LLC. - * - * 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 com.xeiam.xchart.series.markers; - -import java.awt.Graphics2D; -import java.awt.Polygon; - -/** - * @author timmolter - */ -public class TriangleUp extends Marker { - - @Override - public void paint(Graphics2D g, int xOffset, int yOffset) { - - g.setStroke(stroke); - - int[] x = new int[3]; - int[] y = new int[3]; - int n = 3; - - // Make a triangle - int halfSize = (int) (Math.ceil((Marker.SIZE + 1) / 2.0)); - x[0] = xOffset - halfSize + 0; - x[1] = xOffset - halfSize + Marker.SIZE + 1; - x[2] = xOffset - halfSize + halfSize; - - y[0] = yOffset - halfSize + Marker.SIZE + 1; - y[1] = yOffset - halfSize + Marker.SIZE + 1; - y[2] = yOffset - halfSize + 0; - - Polygon triangle = new Polygon(x, y, n); - g.fillPolygon(triangle); - - } -} -- GitLab