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>
......@@ -114,6 +115,33 @@
<autoversionsubmodules>true</autoversionsubmodules>
</configuration>
</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>
</build>
......
......@@ -93,6 +93,7 @@ public class LineChart03 implements ExampleChart {
chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24));
chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18));
chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE);
chart.getStyleManager().setLegendSeriesLineLength(12);
chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11));
chart.getStyleManager().setDatePattern("dd-MMM");
......
......@@ -72,6 +72,7 @@ public class StyleManager {
private Color legendBorderColor;
private Font legendFont;
private int legendPadding;
private int legendSeriesLineLength;
private LegendPosition legendPosition;
// Chart Axes ///////////////////////////////
......@@ -146,6 +147,7 @@ public class StyleManager {
legendBorderColor = theme.getLegendBorderColor();
legendFont = theme.getLegendFont();
legendPadding = theme.getLegendPadding();
legendSeriesLineLength = theme.getLegendSeriesLineLength();
legendPosition = theme.getLegendPosition();
// axes
......@@ -438,6 +440,26 @@ public class StyleManager {
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
*
......
......@@ -93,7 +93,7 @@ public class Legend implements ChartPart {
// determine legend content width
double legendContentWidth = 0;
if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) {
legendContentWidth = 3.0 * Marker.SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
legendContentWidth = getChartPainter().getStyleManager().getLegendSeriesLineLength() + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
}
else {
legendContentWidth = BOX_SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
......@@ -169,14 +169,14 @@ public class Legend implements ChartPart {
if (getChartPainter().getStyleManager().getChartType() != ChartType.Scatter && series.getStroke() != null) {
g.setColor(series.getStrokeColor());
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);
}
// paint marker
if (series.getMarker() != null) {
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 {
......@@ -193,8 +193,8 @@ public class Legend implements ChartPart {
g.setColor(chartPainter.getStyleManager().getChartFontColor());
TextLayout layout = new TextLayout(series.getName(), chartPainter.getStyleManager().getLegendFont(), new FontRenderContext(null, true, false));
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()
.getHeight()) / 2.0));
layout.draw(g, (float) (startx + getChartPainter().getStyleManager().getLegendSeriesLineLength() + chartPainter.getStyleManager().getLegendPadding()),
(float) (starty + (maxContentHeight - 1 + layout.getBounds().getHeight()) / 2.0));
}
else {
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 {
return 10;
}
@Override
public int getLegendSeriesLineLength() {
return 24;
}
@Override
public LegendPosition getLegendPosition() {
......
......@@ -119,6 +119,12 @@ public class MatlabTheme implements Theme {
return 10;
}
@Override
public int getLegendSeriesLineLength() {
return 24;
}
@Override
public LegendPosition getLegendPosition() {
......
......@@ -60,6 +60,8 @@ public interface Theme {
public int getLegendPadding();
public int getLegendSeriesLineLength();
public LegendPosition getLegendPosition();
// Chart Axes ///////////////////////////////
......
......@@ -119,6 +119,12 @@ public class XChartTheme implements Theme {
return 10;
}
@Override
public int getLegendSeriesLineLength() {
return 24;
}
@Override
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