From ca00bd58df4d552a74f0265a85e90a818d2415ab Mon Sep 17 00:00:00 2001 From: Igor Crevar Date: Tue, 17 Sep 2013 22:00:12 +0200 Subject: [PATCH] Add (optional) drawing dots to line series chart drawer --- .../Drawer/LineSeriesChartDrawer.cs | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/WPFCanvasChartSolution/WPFChartControl/Drawer/LineSeriesChartDrawer.cs b/WPFCanvasChartSolution/WPFChartControl/Drawer/LineSeriesChartDrawer.cs index f6f3f77..34bad32 100644 --- a/WPFCanvasChartSolution/WPFChartControl/Drawer/LineSeriesChartDrawer.cs +++ b/WPFCanvasChartSolution/WPFChartControl/Drawer/LineSeriesChartDrawer.cs @@ -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> chartPoints; - private double lineTickness; + public double LineTickness { get; set; } + public DotsSettings Dots { get; set; } - public LineSeriesChartDrawer(IList> chartPoints, double lineTickness = 1.0d) + public LineSeriesChartDrawer(IList> chartPoints) { this.chartPoints = chartPoints; - this.lineTickness = lineTickness; + Dots = new DotsSettings(new SolidColorBrush(), new Pen(), 1.0d, false); + this.LineTickness = 1.0d; } - public LineSeriesChartDrawer(IList chartPoints, double lineTickness = 1.0d) - : this(new List>() { chartPoints }, lineTickness) + public LineSeriesChartDrawer(IList chartPoints) + : this(new List>() { 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) @@ -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); } } }