Skip to content

Commit

Permalink
Add (optional) drawing dots to line series chart drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed Sep 17, 2013
1 parent ea4f2a5 commit ca00bd5
Showing 1 changed file with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,48 @@ namespace IgorCrevar.WPFChartControl.Drawer
{
public class LineSeriesChartDrawer : AbstractChartDrawer
{
public struct DotsSettings
{
public DotsSettings(Brush brush, Pen pen, double size, bool isEnabled = true)
{
DotBrush = brush;
DotBrush.Freeze();
DotPen = pen;
DotPen.Freeze();
Size = size;
IsEnabled = isEnabled;
}

public Brush DotBrush;
public Pen DotPen;
public double Size;
public bool IsEnabled;
}

private IList<IList<Point>> chartPoints;
private double lineTickness;
public double LineTickness { get; set; }
public DotsSettings Dots { get; set; }

public LineSeriesChartDrawer(IList<IList<Point>> chartPoints, double lineTickness = 1.0d)
public LineSeriesChartDrawer(IList<IList<Point>> chartPoints)
{
this.chartPoints = chartPoints;
this.lineTickness = lineTickness;
Dots = new DotsSettings(new SolidColorBrush(), new Pen(), 1.0d, false);
this.LineTickness = 1.0d;
}

public LineSeriesChartDrawer(IList<Point> chartPoints, double lineTickness = 1.0d)
: this(new List<IList<Point>>() { chartPoints }, lineTickness)
public LineSeriesChartDrawer(IList<Point> chartPoints)
: this(new List<IList<Point>>() { chartPoints })
{
}

private void DrawDot(Point point, DrawingContext ctx)
{
if (Dots.IsEnabled)
{
ctx.DrawEllipse(Dots.DotBrush, Dots.DotPen, point, Dots.Size, Dots.Size);
}
}

public override void Draw(DrawingContext ctx)
{
for (int j = 0; j < chartPoints.Count; ++j)
Expand All @@ -34,14 +62,16 @@ public override void Draw(DrawingContext ctx)
continue;
}

Pen pen = new Pen(new SolidColorBrush(Legend[j].Color), lineTickness);
Pen pen = new Pen(new SolidColorBrush(Legend[j].Color), LineTickness);
pen.Freeze();
Point prevPoint = Chart.Point2ChartPoint(seriePoints[0]);
DrawDot(prevPoint, ctx);
for (int i = 1; i < seriePoints.Count; ++i)
{
var currPoint = Chart.Point2ChartPoint(seriePoints[i]);
ctx.DrawLine(pen, prevPoint, currPoint);
prevPoint = currPoint;
DrawDot(prevPoint, ctx);
}
}
}
Expand Down

0 comments on commit ca00bd5

Please sign in to comment.