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

Merge branch 'develop'

parents e16f5b38 8a6c53f3
No related branches found
No related tags found
No related merge requests found
Showing
with 255 additions and 21 deletions
......@@ -21,6 +21,7 @@ log/
# Misc.
.DS_Store
*.bak
# Sample images
*.png
......@@ -29,4 +30,5 @@ log/
*.gif
*.svg
*.pdf
*.eps
\ No newline at end of file
*.eps
......@@ -63,7 +63,7 @@ Add the XChart library as a dependency to your pom.xml file:
<dependency>
<groupId>com.xeiam.xchart</groupId>
<artifactId>xchart</artifactId>
<version>2.4.2</version>
<version>2.4.3</version>
</dependency>
For snapshots, add the following to your pom.xml file:
......@@ -77,8 +77,10 @@ For snapshots, add the following to your pom.xml file:
<dependency>
<groupId>com.xeiam</groupId>
<artifactId>xchart</artifactId>
<version>2.4.3-SNAPSHOT</version>
<version>2.4.4-SNAPSHOT</version>
</dependency>
Snapshots can be manually downloaded from Sonatyope: [https://oss.sonatype.org/content/groups/public/com/xeiam/xchart/xchart/](https://oss.sonatype.org/content/groups/public/com/xeiam/xchart/xchart/)
## Building
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xeiam.xchart</groupId>
<artifactId>xchart-parent</artifactId>
<version>2.4.3-SNAPSHOT</version>
<version>2.4.4-SNAPSHOT</version>
<packaging>pom</packaging>
<name>XChart Parent</name>
<description>Basic Charts for Java Applications</description>
......@@ -136,6 +135,7 @@
</executions>
<configuration>
<excludePackageNames>com.xeiam.xchart.internal.*</excludePackageNames>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
<plugin>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>com.xeiam.xchart</groupId>
<artifactId>xchart-parent</artifactId>
<version>2.4.3-SNAPSHOT</version>
<version>2.4.4-SNAPSHOT</version>
</parent>
<artifactId>xchart-demo</artifactId>
......@@ -17,7 +17,7 @@
<dependency>
<groupId>com.xeiam.xchart</groupId>
<artifactId>xchart</artifactId>
<version>2.4.3-SNAPSHOT</version>
<version>2.4.4-SNAPSHOT</version>
</dependency>
</dependencies>
......
......@@ -41,6 +41,7 @@ import com.xeiam.xchart.demo.charts.bar.BarChart04;
import com.xeiam.xchart.demo.charts.bar.BarChart05;
import com.xeiam.xchart.demo.charts.bar.BarChart06;
import com.xeiam.xchart.demo.charts.bar.BarChart07;
import com.xeiam.xchart.demo.charts.bar.BarChart08;
import com.xeiam.xchart.demo.charts.date.DateChart01;
import com.xeiam.xchart.demo.charts.date.DateChart02;
import com.xeiam.xchart.demo.charts.date.DateChart03;
......@@ -261,6 +262,9 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("BarChart07 - Histogram Not Overlapped", new BarChart07().getChart()));
category.add(defaultMutableTreeNode);
defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("BarChart08 - Histogram with Error Bars", new BarChart08().getChart()));
category.add(defaultMutableTreeNode);
// Theme category
category = new DefaultMutableTreeNode("Chart Themes");
top.add(category);
......
/**
* Copyright 2011 - 2014 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.demo.charts.bar;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.Histogram;
import com.xeiam.xchart.StyleManager.ChartType;
import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart;
/**
* Histogram with Error Bars
* <p>
* Demonstrates the following:
* <ul>
* <li>Histogram
* <li>Bar Chart with error bars
*/
public class BarChart08 implements ExampleChart {
public static void main(String[] args) {
ExampleChart exampleChart = new BarChart08();
Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart();
}
@Override
public Chart getChart() {
// Create Chart
Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Histogram").xAxisTitle("Mean").yAxisTitle("Count").build();
Histogram histogram1 = new Histogram(getGaussianData(10000), 10, -10, 10);
chart.addSeries("histogram", histogram1.getxAxisData(), histogram1.getyAxisData(), getFakeErrorData(histogram1.getxAxisData().size()));
// Customize Chart
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setBarWidthPercentage(.96);
return chart;
}
private List<Double> getGaussianData(int count) {
List<Double> data = new ArrayList<Double>(count);
Random r = new Random();
for (int i = 0; i < count; i++) {
data.add(r.nextGaussian() * 5);
// data.add(r.nextDouble() * 60 - 30);
}
return data;
}
private List<Double> getFakeErrorData(int count) {
List<Double> data = new ArrayList<Double>(count);
Random r = new Random();
for (int i = 0; i < count; i++) {
data.add(r.nextDouble() * 200);
}
return data;
}
}
/**
* Copyright 2013 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.standalone;
import java.io.IOException;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.SeriesLineStyle;
import com.xeiam.xchart.StyleManager;
import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.SwingWrapper;
/**
* @author timmolter
*/
public class TestForIssue83 {
public static void main(String[] args) throws IOException {
final Chart chart = new Chart(500, 580);
final StyleManager styleManager = chart.getStyleManager();
styleManager.setLegendPosition(LegendPosition.InsideNW);
styleManager.setLegendVisible(false);
final double[] keys =
{ 101.6829700157669, 102.4741546172069, 101.56112372430265, 102.29668967750219, 102.1156928915296, 102.96288807133006, 102.85820232291313, 102.70416779932134, 102.75666703633065,
102.54695164724063, 102.64530701963236, 101.42229521418183, 102.6239220187132, 102.65392830689318, 101.3519528210374, 102.29890454069181, 101.45011555581048, 102.80876656547879,
102.9487829236201, 102.65658212119392, 102.5621808062546, 102.54679368788584, 101.44415451644835, 101.52360532420516, 102.7494132740427, 103.03755466140984, 102.75544822301157,
102.47525429542132, 102.63811088590982, 102.59191775294347, 101.32048881637581, 101.44482698818119, 102.80932781766394, 101.38219670988731, 101.46941028338044, 102.66645765488023,
101.79878506072832, 102.12919834900144, 102.65694786373456, 101.34087876032368, 102.35962292551396, 102.73324077985815, 101.6331900389947, 102.68657071464266, 102.31073017053264,
102.95034563173265, 101.56466092390214, 101.44263290542328, 102.54872192620866, 101.51961724673545, 101.56592215239088, 102.62299979115573, 102.16037884019369, 102.76241468528423,
103.06247033542299, 102.50392407673121, 102.71485878177548, 102.30595719462644, 101.83799733593067, 102.64446820738182, 102.95845141559543, 101.44913643540103, 102.62302475018619,
101.35064046209624, 102.49385977096229, 102.47902987190186, 102.6192546853896, 101.31787966105605, 102.61902499800594, 102.75304600782704, 102.66323038080031, 102.62927538605312,
101.41262366698777, 103.06302964768331, 103.01984694209135, 101.54079454702787, 101.7432632007971, 102.64746484983125, 102.94083129713017, 101.38693917529486, 102.28688939180357,
101.77714391046378, 102.61582509980576, 102.889235861335, 102.50686276405479, 103.09822940528373, 102.58948098022869, 102.70749156936542, 102.64387765680111, 102.75465208779484,
102.36218073405826 };
final double[] values =
{ 40.37, 40.59, 40.31, 40.4, 40.39, 40.52, 40.47, 40.56, 40.46, 40.53, 40.58, 40.34, 40.55, 40.58, 40.33, 40.44, 40.36, 40.57, 40.48, 40.53, 40.55, 40.53, 40.3, 40.31, 40.45, 40.49, 40.47,
40.59, 40.55, 40.55, 40.35, 40.32, 40.57, 40.33, 40.34, 40.57, 40.38, 40.39, 40.53, 40.33, 40.41, 40.56, 40.37, 40.46, 40.44, 40.47, 40.31, 40.36, 40.55, 40.36, 40.31, 40.6, 40.39, 40.46,
40.49, 40.42, 40.58, 40.44, 40.38, 40.53, 40.5, 40.32, 40.6, 40.33, 40.41, 40.41, 40.53, 40.35, 40.57, 40.46, 40.56, 40.55, 40.34, 40.49, 40.51, 40.32, 40.37, 40.57, 40.5, 40.35, 40.43,
40.38, 40.58, 40.52, 40.59, 40.49, 40.55, 40.56, 40.53, 40.47, 40.41 };
chart.addSeries("Results", keys, values).setLineStyle(SeriesLineStyle.NONE);
// BitmapEncoder.saveBitmap(chart, "example", BitmapFormat.PNG);
new SwingWrapper(chart).displayChart();
}
}
......@@ -5,7 +5,7 @@
<parent>
<groupId>com.xeiam.xchart</groupId>
<artifactId>xchart-parent</artifactId>
<version>2.4.3-SNAPSHOT</version>
<version>2.4.4-SNAPSHOT</version>
</parent>
<artifactId>xchart</artifactId>
......
......@@ -143,6 +143,7 @@ public class StyleManager {
// Error Bars ///////////////////////////////
private Color errorBarsColor;
private boolean isErrorBarsColorSeriesColor;
// Formatting ////////////////////////////////
private Locale locale;
......@@ -231,6 +232,7 @@ public class StyleManager {
// Error Bars ///////////////////////////////
errorBarsColor = theme.getErrorBarsColor();
isErrorBarsColorSeriesColor = theme.isErrorBarsColorSeriesColor();
// Formatting ////////////////////////////////
locale = Locale.getDefault();
......@@ -1045,7 +1047,7 @@ public class StyleManager {
/**
* set whether or no bars are filled with a solid color or empty.
*
*
* @param isBarFilled
*/
public void setBarFilled(boolean isBarFilled) {
......@@ -1092,6 +1094,21 @@ public class StyleManager {
return errorBarsColor;
}
/**
* Set true if the the error bar color should match the series color
*
* @return
*/
public void setErrorBarsColorSeriesColor(boolean isErrorBarsColorSeriesColor) {
this.isErrorBarsColorSeriesColor = isErrorBarsColorSeriesColor;
}
public boolean isErrorBarsColorSeriesColor() {
return isErrorBarsColorSeriesColor;
}
// Formatting ////////////////////////////////
/**
......
......@@ -64,12 +64,12 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
BigDecimal gridStep = BigDecimal.valueOf(getNumericalGridStep(tickSpace));
// System.out.println("***gridStep: " + gridStep);
BigDecimal cleanedGridStep = gridStep.setScale(16, RoundingMode.HALF_UP); // chop off any double imprecision
BigDecimal cleanedGridStep = gridStep.setScale(10, RoundingMode.HALF_UP).stripTrailingZeros(); // chop off any double imprecision
// System.out.println("cleanedGridStep: " + cleanedGridStep);
BigDecimal firstPosition = BigDecimal.valueOf(getFirstPosition(cleanedGridStep.doubleValue()));
// System.out.println("firstPosition: " + firstPosition); // chop off any double imprecision
BigDecimal cleanedFirstPosition = firstPosition.setScale(16, RoundingMode.HALF_UP); // chop off any double imprecision
// System.out.println("scaledfirstPosition: " + cleanedFirstPosition);
BigDecimal cleanedFirstPosition = firstPosition.setScale(10, RoundingMode.HALF_UP).stripTrailingZeros(); // chop off any double imprecision
// System.out.println("cleanedFirstPosition: " + cleanedFirstPosition);
// generate all tickLabels and tickLocations from the first to last position
for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) {
......
......@@ -17,6 +17,8 @@ package com.xeiam.xchart.internal.chartpart;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
......@@ -122,6 +124,11 @@ public class PlotContentBarChart extends PlotContent {
// all the x-axis data are guaranteed to be the same so we just use the first one
Iterator<? extends Number> yItr = yData.iterator();
Iterator<? extends Number> ebItr = null;
Collection<? extends Number> errorBars = series.getErrorBars();
if (errorBars != null) {
ebItr = errorBars.iterator();
}
int barCounter = 0;
while (yItr.hasNext()) {
......@@ -210,6 +217,41 @@ public class PlotContentBarChart extends PlotContent {
g.draw(path);
}
// paint errorbars
if (errorBars != null) {
double eb = ebItr.next().doubleValue();
// set error bar style
if (getChartPainter().getStyleManager().isErrorBarsColorSeriesColor()) {
g.setColor(series.getStrokeColor());
}
else {
g.setColor(getChartPainter().getStyleManager().getErrorBarsColor());
}
g.setStroke(errorBarStroke);
// Top value
double topValue = y + eb;
double topEBTransform = bounds.getHeight() - (yTopMargin + (topValue - yMin) / (yMax - yMin) * yTickSpace);
double topEBOffset = bounds.getY() + topEBTransform;
// Bottom value
double bottomValue = y - eb;
double bottomEBTransform = bounds.getHeight() - (yTopMargin + (bottomValue - yMin) / (yMax - yMin) * yTickSpace);
double bottomEBOffset = bounds.getY() + bottomEBTransform;
// Draw it
double errorBarOffset = xOffset + barWidth / 2;
Shape line = new Line2D.Double(errorBarOffset, topEBOffset, errorBarOffset, bottomEBOffset);
g.draw(line);
line = new Line2D.Double(errorBarOffset - 3, bottomEBOffset, errorBarOffset + 3, bottomEBOffset);
g.draw(line);
line = new Line2D.Double(errorBarOffset - 3, topEBOffset, errorBarOffset + 3, topEBOffset);
g.draw(line);
}
}
seriesCounter++;
}
......
......@@ -114,7 +114,6 @@ public class PlotContentLineChart extends PlotContent {
yMin = Math.log10(yMin);
yMax = Math.log10(yMax);
}
Collection<? extends Number> errorBars = series.getErrorBars();
double previousX = Integer.MIN_VALUE;
double previousY = Integer.MIN_VALUE;
......@@ -122,6 +121,7 @@ public class PlotContentLineChart extends PlotContent {
Iterator<?> xItr = xData.iterator();
Iterator<? extends Number> yItr = yData.iterator();
Iterator<? extends Number> ebItr = null;
Collection<? extends Number> errorBars = series.getErrorBars();
if (errorBars != null) {
ebItr = errorBars.iterator();
}
......@@ -227,18 +227,20 @@ public class PlotContentLineChart extends PlotContent {
}
// paint errorbars
double eb = 0.0;
if (errorBars != null) {
eb = ebItr.next().doubleValue();
}
if (errorBars != null) {
double eb = ebItr.next().doubleValue();
g.setColor(getChartPainter().getStyleManager().getErrorBarsColor());
// set error bar style
if (getChartPainter().getStyleManager().isErrorBarsColorSeriesColor()) {
g.setColor(series.getStrokeColor());
}
else {
g.setColor(getChartPainter().getStyleManager().getErrorBarsColor());
}
g.setStroke(errorBarStroke);
// Top value
double topValue = 0.0;
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
topValue = yOrig + eb;
......@@ -250,6 +252,7 @@ public class PlotContentLineChart extends PlotContent {
double topEBTransform = bounds.getHeight() - (yTopMargin + (topValue - yMin) / (yMax - yMin) * yTickSpace);
double topEBOffset = bounds.getY() + topEBTransform;
// Bottom value
double bottomValue = 0.0;
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
bottomValue = yOrig - eb;
......@@ -262,6 +265,7 @@ public class PlotContentLineChart extends PlotContent {
double bottomEBTransform = bounds.getHeight() - (yTopMargin + (bottomValue - yMin) / (yMax - yMin) * yTickSpace);
double bottomEBOffset = bounds.getY() + bottomEBTransform;
// Draw it
Shape line = new Line2D.Double(xOffset, topEBOffset, xOffset, bottomEBOffset);
g.draw(line);
line = new Line2D.Double(xOffset - 3, bottomEBOffset, xOffset + 3, bottomEBOffset);
......
......@@ -315,4 +315,9 @@ public class GGPlot2Theme implements Theme {
return ChartColor.getAWTColor(ChartColor.DARK_GREY);
}
@Override
public boolean isErrorBarsColorSeriesColor() {
return false;
}
}
......@@ -316,4 +316,9 @@ public class MatlabTheme implements Theme {
return ChartColor.getAWTColor(ChartColor.BLACK);
}
@Override
public boolean isErrorBarsColorSeriesColor() {
return false;
}
}
......@@ -132,4 +132,6 @@ public interface Theme {
public Color getErrorBarsColor();
public boolean isErrorBarsColorSeriesColor();
}
......@@ -312,7 +312,13 @@ public class XChartTheme implements Theme {
@Override
public Color getErrorBarsColor() {
return ChartColor.getAWTColor(ChartColor.DARK_GREY);
return ChartColor.getAWTColor(ChartColor.BLACK);
}
@Override
public boolean isErrorBarsColorSeriesColor() {
return false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment