From 397d7869b1003d1a806e3c9e977b79750ff8b2cf Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Sun, 10 Feb 2013 11:38:36 +0100 Subject: [PATCH] set most members private and added getters --- .../src/main/java/com/xeiam/xchart/Chart.java | 6 +- .../xeiam/xchart/internal/chartpart/Axis.java | 87 ++++++++++++------- .../xchart/internal/chartpart/AxisPair.java | 69 ++++++++------- .../xchart/internal/chartpart/AxisTick.java | 68 ++++++++------- .../internal/chartpart/AxisTickLabels.java | 28 +++--- .../internal/chartpart/AxisTickMarks.java | 32 +++---- .../xchart/internal/chartpart/AxisTitle.java | 16 +++- .../xchart/internal/chartpart/ChartTitle.java | 2 +- .../xchart/internal/chartpart/Legend.java | 2 +- .../xeiam/xchart/internal/chartpart/Plot.java | 14 +-- .../internal/chartpart/PlotContent.java | 16 ++-- .../internal/chartpart/PlotSurface.java | 7 +- 12 files changed, 202 insertions(+), 145 deletions(-) diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index b82140fa..ef91f015 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -95,7 +95,7 @@ public class Chart { public void paint(Graphics2D g) { // Sanity check - if (axisPair.seriesMap.isEmpty()) { + if (axisPair.getSeriesMap().isEmpty()) { throw new RuntimeException("No series defined for Chart!!!"); } @@ -235,7 +235,7 @@ public class Chart { } else { styleManager.setxAxisTitleVisible(true); } - this.axisPair.xAxis.axisTitle.text = title; + this.axisPair.getxAxis().getAxisTitle().setText(title); } /** @@ -250,7 +250,7 @@ public class Chart { } else { styleManager.setyAxisTitleVisible(true); } - this.axisPair.yAxis.axisTitle.text = title; + this.axisPair.getyAxis().getAxisTitle().setText(title); } /** diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index cd6e0d20..ff976312 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -36,23 +36,23 @@ public class Axis implements ChartPart { } /** parent */ - protected AxisPair axisPair; + private AxisPair axisPair; /** the axisType */ - protected AxisType axisType; + private AxisType axisType; /** the axis title */ - public AxisTitle axisTitle; + private AxisTitle axisTitle; /** the axis tick */ - public AxisTick axisTick; + private AxisTick axisTick; /** the axis direction */ - protected Direction direction; + private Direction direction; - protected BigDecimal min = null; + private BigDecimal min = null; - protected BigDecimal max = null; + private BigDecimal max = null; /** the bounds */ private Rectangle bounds; @@ -117,21 +117,6 @@ public class Axis implements ChartPart { return bounds; } - protected Rectangle getPaintZone() { - - return paintZone; - } - - public AxisTitle getAxisTitle() { - - return axisTitle; - } - - protected void setAxisTitle(AxisTitle axisTitle) { - - this.axisTitle = axisTitle; - } - /** * @return */ @@ -142,15 +127,15 @@ public class Axis implements ChartPart { // Axis title double titleHeight = 0.0; if (getChart().getStyleManager().isxAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.text, axisTick.axis.getChart().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(axisTitle.getText(), getChart().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); - titleHeight = rectangle.getHeight() + axisTick.axis.getChart().getStyleManager().getAxisTitlePadding(); + titleHeight = rectangle.getHeight() + getChart().getStyleManager().getAxisTitlePadding(); } // Axis tick labels double axisTickLabelsHeight = 0.0; if (getChart().getStyleManager().isxAxisTicksVisible()) { - TextLayout textLayout = new TextLayout("0", axisTick.axis.getChart().getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout("0", getChart().getStyleManager().getAxisTicksFont(), new FontRenderContext(null, true, false)); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); axisTickLabelsHeight = rectangle.getHeight() + getChart().getStyleManager().getAxisTickPadding() + getChart().getStyleManager().getAxisTickMarkLength() + getChart().getStyleManager().getPlotPadding(); @@ -178,9 +163,9 @@ public class Axis implements ChartPart { // | // ---- int xOffset = getChart().getStyleManager().getChartPadding(); - int yOffset = (int) (axisPair.getChartTitleBounds().getY() + axisPair.getChartTitleBounds().getHeight() + getChart().getStyleManager().getChartPadding()); + int yOffset = (int) (getChart().getChartTitle().getBounds().getY() + getChart().getChartTitle().getBounds().getHeight() + getChart().getStyleManager().getChartPadding()); int width = 80; // arbitrary, final width depends on Axis tick labels - int height = getChart().height - yOffset - axisPair.xAxis.getSizeHint() - getChart().getStyleManager().getChartPadding(); + int height = getChart().height - yOffset - axisPair.getxAxis().getSizeHint() - getChart().getStyleManager().getChartPadding(); Rectangle yAxisRectangle = new Rectangle(xOffset, yOffset, width, height); this.paintZone = yAxisRectangle; // g.setColor(Color.green); @@ -203,10 +188,10 @@ public class Axis implements ChartPart { // calculate paint zone // |____________________| - int xOffset = (int) (axisPair.yAxis.getBounds().getWidth() + (getChart().getStyleManager().isyAxisTicksVisible() ? getChart().getStyleManager().getPlotPadding() : 0) + getChart() + int xOffset = (int) (axisPair.getyAxis().getBounds().getWidth() + (getChart().getStyleManager().isyAxisTicksVisible() ? getChart().getStyleManager().getPlotPadding() : 0) + getChart() .getStyleManager().getChartPadding()); - int yOffset = (int) (axisPair.yAxis.getBounds().getY() + axisPair.yAxis.getBounds().getHeight()); - int width = (int) (getChart().width - axisPair.yAxis.getBounds().getWidth() - axisPair.getChartLegendBounds().getWidth() - (getChart().getStyleManager().isLegendVisible() ? 3 : 2) + int yOffset = (int) (axisPair.getyAxis().getBounds().getY() + axisPair.getyAxis().getBounds().getHeight()); + int width = (int) (getChart().width - axisPair.getyAxis().getBounds().getWidth() - getChart().getChartLegend().getBounds().getWidth() - (getChart().getStyleManager().isLegendVisible() ? 3 : 2) * getChart().getStyleManager().getChartPadding()); int height = this.getSizeHint(); Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); @@ -234,4 +219,46 @@ public class Axis implements ChartPart { return axisPair.getChart(); } + + // Getters ///////////////////////////////////////////////// + + public AxisType getAxisType() { + + return axisType; + } + + public BigDecimal getMax() { + + return max; + } + + public BigDecimal getMin() { + + return min; + } + + public AxisTick getAxisTick() { + + return axisTick; + } + + public Direction getDirection() { + + return direction; + } + + protected Rectangle getPaintZone() { + + return paintZone; + } + + public AxisTitle getAxisTitle() { + + return axisTitle; + } + + protected void setAxisTitle(AxisTitle axisTitle) { + + this.axisTitle = axisTitle; + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java index af24bf51..3fa995c6 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java @@ -37,14 +37,14 @@ public class AxisPair implements ChartPart { /** parent */ private final Chart chart; - public Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>(); + private Map<Integer, Series> seriesMap = new LinkedHashMap<Integer, Series>(); private int seriesCount; - public Axis xAxis; - public Axis yAxis; + private Axis xAxis; + private Axis yAxis; - public SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(); + private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(); /** * Constructor @@ -92,7 +92,7 @@ public class AxisPair implements ChartPart { xAxis.setAxisType(AxisType.DATE); } yAxis.setAxisType(AxisType.NUMBER); - series = new Series(seriesName, xData, xAxis.axisType, yData, yAxis.axisType, errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); + series = new Series(seriesName, xData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); } else { // generate xData Collection<Number> generatedXData = new ArrayList<Number>(); for (int i = 1; i < yData.size() + 1; i++) { @@ -100,7 +100,7 @@ public class AxisPair implements ChartPart { } xAxis.setAxisType(AxisType.NUMBER); yAxis.setAxisType(AxisType.NUMBER); - series = new Series(seriesName, generatedXData, xAxis.axisType, yData, yAxis.axisType, errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); + series = new Series(seriesName, generatedXData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); } // Sanity check @@ -120,18 +120,44 @@ public class AxisPair implements ChartPart { return series; } - // TODO remove - protected Rectangle getChartTitleBounds() { + @Override + public void paint(Graphics2D g) { + + yAxis.paint(g); + xAxis.paint(g); + } + + @Override + public Rectangle getBounds() { + + return null; // should never be called + } + + @Override + public Chart getChart() { - return chart.getChartTitle().getBounds(); + return chart; } - // TODO remove - protected Rectangle getChartLegendBounds() { + // Getters ///////////////////////////////////////////////// + + public Map<Integer, Series> getSeriesMap() { - return chart.getChartLegend().getBounds(); + return seriesMap; } + public Axis getxAxis() { + + return xAxis; + } + + public Axis getyAxis() { + + return yAxis; + } + + // Helper Methods /////////////// + /** * Gets the percentage of working space allowed for tick marks * @@ -156,23 +182,4 @@ public class AxisPair implements ChartPart { return (int) (marginSpace / 2.0); } - @Override - public void paint(Graphics2D g) { - - yAxis.paint(g); - xAxis.paint(g); - } - - @Override - public Rectangle getBounds() { - - return null; // should never be called - } - - @Override - public Chart getChart() { - - return chart; - } - } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index 833fea04..bf0e2a8c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -20,8 +20,6 @@ import java.awt.Rectangle; import java.math.BigDecimal; import java.util.LinkedList; import java.util.List; -import java.util.Locale; -import java.util.TimeZone; import com.xeiam.xchart.Chart; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; @@ -39,32 +37,22 @@ public class AxisTick implements ChartPart { private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44; /** parent */ - protected Axis axis; + private Axis axis; /** the axisticklabels */ - public AxisTickLabels axisTickLabels; + private AxisTickLabels axisTickLabels; /** the axistickmarks */ - protected AxisTickMarks axisTickMarks; + private AxisTickMarks axisTickMarks; /** the List of tick label position in pixels */ - protected List<Integer> tickLocations; + private List<Integer> tickLocations; /** the List of tick label values */ - protected List<String> tickLabels; + private List<String> tickLabels; private int workingSpace; - /** the Locale for tick labels */ - public Locale locale; - - /** the TimeZone for Date tick labels */ - public TimeZone timezone; - - public String normalDecimalPattern = null; - public String scientificDecimalPattern = null; - public String datePattern = null; - /** the bounds */ private Rectangle bounds; @@ -96,7 +84,7 @@ public class AxisTick implements ChartPart { bounds = new Rectangle(); - if (axis.direction == Axis.Direction.Y) { + if (axis.getDirection() == 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 { @@ -117,7 +105,7 @@ public class AxisTick implements ChartPart { axisTickLabels.paint(g); axisTickMarks.paint(g); - if (axis.direction == Axis.Direction.Y) { + if (axis.getDirection() == Axis.Direction.Y) { bounds = new Rectangle((int) axisTickLabels.getBounds().getX(), (int) (axisTickLabels.getBounds().getY()), (int) (axisTickLabels.getBounds().getWidth() + getChart().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth()), (int) (axisTickMarks.getBounds().getHeight())); // g.setColor(Color.red); @@ -149,12 +137,12 @@ public class AxisTick implements ChartPart { int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // a check if all axis data are the exact same values - if (axis.max == axis.min) { - tickLabels.add(format(axis.max)); + if (axis.getMax() == axis.getMin()) { + tickLabels.add(format(axis.getMax())); tickLocations.add((int) (margin + tickSpace / 2.0)); } else { - final BigDecimal min = new BigDecimal(axis.min.doubleValue()); + final BigDecimal min = new BigDecimal(axis.getMin().doubleValue()); BigDecimal firstPosition; BigDecimal gridStep = getGridStep(tickSpace); @@ -165,11 +153,11 @@ public class AxisTick implements ChartPart { firstPosition = min.subtract(min.remainder(gridStep)).add(gridStep); } - for (BigDecimal b = firstPosition; b.compareTo(axis.max) <= 0; b = b.add(gridStep)) { + for (BigDecimal b = firstPosition; b.compareTo(axis.getMax()) <= 0; b = b.add(gridStep)) { // System.out.println("b= " + b); tickLabels.add(format(b)); - int tickLabelPosition = (int) (margin + ((b.subtract(axis.min)).doubleValue() / (axis.max.subtract(axis.min)).doubleValue() * tickSpace)); + int tickLabelPosition = (int) (margin + ((b.subtract(axis.getMin())).doubleValue() / (axis.getMax().subtract(axis.getMin())).doubleValue() * tickSpace)); // System.out.println("tickLabelPosition= " + tickLabelPosition); tickLocations.add(tickLabelPosition); @@ -179,13 +167,13 @@ public class AxisTick implements ChartPart { private BigDecimal getGridStep(int tickSpace) { - double length = Math.abs(axis.max.subtract(axis.min).doubleValue()); + double length = Math.abs(axis.getMax().subtract(axis.getMin()).doubleValue()); // System.out.println(axis.getMax()); // System.out.println(axis.min); // System.out.println(length); - int tickMarkSpaceHint = (axis.direction == Direction.X ? DEFAULT_TICK_MARK_STEP_HINT_X : DEFAULT_TICK_MARK_STEP_HINT_Y); + int tickMarkSpaceHint = (axis.getDirection() == Direction.X ? DEFAULT_TICK_MARK_STEP_HINT_X : DEFAULT_TICK_MARK_STEP_HINT_Y); // for very short plots, squeeze some more ticks in than normal - if (axis.direction == Direction.Y && tickSpace < 160) { + if (axis.getDirection() == Direction.Y && tickSpace < 160) { tickMarkSpaceHint = 25; } double gridStepHint = length / tickSpace * tickMarkSpaceHint; @@ -252,13 +240,13 @@ public class AxisTick implements ChartPart { */ private String format(BigDecimal value) { - if (axis.axisType == AxisType.NUMBER) { + if (axis.getAxisType() == AxisType.NUMBER) { return getChart().getValueFormatter().formatNumber(value); } else { - return getChart().getValueFormatter().formatDateValue(value, axis.min, axis.max); + return getChart().getValueFormatter().formatDateValue(value, axis.getMin(), axis.getMax()); } } @@ -268,4 +256,26 @@ public class AxisTick implements ChartPart { return axis.getChart(); } + + // Getters ///////////////////////////////////////////////// + + public List<Integer> getTickLocations() { + + return tickLocations; + } + + public List<String> getTickLabels() { + + return tickLabels; + } + + public Axis getAxis() { + + return axis; + } + + public AxisTickLabels getAxisTickLabels() { + + return axisTickLabels; + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java index 55b5bd6f..90a87199 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java @@ -57,22 +57,22 @@ public class AxisTickLabels implements ChartPart { g.setColor(getChart().getStyleManager().getChartFontColor()); - if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis + if (axisTick.getAxis().getDirection() == 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 xOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getX() + axisTick.getAxis().getAxisTitle().getBounds().getWidth()); + int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); int maxTickLabelWidth = 0; - for (int i = 0; i < axisTick.tickLabels.size(); i++) { + for (int i = 0; i < axisTick.getTickLabels().size(); i++) { - String tickLabel = axisTick.tickLabels.get(i); + String tickLabel = axisTick.getTickLabels().get(i); // System.out.println(tickLabel); - int tickLocation = axisTick.tickLocations.get(i); + int tickLocation = axisTick.getTickLocations().get(i); FontRenderContext frc = g.getFontRenderContext(); // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTicksFont(), frc); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); - layout.draw(g, xOffset, (int) (yOffset + axisTick.axis.getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); + layout.draw(g, xOffset, (int) (yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); if (tickLabelBounds.getWidth() > maxTickLabelWidth) { maxTickLabelWidth = (int) tickLabelBounds.getWidth(); @@ -80,19 +80,19 @@ public class AxisTickLabels implements ChartPart { } // bounds - bounds = new Rectangle(xOffset, yOffset, maxTickLabelWidth, (int) axisTick.axis.getPaintZone().getHeight()); + bounds = new Rectangle(xOffset, yOffset, maxTickLabelWidth, (int) axisTick.getAxis().getPaintZone().getHeight()); // g.setColor(Color.blue); // g.draw(bounds); } else { // X-Axis - int xOffset = (int) (axisTick.axis.getPaintZone().getX()); - int yOffset = (int) (axisTick.axis.getAxisTitle().getBounds().getY()); + int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); + int yOffset = (int) (axisTick.getAxis().getAxisTitle().getBounds().getY()); int maxTickLabelHeight = 0; - for (int i = 0; i < axisTick.tickLabels.size(); i++) { + for (int i = 0; i < axisTick.getTickLabels().size(); i++) { - String tickLabel = axisTick.tickLabels.get(i); - int tickLocation = axisTick.tickLocations.get(i); + String tickLabel = axisTick.getTickLabels().get(i); + int tickLocation = axisTick.getTickLocations().get(i); FontRenderContext frc = g.getFontRenderContext(); TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTicksFont(), frc); @@ -105,7 +105,7 @@ public class AxisTickLabels implements ChartPart { } // bounds - bounds = new Rectangle(xOffset, yOffset - maxTickLabelHeight, (int) axisTick.axis.getPaintZone().getWidth(), maxTickLabelHeight); + bounds = new Rectangle(xOffset, yOffset - maxTickLabelHeight, (int) axisTick.getAxis().getPaintZone().getWidth(), maxTickLabelHeight); // g.setColor(Color.blue); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java index f3640b68..4e23f890 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickMarks.java @@ -31,7 +31,7 @@ public class AxisTickMarks implements ChartPart { private AxisTick axisTick; /** the line style */ - private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); + private final Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); /** the bounds */ private Rectangle bounds; @@ -59,44 +59,44 @@ public class AxisTickMarks implements ChartPart { g.setColor(getChart().getStyleManager().getChartBordersColor()); - if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis + if (axisTick.getAxis().getDirection() == Axis.Direction.Y) { // Y-Axis - int xOffset = (int) (axisTick.axisTickLabels.getBounds().getX() + axisTick.axisTickLabels.getBounds().getWidth() + getChart().getStyleManager().getAxisTickPadding()); - int yOffset = (int) (axisTick.axis.getPaintZone().getY()); + int xOffset = (int) (axisTick.getAxisTickLabels().getBounds().getX() + axisTick.getAxisTickLabels().getBounds().getWidth() + getChart().getStyleManager().getAxisTickPadding()); + int yOffset = (int) (axisTick.getAxis().getPaintZone().getY()); // tick marks - for (int i = 0; i < axisTick.tickLabels.size(); i++) { + for (int i = 0; i < axisTick.getTickLabels().size(); i++) { - int tickLocation = axisTick.tickLocations.get(i); + int tickLocation = axisTick.getTickLocations().get(i); g.setColor(getChart().getStyleManager().getChartBordersColor()); g.setStroke(stroke); - g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset - + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation)); + g.drawLine(xOffset, yOffset + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation), xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset + + (int) (axisTick.getAxis().getPaintZone().getHeight() - tickLocation)); } // Line if (getChart().getStyleManager().isAxisTicksLineVisible()) { g.drawLine(xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChart().getStyleManager().getAxisTickMarkLength(), yOffset - + (int) axisTick.axis.getPaintZone().getHeight()); + + (int) axisTick.getAxis().getPaintZone().getHeight()); } // bounds - bounds = new Rectangle(xOffset, yOffset, getChart().getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getHeight()); + bounds = new Rectangle(xOffset, yOffset, getChart().getStyleManager().getAxisTickMarkLength(), (int) axisTick.getAxis().getPaintZone().getHeight()); // g.setColor(Color.yellow); // g.draw(bounds); } else { // X-Axis - int xOffset = (int) (axisTick.axis.getPaintZone().getX()); - int yOffset = (int) (axisTick.axisTickLabels.getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); + int xOffset = (int) (axisTick.getAxis().getPaintZone().getX()); + int yOffset = (int) (axisTick.getAxisTickLabels().getBounds().getY() - getChart().getStyleManager().getAxisTickPadding()); // tick marks - for (int i = 0; i < axisTick.tickLabels.size(); i++) { + for (int i = 0; i < axisTick.getTickLabels().size(); i++) { - int tickLocation = axisTick.tickLocations.get(i); + int tickLocation = axisTick.getTickLocations().get(i); g.setColor(getChart().getStyleManager().getChartBordersColor()); g.setStroke(stroke); @@ -107,12 +107,12 @@ public class AxisTickMarks implements ChartPart { // Line if (getChart().getStyleManager().isAxisTicksLineVisible()) { - g.drawLine(xOffset, yOffset - getChart().getStyleManager().getAxisTickMarkLength(), xOffset + (int) axisTick.axis.getPaintZone().getWidth(), yOffset + g.drawLine(xOffset, yOffset - getChart().getStyleManager().getAxisTickMarkLength(), xOffset + (int) axisTick.getAxis().getPaintZone().getWidth(), yOffset - getChart().getStyleManager().getAxisTickMarkLength()); } // bounds - bounds = new Rectangle(xOffset, yOffset - getChart().getStyleManager().getAxisTickMarkLength(), (int) axisTick.axis.getPaintZone().getWidth(), getChart().getStyleManager() + bounds = new Rectangle(xOffset, yOffset - getChart().getStyleManager().getAxisTickMarkLength(), (int) axisTick.getAxis().getPaintZone().getWidth(), getChart().getStyleManager() .getAxisTickMarkLength()); // g.setColor(Color.yellow); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java index 32d6b681..434952b6 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java @@ -32,7 +32,7 @@ public class AxisTitle implements ChartPart { private final Axis axis; /** the title text */ - public String text = ""; // default to "" + private String text = ""; // default to "" /** the bounds */ private Rectangle bounds; @@ -61,7 +61,7 @@ public class AxisTitle implements ChartPart { g.setColor(getChart().getStyleManager().getChartFontColor()); g.setFont(getChart().getStyleManager().getAxisTitleFont()); - if (axis.direction == Axis.Direction.Y) { + if (axis.getDirection() == Axis.Direction.Y) { if (getChart().getStyleManager().isyAxisTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); @@ -134,4 +134,16 @@ public class AxisTitle implements ChartPart { return axis.getChart(); } + + // Getters ///////////////////////////////////////////////// + + public String getText() { + + return text; + } + + public void setText(String text) { + + this.text = text; + } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java index edb759db..5add2240 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java @@ -34,7 +34,7 @@ public class ChartTitle implements ChartPart { private Rectangle bounds; /** the title text */ - protected String text = ""; // default to "" + private String text = ""; // default to "" /** * Constructor diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java index f1ce8b7a..72bedb43 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Legend.java @@ -54,7 +54,7 @@ public class Legend implements ChartPart { if (chart.getStyleManager().isLegendVisible()) { - Map<Integer, Series> seriesMap = chart.getAxisPair().seriesMap; + Map<Integer, Series> seriesMap = chart.getAxisPair().getSeriesMap(); // determine legend text content max width int legendTextContentMaxWidth = 0; diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java index 5044d06e..924ad712 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Plot.java @@ -31,9 +31,9 @@ public class Plot implements ChartPart { /** the bounds */ private Rectangle bounds; - protected PlotSurface plotSurface; + private PlotSurface plotSurface; - protected PlotContent plotContent; + private PlotContent plotContent; /** * Constructor @@ -59,11 +59,11 @@ public class Plot implements ChartPart { bounds = new Rectangle(); // calculate bounds - int xOffset = (int) (chart.getAxisPair().yAxis.getBounds().getX() + chart.getAxisPair().yAxis.getBounds().getWidth() + (chart.getStyleManager().isyAxisTicksVisible() ? (chart.getStyleManager() - .getPlotPadding() + 1) : 0)); - int yOffset = (int) (chart.getAxisPair().yAxis.getBounds().getY()); - int width = (int) chart.getAxisPair().xAxis.getBounds().getWidth(); - int height = (int) chart.getAxisPair().yAxis.getBounds().getHeight(); + int xOffset = (int) (chart.getAxisPair().getyAxis().getBounds().getX() + chart.getAxisPair().getyAxis().getBounds().getWidth() + (chart.getStyleManager().isyAxisTicksVisible() ? (chart + .getStyleManager().getPlotPadding() + 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(); bounds = new Rectangle(xOffset, yOffset, width, height); // g.setColor(Color.green); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java index 4ee83538..aab9241b 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java @@ -37,7 +37,7 @@ public class PlotContent implements ChartPart { /** parent */ private Plot plot; - Stroke errorBarStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); + private final Stroke errorBarStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL); /** * Constructor @@ -60,7 +60,7 @@ public class PlotContent implements ChartPart { Rectangle bounds = plot.getBounds(); - Map<Integer, Series> seriesMap = getChart().getAxisPair().seriesMap; + Map<Integer, Series> seriesMap = getChart().getAxisPair().getSeriesMap(); for (Integer seriesId : seriesMap.keySet()) { Series series = seriesMap.get(seriesId); @@ -75,11 +75,11 @@ public class PlotContent implements ChartPart { // data points Collection<?> xData = series.xData; - BigDecimal xMin = getChart().getAxisPair().xAxis.min; - BigDecimal xMax = getChart().getAxisPair().xAxis.max; + BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin(); + BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax(); Collection<Number> yData = series.yData; - BigDecimal yMin = getChart().getAxisPair().yAxis.min; - BigDecimal yMax = getChart().getAxisPair().yAxis.max; + BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); + BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); Collection<Number> errorBars = series.errorBars; int previousX = Integer.MIN_VALUE; @@ -94,10 +94,10 @@ public class PlotContent implements ChartPart { while (xItr.hasNext()) { BigDecimal x = null; - if (getChart().getAxisPair().xAxis.axisType == AxisType.NUMBER) { + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.NUMBER) { x = new BigDecimal(((Number) xItr.next()).doubleValue()); } - if (getChart().getAxisPair().xAxis.axisType == AxisType.DATE) { + if (getChart().getAxisPair().getxAxis().getAxisType() == AxisType.DATE) { x = new BigDecimal(((Date) xItr.next()).getTime()); // System.out.println(x); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java index 873748e4..ea5d9831 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotSurface.java @@ -18,6 +18,7 @@ package com.xeiam.xchart.internal.chartpart; import java.awt.BasicStroke; import java.awt.Graphics2D; import java.awt.Rectangle; +import java.awt.Stroke; import java.util.List; import com.xeiam.xchart.Chart; @@ -31,7 +32,7 @@ public class PlotSurface implements ChartPart { private Plot plot; /** 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 final Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f); /** * Constructor @@ -66,7 +67,7 @@ public class PlotSurface implements ChartPart { if (getChart().getStyleManager().isPlotGridLinesVisible()) { // horizontal - List<Integer> yAxisTickLocations = getChart().getAxisPair().yAxis.axisTick.tickLocations; + List<Integer> yAxisTickLocations = getChart().getAxisPair().getyAxis().getAxisTick().getTickLocations(); for (int i = 0; i < yAxisTickLocations.size(); i++) { int tickLocation = yAxisTickLocations.get(i); @@ -79,7 +80,7 @@ public class PlotSurface implements ChartPart { } // vertical - List<Integer> xAxisTickLocations = getChart().getAxisPair().xAxis.axisTick.tickLocations; + List<Integer> xAxisTickLocations = getChart().getAxisPair().getxAxis().getAxisTick().getTickLocations(); for (int i = 0; i < xAxisTickLocations.size(); i++) { int tickLocation = xAxisTickLocations.get(i); -- GitLab