Skip to content
Snippets Groups Projects
Commit 43e96aa9 authored by Tim Molter's avatar Tim Molter
Browse files

added sanity check for log data - cannot be less than zero

parent fbee064d
Branches
No related tags found
No related merge requests found
......@@ -20,7 +20,6 @@ import java.util.List;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart;
import com.xeiam.xchart.style.StyleManager.LegendPosition;
......@@ -47,11 +46,11 @@ public class LineChart01 implements ExampleChart {
public Chart getChart() {
// generates Log data
List<Number> xData1 = new ArrayList<Number>();
List<Number> yData1 = new ArrayList<Number>();
for (int i = 0; i <= 10; i++) {
xData1.add(i);
yData1.add(Math.pow(10, i));
List<Number> xData = new ArrayList<Number>();
List<Number> yData = new ArrayList<Number>();
for (int i = -3; i <= 3; i++) {
xData.add(i);
yData.add(Math.pow(10, i) - 1);
}
// Create Chart
......@@ -63,7 +62,7 @@ public class LineChart01 implements ExampleChart {
chart.getStyleManager().setYAxisLogarithmic(true);
// Series
Series series = chart.addSeries("10^x", xData1, yData1);
chart.addSeries("10^x", xData, yData);
return chart;
}
......
......@@ -17,6 +17,7 @@ package com.xeiam.xchart;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
......@@ -97,10 +98,16 @@ public class Chart {
*/
public void paint(Graphics2D g) {
// Sanity check
// Sanity checks
if (axisPair.getSeriesMap().isEmpty()) {
throw new RuntimeException("No series defined for Chart!!!");
}
if (getStyleManager().isXAxisLogarithmic() && axisPair.getxAxis().getMin().compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Series data cannot be less or equal to zero for a logarithmic X-Axis!!!");
}
if (getStyleManager().isYAxisLogarithmic() && axisPair.getyAxis().getMin().compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Series data cannot be less or equal to zero for a logarithmic Y-Axis!!!");
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint
g.setColor(styleManager.getChartBackgroundColor());
......
......@@ -25,9 +25,10 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Cycles through the different colors, markers, and strokes in a predetermined way
* <p>
* This is an internal class that should not be used be clients
*
* @author timmolter
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment