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

bar charts - legend, vertical plot area lines

parent bba5cb37
No related branches found
No related tags found
No related merge requests found
......@@ -100,11 +100,6 @@ public class AxisTick implements ChartPart {
}
// if (getChart().getStyleManager()) {
//
// gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager());
// }
if (isVisible) {
axisTickLabels.paint(g);
......
......@@ -24,6 +24,7 @@ import java.util.Map;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.internal.markers.Marker;
import com.xeiam.xchart.style.StyleManager.ChartType;
/**
* @author timmolter
......@@ -31,6 +32,7 @@ import com.xeiam.xchart.internal.markers.Marker;
public class Legend implements ChartPart {
private static final int LEGEND_MARGIN = 6;
private static final int BOX_SIZE = 20;
/** parent */
private final Chart chart;
......@@ -77,13 +79,21 @@ public class Legend implements ChartPart {
}
// determine legend content height
int legendContentHeight = 0;
int maxContentHeight = Math.max(legendTextContentMaxHeight, Marker.SIZE);
legendContentHeight = maxContentHeight * seriesMap.size() + chart.getStyleManager().getLegendPadding() * (seriesMap.size() - 1);
int maxContentHeight = 0;
if (getChart().getStyleManager().getChartType() != ChartType.Bar) {
maxContentHeight = Math.max(legendTextContentMaxHeight, Marker.SIZE);
} else {
maxContentHeight = Math.max(legendTextContentMaxHeight, BOX_SIZE);
}
int legendContentHeight = maxContentHeight * seriesMap.size() + chart.getStyleManager().getLegendPadding() * (seriesMap.size() - 1);
// determine legend content width
int legendContentWidth = (int) (3.0 * Marker.SIZE + chart.getStyleManager().getLegendPadding() + legendTextContentMaxWidth);
int legendContentWidth = 0;
if (getChart().getStyleManager().getChartType() != ChartType.Bar) {
legendContentWidth = (int) (3.0 * Marker.SIZE + chart.getStyleManager().getLegendPadding() + legendTextContentMaxWidth);
} else {
legendContentWidth = BOX_SIZE + chart.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
}
// Draw Legend Box
int legendBoxWidth = legendContentWidth + 2 * chart.getStyleManager().getLegendPadding();
int legendBoxHeight = legendContentHeight + 2 * chart.getStyleManager().getLegendPadding();
......@@ -146,23 +156,41 @@ public class Legend implements ChartPart {
int starty = yOffset + chart.getStyleManager().getLegendPadding();
for (Integer seriesId : seriesMap.keySet()) {
Series series = seriesMap.get(seriesId);
// paint line
if (series.getStroke() != null) {
g.setColor(series.getStrokeColor());
g.setStroke(series.getStroke());
g.drawLine(startx, starty - Marker.Y_OFFSET, (int) (startx + Marker.SIZE * 3.0), starty - Marker.Y_OFFSET);
}
// paint marker
if (series.getMarker() != null) {
g.setColor(series.getMarkerColor());
series.getMarker().paint(g, (int) (startx + (Marker.SIZE * 1.5)), starty - Marker.Y_OFFSET);
if (getChart().getStyleManager().getChartType() != ChartType.Bar) {
// paint line
if (series.getStroke() != null) {
g.setColor(series.getStrokeColor());
g.setStroke(series.getStroke());
g.drawLine(startx, starty - Marker.Y_OFFSET, (int) (startx + Marker.SIZE * 3.0), starty - Marker.Y_OFFSET);
}
// paint marker
if (series.getMarker() != null) {
g.setColor(series.getMarkerColor());
series.getMarker().paint(g, (int) (startx + (Marker.SIZE * 1.5)), starty - Marker.Y_OFFSET);
}
} else {
// paint box
if (series.getStroke() != null) {
g.setColor(series.getStrokeColor());
g.fillPolygon(new int[] { startx, startx + BOX_SIZE, startx + BOX_SIZE, startx }, new int[] { starty, starty, starty + BOX_SIZE, starty + BOX_SIZE }, 4);
g.setStroke(series.getStroke());
g.drawPolygon(new int[] { startx, startx + BOX_SIZE, startx + BOX_SIZE, startx }, new int[] { starty, starty, starty + BOX_SIZE, starty + BOX_SIZE }, 4);
}
}
// paint series name
g.setColor(chart.getStyleManager().getChartFontColor());
TextLayout layout = new TextLayout(series.getName(), chart.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false));
layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + chart.getStyleManager().getLegendPadding()), (starty + Marker.SIZE));
starty = starty + legendTextContentMaxHeight + chart.getStyleManager().getLegendPadding();
if (getChart().getStyleManager().getChartType() != ChartType.Bar) {
layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + chart.getStyleManager().getLegendPadding()),
(int) (starty + (Marker.SIZE + chart.getStyleManager().getLegendPadding()) / 2.0));
starty = starty + legendTextContentMaxHeight + chart.getStyleManager().getLegendPadding();
} else {
layout.draw(g, startx + BOX_SIZE + chart.getStyleManager().getLegendPadding(), (int) (starty + (BOX_SIZE + chart.getStyleManager().getLegendPadding()) / 2.0));
starty = starty + legendTextContentMaxHeight + chart.getStyleManager().getLegendPadding();
}
}
// bounds
......
......@@ -38,7 +38,7 @@ public class PlotContent implements ChartPart {
/** parent */
private Plot plot;
private final Stroke errorBarStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
private final Stroke errorBarStroke = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
/**
* Constructor
......
......@@ -21,6 +21,7 @@ import java.awt.Stroke;
import java.util.List;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.style.StyleManager.ChartType;
/**
* @author timmolter
......@@ -82,15 +83,18 @@ public class PlotSurface implements ChartPart {
}
// vertical
List<Integer> xAxisTickLocations = getChart().getAxisPair().getxAxis().getAxisTick().getTickLocations();
for (int i = 0; i < xAxisTickLocations.size(); i++) {
if (getChart().getStyleManager().getChartType() != ChartType.Bar) {
int tickLocation = xAxisTickLocations.get(i);
List<Integer> xAxisTickLocations = getChart().getAxisPair().getxAxis().getAxisTick().getTickLocations();
for (int i = 0; i < xAxisTickLocations.size(); i++) {
g.setColor(getChart().getStyleManager().getPlotGridLinesColor());
g.setStroke(stroke);
int tickLocation = xAxisTickLocations.get(i);
g.setColor(getChart().getStyleManager().getPlotGridLinesColor());
g.setStroke(stroke);
g.drawLine((int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY()), (int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + bounds.getHeight() - 1));
g.drawLine((int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY()), (int) (bounds.getX() + tickLocation - 1), (int) (bounds.getY() + bounds.getHeight() - 1));
}
}
}
}
......
......@@ -28,16 +28,16 @@ public enum SeriesLineStyle {
NONE(-1, null),
/** SOLID */
SOLID(0, new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)),
SOLID(0, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)),
/** DASH_DOT */
DASH_DOT(1, new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f)),
DASH_DOT(1, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 1.0f }, 0.0f)),
/** DASH_DASH */
DASH_DASH(2, new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f)),
DASH_DASH(2, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 3.0f, 3.0f }, 0.0f)),
/** DOT_DOT */
DOT_DOT(3, new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f));
DOT_DOT(3, new BasicStroke(1.8f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f));
/** The index */
private int index;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment