Skip to content

Commit e9f47e7

Browse files
committed
Add checks for non-positive StrokeThickess and LineStyle.None in various places (oxyplot#1312)
1 parent 2c254dc commit e9f47e7

File tree

14 files changed

+318
-249
lines changed

14 files changed

+318
-249
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ All notable changes to this project will be documented in this file.
5858
- CandleStick is overlapped when item.open == item.close in the CandleStickAndVolumeSeries (#1245)
5959
- Out of memory exception and performance issue with Catmull-Rom Spline (#1237)
6060
- Cache and Dispose Brush and Pen objects used by GraphicsRenderContext (#1230)
61+
- Add checks for non-positive StrokeThickess and LineStyle.None in various places (#1312)
6162

6263
## [1.0.0] - 2016-09-11
6364
### Added

Source/Examples/ExampleLibrary/CustomSeries/LineSegmentSeries.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ public override void Render(IRenderContext rc)
8282
}
8383
}
8484

85-
rc.DrawClippedLineSegments(clippingRect, screenPoints, this.ActualColor, this.StrokeThickness, this.LineStyle.GetDashArray(), this.LineJoin, false);
86-
rc.DrawClippedLineSegments(clippingRect, verticalLines, this.ActualColor, this.StrokeThickness / 3, LineStyle.Dash.GetDashArray(), this.LineJoin, false);
85+
if (this.StrokeThickness > 0)
86+
{
87+
if (this.LineStyle != LineStyle.None)
88+
{
89+
rc.DrawClippedLineSegments(clippingRect, screenPoints, this.ActualColor, this.StrokeThickness, this.LineStyle.GetDashArray(), this.LineJoin, false);
90+
}
91+
92+
rc.DrawClippedLineSegments(clippingRect, verticalLines, this.ActualColor, this.StrokeThickness / 3, LineStyle.Dash.GetDashArray(), this.LineJoin, false);
93+
}
8794

8895
rc.DrawMarkers(screenPoints, clippingRect, this.MarkerType, null, this.MarkerSize, this.MarkerFill, this.MarkerStroke, this.MarkerStrokeThickness);
8996
}
@@ -157,4 +164,4 @@ public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpo
157164
return null;
158165
}
159166
}
160-
}
167+
}

Source/OxyPlot/Annotations/ArrowAnnotation.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,25 @@ public override void Render(IRenderContext rc)
128128

129129
var dashArray = this.LineStyle.GetDashArray();
130130

131-
rc.DrawClippedLine(
132-
clippingRectangle,
133-
new[] { this.screenStartPoint, p4 },
134-
MinimumSegmentLength * MinimumSegmentLength,
135-
this.GetSelectableColor(this.Color),
136-
this.StrokeThickness,
137-
dashArray,
138-
this.LineJoin,
139-
false);
140-
141-
rc.DrawClippedPolygon(
142-
clippingRectangle,
143-
new[] { p3, this.screenEndPoint, p2, p4 },
144-
MinimumSegmentLength * MinimumSegmentLength,
145-
this.GetSelectableColor(this.Color),
146-
OxyColors.Undefined);
131+
if (this.StrokeThickness > 0 && this.LineStyle != LineStyle.None)
132+
{
133+
rc.DrawClippedLine(
134+
clippingRectangle,
135+
new[] { this.screenStartPoint, p4 },
136+
MinimumSegmentLength * MinimumSegmentLength,
137+
this.GetSelectableColor(this.Color),
138+
this.StrokeThickness,
139+
dashArray,
140+
this.LineJoin,
141+
false);
142+
143+
rc.DrawClippedPolygon(
144+
clippingRectangle,
145+
new[] { p3, this.screenEndPoint, p2, p4 },
146+
MinimumSegmentLength * MinimumSegmentLength,
147+
this.GetSelectableColor(this.Color),
148+
OxyColors.Undefined);
149+
}
147150

148151
if (!string.IsNullOrEmpty(this.Text))
149152
{
@@ -199,4 +202,4 @@ protected override HitTestResult HitTestOverride(HitTestArguments args)
199202
return null;
200203
}
201204
}
202-
}
205+
}

