diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index d42a54ce4142d80346d75a3fd96c3e3c626570dd..0000000000000000000000000000000000000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Tue May 31 11:25:17 CEST 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/dist/xchart-1.0.0.jar b/dist/xchart-1.0.0.jar deleted file mode 100644 index a3d94874742bece37235d508f599ed4b9f845d8e..0000000000000000000000000000000000000000 Binary files a/dist/xchart-1.0.0.jar and /dev/null differ diff --git a/src/com/xeiam/xcharts/AxisPair.java b/src/com/xeiam/xcharts/AxisPair.java index ca1735241dc8988aea3d498a73d30290c247cc48..6fe117e36611335307f725d7cec39b79a03bc079 100644 --- a/src/com/xeiam/xcharts/AxisPair.java +++ b/src/com/xeiam/xcharts/AxisPair.java @@ -98,16 +98,15 @@ public class AxisPair implements IChartPart { } public static int getTickSpace(int workingSpace) { - int tickSpace = (int) (workingSpace * 0.95); return tickSpace; } - public static int getLeftMargin(int workingSpace, int tickSpace) { + public static int getMargin(int workingSpace, int tickSpace) { int marginSpace = workingSpace - tickSpace; - int leftMargin = (int) (marginSpace / 2.0); - return leftMargin; + int margin = (int) (marginSpace / 2.0); + return margin; } @Override diff --git a/src/com/xeiam/xcharts/AxisTick.java b/src/com/xeiam/xcharts/AxisTick.java index 61c8c50216281e8ad48c169cfd70adad7d029066..4d0a14e292b7d52220ba13db411da3494965086b 100644 --- a/src/com/xeiam/xcharts/AxisTick.java +++ b/src/com/xeiam/xcharts/AxisTick.java @@ -131,47 +131,51 @@ public class AxisTick implements IChartPart { */ private void determineAxisTick() { + System.out.println("workingSpace= " + workingSpace); + int tickSpace = AxisPair.getTickSpace(workingSpace); - int leftMargin = AxisPair.getLeftMargin(workingSpace, tickSpace); + System.out.println("tickSpace= " + tickSpace); + + int margin = AxisPair.getMargin(workingSpace, tickSpace); final BigDecimal MIN = new BigDecimal(new Double(axis.getMin()).toString()); BigDecimal firstPosition; - BigDecimal tickStep = getGridStep(); + BigDecimal gridStep = getGridStep(tickSpace); - if (MIN.remainder(tickStep).doubleValue() <= 0) { - firstPosition = MIN.subtract(MIN.remainder(tickStep)); + double xyz = MIN.remainder(gridStep).doubleValue(); + if (xyz <= 0.0) { + firstPosition = MIN.subtract(MIN.remainder(gridStep)); } else { - firstPosition = MIN.subtract(MIN.remainder(tickStep)).add(tickStep); + firstPosition = MIN.subtract(MIN.remainder(gridStep)).add(gridStep); } - for (BigDecimal b = firstPosition; b.doubleValue() <= axis.getMax(); b = b.add(tickStep)) { + for (BigDecimal b = firstPosition; b.doubleValue() <= axis.getMax(); b = b.add(gridStep)) { // System.out.println("b= " + b); tickLabels.add(format(b.doubleValue())); - int tickLabelPosition = (int) (leftMargin + ((b.doubleValue() - axis.getMin()) / (axis.getMax() - axis.getMin()) * tickSpace)); + int tickLabelPosition = (int) (margin + ((b.doubleValue() - axis.getMin()) / (axis.getMax() - axis.getMin()) * tickSpace)); + // System.out.println("tickLabelPosition= " + tickLabelPosition); // a check if all axis data are the exact same values if (Math.abs(axis.getMax() - axis.getMin()) / 5 == 0.0) { - tickLabelPosition = (int) (leftMargin + tickSpace / 2.0); + tickLabelPosition = (int) (margin + tickSpace / 2.0); } tickLocations.add(tickLabelPosition); } } - private BigDecimal getGridStep() { + private BigDecimal getGridStep(int tickSpace) { double length = Math.abs(axis.getMax() - axis.getMin()); - double gridStepHint = length / workingSpace * DEFAULT_TICK_MARK_STEP_HINT; + 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) { - // mantissa = 0.0; exponent = 1; - } else if (mantissa < 1) { while (mantissa < 1) { mantissa *= 10.0; diff --git a/src/com/xeiam/xcharts/AxisTickLabels.java b/src/com/xeiam/xcharts/AxisTickLabels.java index c502526c745c7ad23cb83df7e007387e2b7b8cc0..9889408c1f0d6f1e60302efc4dbd6d738464fdf4 100644 --- a/src/com/xeiam/xcharts/AxisTickLabels.java +++ b/src/com/xeiam/xcharts/AxisTickLabels.java @@ -68,11 +68,11 @@ public class AxisTickLabels implements IChartPart { for (int i = 0; i < axisTick.getTickLabels().size(); i++) { String tickLabel = axisTick.getTickLabels().get(i); - int tickLocation = axisTick.getTickLocations().get(axisTick.getTickLocations().size() - i - 1); // reverse traverse + int tickLocation = axisTick.getTickLocations().get(i); TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); - layout.draw(g, xOffset, (int) (yOffset + tickLocation + tickLabelBounds.getHeight() / 2.0)); + layout.draw(g, xOffset, (int) (yOffset + axis.getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); if (tickLabelBounds.getWidth() > maxTickLabelWidth) { maxTickLabelWidth = (int) tickLabelBounds.getWidth(); diff --git a/src/com/xeiam/xcharts/AxisTickMarks.java b/src/com/xeiam/xcharts/AxisTickMarks.java index 17b7456de20e9964c33bf638c04cabdd62233d9a..aae1106e2da1270a75c19159bf9ce56fb0e89169 100644 --- a/src/com/xeiam/xcharts/AxisTickMarks.java +++ b/src/com/xeiam/xcharts/AxisTickMarks.java @@ -57,7 +57,7 @@ public class AxisTickMarks implements IChartPart { g.setColor(foreground); - if (axis.getDirection() == Axis.Direction.Y) { + if (axis.getDirection() == Axis.Direction.Y) { // Y-Axis int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + AxisTick.AXIS_TICK_PADDING); int yOffset = (int) (axis.getPaintZone().getY()); @@ -68,7 +68,7 @@ public class AxisTickMarks implements IChartPart { g.setColor(foreground); g.setStroke(stroke); - g.drawLine(xOffset, yOffset + tickLocation, xOffset + TICK_LENGTH, yOffset + tickLocation); + g.drawLine(xOffset, yOffset + (int) (axis.getPaintZone().getHeight() - tickLocation), xOffset + TICK_LENGTH, yOffset + (int) (axis.getPaintZone().getHeight() - tickLocation)); } @@ -77,7 +77,7 @@ public class AxisTickMarks implements IChartPart { // g.setColor(Color.blue); // g.draw(bounds); - } else { + } else { // X-Axis int xOffset = (int) (axis.getPaintZone().getX()); int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - AxisTick.AXIS_TICK_PADDING); diff --git a/src/com/xeiam/xcharts/PlotContent.java b/src/com/xeiam/xcharts/PlotContent.java index e4c96288753540ce3236b3bc1be914ad38dcdade..3e45d23065c32f5365732bef7dc1e0225ca83c32 100644 --- a/src/com/xeiam/xcharts/PlotContent.java +++ b/src/com/xeiam/xcharts/PlotContent.java @@ -53,11 +53,11 @@ public class PlotContent implements IChartPart { // X-Axis int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth()); - int xLeftMargin = AxisPair.getLeftMargin((int) bounds.getWidth(), xTickSpace); + int xLeftMargin = AxisPair.getMargin((int) bounds.getWidth(), xTickSpace); // Y-Axis int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight()); - int yLeftMargin = AxisPair.getLeftMargin((int) bounds.getHeight(), yTickSpace); + int yTopMargin = AxisPair.getMargin((int) bounds.getHeight(), yTickSpace); // data points double[] xData = series.getxData(); @@ -72,8 +72,16 @@ public class PlotContent implements IChartPart { for (int i = 0; i < xData.length; i++) { + if (Double.isInfinite(xData[i]) || Double.isNaN(xData[i])) { + throw new RuntimeException("Infinite or NaN values in xAxis Data not allowed!!!"); + } + + if (Double.isInfinite(yData[i]) || Double.isNaN(yData[i])) { + throw new RuntimeException("Infinite or NaN values in yAxis Data not allowed!!!"); + } + int xTransform = (int) (xLeftMargin + ((xData[i] - xMin) / (xMax - xMin) * xTickSpace)); - int yTransform = (int) (bounds.getHeight() - (yLeftMargin + (yData[i] - yMin) / (yMax - yMin) * yTickSpace)); + int yTransform = (int) (bounds.getHeight() - (yTopMargin + (yData[i] - yMin) / (yMax - yMin) * yTickSpace)); // a check if all y data are the exact same values if (Math.abs(xMax - xMin) / 5 == 0.0) { diff --git a/src/com/xeiam/xcharts/PlotSurface.java b/src/com/xeiam/xcharts/PlotSurface.java index 7bff15663fc87c8c5658a146c110cea293742157..c62301c5d26b203f3bce6c8c9e05afe2da6d339a 100644 --- a/src/com/xeiam/xcharts/PlotSurface.java +++ b/src/com/xeiam/xcharts/PlotSurface.java @@ -73,8 +73,8 @@ public class PlotSurface implements IChartPart { g.setColor(foreground); g.setStroke(stroke); - - g.drawLine((int) bounds.getX(), (int) (bounds.getY() + tickLocation), (int) (bounds.getX() + bounds.getWidth() - 2), (int) (bounds.getY() + tickLocation)); + // 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 diff --git a/src/com/xeiam/xcharts/example/SwingChart4.java b/src/com/xeiam/xcharts/example/SwingChart4.java new file mode 100644 index 0000000000000000000000000000000000000000..0ebd99309407beff927461157ee8bf154c6b4e27 --- /dev/null +++ b/src/com/xeiam/xcharts/example/SwingChart4.java @@ -0,0 +1,83 @@ +/** + * Copyright 2011 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.xcharts.example; + +import java.awt.BorderLayout; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +import com.xeiam.xcharts.Chart; +import com.xeiam.xcharts.JChartPanel; +import com.xeiam.xcharts.series.Series; +import com.xeiam.xcharts.series.SeriesMarker; + +/** + * Demonstrated/Tests plotting horizontal and vertical lines + * + * @author timmolter + */ +public class SwingChart4 { + + private static void createAndShowGUI() { + + // generates linear data + double[] yData1 = new double[] { 0.0, 0.0, 0.0, -10.0, 15.0, 15.0 }; + + // Create and set up the window. + JFrame frame = new JFrame("XChart"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setUndecorated(true); + + // Create Chart + Chart chart = new Chart(800, 600); + + // Customize Chart + chart.setChartTitle("Sample Chart"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + chart.setChartTitleVisible(false); + chart.setChartLegendVisible(false); + chart.setAxisTitlesVisible(false); + + // Series + Series series1 = chart.addSeries("y=0", null, yData1); + series1.setMarker(SeriesMarker.NONE); + + // Swing + JPanel chartPanel = new JChartPanel(chart); + + // add the panel to the content pane + frame.getContentPane().add(chartPanel, BorderLayout.CENTER); + + // Display the window + frame.pack(); + frame.setLocationRelativeTo(null); // centers on screen + frame.setVisible(true); + } + + public static void main(String[] args) { + + // Schedule a job for the event-dispatching thread: + // creating and showing this application's GUI. + javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + createAndShowGUI(); + } + }); + } +}