Skip to content
Snippets Groups Projects
Commit 889a73c0 authored by timmolter's avatar timmolter
Browse files

cleaned up internal code - locked down visibility, got rid of getters, moved classes around

parent c5ff7a3d
No related branches found
No related tags found
No related merge requests found
Showing
with 151 additions and 260 deletions
......@@ -35,11 +35,11 @@ public class Axis implements IChartPart {
NUMBER, DATE;
}
/** the axisPair */
/** parent */
protected AxisPair axisPair;
/** the seriesType */
private AxisType axisType;
/** the axisType */
protected AxisType axisType;
/** the axis title */
protected AxisTitle axisTitle;
......@@ -48,11 +48,11 @@ public class Axis implements IChartPart {
protected AxisTick axisTick;
/** the axis direction */
private Direction direction;
protected Direction direction;
private BigDecimal min = null;
protected BigDecimal min = null;
private BigDecimal max = null;
protected BigDecimal max = null;
/** the bounds */
private Rectangle bounds;
......@@ -61,7 +61,7 @@ public class Axis implements IChartPart {
private Rectangle paintZone;
/** An axis direction */
public enum Direction {
protected enum Direction {
/** the constant to represent X axis */
X,
......@@ -76,7 +76,7 @@ public class Axis implements IChartPart {
* @param direction the axis direction (X or Y)
* @param chart the chart
*/
public Axis(AxisPair axisPair, Direction direction) {
protected Axis(AxisPair axisPair, Direction direction) {
this.axisPair = axisPair;
this.direction = direction;
......@@ -89,7 +89,7 @@ public class Axis implements IChartPart {
* @param min
* @param max
*/
public void addMinMax(BigDecimal min, BigDecimal max) {
protected void addMinMax(BigDecimal min, BigDecimal max) {
// System.out.println(min);
// System.out.println(max);
......@@ -104,7 +104,7 @@ public class Axis implements IChartPart {
// System.out.println(this.max);
}
public void setAxisType(AxisType axisType) {
protected void setAxisType(AxisType axisType) {
if (this.axisType != null && this.axisType != axisType) {
throw new IllegalArgumentException("Date and Number Axes cannot be mixed on the same chart!! ");
......@@ -112,23 +112,13 @@ public class Axis implements IChartPart {
this.axisType = axisType;
}
public AxisType getAxisType() {
return axisType;
}
public Direction getDirection() {
return direction;
}
@Override
public Rectangle getBounds() {
return bounds;
}
public Rectangle getPaintZone() {
protected Rectangle getPaintZone() {
return paintZone;
}
......@@ -138,30 +128,20 @@ public class Axis implements IChartPart {
return axisTitle;
}
public void setAxisTitle(String title) {
protected void setAxisTitle(String title) {
this.axisTitle.setText(title);
}
public void setAxisTitle(AxisTitle axisTitle) {
protected void setAxisTitle(AxisTitle axisTitle) {
this.axisTitle = axisTitle;
}
public BigDecimal getMin() {
return min;
}
public BigDecimal getMax() {
return max;
}
/**
* @return
*/
public int getSizeHint() {
protected int getSizeHint() {
if (direction == Direction.X) { // X-Axis
......@@ -176,7 +156,7 @@ public class Axis implements IChartPart {
// Axis tick labels
double axisTickLabelsHeight = 0.0;
if (axisTick.isVisible) {
TextLayout textLayout = new TextLayout("0", axisTick.getAxisTickLabels().font, new FontRenderContext(null, true, false));
TextLayout textLayout = new TextLayout("0", axisTick.axisTickLabels.font, new FontRenderContext(null, true, false));
Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0);
axisTickLabelsHeight = rectangle.getHeight() + AxisTick.AXIS_TICK_PADDING + AxisTickMarks.TICK_LENGTH + Plot.PLOT_PADDING;
}
......@@ -205,7 +185,7 @@ public class Axis implements IChartPart {
int xOffset = Chart.CHART_PADDING;
int yOffset = (int) (axisPair.getChartTitleBounds().getY() + axisPair.getChartTitleBounds().getHeight() + Chart.CHART_PADDING);
int width = 80; // arbitrary, final width depends on Axis tick labels
int height = axisPair.chart.getHeight() - yOffset - axisPair.getXAxis().getSizeHint() - Chart.CHART_PADDING;
int height = axisPair.chart.height - yOffset - axisPair.xAxis.getSizeHint() - Chart.CHART_PADDING;
Rectangle yAxisRectangle = new Rectangle(xOffset, yOffset, width, height);
this.paintZone = yAxisRectangle;
// g.setColor(Color.green);
......@@ -228,9 +208,9 @@ public class Axis implements IChartPart {
// calculate paint zone
// |____________________|
int xOffset = (int) (axisPair.getYAxis().getBounds().getWidth() + (axisPair.getYAxis().axisTick.isVisible ? Plot.PLOT_PADDING : 0) + Chart.CHART_PADDING);
int yOffset = (int) (axisPair.getYAxis().getBounds().getY() + axisPair.getYAxis().getBounds().getHeight());
int width = (int) (axisPair.chart.getWidth() - axisPair.getYAxis().getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (axisPair.chart.getLegend().isVisible ? 3 : 2) * Chart.CHART_PADDING);
int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (axisPair.yAxis.axisTick.isVisible ? Plot.PLOT_PADDING : 0) + Chart.CHART_PADDING);
int yOffset = (int) (axisPair.yAxis.getBounds().getY() + axisPair.yAxis.getBounds().getHeight());
int width = (int) (axisPair.chart.width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (axisPair.chart.chartLegend.isVisible ? 3 : 2) * Chart.CHART_PADDING);
int height = this.getSizeHint();
Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height);
this.paintZone = xAxisRectangle;
......
......@@ -33,24 +33,25 @@ import com.xeiam.xchart.series.Series;
*/
public class AxisPair implements IChartPart {
/** the chart */
/** parent */
protected Chart chart;
private Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>();
protected Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>();
int seriesCount = 0;
private int seriesCount;
Axis xAxis;
Axis yAxis;
protected Axis xAxis;
protected Axis yAxis;
/**
* Constructor.
*
* @param chart the chart
*/
public AxisPair(Chart chart) {
protected AxisPair(Chart chart) {
this.chart = chart;
seriesCount = 0;
// add axes
xAxis = new Axis(this, Axis.Direction.X);
......@@ -62,7 +63,7 @@ public class AxisPair implements IChartPart {
* @param xData
* @param yData
*/
public <T> Series addSeries(String seriesName, Collection<T> xData, Collection<Number> yData, Collection<Number> errorBars) {
protected <T> Series addSeries(String seriesName, Collection<T> xData, Collection<Number> yData, Collection<Number> errorBars) {
// Sanity checks
if (seriesName == null) {
......@@ -89,7 +90,7 @@ public class AxisPair implements IChartPart {
xAxis.setAxisType(AxisType.DATE);
}
yAxis.setAxisType(AxisType.NUMBER);
series = new Series(seriesName, xData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars);
series = new Series(seriesName, xData, xAxis.axisType, yData, yAxis.axisType, errorBars);
} else { // generate xData
Collection<Number> generatedXData = new ArrayList<Number>();
for (int i = 1; i < yData.size(); i++) {
......@@ -97,7 +98,7 @@ public class AxisPair implements IChartPart {
}
xAxis.setAxisType(AxisType.NUMBER);
yAxis.setAxisType(AxisType.NUMBER);
series = new Series(seriesName, generatedXData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars);
series = new Series(seriesName, generatedXData, xAxis.axisType, yData, yAxis.axisType, errorBars);
}
// Sanity check
......@@ -117,38 +118,23 @@ public class AxisPair implements IChartPart {
return series;
}
protected Axis getXAxis() {
return xAxis;
}
protected Axis getYAxis() {
return yAxis;
}
protected Rectangle getChartTitleBounds() {
return chart.getTitle().getBounds();
return chart.chartTitle.getBounds();
}
protected Rectangle getChartLegendBounds() {
return chart.getLegend().getBounds();
}
protected Map<Integer, Series> getSeriesMap() {
return seriesMap;
return chart.chartLegend.getBounds();
}
public static int getTickSpace(int workingSpace) {
protected static int getTickSpace(int workingSpace) {
int tickSpace = (int) (workingSpace * 0.95);
return tickSpace;
}
public static int getMargin(int workingSpace, int tickSpace) {
protected static int getMargin(int workingSpace, int tickSpace) {
int marginSpace = workingSpace - tickSpace;
int margin = (int) (marginSpace / 2.0);
......
......@@ -33,29 +33,29 @@ import com.xeiam.xchart.interfaces.IHideable;
*/
public class AxisTick implements IChartPart, IHideable {
/** the axis */
/** the default tick mark step hint */
private static final int DEFAULT_TICK_MARK_STEP_HINT = 64;
/** the padding between the tick labels and the tick marks */
protected final static int AXIS_TICK_PADDING = 4;
/** parent */
protected Axis axis;
/** the axisticklabels */
protected AxisTickLabels axisTickLabels;
/** the axistickmarks */
private AxisTickMarks axisTickMarks;
protected AxisTickMarks axisTickMarks;
/** the arraylist of tick label position in pixels */
private List<Integer> tickLocations;
protected List<Integer> tickLocations;
/** the arraylist of tick label vales */
private List<String> tickLabels;
/** the arraylist of tick label values */
protected List<String> tickLabels;
private int workingSpace;
/** the default tick mark step hint */
private static final int DEFAULT_TICK_MARK_STEP_HINT = 64;
/** the padding between the tick labels and the tick marks */
protected final static int AXIS_TICK_PADDING = 4;
/** the normal format for tick labels */
private Format normalFormat = new DecimalFormat("#.###########");
......@@ -85,43 +85,18 @@ public class AxisTick implements IChartPart, IHideable {
}
public AxisTickLabels getAxisTickLabels() {
return axisTickLabels;
}
public AxisTickMarks getAxisTickMarks() {
return axisTickMarks;
}
public List<String> getTickLabels() {
return tickLabels;
}
public List<Integer> getTickLocations() {
return tickLocations;
}
@Override
public Rectangle getBounds() {
return bounds;
}
protected int getWorkingSpace() {
return this.workingSpace;
}
@Override
public void paint(Graphics2D g) {
bounds = new Rectangle();
if (axis.getDirection() == Axis.Direction.Y) {
if (axis.direction == Axis.Direction.Y) {
workingSpace = (int) axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace);
} else {
......@@ -142,7 +117,7 @@ public class AxisTick implements IChartPart, IHideable {
axisTickLabels.paint(g);
axisTickMarks.paint(g);
if (axis.getDirection() == Axis.Direction.Y) {
if (axis.direction == Axis.Direction.Y) {
bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()),
(int) (axisTickLabels.getBounds().getWidth() + AXIS_TICK_PADDING + axisTickMarks.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight()));
// g.setColor(Color.red);
......@@ -173,12 +148,12 @@ public class AxisTick implements IChartPart, IHideable {
int margin = AxisPair.getMargin(workingSpace, tickSpace);
// a check if all axis data are the exact same values
if (axis.getMax() == axis.getMin()) {
tickLabels.add(format(axis.getMax()));
if (axis.max == axis.min) {
tickLabels.add(format(axis.max));
tickLocations.add((int) (margin + tickSpace / 2.0));
} else {
final BigDecimal MIN = new BigDecimal(axis.getMin().doubleValue());
final BigDecimal MIN = new BigDecimal(axis.min.doubleValue());
BigDecimal firstPosition;
BigDecimal gridStep = getGridStep(tickSpace);
......@@ -189,11 +164,11 @@ public class AxisTick implements IChartPart, IHideable {
firstPosition = MIN.subtract(MIN.remainder(gridStep)).add(gridStep);
}
for (BigDecimal b = firstPosition; b.compareTo(axis.getMax()) <= 0; b = b.add(gridStep)) {
for (BigDecimal b = firstPosition; b.compareTo(axis.max) <= 0; b = b.add(gridStep)) {
// System.out.println("b= " + b);
tickLabels.add(format(b));
int tickLabelPosition = (int) (margin + ((b.subtract(axis.getMin())).doubleValue() / (axis.getMax().subtract(axis.getMin())).doubleValue() * tickSpace));
int tickLabelPosition = (int) (margin + ((b.subtract(axis.min)).doubleValue() / (axis.max.subtract(axis.min)).doubleValue() * tickSpace));
// System.out.println("tickLabelPosition= " + tickLabelPosition);
tickLocations.add(tickLabelPosition);
......@@ -203,9 +178,9 @@ public class AxisTick implements IChartPart, IHideable {
private BigDecimal getGridStep(int tickSpace) {
double length = Math.abs(axis.getMax().subtract(axis.getMin()).doubleValue());
double length = Math.abs(axis.max.subtract(axis.min).doubleValue());
// System.out.println(axis.getMax());
// System.out.println(axis.getMin());
// System.out.println(axis.min);
// System.out.println(length);
double gridStepHint = length / tickSpace * DEFAULT_TICK_MARK_STEP_HINT;
......@@ -265,7 +240,7 @@ public class AxisTick implements IChartPart, IHideable {
private String format(BigDecimal value) {
if (axis.getAxisType() == AxisType.NUMBER) {
if (axis.axisType == AxisType.NUMBER) {
if (Math.abs(value.doubleValue()) < 9999 && Math.abs(value.doubleValue()) > .0001 || value.doubleValue() == 0) {
return normalFormat.format(value.doubleValue());
} else {
......
......@@ -28,6 +28,7 @@ import com.xeiam.xchart.interfaces.IChartPart;
*/
public class AxisTickLabels implements IChartPart {
/** parent */
private AxisTick axisTick;
/** the font */
......@@ -60,15 +61,15 @@ public class AxisTickLabels implements IChartPart {
g.setColor(axisTick.axis.axisPair.chart.fontColor);
if (axisTick.axis.getDirection() == Axis.Direction.Y) { // Y-Axis
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
int xOffset = (int) (axisTick.axis.getAxisTitle().getBounds().getX() + axisTick.axis.getAxisTitle().getBounds().getWidth());
int yOffset = (int) (axisTick.axis.getPaintZone().getY());
int maxTickLabelWidth = 0;
for (int i = 0; i < axisTick.getTickLabels().size(); i++) {
for (int i = 0; i < axisTick.tickLabels.size(); i++) {
String tickLabel = axisTick.getTickLabels().get(i);
int tickLocation = axisTick.getTickLocations().get(i);
String tickLabel = axisTick.tickLabels.get(i);
int tickLocation = axisTick.tickLocations.get(i);
FontRenderContext frc = g.getFontRenderContext();
// TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false));
......@@ -91,10 +92,10 @@ public class AxisTickLabels implements IChartPart {
int xOffset = (int) (axisTick.axis.getPaintZone().getX());
int yOffset = (int) (axisTick.axis.getAxisTitle().getBounds().getY());
int maxTickLabelHeight = 0;
for (int i = 0; i < axisTick.getTickLabels().size(); i++) {
for (int i = 0; i < axisTick.tickLabels.size(); i++) {
String tickLabel = axisTick.getTickLabels().get(i);
int tickLocation = axisTick.getTickLocations().get(i);
String tickLabel = axisTick.tickLabels.get(i);
int tickLocation = axisTick.tickLocations.get(i);
FontRenderContext frc = g.getFontRenderContext();
TextLayout layout = new TextLayout(tickLabel, font, frc);
......
......@@ -27,14 +27,15 @@ import com.xeiam.xchart.interfaces.IChartPart;
*/
public class AxisTickMarks implements IChartPart {
/** the tick length */
public static final int TICK_LENGTH = 3;
/** parent */
private AxisTick axisTick;
/** the line style */
private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
/** the tick length */
public static final int TICK_LENGTH = 3;
/** the bounds */
private Rectangle bounds;
......@@ -44,7 +45,7 @@ public class AxisTickMarks implements IChartPart {
* @param axis
* @param axisTick
*/
public AxisTickMarks(AxisTick axisTick) {
protected AxisTickMarks(AxisTick axisTick) {
this.axisTick = axisTick;
}
......@@ -62,15 +63,15 @@ public class AxisTickMarks implements IChartPart {
g.setColor(axisTick.axis.axisPair.chart.bordersColor);
if (axisTick.axis.getDirection() == Axis.Direction.Y) { // Y-Axis
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + AxisTick.AXIS_TICK_PADDING);
int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + AxisTick.AXIS_TICK_PADDING);
int yOffset = (int) (axisTick.axis.getPaintZone().getY());
// tick marks
for (int i = 0; i < axisTick.getTickLabels().size(); i++) {
for (int i = 0; i < axisTick.tickLabels.size(); i++) {
int tickLocation = axisTick.getTickLocations().get(i);
int tickLocation = axisTick.tickLocations.get(i);
g.setColor(axisTick.axis.axisPair.chart.bordersColor);
g.setStroke(stroke);
......@@ -89,12 +90,12 @@ public class AxisTickMarks implements IChartPart {
} else { // X-Axis
int xOffset = (int) (axisTick.axis.getPaintZone().getX());
int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - AxisTick.AXIS_TICK_PADDING);
int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - AxisTick.AXIS_TICK_PADDING);
// tick marks
for (int i = 0; i < axisTick.getTickLabels().size(); i++) {
for (int i = 0; i < axisTick.tickLabels.size(); i++) {
int tickLocation = axisTick.getTickLocations().get(i);
int tickLocation = axisTick.tickLocations.get(i);
g.setColor(axisTick.axis.axisPair.chart.bordersColor);
g.setStroke(stroke);
......
......@@ -31,7 +31,7 @@ public class AxisTitle implements IHideable {
protected final static int AXIS_TITLE_PADDING = 10;
/** the chart */
/** parent */
private Axis axis;
/** the title text */
......@@ -51,7 +51,7 @@ public class AxisTitle implements IHideable {
*
* @param axis the axis
*/
public AxisTitle(Axis axis) {
protected AxisTitle(Axis axis) {
this.axis = axis;
font = new Font(Font.SANS_SERIF, Font.BOLD, 12); // default font
......@@ -96,7 +96,7 @@ public class AxisTitle implements IHideable {
g.setColor(axis.axisPair.chart.fontColor);
if (axis.getDirection() == Axis.Direction.Y) {
if (axis.direction == Axis.Direction.Y) {
if (isVisible) {
FontRenderContext frc = g.getFontRenderContext();
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.io;
package com.xeiam.xchart;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
......@@ -22,8 +22,6 @@ import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.xeiam.xchart.Chart;
/**
* @author timmolter
*/
......@@ -37,7 +35,7 @@ public class BitmapEncoder {
*/
public static void savePNG(Chart chart, String pFileName) throws Exception {
BufferedImage lBufferedImage = new BufferedImage(chart.getWidth(), chart.getHeight(), BufferedImage.TYPE_INT_RGB);
BufferedImage lBufferedImage = new BufferedImage(chart.width, chart.height, BufferedImage.TYPE_INT_RGB);
Graphics2D lGraphics2D = lBufferedImage.createGraphics();
chart.paint(lGraphics2D);
......
......@@ -33,18 +33,18 @@ import com.xeiam.xchart.series.SeriesMarker;
*/
public class Chart {
private int width;
private int height;
protected int width;
protected int height;
private Color backgroundColor;
protected Color bordersColor;
protected Color fontColor;
protected final static int CHART_PADDING = 10;
private ChartTitle chartTitle = new ChartTitle(this);
private ChartLegend chartLegend = new ChartLegend(this);
private AxisPair axisPair = new AxisPair(this);
private Plot plot = new Plot(this);
protected ChartTitle chartTitle = new ChartTitle(this);
protected ChartLegend chartLegend = new ChartLegend(this);
protected AxisPair axisPair = new AxisPair(this);
protected Plot plot = new Plot(this);
/**
* Constructor
......@@ -64,7 +64,7 @@ public class Chart {
/**
* @param g
*/
public void paint(Graphics2D g, int width, int height) {
protected void paint(Graphics2D g, int width, int height) {
this.width = width;
this.height = height;
......@@ -75,10 +75,10 @@ public class Chart {
/**
* @param g
*/
public void paint(Graphics2D g) {
protected void paint(Graphics2D g) {
// Sanity check
if (axisPair.getSeriesMap().isEmpty()) {
if (axisPair.seriesMap.isEmpty()) {
throw new RuntimeException("No series defined for Chart!!!");
}
......@@ -100,38 +100,6 @@ public class Chart {
}
// GETTERS & SETTERS
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
protected ChartTitle getTitle() {
return chartTitle;
}
protected ChartLegend getLegend() {
return chartLegend;
}
protected AxisPair getAxisPair() {
return axisPair;
}
protected Plot getPlot() {
return plot;
}
// PUBLIC SETTERS
/**
......@@ -220,12 +188,12 @@ public class Chart {
public void setXAxisTitle(String title) {
this.axisPair.getXAxis().setAxisTitle(title);
this.axisPair.xAxis.setAxisTitle(title);
}
public void setYAxisTitle(String title) {
this.axisPair.getYAxis().setAxisTitle(title);
this.axisPair.yAxis.setAxisTitle(title);
}
// ChartPart visibility ////////////////////////////////
......@@ -237,18 +205,18 @@ public class Chart {
public void setAxisTitlesVisible(boolean isVisible) {
this.axisPair.getXAxis().getAxisTitle().setVisible(isVisible);
this.axisPair.getYAxis().getAxisTitle().setVisible(isVisible);
this.axisPair.xAxis.getAxisTitle().setVisible(isVisible);
this.axisPair.yAxis.getAxisTitle().setVisible(isVisible);
}
public void setXAxisTitleVisible(boolean isVisible) {
this.axisPair.getXAxis().getAxisTitle().setVisible(isVisible);
this.axisPair.xAxis.getAxisTitle().setVisible(isVisible);
}
public void setYAxisTitleVisible(boolean isVisible) {
this.axisPair.getYAxis().getAxisTitle().setVisible(isVisible);
this.axisPair.yAxis.getAxisTitle().setVisible(isVisible);
}
public void setChartLegendVisible(boolean isVisible) {
......@@ -258,23 +226,23 @@ public class Chart {
public void setAxisTicksVisible(boolean isVisible) {
this.axisPair.getXAxis().axisTick.setVisible(isVisible);
this.axisPair.getYAxis().axisTick.setVisible(isVisible);
this.axisPair.xAxis.axisTick.setVisible(isVisible);
this.axisPair.yAxis.axisTick.setVisible(isVisible);
}
public void setXAxisTicksVisible(boolean isVisible) {
this.axisPair.getXAxis().axisTick.setVisible(isVisible);
this.axisPair.xAxis.axisTick.setVisible(isVisible);
}
public void setYAxisTicksVisible(boolean isVisible) {
this.axisPair.getYAxis().axisTick.setVisible(isVisible);
this.axisPair.yAxis.axisTick.setVisible(isVisible);
}
public void setChartGridlinesVisible(boolean isVisible) {
this.plot.getPlotSurface().setVisible(isVisible);
this.plot.plotSurface.setVisible(isVisible);
}
public void setChartBackgroundColor(Color color) {
......@@ -284,17 +252,17 @@ public class Chart {
public void setChartForegroundColor(Color color) {
this.plot.getPlotSurface().setForegroundColor(color);
this.plot.plotSurface.setForegroundColor(color);
}
public void setChartGridLinesColor(Color color) {
this.plot.getPlotSurface().setGridLinesColor(color);
this.plot.plotSurface.setGridLinesColor(color);
}
public void setChartLegendBackgroundColor(Color color) {
this.chartLegend.setBackgroundColor(color);
this.chartLegend.backgroundColor = color;
}
public void setChartBordersColor(Color color) {
......
......@@ -34,7 +34,7 @@ public class ChartLegend implements IHideable {
private final int LEGEND_PADDING = 10;
/** the chart */
/** parent */
private Chart chart;
/** the visibility state of legend */
......@@ -44,7 +44,7 @@ public class ChartLegend implements IHideable {
protected Font font;
/** the background color */
private Color backgroundColor;
protected Color backgroundColor;
/** the bounds */
private Rectangle bounds;
......@@ -72,7 +72,7 @@ public class ChartLegend implements IHideable {
if (isVisible) {
Map<Integer, Series> seriesMap = chart.getAxisPair().getSeriesMap();
Map<Integer, Series> seriesMap = chart.axisPair.seriesMap;
// determine legend text content max width
int legendTextContentMaxWidth = 0;
......@@ -102,8 +102,8 @@ public class ChartLegend implements IHideable {
// Draw Legend Box
int legendBoxWidth = legendContentWidth + 2 * LEGEND_PADDING;
int legendBoxHeight = legendContentHeight + 2 * LEGEND_PADDING;
int xOffset = chart.getWidth() - legendBoxWidth - Chart.CHART_PADDING;
int yOffset = (int) ((chart.getHeight() - legendBoxHeight) / 2.0 + chart.getTitle().getBounds().getY() + chart.getTitle().getBounds().getHeight());
int xOffset = chart.width - legendBoxWidth - Chart.CHART_PADDING;
int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.chartTitle.getBounds().getY() + chart.chartTitle.getBounds().getHeight());
g.setColor(chart.bordersColor);
g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight);
......@@ -148,12 +148,4 @@ public class ChartLegend implements IHideable {
return bounds;
}
/**
* @param backgroundColor the backgroundColor to set
*/
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
}
......@@ -28,8 +28,8 @@ import com.xeiam.xchart.interfaces.IHideable;
*/
public class ChartTitle implements IHideable {
/** the chart */
protected Chart chart;
/** parent */
private Chart chart;
/** the title text */
protected String text = ""; // default to ""
......@@ -52,7 +52,7 @@ public class ChartTitle implements IHideable {
font = new Font(Font.SANS_SERIF, Font.BOLD, 14); // default font
}
public void setText(String text) {
protected void setText(String text) {
if (text.trim().equalsIgnoreCase("")) {
this.isVisible = false;
......@@ -78,7 +78,7 @@ public class ChartTitle implements IHideable {
FontRenderContext frc = g.getFontRenderContext();
TextLayout textLayout = new TextLayout(text, font, frc);
Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0);
int xOffset = (int) ((chart.getWidth() - rectangle.getWidth()) / 2.0);
int xOffset = (int) ((chart.width - rectangle.getWidth()) / 2.0);
int yOffset = (int) ((isVisible ? (Chart.CHART_PADDING - rectangle.getY()) : 0));
bounds = new Rectangle(xOffset, yOffset + (isVisible ? (int) rectangle.getY() : 0), (int) rectangle.getWidth(), (int) (isVisible ? rectangle.getHeight() : 0));
......
......@@ -25,22 +25,23 @@ import com.xeiam.xchart.interfaces.IChartPart;
*/
public class Plot implements IChartPart {
/** parent */
protected Chart chart;
private PlotSurface plotSurface;
protected PlotSurface plotSurface;
private PlotContent plotContent;
protected PlotContent plotContent;
public static final int PLOT_PADDING = 3;
/** the bounds */
private Rectangle bounds;
public Plot(Chart chart) {
protected Plot(Chart chart) {
this.chart = chart;
this.plotSurface = new PlotSurface(chart, this);
this.plotContent = new PlotContent(chart, this);
this.plotSurface = new PlotSurface(this);
this.plotContent = new PlotContent(this);
}
@Override
......@@ -55,10 +56,10 @@ public class Plot implements IChartPart {
bounds = new Rectangle();
// calculate bounds
int xOffset = (int) (chart.getAxisPair().getYAxis().getBounds().getX() + chart.getAxisPair().getYAxis().getBounds().getWidth() + (chart.getAxisPair().getYAxis().axisTick.isVisible ? (Plot.PLOT_PADDING + 1) : 0));
int yOffset = (int) (chart.getAxisPair().getYAxis().getBounds().getY());
int width = (int) chart.getAxisPair().getXAxis().getBounds().getWidth();
int height = (int) chart.getAxisPair().getYAxis().getBounds().getHeight();
int xOffset = (int) (chart.axisPair.yAxis.getBounds().getX() + chart.axisPair.yAxis.getBounds().getWidth() + (chart.axisPair.yAxis.axisTick.isVisible ? (Plot.PLOT_PADDING + 1) : 0));
int yOffset = (int) (chart.axisPair.yAxis.getBounds().getY());
int width = (int) chart.axisPair.xAxis.getBounds().getWidth();
int height = (int) chart.axisPair.yAxis.getBounds().getHeight();
bounds = new Rectangle(xOffset, yOffset, width, height);
// g.setColor(Color.green);
// g.draw(bounds);
......@@ -68,12 +69,4 @@ public class Plot implements IChartPart {
}
/**
* @return the plotSurface
*/
public PlotSurface getPlotSurface() {
return plotSurface;
}
}
......@@ -33,13 +33,16 @@ import com.xeiam.xchart.series.SeriesLineStyle;
*/
public class PlotContent implements IChartPart {
private Chart chart;
/** parent */
private Plot plot;
public PlotContent(Chart chart, Plot plot) {
/**
* Constructor
*
* @param plot
*/
protected PlotContent(Plot plot) {
this.chart = chart;
this.plot = plot;
}
......@@ -54,7 +57,7 @@ public class PlotContent implements IChartPart {
Rectangle bounds = plot.getBounds();
Map<Integer, Series> seriesMap = chart.getAxisPair().getSeriesMap();
Map<Integer, Series> seriesMap = plot.chart.axisPair.seriesMap;
for (Integer seriesId : seriesMap.keySet()) {
Series series = seriesMap.get(seriesId);
......@@ -69,11 +72,11 @@ public class PlotContent implements IChartPart {
// data points
Collection<?> xData = series.getxData();
BigDecimal xMin = chart.getAxisPair().getXAxis().getMin();
BigDecimal xMax = chart.getAxisPair().getXAxis().getMax();
BigDecimal xMin = plot.chart.axisPair.xAxis.min;
BigDecimal xMax = plot.chart.axisPair.xAxis.max;
Collection<Number> yData = series.getyData();
BigDecimal yMin = chart.getAxisPair().getYAxis().getMin();
BigDecimal yMax = chart.getAxisPair().getYAxis().getMax();
BigDecimal yMin = plot.chart.axisPair.yAxis.min;
BigDecimal yMax = plot.chart.axisPair.yAxis.max;
Collection<Number> errorBars = series.getErrorBars();
int previousX = Integer.MIN_VALUE;
......@@ -88,10 +91,10 @@ public class PlotContent implements IChartPart {
while (xItr.hasNext()) {
BigDecimal x = null;
if (chart.getAxisPair().getXAxis().getAxisType() == AxisType.NUMBER) {
if (plot.chart.axisPair.xAxis.axisType == AxisType.NUMBER) {
x = new BigDecimal(((Number) xItr.next()).doubleValue());
}
if (chart.getAxisPair().getXAxis().getAxisType() == AxisType.DATE) {
if (plot.chart.axisPair.xAxis.axisType == AxisType.DATE) {
x = new BigDecimal(((Date) xItr.next()).getTime());
// System.out.println(x);
}
......
......@@ -29,8 +29,7 @@ import com.xeiam.xchart.interfaces.IHideable;
*/
public class PlotSurface implements IChartPart, IHideable {
private Chart chart;
/** parent */
private Plot plot;
/** the gridLines Color */
......@@ -40,7 +39,7 @@ public class PlotSurface implements IChartPart, IHideable {
private Color foregroundColor;
/** the line style */
private BasicStroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f);
private BasicStroke stroke;
/** the visibility state of PlotSurface */
protected boolean isVisible = true; // default to true
......@@ -51,12 +50,12 @@ public class PlotSurface implements IChartPart, IHideable {
* @param chart
* @param plot
*/
public PlotSurface(Chart chart, Plot plot) {
protected PlotSurface(Plot plot) {
this.chart = chart;
this.plot = plot;
gridLinesColor = ChartColor.getAWTColor(ChartColor.GREY); // default gridLines color
foregroundColor = ChartColor.getAWTColor(ChartColor.LIGHT_GREY); // default foreground Color color
stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f);
}
@Override
......@@ -75,13 +74,13 @@ public class PlotSurface implements IChartPart, IHideable {
g.setColor(foregroundColor);
g.fill(backgroundRectangle);
Rectangle borderRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight());
g.setColor(chart.bordersColor);
g.setColor(plot.chart.bordersColor);
g.draw(borderRectangle);
// paint grid lines
if (isVisible) {
// horizontal
List<Integer> yAxisTickLocations = chart.getAxisPair().getYAxis().axisTick.getTickLocations();
List<Integer> yAxisTickLocations = plot.chart.axisPair.yAxis.axisTick.tickLocations;
for (int i = 0; i < yAxisTickLocations.size(); i++) {
int tickLocation = yAxisTickLocations.get(i);
......@@ -93,7 +92,7 @@ public class PlotSurface implements IChartPart, IHideable {
}
// vertical
List<Integer> xAxisTickLocations = chart.getAxisPair().getXAxis().axisTick.getTickLocations();
List<Integer> xAxisTickLocations = plot.chart.axisPair.xAxis.axisTick.tickLocations;
for (int i = 0; i < xAxisTickLocations.size(); i++) {
int tickLocation = xAxisTickLocations.get(i);
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.io;
package com.xeiam.xchart;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
......@@ -21,8 +21,6 @@ import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import com.xeiam.xchart.Chart;
/**
* @author timmolter
*/
......@@ -36,7 +34,7 @@ public class ServletEncoder {
*/
public static void streamPNG(ServletOutputStream out, Chart chart) throws Exception {
BufferedImage lBufferedImage = new BufferedImage(chart.getWidth(), chart.getHeight(), BufferedImage.TYPE_INT_RGB);
BufferedImage lBufferedImage = new BufferedImage(chart.width, chart.height, BufferedImage.TYPE_INT_RGB);
Graphics2D lGraphics2D = lBufferedImage.createGraphics();
chart.paint(lGraphics2D);
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.swing;
package com.xeiam.xchart;
import java.awt.GridLayout;
import java.util.ArrayList;
......@@ -22,7 +22,6 @@ import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.xeiam.xchart.Chart;
/**
* @author timmolter
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xeiam.xchart.swing;
package com.xeiam.xchart;
import java.awt.Dimension;
import java.awt.Graphics;
......@@ -21,8 +21,6 @@ import java.awt.Graphics2D;
import javax.swing.JPanel;
import com.xeiam.xchart.Chart;
/**
* @author timmolter
* @create Sep 9, 2012
......@@ -48,6 +46,6 @@ public class XChartJPanel extends JPanel {
@Override
public Dimension getPreferredSize() {
return new Dimension(chart.getWidth(), chart.getHeight());
return new Dimension(chart.width, chart.height);
}
}
......@@ -27,7 +27,7 @@ import javax.servlet.http.HttpServletResponse;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.QuickChart;
import com.xeiam.xchart.io.ServletEncoder;
import com.xeiam.xchart.ServletEncoder;
/**
* Generates, stores, and serves charts
......
......@@ -18,8 +18,8 @@ package com.xeiam.xchart.example;
import java.util.Arrays;
import java.util.Collection;
import com.xeiam.xchart.BitmapEncoder;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.io.BitmapEncoder;
/**
* Creates a simple charts and saves it as a PNG image file.
......
......@@ -19,11 +19,11 @@ import java.util.ArrayList;
import java.util.Collection;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.SwingWrapper;
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
......
......@@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.Collection;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.swing.SwingWrapper;
import com.xeiam.xchart.SwingWrapper;
/**
* Create multiple curves on one chart
......
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