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

allow setting of legend series line length: issue #38

parent cffc96d9
No related branches found
No related tags found
No related merge requests found
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
...@@ -114,6 +115,33 @@ ...@@ -114,6 +115,33 @@
<autoversionsubmodules>true</autoversionsubmodules> <autoversionsubmodules>true</autoversionsubmodules>
</configuration> </configuration>
</plugin> </plugin>
<!-- <plugin> -->
<!-- <artifactId>maven-enforcer-plugin</artifactId> -->
<!-- <version>1.2</version> -->
<!-- <dependencies> -->
<!-- <dependency> -->
<!-- <groupId>de.andrena.tools.nopackagecycles</groupId> -->
<!-- <artifactId>no-package-cycles-enforcer-rule</artifactId> -->
<!-- <version>1.0.0</version> -->
<!-- </dependency> -->
<!-- </dependencies> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <id>enforce-no-package-cycles</id> -->
<!-- <goals> -->
<!-- <goal>enforce</goal> -->
<!-- </goals> -->
<!-- <phase>compile</phase> -->
<!-- <configuration> -->
<!-- <rules> -->
<!-- <NoPackageCyclesRule -->
<!-- implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule"
/> -->
<!-- </rules> -->
<!-- </configuration> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> -->
</plugins> </plugins>
</build> </build>
......
...@@ -93,6 +93,7 @@ public class LineChart03 implements ExampleChart { ...@@ -93,6 +93,7 @@ public class LineChart03 implements ExampleChart {
chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24));
chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18));
chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE); chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE);
chart.getStyleManager().setLegendSeriesLineLength(12);
chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11));
chart.getStyleManager().setDatePattern("dd-MMM"); chart.getStyleManager().setDatePattern("dd-MMM");
......
...@@ -72,6 +72,7 @@ public class StyleManager { ...@@ -72,6 +72,7 @@ public class StyleManager {
private Color legendBorderColor; private Color legendBorderColor;
private Font legendFont; private Font legendFont;
private int legendPadding; private int legendPadding;
private int legendSeriesLineLength;
private LegendPosition legendPosition; private LegendPosition legendPosition;
// Chart Axes /////////////////////////////// // Chart Axes ///////////////////////////////
...@@ -146,6 +147,7 @@ public class StyleManager { ...@@ -146,6 +147,7 @@ public class StyleManager {
legendBorderColor = theme.getLegendBorderColor(); legendBorderColor = theme.getLegendBorderColor();
legendFont = theme.getLegendFont(); legendFont = theme.getLegendFont();
legendPadding = theme.getLegendPadding(); legendPadding = theme.getLegendPadding();
legendSeriesLineLength = theme.getLegendSeriesLineLength();
legendPosition = theme.getLegendPosition(); legendPosition = theme.getLegendPosition();
// axes // axes
...@@ -438,6 +440,26 @@ public class StyleManager { ...@@ -438,6 +440,26 @@ public class StyleManager {
return legendPadding; return legendPadding;
} }
/**
* Set the chart legend series line length
*
* @param legendPadding
*/
public void setLegendSeriesLineLength(int legendSeriesLineLength) {
if (legendSeriesLineLength < 0) {
this.legendSeriesLineLength = 0;
}
else {
this.legendSeriesLineLength = legendSeriesLineLength;
}
}
public int getLegendSeriesLineLength() {
return legendSeriesLineLength;
}
/** /**
* sets the legend position * sets the legend position
* *
......
...@@ -93,7 +93,7 @@ public class Legend implements ChartPart { ...@@ -93,7 +93,7 @@ public class Legend implements ChartPart {
// determine legend content width // determine legend content width
double legendContentWidth = 0; double legendContentWidth = 0;
if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) { if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) {
legendContentWidth = 3.0 * Marker.SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth; legendContentWidth = getChartPainter().getStyleManager().getLegendSeriesLineLength() + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
} }
else { else {
legendContentWidth = BOX_SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth; legendContentWidth = BOX_SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
...@@ -169,14 +169,14 @@ public class Legend implements ChartPart { ...@@ -169,14 +169,14 @@ public class Legend implements ChartPart {
if (getChartPainter().getStyleManager().getChartType() != ChartType.Scatter && series.getStroke() != null) { if (getChartPainter().getStyleManager().getChartType() != ChartType.Scatter && series.getStroke() != null) {
g.setColor(series.getStrokeColor()); g.setColor(series.getStrokeColor());
g.setStroke(series.getStroke()); g.setStroke(series.getStroke());
Shape line = new Line2D.Double(startx, starty + maxContentHeight / 2.0, startx + Marker.SIZE * 3.0, starty + maxContentHeight / 2.0); Shape line = new Line2D.Double(startx, starty + maxContentHeight / 2.0, startx + getChartPainter().getStyleManager().getLegendSeriesLineLength(), starty + maxContentHeight / 2.0);
g.draw(line); g.draw(line);
} }
// paint marker // paint marker
if (series.getMarker() != null) { if (series.getMarker() != null) {
g.setColor(series.getMarkerColor()); g.setColor(series.getMarkerColor());
series.getMarker().paint(g, startx + (Marker.SIZE * 1.5), starty + maxContentHeight / 2.0); series.getMarker().paint(g, startx + getChartPainter().getStyleManager().getLegendSeriesLineLength() / 2.0, starty + maxContentHeight / 2.0);
} }
} }
else { else {
...@@ -193,8 +193,8 @@ public class Legend implements ChartPart { ...@@ -193,8 +193,8 @@ public class Legend implements ChartPart {
g.setColor(chartPainter.getStyleManager().getChartFontColor()); g.setColor(chartPainter.getStyleManager().getChartFontColor());
TextLayout layout = new TextLayout(series.getName(), chartPainter.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false)); TextLayout layout = new TextLayout(series.getName(), chartPainter.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false));
if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) { if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) {
layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + chartPainter.getStyleManager().getLegendPadding()), (float) (starty + (maxContentHeight - 1 + layout.getBounds() layout.draw(g, (float) (startx + getChartPainter().getStyleManager().getLegendSeriesLineLength() + chartPainter.getStyleManager().getLegendPadding()),
.getHeight()) / 2.0)); (float) (starty + (maxContentHeight - 1 + layout.getBounds().getHeight()) / 2.0));
} }
else { else {
layout.draw(g, (float) (startx + BOX_SIZE + chartPainter.getStyleManager().getLegendPadding()), (float) (starty + (maxContentHeight + layout.getBounds().getHeight()) / 2.0)); layout.draw(g, (float) (startx + BOX_SIZE + chartPainter.getStyleManager().getLegendPadding()), (float) (starty + (maxContentHeight + layout.getBounds().getHeight()) / 2.0));
......
...@@ -118,6 +118,12 @@ public class GGPlot2Theme implements Theme { ...@@ -118,6 +118,12 @@ public class GGPlot2Theme implements Theme {
return 10; return 10;
} }
@Override
public int getLegendSeriesLineLength() {
return 24;
}
@Override @Override
public LegendPosition getLegendPosition() { public LegendPosition getLegendPosition() {
......
...@@ -119,6 +119,12 @@ public class MatlabTheme implements Theme { ...@@ -119,6 +119,12 @@ public class MatlabTheme implements Theme {
return 10; return 10;
} }
@Override
public int getLegendSeriesLineLength() {
return 24;
}
@Override @Override
public LegendPosition getLegendPosition() { public LegendPosition getLegendPosition() {
......
...@@ -60,6 +60,8 @@ public interface Theme { ...@@ -60,6 +60,8 @@ public interface Theme {
public int getLegendPadding(); public int getLegendPadding();
public int getLegendSeriesLineLength();
public LegendPosition getLegendPosition(); public LegendPosition getLegendPosition();
// Chart Axes /////////////////////////////// // Chart Axes ///////////////////////////////
......
...@@ -119,6 +119,12 @@ public class XChartTheme implements Theme { ...@@ -119,6 +119,12 @@ public class XChartTheme implements Theme {
return 10; return 10;
} }
@Override
public int getLegendSeriesLineLength() {
return 24;
}
@Override @Override
public LegendPosition getLegendPosition() { public LegendPosition getLegendPosition() {
......
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