Source/OxyPlot/Annotations/PathAnnotation.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,20 @@ public override void Render(IRenderContext rc)
189189
var clippedPoints = new List<ScreenPoint>();
190190
var dashArray = this.LineStyle.GetDashArray();
191191

192-
rc.DrawClippedLine(
193-
clippingRectangle,
194-
this.screenPoints,
195-
MinimumSegmentLength * MinimumSegmentLength,
196-
this.GetSelectableColor(this.Color),
197-
this.StrokeThickness,
198-
dashArray,
199-
this.LineJoin,
200-
this.Aliased,
201-
null,
202-
clippedPoints.AddRange);
192+
if (this.StrokeThickness > 0 && this.LineStyle != LineStyle.None)
193+
{
194+
rc.DrawClippedLine(
195+
clippingRectangle,
196+
this.screenPoints,
197+
MinimumSegmentLength * MinimumSegmentLength,
198+
this.GetSelectableColor(this.Color),
199+
this.StrokeThickness,
200+
dashArray,
201+
this.LineJoin,
202+
this.Aliased,
203+
null,
204+
clippedPoints.AddRange);
205+
}
203206

204207
ScreenPoint position;
205208
double angle;
@@ -404,4 +407,4 @@ private static bool GetPointAtRelativeDistance(
404407
return false;
405408
}
406409
}
407-
}
410+
}

Source/OxyPlot/Rendering/RenderContext/RenderingExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ public static void DrawClippedPolygon(
351351
LineJoin lineJoin = LineJoin.Miter,
352352
bool aliased = false)
353353
{
354+
if (lineStyle == LineStyle.None)
355+
{
356+
return;
357+
}
358+
354359
// TODO: minDistSquared should be implemented or removed
355360
if (rc.SetClip(clippingRectangle))
356361
{

Source/OxyPlot/Series/AreaSeries.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,12 @@ public override void RenderLegend(IRenderContext rc, OxyRect legendBox)
334334
var pts = new List<ScreenPoint>();
335335
pts.AddRange(pts0);
336336
pts.AddRange(pts1);
337-
rc.DrawLine(pts0, this.GetSelectableColor(this.ActualColor), this.StrokeThickness, this.ActualLineStyle.GetDashArray());
338-
rc.DrawLine(pts1, this.GetSelectableColor(this.ActualColor2), this.StrokeThickness, this.ActualLineStyle.GetDashArray());
337+
338+
if (this.StrokeThickness > 0 && this.ActualLineStyle != LineStyle.None)
339+
{
340+
rc.DrawLine(pts0, this.GetSelectableColor(this.ActualColor), this.StrokeThickness, this.ActualLineStyle.GetDashArray());
341+
rc.DrawLine(pts1, this.GetSelectableColor(this.ActualColor2), this.StrokeThickness, this.ActualLineStyle.GetDashArray());
342+
}
339343
rc.DrawPolygon(pts, this.GetSelectableFillColor(this.ActualFill), OxyColors.Undefined);
340344
}
341345

Source/OxyPlot/Series/BoxPlotSeries.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -321,24 +321,28 @@ public override void Render(IRenderContext rc)
321321
var topWhiskerBottom = this.Transform(item.X, item.BoxTop);
322322
var bottomWhiskerTop = this.Transform(item.X, item.BoxBottom);
323323
var bottomWhiskerBottom = this.Transform(item.X, item.LowerWhisker);
324-
rc.DrawClippedLine(
325-
clippingRect,
326-
new[] { topWhiskerTop, topWhiskerBottom },
327-
0,
328-
strokeColor,
329-
this.StrokeThickness,
330-
dashArray,
331-
LineJoin.Miter,
332-
true);
333-
rc.DrawClippedLine(
334-
clippingRect,
335-
new[] { bottomWhiskerTop, bottomWhiskerBottom },
336-
0,
337-
strokeColor,
338-
this.StrokeThickness,
339-
dashArray,
340-
LineJoin.Miter,
341-
true);
324+
325+
if (this.StrokeThickness > 0 && this.LineStyle != LineStyle.None)
326+
{
327+
rc.DrawClippedLine(
328+
clippingRect,
329+
new[] { topWhiskerTop, topWhiskerBottom },
330+
0,
331+
strokeColor,
332+
this.StrokeThickness,
333+
dashArray,
334+
LineJoin.Miter,
335+
true);
336+
rc.DrawClippedLine(
337+
clippingRect,
338+
new[] { bottomWhiskerTop, bottomWhiskerBottom },
339+
0,
340+
strokeColor,
341+
this.StrokeThickness,
342+
dashArray,
343+
LineJoin.Miter,
344+
true);
345+
}
342346

343347
// Draw the whiskers
344348
if (this.WhiskerWidth > 0)
@@ -679,4 +683,4 @@ private void ClearItemsSourceItems()
679683
this.ownsItemsSourceItems = true;
680684
}
681685
}
682-
}
686+
}

Source/OxyPlot/Series/FinancialSeries/CandleStickAndVolumeSeries.cs

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -390,34 +390,37 @@ public override void Render(IRenderContext rc)
390390
}
391391
}
392392

393-
// draw volume & bar separation line
394-
if (this.VolumeStyle != VolumeStyle.None)
393+
if (this.SeparatorStrokeThickness > 0 && this.SeparatorLineStyle != LineStyle.None)
395394
{
396-
var ysep = (clippingSep.Bottom + clippingSep.Top) / 2.0;
397-
rc.DrawClippedLine(
398-
clippingSep,
399-
new[] { new ScreenPoint(clippingSep.Left, ysep), new ScreenPoint(clippingSep.Right, ysep) },
400-
0,
401-
this.SeparatorColor,
402-
this.SeparatorStrokeThickness,
403-
this.SeparatorLineStyle.GetDashArray(),
404-
LineJoin.Miter,
405-
true);
406-
}
395+
// draw volume & bar separation line
396+
if (this.VolumeStyle != VolumeStyle.None)
397+
{
398+
var ysep = (clippingSep.Bottom + clippingSep.Top) / 2.0;
399+
rc.DrawClippedLine(
400+
clippingSep,
401+
new[] { new ScreenPoint(clippingSep.Left, ysep), new ScreenPoint(clippingSep.Right, ysep) },
402+
0,
403+
this.SeparatorColor,
404+
this.SeparatorStrokeThickness,
405+
this.SeparatorLineStyle.GetDashArray(),
406+
LineJoin.Miter,
407+
true);
408+
}
407409

408-
// draw volume y=0 line
409-
if (this.VolumeAxis != null && this.VolumeStyle == VolumeStyle.PositiveNegative)
410-
{
411-
var y0 = this.VolumeAxis.Transform(0);
412-
rc.DrawClippedLine(
413-
clippingVol,
414-
new[] { new ScreenPoint(clippingVol.Left, y0), new ScreenPoint(clippingVol.Right, y0) },
415-
0,
416-
OxyColors.Goldenrod,
417-
this.SeparatorStrokeThickness,
418-
this.SeparatorLineStyle.GetDashArray(),
419-
LineJoin.Miter,
420-
true);
410+
// draw volume y=0 line
411+
if (this.VolumeAxis != null && this.VolumeStyle == VolumeStyle.PositiveNegative)
412+
{
413+
var y0 = this.VolumeAxis.Transform(0);
414+
rc.DrawClippedLine(
415+
clippingVol,
416+
new[] { new ScreenPoint(clippingVol.Left, y0), new ScreenPoint(clippingVol.Right, y0) },
417+
0,
418+
OxyColors.Goldenrod,
419+
this.SeparatorStrokeThickness,
420+
this.SeparatorLineStyle.GetDashArray(),
421+
LineJoin.Miter,
422+
true);
423+
}
421424
}
422425
}
423426

@@ -442,19 +445,22 @@ public override void RenderLegend(IRenderContext rc, OxyRect legendBox)
442445
legendBox.Width,
443446
this.XAxis.Transform(this.data[0].X + datacandlewidth) - this.XAxis.Transform(this.data[0].X));
444447

