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

code format

parent ee82986e
No related branches found
No related tags found
No related merge requests found
Showing
with 81 additions and 231 deletions
......@@ -56,186 +56,24 @@ public class AreaLineChart03 implements ExampleChart {
chart.getStyleManager().setChartType(ChartType.Line);
// @formatter:off
double[] xAges = new double[]{
60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
double[] xAges = new double[] { 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 };
double[] yLiability = new double[]{
672234,
691729,
711789,
732431,
753671,
775528,
798018,
821160,
844974,
869478,
907735,
887139,
865486,
843023,
819621,
795398,
770426,
744749,
719011,
693176,
667342,
641609,
616078,
590846,
565385,
540002,
514620,
489380,
465149,
441817,
419513,
398465,
377991,
358784,
340920,
323724,
308114,
293097,
279356,
267008,
254873
};
double[] yLiability = new double[] { 672234, 691729, 711789, 732431, 753671, 775528, 798018, 821160, 844974, 869478, 907735, 887139, 865486,
843023, 819621, 795398, 770426, 744749, 719011, 693176, 667342, 641609, 616078, 590846, 565385, 540002, 514620, 489380, 465149, 441817,
419513, 398465, 377991, 358784, 340920, 323724, 308114, 293097, 279356, 267008, 254873 };
double[] yPercentile75th = new double[]{
800000,
878736,
945583,
1004209,
1083964,
1156332,
1248041,
1340801,
1440138,
1550005,
1647728,
1705046,
1705032,
1710672,
1700847,
1683418,
1686522,
1674901,
1680456,
1679164,
1668514,
1672860,
1673988,
1646597,
1641842,
1653758,
1636317,
1620725,
1589985,
1586451,
1559507,
1544234,
1529700,
1507496,
1474907,
1422169,
1415079,
1346929,
1311689,
1256114,
1221034
};
double[] yPercentile75th = new double[] { 800000, 878736, 945583, 1004209, 1083964, 1156332, 1248041, 1340801, 1440138, 1550005, 1647728,
1705046, 1705032, 1710672, 1700847, 1683418, 1686522, 1674901, 1680456, 1679164, 1668514, 1672860, 1673988, 1646597, 1641842, 1653758,
1636317, 1620725, 1589985, 1586451, 1559507, 1544234, 1529700, 1507496, 1474907, 1422169, 1415079, 1346929, 1311689, 1256114, 1221034 };
double[] yPercentile50th = new double[]{
800000,
835286,
873456,
927048,
969305,
1030749,
1101102,
1171396,
1246486,
1329076,
1424666,
1424173,
1421853,
1397093,
1381882,
1364562,
1360050,
1336885,
1340431,
1312217,
1288274,
1271615,
1262682,
1237287,
1211335,
1191953,
1159689,
1117412,
1078875,
1021020,
974933,
910189,
869154,
798476,
744934,
674501,
609237,
524516,
442234,
343960,
257025
};
double[] yPercentile50th = new double[] { 800000, 835286, 873456, 927048, 969305, 1030749, 1101102, 1171396, 1246486, 1329076, 1424666, 1424173,
1421853, 1397093, 1381882, 1364562, 1360050, 1336885, 1340431, 1312217, 1288274, 1271615, 1262682, 1237287, 1211335, 1191953, 1159689,
1117412, 1078875, 1021020, 974933, 910189, 869154, 798476, 744934, 674501, 609237, 524516, 442234, 343960, 257025 };
double[] yPercentile25th = new double[]{
800000,
791439,
809744,
837020,
871166,
914836,
958257,
1002955,
1054094,
1118934,
1194071,
1185041,
1175401,
1156578,
1132121,
1094879,
1066202,
1054411,
1028619,
987730,
944977,
914929,
880687,
809330,
783318,
739751,
696201,
638242,
565197,
496959,
421280,
358113,
276518,
195571,
109514,
13876,
29,
0,
0,
0,
0};
double[] yPercentile25th = new double[] { 800000, 791439, 809744, 837020, 871166, 914836, 958257, 1002955, 1054094, 1118934, 1194071, 1185041,
1175401, 1156578, 1132121, 1094879, 1066202, 1054411, 1028619, 987730, 944977, 914929, 880687, 809330, 783318, 739751, 696201, 638242,
565197, 496959, 421280, 358113, 276518, 195571, 109514, 13876, 29, 0, 0, 0, 0 };
// @formatter:on
Series seriesLiability = chart.addSeries("Liability", xAges, yLiability);
......
......@@ -36,22 +36,22 @@ public class TestForIssue83 {
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 };
{ 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 };
{ 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);
......
......@@ -53,7 +53,7 @@ public final class BitmapEncoder {
public enum BitmapFormat {
PNG, JPG, BMP, GIF;
}
/**
* Only adds the extension of the BitmapFormat to the filename if the filename doesn't already have it.
*
......@@ -62,13 +62,13 @@ public final class BitmapEncoder {
* @return filename (if extension already exists), otherwise;: filename + "." + extension
*/
public static String addFileExtension(String fileName, BitmapFormat bitmapFormat) {
String fileNameWithFileExtension = fileName;
final String newFileExtension = "." + bitmapFormat.toString().toLowerCase();
if (fileName.length() <= newFileExtension.length() ||
!fileName.substring(fileName.length()-newFileExtension.length(), fileName.length()).equalsIgnoreCase(newFileExtension)) {
fileNameWithFileExtension = fileName + newFileExtension;
}
return fileNameWithFileExtension;
String fileNameWithFileExtension = fileName;
final String newFileExtension = "." + bitmapFormat.toString().toLowerCase();
if (fileName.length() <= newFileExtension.length() || !fileName.substring(fileName.length() - newFileExtension.length(), fileName.length()).equalsIgnoreCase(newFileExtension)) {
fileNameWithFileExtension = fileName + newFileExtension;
}
return fileNameWithFileExtension;
}
/**
......@@ -101,8 +101,7 @@ public final class BitmapEncoder {
double scaleFactor = DPI / 72.0;
BufferedImage bufferedImage = new BufferedImage((int) (chart.getWidth() * scaleFactor), (int) (chart.getHeight() * scaleFactor),
BufferedImage.TYPE_INT_RGB);
BufferedImage bufferedImage = new BufferedImage((int) (chart.getWidth() * scaleFactor), (int) (chart.getHeight() * scaleFactor), BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
......
......@@ -25,8 +25,8 @@ import java.util.Collection;
import java.util.Iterator;
/**
* This class is used to export Chart data to a folder containing one or more CSV files. The parent folder's name is the title of the chart. Each series becomes a CSV file in the folder. The series'
* name becomes the CSV files' name.
* This class is used to export Chart data to a folder containing one or more CSV files. The parent folder's name is the title of the chart. Each
* series becomes a CSV file in the folder. The series' name becomes the CSV files' name.
*
* @author timmolter
*/
......
......@@ -25,8 +25,8 @@ import java.util.List;
import com.xeiam.xchart.StyleManager.ChartTheme;
/**
* This class is used to create a Chart object from a folder containing one or more CSV files. The parent folder's name becomes the title of the chart. Each CSV file in the folder becomes a series on
* the chart. the CSV file's name becomes the series' name.
* This class is used to create a Chart object from a folder containing one or more CSV files. The parent folder's name becomes the title of the
* chart. Each CSV file in the folder becomes a series on the chart. the CSV file's name becomes the series' name.
*
* @author timmolter
*/
......
......@@ -93,11 +93,14 @@ public class Histogram {
int bin = (int) ((doubleValue - min) / binSize); // changed this from numBins
if (bin < 0) { /* this data is smaller than min */
// System.out.println("less than");
} else if (doubleValue == max) { // the value falls exactly on the max value
}
else if (doubleValue == max) { // the value falls exactly on the max value
tempYAxisData[bin - 1] += 1;
} else if (bin > numBins || bin == numBins) { /* this data point is bigger than max */
}
else if (bin > numBins || bin == numBins) { /* this data point is bigger than max */
// System.out.println("greater than");
} else {
}
else {
tempYAxisData[bin] += 1;
}
}
......
......@@ -142,20 +142,26 @@ public class XChartPanel extends JPanel {
try {
if (fileChooser.getFileFilter() == null) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath().toString(), BitmapFormat.PNG);
} else if (fileChooser.getFileFilter().getDescription().equals("*.jpg,*.JPG")) {
BitmapEncoder.saveJPGWithQuality(chart, BitmapEncoder.addFileExtension(theFileToSave.getCanonicalPath().toString(), BitmapFormat.JPG),
1.0f);
} else if (fileChooser.getFileFilter().getDescription().equals("*.png,*.PNG")) {
}
else if (fileChooser.getFileFilter().getDescription().equals("*.jpg,*.JPG")) {
BitmapEncoder.saveJPGWithQuality(chart, BitmapEncoder.addFileExtension(theFileToSave.getCanonicalPath().toString(), BitmapFormat.JPG), 1.0f);
}
else if (fileChooser.getFileFilter().getDescription().equals("*.png,*.PNG")) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath().toString(), BitmapFormat.PNG);
} else if (fileChooser.getFileFilter().getDescription().equals("*.bmp,*.BMP")) {
}
else if (fileChooser.getFileFilter().getDescription().equals("*.bmp,*.BMP")) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath().toString(), BitmapFormat.BMP);
} else if (fileChooser.getFileFilter().getDescription().equals("*.gif,*.GIF")) {
}
else if (fileChooser.getFileFilter().getDescription().equals("*.gif,*.GIF")) {
BitmapEncoder.saveBitmap(chart, theFileToSave.getCanonicalPath().toString(), BitmapFormat.GIF);
} else if (fileChooser.getFileFilter().getDescription().equals("*.svg,*.SVG")) {
}
else if (fileChooser.getFileFilter().getDescription().equals("*.svg,*.SVG")) {
VectorGraphicsEncoder.saveVectorGraphic(chart, theFileToSave.getCanonicalPath().toString(), VectorGraphicsFormat.SVG);
} else if (fileChooser.getFileFilter().getDescription().equals("*.eps,*.EPS")) {
}
else if (fileChooser.getFileFilter().getDescription().equals("*.eps,*.EPS")) {
VectorGraphicsEncoder.saveVectorGraphic(chart, theFileToSave.getCanonicalPath().toString(), VectorGraphicsFormat.EPS);
} else if (fileChooser.getFileFilter().getDescription().equals("*.pdf,*.PDF")) {
}
else if (fileChooser.getFileFilter().getDescription().equals("*.pdf,*.PDF")) {
VectorGraphicsEncoder.saveVectorGraphic(chart, theFileToSave.getCanonicalPath().toString(), VectorGraphicsFormat.PDF);
}
} catch (IOException e) {
......@@ -172,12 +178,14 @@ public class XChartPanel extends JPanel {
* @author Benedikt Bünz
*/
private class SuffixSaveFilter extends FileFilter {
private final String suffix;
/**
* @param suffix This file filter accepts all files that end with .suffix or the capitalized suffix.
*/
public SuffixSaveFilter(String suffix) {
this.suffix = suffix;
}
......
......@@ -147,11 +147,11 @@ public class Axis implements ChartPart {
// Axis tick labels
double axisTickLabelsHeight = 0.0;
if (getChartPainter().getStyleManager().isXAxisTicksVisible()) {
String tickLabel = getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ?
new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0";
String tickLabel =
getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ? new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0";
TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
AffineTransform rot = getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null :
AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
AffineTransform rot =
getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength();
......
......@@ -88,8 +88,8 @@ public class AxisTickLabels implements ChartPart {
for (Double tickLocation : axisLabelTextLayouts.keySet()) {
TextLayout axisLabelTextLayout = axisLabelTextLayouts.get(tickLocation);
AffineTransform rot = getChartPainter().getStyleManager().getYAxisLabelRotation() == 0 ? null :
AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getYAxisLabelRotation()));
AffineTransform rot =
getChartPainter().getStyleManager().getYAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getYAxisLabelRotation()));
Shape shape = axisLabelTextLayout.getOutline(rot);
Rectangle2D tickLabelBounds = shape.getBounds();
......@@ -144,8 +144,8 @@ public class AxisTickLabels implements ChartPart {
TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc);
// Shape shape = v.getOutline();
AffineTransform rot = getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null :
AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
AffineTransform rot =
getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D tickLabelBounds = shape.getBounds2D();
......
......@@ -60,11 +60,11 @@ public class Plot implements ChartPart {
// calculate bounds
double xOffset = chartPainter.getAxisPair().getYAxis().getBounds().getX()
+ chartPainter.getAxisPair().getYAxis().getBounds().getWidth()
+ chartPainter.getAxisPair().getYAxis().getBounds().getWidth()
+ (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding()) : 0)
+ (chartPainter.getStyleManager().isYAxisTicksVisible() ? (chartPainter.getStyleManager().getPlotPadding()) : 0)
;
;
double yOffset = chartPainter.getAxisPair().getYAxis().getBounds().getY();
double width = chartPainter.getAxisPair().getXAxis().getBounds().getWidth();
......
......@@ -16,7 +16,9 @@
package com.xeiam.xchart;
import static org.fest.assertions.api.Assertions.assertThat;
import java.util.Arrays;
import org.junit.Test;
/**
......@@ -34,9 +36,9 @@ public class HistogramTest {
assertThat(histogram.getNumBins()).isEqualTo(2);
assertThat(histogram.getyAxisData().get(0) + histogram.getyAxisData().get(1)).isEqualTo(4);
// Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).build();
// chart.addSeries("histogram 1", histogram.getxAxisData(), histogram.getyAxisData());
// new SwingWrapper(chart).displayChart();
// Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).build();
// chart.addSeries("histogram 1", histogram.getxAxisData(), histogram.getyAxisData());
// new SwingWrapper(chart).displayChart();
}
@Test
......
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