From 549b47d2ff9a543c6df7d4fa30acdbfd84a82731 Mon Sep 17 00:00:00 2001 From: timmolter <tim.molter@gmail.com> Date: Tue, 14 Aug 2012 15:20:07 +0200 Subject: [PATCH] made API prefer to accept a Collection of Number objects for the axis data --- Sample_Chart.png | Bin 0 -> 10718 bytes src/main/java/com/xeiam/xchart/AxisPair.java | 54 ++++-------- src/main/java/com/xeiam/xchart/Chart.java | 24 +++++- .../java/com/xeiam/xchart/PlotContent.java | 26 +++--- .../java/com/xeiam/xchart/series/Series.java | 49 +++++++---- .../xchart/example/ChartServletExample.java | 78 ++++++++++++++++++ .../com/xeiam/xchart/example/Example1.java | 46 +++++++++++ .../com/xeiam/xchart/example/Example2.java | 62 ++++++++++++++ .../com/xeiam/xchart/example/Example3.java | 57 +++++++++++++ .../com/xeiam/xchart/example/Example4.java | 60 ++++++++++++++ .../com/xeiam/xchart/example/Example5.java | 44 ++++++++++ .../com/xeiam/xchart/example/Example6.java | 43 ++++++++++ .../com/xeiam/xchart/example/Example7.java | 43 ++++++++++ .../xchart/unit/TestNumberCollection.java | 46 +++++++++++ 14 files changed, 566 insertions(+), 66 deletions(-) create mode 100644 Sample_Chart.png create mode 100644 src/test/java/com/xeiam/xchart/example/ChartServletExample.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example1.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example2.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example3.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example4.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example5.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example6.java create mode 100644 src/test/java/com/xeiam/xchart/example/Example7.java create mode 100644 src/test/java/com/xeiam/xchart/unit/TestNumberCollection.java diff --git a/Sample_Chart.png b/Sample_Chart.png new file mode 100644 index 0000000000000000000000000000000000000000..03e05bd1563293430821ae7728851814299036eb GIT binary patch literal 10718 zcmZvC2{@E{^#7=EqjbBG>_y1Fh3qNImFy&YSwqM+W9L>XSt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+ckDJS_F9u62@QYWID6q7ZmnUx_JL69|9!@b8Qw z5pp1(v>q1FK8r3(Fym;B<r1^7Tb=prXQ_kMZfRo>^|k~ZWl(UiNw6g9`b~c%7~%97 zpZMO|`uF5yNcT%VBKhUZ^LSPsji`6yF6|(=UTj-vUE<mSYdZQBHG-#ZSWkGVjTY!Z zGZDFWs-!6-2EU~wEd0uS_$}!An!rQB%~34NW1MVk^L27?;!S^V&`e)jzv1v9KR>^H z69b|EwDUlY(kWA1IWKL2g;<eHcvMtlVj|^xQ=|hIpf(B~P=7dbU03%;MNKi|4P_E; z;9eX?>sjiH(aDQV0|U&JLZS${!)r@REaJDqRve+lwTX*DLfUO3#fCTK65^Tt2g<Ar zGK-!GjxK_Zvxn%gVyb_G^p_md{|>?r9Ppvn@q9YZTD)=uV+Q~~12RK;div*FO<bg+ zpy0K!{#G0=zS|9w(6mfT%@Z>++=?Mr9qdn}Y(>kCJlV@=Y*d4;%pnvkZJDjtu=ml> z(w4~I#cB^moZ@evH&gyJ>FMKBrI^IC_3qu}qFn$W7YM9CZ4<+yF(5$luep2(LAak0 z(gQliQf-A7f}6H-%K!6})d#R6H*{A<PImgeo8Sxr9OGc?<=6h-f45$seZZeTyF8_) zKMhu?re_PXy1)r!2TCoR%5RQ@?gg9EfaM&-DRy>Zkfz5h8NTop?E3Zafvv*2On_2y z<{pEu$LPiC{`~XLThC&-4qYZ?D+6`VyFvP!g-5-*D}ZPHhn;EA8%@XbI;k&{ZfR)5 zu+J_oicOB>X)~LH#hnLq=lS_58ymtmUuT0sT+gESbXT4Zw1_6##UTln+u~br$zsV~ z9-nj6b#)m;4nv!BDUuG?zycCj>YJ$BBzSjgVfE54A(H^H{(n~<e;xUMyC7SBJJewK XrqST^<x;S>3DZ*7RV%x4>;C@$O-Izg literal 0 HcmV?d00001 diff --git a/src/main/java/com/xeiam/xchart/AxisPair.java b/src/main/java/com/xeiam/xchart/AxisPair.java index edd8a8fa..2c599cbd 100644 --- a/src/main/java/com/xeiam/xchart/AxisPair.java +++ b/src/main/java/com/xeiam/xchart/AxisPair.java @@ -17,13 +17,14 @@ package com.xeiam.xchart; import java.awt.Graphics2D; import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import com.xeiam.xchart.interfaces.IChartPart; import com.xeiam.xchart.series.Series; - /** * @author timmolter */ @@ -57,45 +58,42 @@ public class AxisPair implements IChartPart { * @param xData * @param yData */ - public Series addSeries(String seriesName, double[] xData, double[] yData) { + public Series addSeries(String seriesName, Collection<Number> xData, Collection<Number> yData) { // Sanity checks if (seriesName == null) { - throw new RuntimeException("Series Name cannot be null!!!"); + throw new IllegalArgumentException("Series Name cannot be null!!!"); } if (yData == null) { - throw new RuntimeException("Y-Axis data cannot be null!!!"); + throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); } - if (yData.length == 0) { - throw new RuntimeException("Y-Axis data cannot be empty!!!"); + if (yData.size() == 0) { + throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); } - if (xData != null && xData.length == 0) { - throw new RuntimeException("X-Axis data cannot be empty!!!"); + if (xData != null && xData.size() == 0) { + throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); } - if (xData != null && xData.length == 1 && Double.isNaN(yData[0])) { - throw new RuntimeException("X-Axis data cannot contain a single NaN value!!!"); + if (xData != null && xData.size() == 1 && Double.isNaN(xData.iterator().next().doubleValue())) { + throw new IllegalArgumentException("X-Axis data cannot contain a single NaN value!!!"); } - if (yData.length == 1 && Double.isNaN(yData[0])) { - throw new RuntimeException("Y-Axis data cannot contain a single NaN value!!!"); + if (yData.size() == 1 && Double.isNaN(yData.iterator().next().doubleValue())) { + throw new IllegalArgumentException("Y-Axis data cannot contain a single NaN value!!!"); } Series series; if (xData != null) { - verifyValues(xData); - verifyValues(yData); series = new Series(seriesName, xData, yData); } else { // generate xData - double[] generatedXData = new double[yData.length]; - verifyValues(yData); - for (int i = 1; i < yData.length; i++) { - generatedXData[i] = i; + Collection<Number> generatedXData = new ArrayList<Number>(); + for (int i = 1; i < yData.size(); i++) { + generatedXData.add(i); } series = new Series(seriesName, generatedXData, yData); } // Sanity check - if (xData != null && xData.length != yData.length) { - throw new RuntimeException("X and Y-Axis lengths are not the same!!! "); + if (xData != null && xData.size() != yData.size()) { + throw new IllegalArgumentException("X and Y-Axis lengths are not the same!!! "); } seriesMap.put(seriesCount++, series); @@ -107,22 +105,6 @@ public class AxisPair implements IChartPart { return series; } - /** - * Checks for invalid values in data array - * - * @param data - */ - private void verifyValues(double[] data) { - - for (int i = 0; i < data.length; i++) { - if (data[i] == Double.POSITIVE_INFINITY) { - throw new RuntimeException("Axis data cannot contain Double.POSITIVE_INFINITY!!!"); - } else if (data[i] == Double.NEGATIVE_INFINITY) { - throw new RuntimeException("Axis data cannot contain Double.NEGATIVE_INFINITY!!!"); - } - } - } - protected Axis getXAxis() { return xAxis; diff --git a/src/main/java/com/xeiam/xchart/Chart.java b/src/main/java/com/xeiam/xchart/Chart.java index 3b6ee801..0350c7f8 100644 --- a/src/main/java/com/xeiam/xchart/Chart.java +++ b/src/main/java/com/xeiam/xchart/Chart.java @@ -17,6 +17,8 @@ package com.xeiam.xchart; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.util.ArrayList; +import java.util.Collection; import com.xeiam.xchart.series.Series; import com.xeiam.xchart.series.SeriesColor; @@ -107,13 +109,31 @@ public class Chart { return plot; } - // EXTERNAL GETTERS & SETTERS + // PUBLIC SETTERS - public Series addSeries(String seriesName, double[] xData, double[] yData) { + public Series addSeries(String seriesName, Collection<Number> xData, Collection<Number> yData) { return axisPair.addSeries(seriesName, xData, yData); } + @Deprecated + public Series addSeries(String seriesName, double[] xData, double[] yData) { + + Collection<Number> xDataNumber = null; + if (xData != null) { + xDataNumber = new ArrayList<Number>(); + for (double d : xData) { + xDataNumber.add(new Double(d)); + } + } + Collection<Number> yDataNumber = new ArrayList<Number>(); + for (double d : yData) { + yDataNumber.add(new Double(d)); + } + + return axisPair.addSeries(seriesName, xDataNumber, yDataNumber); + } + public void setChartTitle(String title) { this.chartTitle.setText(title); diff --git a/src/main/java/com/xeiam/xchart/PlotContent.java b/src/main/java/com/xeiam/xchart/PlotContent.java index 7c4f8870..8e83f5c8 100644 --- a/src/main/java/com/xeiam/xchart/PlotContent.java +++ b/src/main/java/com/xeiam/xchart/PlotContent.java @@ -17,12 +17,13 @@ package com.xeiam.xchart; import java.awt.Graphics2D; import java.awt.Rectangle; +import java.util.Collection; +import java.util.Iterator; import java.util.Map; import com.xeiam.xchart.interfaces.IChartPart; import com.xeiam.xchart.series.Series; - /** * @author timmolter */ @@ -63,30 +64,27 @@ public class PlotContent implements IChartPart { int yTopMargin = AxisPair.getMargin((int) bounds.getHeight(), yTickSpace); // data points - double[] xData = series.getxData(); + Collection<Number> xData = series.getxData(); double xMin = chart.getAxisPair().getXAxis().getMin(); double xMax = chart.getAxisPair().getXAxis().getMax(); - double[] yData = series.getyData(); + Collection<Number> yData = series.getyData(); double yMin = chart.getAxisPair().getYAxis().getMin(); double yMax = chart.getAxisPair().getYAxis().getMax(); int previousX = Integer.MIN_VALUE; int previousY = Integer.MIN_VALUE; - for (int i = 0; i < xData.length; i++) { - - if (Double.isInfinite(xData[i])) { - throw new RuntimeException("Infinite values in xAxis Data not allowed!!!"); - } + Iterator<Number> xItr = xData.iterator(); + Iterator<Number> yItr = yData.iterator(); + while (xItr.hasNext()) { - if (Double.isInfinite(yData[i])) { - throw new RuntimeException("Infinite values in yAxis Data not allowed!!!"); - } + double x = xItr.next().doubleValue(); + double y = yItr.next().doubleValue(); - if (!Double.isNaN(xData[i]) && !Double.isNaN(yData[i])) { + if (!Double.isNaN(x) && !Double.isNaN(y)) { - int xTransform = (int) (xLeftMargin + ((xData[i] - xMin) / (xMax - xMin) * xTickSpace)); - int yTransform = (int) (bounds.getHeight() - (yTopMargin + (yData[i] - yMin) / (yMax - yMin) * yTickSpace)); + int xTransform = (int) (xLeftMargin + ((x - xMin) / (xMax - xMin) * xTickSpace)); + int yTransform = (int) (bounds.getHeight() - (yTopMargin + (y - 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/main/java/com/xeiam/xchart/series/Series.java b/src/main/java/com/xeiam/xchart/series/Series.java index 70f12296..585f1561 100644 --- a/src/main/java/com/xeiam/xchart/series/Series.java +++ b/src/main/java/com/xeiam/xchart/series/Series.java @@ -17,10 +17,10 @@ package com.xeiam.xchart.series; import java.awt.BasicStroke; import java.awt.Color; +import java.util.Collection; import com.xeiam.xchart.series.markers.Marker; - /** * @author timmolter */ @@ -28,9 +28,9 @@ public class Series { private String name = ""; - protected double[] xData; + protected Collection<Number> xData; - protected double[] yData; + protected Collection<Number> yData; /** the minimum value of axis range */ private double xMin; @@ -63,7 +63,7 @@ public class Series { * @param xData * @param yData */ - public Series(String name, double[] xData, double[] yData) { + public Series(String name, Collection<Number> xData, Collection<Number> yData) { this.name = name; this.xData = xData; @@ -90,36 +90,57 @@ public class Series { } - private double[] findMinMax(double[] data) { + /** + * Finds the min and max of a dataset + * + * @param data + * @return + */ + private double[] findMinMax(Collection<Number> data) { Double min = null; Double max = null; - for (int i = 0; i < data.length; i++) { - if (min == null || data[i] < min) { - if (!Double.isNaN(data[i])) { - min = data[i]; + for (Number number : data) { + verify(number.doubleValue()); + if (min == null || number.doubleValue() < min) { + if (!Double.isNaN(number.doubleValue())) { + min = number.doubleValue(); } } - if (max == null || data[i] > max) { - if (!Double.isNaN(data[i])) { - max = data[i]; + if (max == null || number.doubleValue() > max) { + if (!Double.isNaN(number.doubleValue())) { + max = number.doubleValue(); } } } return new double[] { min, max }; } + /** + * Checks for invalid values in data array + * + * @param data + */ + private void verify(double value) { + + if (value == Double.POSITIVE_INFINITY) { + throw new RuntimeException("Axis data cannot contain Double.POSITIVE_INFINITY!!!"); + } else if (value == Double.NEGATIVE_INFINITY) { + throw new RuntimeException("Axis data cannot contain Double.NEGATIVE_INFINITY!!!"); + } + } + public String getName() { return name; } - public double[] getxData() { + public Collection<Number> getxData() { return xData; } - public double[] getyData() { + public Collection<Number> getyData() { return yData; } diff --git a/src/test/java/com/xeiam/xchart/example/ChartServletExample.java b/src/test/java/com/xeiam/xchart/example/ChartServletExample.java new file mode 100644 index 00000000..2efb359e --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/ChartServletExample.java @@ -0,0 +1,78 @@ +/** + * 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.example; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.xeiam.xchart.BitmapEncoder; +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.QuickChart; + +/** + * Generates, stores, and serves charts + * + * @author timmolter + */ +@javax.servlet.annotation.WebServlet(name = "ChartServlet", urlPatterns = { "/chart" }, asyncSupported = true) +public class ChartServletExample extends HttpServlet { + + private static Map<String, Chart> chartMap = new HashMap<String, Chart>(); + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { + + String id = request.getParameter("id"); + + Chart chart = chartMap.get(id); + + response.setContentType("image/png"); + ServletOutputStream out = response.getOutputStream(); + + try { + BitmapEncoder.streamPNG(out, chart); + } catch (Exception e) { + e.printStackTrace(); + } + + out.close(); + + chart = null; + + chartMap.remove(id); + } + + /** + * Generates a chart and puts it in chartMap + * + * @return UUID uniquely identifying chart in the chartMap + */ + public static String generateDummyChart() { + + Chart chart = QuickChart.getChart("Sample Chart", "X", "Y", null, null, new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + String uuid = UUID.randomUUID().toString(); + chartMap.put(uuid, chart); + + return uuid; + } +} diff --git a/src/test/java/com/xeiam/xchart/example/Example1.java b/src/test/java/com/xeiam/xchart/example/Example1.java new file mode 100644 index 00000000..7eff2381 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example1.java @@ -0,0 +1,46 @@ +/** + * 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.example; + +import com.xeiam.xchart.BitmapEncoder; +import com.xeiam.xchart.Chart; + +/** + * Creates a simple charts and saves it as aPNG image file. + * + * @author timmolter + */ +public class Example1 { + + public static void main(String[] args) { + + double[] xData = { 0.0, 1.0, 2.0 }; + double[] yData = { 0.0, 1.0, 2.0 }; + + // Create Chart + Chart chart = new Chart(500, 400); + chart.setChartTitle("Sample Chart"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + chart.addSeries("y(x)", xData, yData); + + try { + BitmapEncoder.savePNG(chart, "./Sample_Chart.png"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/com/xeiam/xchart/example/Example2.java b/src/test/java/com/xeiam/xchart/example/Example2.java new file mode 100644 index 00000000..02a1f115 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example2.java @@ -0,0 +1,62 @@ +/** + * 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.example; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.series.Series; +import com.xeiam.xchart.series.SeriesColor; +import com.xeiam.xchart.series.SeriesLineStyle; +import com.xeiam.xchart.series.SeriesMarker; +import com.xeiam.xchart.swing.SwingWrapper; + +/** + * Embed a Chart in a simple Swing application + * + * @author timmolter + */ +public class Example2 { + + public static void main(String[] args) { + + // generates sine data + int size = 30; + double[] xData1 = new double[size + 1]; + double[] yData1 = new double[size + 1]; + for (int i = 0; i <= size; i++) { + double radians = (Math.PI / (size / 2) * i); + xData1[i] = i - size / 2; + yData1[i] = size * Math.sin(radians); + } + + // Create Chart + Chart chart = new Chart(440, 300); + + // Customize Chart + chart.setChartTitleVisible(false); + chart.setChartLegendVisible(false); + chart.setAxisTitlesVisible(false); + + // Series 1 + Series series1 = chart.addSeries("y=sin(x)", xData1, yData1); + series1.setLineColor(SeriesColor.PURPLE); + series1.setLineStyle(SeriesLineStyle.DASH_DASH); + series1.setMarkerColor(SeriesColor.GREEN); + series1.setMarker(SeriesMarker.SQUARE); + + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/src/test/java/com/xeiam/xchart/example/Example3.java b/src/test/java/com/xeiam/xchart/example/Example3.java new file mode 100644 index 00000000..bd5bf769 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example3.java @@ -0,0 +1,57 @@ +/** + * 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.example; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.swing.SwingWrapper; + +/** + * Create multiple curves on one chart + * + * @author timmolter + */ +public class Example3 { + + public static void main(String[] args) { + + // Create Chart + Chart chart = new Chart(700, 500); + + for (int i = 1; i <= 14; i++) { + + // generates linear data + int b = 20; + double[] xData = new double[b + 1]; + double[] yData = new double[b + 1]; + for (int x = 0; x <= b; x++) { + xData[x] = 2 * x - b; + yData[x] = 2 * i * x - i * b; + } + + // Customize Chart + chart.setChartTitle("Sample Chart"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + + String seriesName = "y=" + 2 * i + "x-" + i * b + "b"; + chart.addSeries(seriesName, xData, yData); + + } + + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/src/test/java/com/xeiam/xchart/example/Example4.java b/src/test/java/com/xeiam/xchart/example/Example4.java new file mode 100644 index 00000000..56fbeee6 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example4.java @@ -0,0 +1,60 @@ +/** + * 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.example; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.QuickChart; +import com.xeiam.xchart.swing.SwingWrapper; + +/** + * Create a chart matrix + * + * @author timmolter + */ +public class Example4 { + + public static void main(String[] args) { + + int numRows = 2; + int numCols = 2; + Chart[] charts = new Chart[numRows * numCols]; + + int chartCount = 0; + for (int i = 0; i < numRows; i++) { + for (int j = 0; j < numCols; j++) { + + charts[chartCount++] = QuickChart.getChart(i + "," + j, "X", "Y", null, null, getRandomWalk(1000)); + } + } + new SwingWrapper(charts, numRows, numCols).displayChartMatrix(); + } + + /** + * Generates a set of random walk data + * + * @param numPoints + * @return + */ + private static double[] getRandomWalk(int numPoints) { + + double[] y = new double[numPoints]; + y[0] = 0; + for (int i = 1; i < y.length; i++) { + y[i] = y[i - 1] + Math.random() - .5; + } + return y; + } +} diff --git a/src/test/java/com/xeiam/xchart/example/Example5.java b/src/test/java/com/xeiam/xchart/example/Example5.java new file mode 100644 index 00000000..bb765cd9 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example5.java @@ -0,0 +1,44 @@ +/** + * 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.example; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.swing.SwingWrapper; + +/** + * Plot vertical and horizontal lines + * + * @author timmolter + */ +public class Example5 { + + public static void main(String[] args) { + + // Create Chart + Chart chart = new Chart(700, 500); + + // Customize Chart + chart.setChartTitle("Sample Chart"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + + chart.addSeries("vertical", new double[] { 1, 1 }, new double[] { -10, 10 }); + chart.addSeries("horizontal", new double[] { -10, 10 }, new double[] { 0, 0 }); + + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/src/test/java/com/xeiam/xchart/example/Example6.java b/src/test/java/com/xeiam/xchart/example/Example6.java new file mode 100644 index 00000000..a283dc64 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example6.java @@ -0,0 +1,43 @@ +/** + * 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.example; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.swing.SwingWrapper; + +/** + * Create chart with single point + * + * @author timmolter + */ +public class Example6 { + + public static void main(String[] args) { + + // Create Chart + Chart chart = new Chart(700, 500); + + // Customize Chart + chart.setChartTitle("Sample Chart"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + + chart.addSeries("single point (1,1)", new double[] { 1 }, new double[] { 1 }); + + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/src/test/java/com/xeiam/xchart/example/Example7.java b/src/test/java/com/xeiam/xchart/example/Example7.java new file mode 100644 index 00000000..8a4949e6 --- /dev/null +++ b/src/test/java/com/xeiam/xchart/example/Example7.java @@ -0,0 +1,43 @@ +/** + * 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.example; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.swing.SwingWrapper; + +/** + * Create chart with NaN values + * + * @author timmolter + */ +public class Example7 { + + public static void main(String[] args) { + + // Create Chart + Chart chart = new Chart(700, 500); + + // Customize Chart + chart.setChartTitle("Sample Chart"); + chart.setXAxisTitle("X"); + chart.setYAxisTitle("Y"); + + chart.addSeries("NaN Value at (3,2)", null, new double[] { 0, 1, Double.NaN, 3, 4 }); + + new SwingWrapper(chart).displayChart(); + } + +} diff --git a/src/test/java/com/xeiam/xchart/unit/TestNumberCollection.java b/src/test/java/com/xeiam/xchart/unit/TestNumberCollection.java new file mode 100644 index 00000000..eaf5b86c --- /dev/null +++ b/src/test/java/com/xeiam/xchart/unit/TestNumberCollection.java @@ -0,0 +1,46 @@ +package com.xeiam.xchart.unit; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Test; + +/** + * @author timmolter + * @create Aug 14, 2012 + */ +public class TestNumberCollection { + + @Test + public void testNumber2double() { + + Number myInteger = new Integer(688); + assertThat(myInteger.doubleValue(), is(equalTo(new Double(688).doubleValue()))); + + Number myLong = new Long(976320011); + assertThat(myLong.doubleValue(), is(equalTo(new Long(976320011).doubleValue()))); + + Number myFloat = new Float(95.4765217889); + assertThat(myFloat.doubleValue(), is(equalTo(new Float(95.4765217889).doubleValue()))); + + Number myDouble = new Double(33.2); + assertThat(myDouble.doubleValue(), is(equalTo(33.2))); + + } + + @Test + public void testDoubleInfinity() { + + Number myDouble = new Double(33.2); + assertThat(myDouble.doubleValue(), is(not(equalTo(Double.POSITIVE_INFINITY)))); + + myDouble = new Double(Double.POSITIVE_INFINITY); + assertThat(myDouble.doubleValue(), is(equalTo(Double.POSITIVE_INFINITY))); + + Number myInteger = new Integer(688); + assertThat(myInteger.doubleValue(), is(not(equalTo(Double.POSITIVE_INFINITY)))); + + } +} -- GitLab