445-
rc.DrawLine(
446-
new[] { new ScreenPoint(xmid, legendBox.Top), new ScreenPoint(xmid, legendBox.Bottom) },
447-
lineUp,
448-
this.StrokeThickness,
449-
dashArray,
450-
LineJoin.Miter,
451-
true);
452-
453-
rc.DrawRectangleAsPolygon(
454-
new OxyRect(xmid - (candlewidth * 0.5), yclose, candlewidth, yopen - yclose),
455-
fillUp,
456-
lineUp,
457-
this.StrokeThickness);
448+
if (this.StrokeThickness > 0)
449+
{
450+
rc.DrawLine(
451+
new[] { new ScreenPoint(xmid, legendBox.Top), new ScreenPoint(xmid, legendBox.Bottom) },
452+
lineUp,
453+
this.StrokeThickness,
454+
dashArray,
455+
LineJoin.Miter,
456+
true);
457+
458+
rc.DrawRectangleAsPolygon(
459+
new OxyRect(xmid - (candlewidth * 0.5), yclose, candlewidth, yopen - yclose),
460+
fillUp,
461+
lineUp,
462+
this.StrokeThickness);
463+
}
458464
}
459465

460466
/// <summary>

Source/OxyPlot/Series/FinancialSeries/CandleStickSeries.cs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,30 @@ public override void Render(IRenderContext rc)
135135
var max = new ScreenPoint(open.X, Math.Max(open.Y, close.Y));
136136
var min = new ScreenPoint(open.X, Math.Min(open.Y, close.Y));
137137

138-
// Upper extent
139-
rc.DrawClippedLine(
140-
clippingRect,
141-
new[] { high, min },
142-
0,
143-
lineColor,
144-
this.StrokeThickness,
145-
dashArray,
146-
this.LineJoin,
147-
true);
148-
149-
// Lower extent
150-
rc.DrawClippedLine(
151-
clippingRect,
152-
new[] { max, low },
153-
0,
154-
lineColor,
155-
this.StrokeThickness,
156-
dashArray,
157-
this.LineJoin,
158-
true);
138+
if (this.StrokeThickness > 0 && this.LineStyle != LineStyle.None)
139+
{
140+
// Upper extent
141+
rc.DrawClippedLine(
142+
clippingRect,
143+
new[] { high, min },
144+
0,
145+
lineColor,
146+
this.StrokeThickness,
147+
dashArray,
148+
this.LineJoin,
149+
true);
150+
151+
// Lower extent
152+
rc.DrawClippedLine(
153+
clippingRect,
154+
new[] { max, low },
155+
0,
156+
lineColor,
157+
this.StrokeThickness,
158+
dashArray,
159+
this.LineJoin,
160+
true);
161+
}
159162

160163
// Body
161164
var openLeft = open + new ScreenVector(-candlewidth * 0.5, 0);
@@ -196,13 +199,16 @@ public override void RenderLegend(IRenderContext rc, OxyRect legendBox)
196199
legendBox.Width,
197200
this.XAxis.Transform(this.Items[0].X + datacandlewidth) - this.XAxis.Transform(this.Items[0].X));
198201

199-
rc.DrawLine(
200-
new[] { new ScreenPoint(xmid, legendBox.Top), new ScreenPoint(xmid, legendBox.Bottom) },
201-
this.GetSelectableColor(this.ActualColor),
202-
this.StrokeThickness,
203-
dashArray,
204-
LineJoin.Miter,
205-
true);
202+
if (this.StrokeThickness > 0 && this.LineStyle != LineStyle.None)
203+
{
204+
rc.DrawLine(
205+
new[] { new ScreenPoint(xmid, legendBox.Top), new ScreenPoint(xmid, legendBox.Bottom) },
206+
this.GetSelectableColor(this.ActualColor),
207+
this.StrokeThickness,
208+
dashArray,
209+
LineJoin.Miter,
210+
true);
211+
}
206212

207213
rc.DrawRectangleAsPolygon(
208214
new OxyRect(xmid - (candlewidth * 0.5), yclose, candlewidth, yopen - yclose),

0 commit comments

Comments
 (0)