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

cleaned up and fixed marker drawing

parent bc9d346e
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ package com.xeiam.xchart.standalone;
import com.xeiam.xchart.BitmapEncoder;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesMarker;
/**
* Creates a simple Chart and saves it as a PNG and JPEG image file.
......@@ -32,7 +34,8 @@ public class Example1 {
chart.setChartTitle("Sample Chart");
chart.setXAxisTitle("X");
chart.setYAxisTitle("Y");
chart.addSeries("y(x)", null, yData);
Series series = chart.addSeries("y(x)", null, yData);
series.setMarker(SeriesMarker.CIRCLE);
BitmapEncoder.savePNG(chart, "./Sample_Chart.png");
BitmapEncoder.savePNGWithDPI(chart, "./Sample_Chart_300_DPI.png", 300);
......
......@@ -28,7 +28,7 @@ public class Circle extends Marker {
public void paint(Graphics2D g, double xOffset, double yOffset) {
g.setStroke(stroke);
Shape circle = new Ellipse2D.Double(xOffset + Marker.X_OFFSET, yOffset + Marker.Y_OFFSET, Marker.SIZE, Marker.SIZE);
Shape circle = new Ellipse2D.Double(xOffset - Marker.HALF_SIZE, yOffset - Marker.HALF_SIZE, Marker.SIZE, Marker.SIZE);
g.fill(circle);
}
......
......@@ -29,13 +29,13 @@ public class Diamond extends Marker {
g.setStroke(stroke);
// Make a diamond
double halfSize = Math.ceil((Marker.SIZE + 3) / 2.0);
double diamondHalfSize = Marker.HALF_SIZE * 1.3;
Path2D.Double path = new Path2D.Double();
path.moveTo(xOffset - halfSize, yOffset - halfSize + halfSize);
path.lineTo(xOffset - halfSize + halfSize, yOffset - halfSize + Marker.SIZE + 3);
path.lineTo(xOffset - halfSize + Marker.SIZE + 3, yOffset - halfSize + halfSize);
path.lineTo(xOffset - halfSize + halfSize, yOffset - halfSize);
path.moveTo(xOffset - diamondHalfSize, yOffset);
path.lineTo(xOffset, yOffset - diamondHalfSize);
path.lineTo(xOffset + diamondHalfSize, yOffset);
path.lineTo(xOffset, yOffset + diamondHalfSize);
path.closePath();
g.fill(path);
......
......@@ -27,8 +27,7 @@ public abstract class Marker {
public static final double SIZE = 8;
public static final double X_OFFSET = -1.0 * (SIZE / 2.0);
public static final double Y_OFFSET = -1.0 * (SIZE / 2.0);
public static final double HALF_SIZE = SIZE / 2.0;
public abstract void paint(Graphics2D g, double xOffset, double yOffset);
}
......@@ -28,7 +28,7 @@ public class Square extends Marker {
public void paint(Graphics2D g, double xOffset, double yOffset) {
g.setStroke(stroke);
Shape square = new Rectangle2D.Double(xOffset + Marker.X_OFFSET, yOffset + Marker.Y_OFFSET, Marker.SIZE, Marker.SIZE);
Shape square = new Rectangle2D.Double(xOffset - Marker.HALF_SIZE, yOffset - Marker.HALF_SIZE, Marker.SIZE, Marker.SIZE);
g.fill(square);
}
......
......@@ -29,12 +29,10 @@ public class TriangleDown extends Marker {
g.setStroke(stroke);
// Make a triangle
double halfSize = Math.ceil((Marker.SIZE + 1) / 2.0);
Path2D.Double path = new Path2D.Double();
path.moveTo(xOffset - halfSize + 0, 1 + yOffset - halfSize + 0);
path.lineTo(xOffset - halfSize + halfSize, 1 + yOffset - halfSize + Marker.SIZE + 1);
path.lineTo(xOffset - halfSize + Marker.SIZE + 1, 1 + yOffset - halfSize + 0);
path.moveTo(xOffset - Marker.HALF_SIZE, 1 + yOffset - Marker.HALF_SIZE);
path.lineTo(xOffset, 1 + yOffset - Marker.HALF_SIZE + Marker.SIZE + 1);
path.lineTo(xOffset - Marker.HALF_SIZE + Marker.SIZE + 1, 1 + yOffset - Marker.HALF_SIZE);
path.closePath();
g.fill(path);
......
......@@ -29,12 +29,10 @@ public class TriangleUp extends Marker {
g.setStroke(stroke);
// Make a triangle
double halfSize = Math.ceil((Marker.SIZE + 1) / 2.0);
Path2D.Double path = new Path2D.Double();
path.moveTo(xOffset - halfSize, yOffset - halfSize + Marker.SIZE + 1);
path.lineTo(xOffset - halfSize + Marker.SIZE + 1, yOffset - halfSize + Marker.SIZE + 1);
path.lineTo(xOffset - halfSize + halfSize, yOffset - halfSize + 0);
path.moveTo(xOffset - Marker.HALF_SIZE, yOffset - Marker.HALF_SIZE + Marker.SIZE + 1);
path.lineTo(xOffset - Marker.HALF_SIZE + Marker.SIZE + 1, yOffset - Marker.HALF_SIZE + Marker.SIZE + 1);
path.lineTo(xOffset, yOffset - Marker.HALF_SIZE);
path.closePath();
g.fill(path);
......
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