Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit acf0634

Browse files
Merge pull request #518 from telerik/dtraykov/development-add-spline-tension-property
Expose SplineTension property for spline series
2 parents a8683b7 + 8c92b2f commit acf0634

File tree

13 files changed

+282
-43
lines changed

13 files changed

+282
-43
lines changed

Controls/Chart/Chart.UWP/Visualization/CartesianChart/Series/Categorical/SplineAreaSeries.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System;
1+
using Telerik.Core;
22
using Telerik.UI.Automation.Peers;
3+
using Windows.UI.Xaml;
34
using Windows.UI.Xaml.Automation.Peers;
45

56
namespace Telerik.UI.Xaml.Controls.Chart
@@ -9,6 +10,12 @@ namespace Telerik.UI.Xaml.Controls.Chart
910
/// </summary>
1011
public class SplineAreaSeries : AreaSeries
1112
{
13+
/// <summary>
14+
/// Identifies the <see cref="SplineTension"/> property.
15+
/// </summary>
16+
public static readonly DependencyProperty SplineTensionProperty =
17+
DependencyProperty.Register("SplineTension", typeof(double), typeof(SplineAreaSeries), new PropertyMetadata(SplineHelper.DefaultTension, OnSplineTensionChanged));
18+
1219
/// <summary>
1320
/// Initializes a new instance of the <see cref="SplineAreaSeries"/> class.
1421
/// </summary>
@@ -17,15 +24,37 @@ public SplineAreaSeries()
1724
this.DefaultStyleKey = typeof(SplineAreaSeries);
1825
}
1926

27+
/// <summary>
28+
/// Gets or sets the <see cref="SplineTension"/> that is used to determine the tension of the additional spline points.
29+
/// The default value is 0.5d. The tension works with relative values between 0 and 1.
30+
/// Values outside this range will be coerced internally.
31+
/// </summary>
32+
public double SplineTension
33+
{
34+
get { return (double)this.GetValue(SplineTensionProperty); }
35+
set { this.SetValue(SplineTensionProperty, value); }
36+
}
37+
2038
internal override LineRenderer CreateRenderer()
2139
{
22-
return new SplineAreaRenderer();
40+
return new SplineAreaRenderer()
41+
{
42+
splineTension = this.SplineTension
43+
};
2344
}
2445

2546
/// <inheritdoc/>
2647
protected override AutomationPeer OnCreateAutomationPeer()
2748
{
2849
return new SplineAreaSeriesAutomationPeer(this);
2950
}
51+
52+
private static void OnSplineTensionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
53+
{
54+
SplineAreaSeries series = (SplineAreaSeries)d;
55+
SplineAreaRenderer renderer = (SplineAreaRenderer)series.renderer;
56+
renderer.splineTension = RadMath.CoerceValue((double)e.NewValue, SplineHelper.MinTension, SplineHelper.MaxTension);
57+
series.InvalidateCore();
58+
}
3059
}
3160
}
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
using System;
1+
using Telerik.Core;
22
using Telerik.UI.Automation.Peers;
3+
using Windows.UI.Xaml;
34
using Windows.UI.Xaml.Automation.Peers;
45

56
namespace Telerik.UI.Xaml.Controls.Chart
67
{
78
/// <summary>
8-
/// Visualizes a collection of data points using a smooth <see cref="Windows.UI.Xaml.Shapes.Line"/> shape.
9+
/// Visualizes a collection of data points using a smooth <see cref="Microsoft.UI.Xaml.Shapes.Line"/> shape.
910
/// </summary>
1011
public class SplineSeries : LineSeries
1112
{
13+
/// <summary>
14+
/// Identifies the <see cref="SplineTension"/> property.
15+
/// </summary>
16+
public static readonly DependencyProperty SplineTensionProperty =
17+
DependencyProperty.Register("SplineTension", typeof(double), typeof(SplineSeries), new PropertyMetadata(SplineHelper.DefaultTension, OnSplineTensionChanged));
18+
1219
/// <summary>
1320
/// Initializes a new instance of the <see cref="SplineSeries"/> class.
1421
/// </summary>
@@ -17,15 +24,37 @@ public SplineSeries()
1724
this.DefaultStyleKey = typeof(SplineSeries);
1825
}
1926

27+
/// <summary>
28+
/// Gets or sets the <see cref="SplineTension"/> that is used to determine the tension of the additional spline points.
29+
/// The default value is 0.5d. The tension works with relative values between 0 and 1.
30+
/// Values outside this range will be coerced internally.
31+
/// </summary>
32+
public double SplineTension
33+
{
34+
get { return (double)this.GetValue(SplineTensionProperty); }
35+
set { this.SetValue(SplineTensionProperty, value); }
36+
}
37+
2038
internal override LineRenderer CreateRenderer()
2139
{
22-
return new SplineRenderer();
40+
return new SplineRenderer()
41+
{
42+
splineTension = this.SplineTension
43+
};
2344
}
2445

2546
/// <inheritdoc/>
2647
protected override AutomationPeer OnCreateAutomationPeer()
2748
{
2849
return new SplineSeriesAutomationPeer(this);
2950
}
51+
52+
private static void OnSplineTensionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
53+
{
54+
SplineSeries series = (SplineSeries)d;
55+
SplineRenderer renderer = (SplineRenderer)series.renderer;
56+
renderer.splineTension = RadMath.CoerceValue((double)e.NewValue, SplineHelper.MinTension, SplineHelper.MaxTension);
57+
series.InvalidateCore();
58+
}
3059
}
3160
}
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System;
2-
using Telerik.Charting;
1+
using Telerik.Charting;
2+
using Telerik.Core;
33
using Telerik.UI.Automation.Peers;
4+
using Windows.UI.Xaml;
45
using Windows.UI.Xaml.Automation.Peers;
56

67
namespace Telerik.UI.Xaml.Controls.Chart
@@ -10,6 +11,12 @@ namespace Telerik.UI.Xaml.Controls.Chart
1011
/// </summary>
1112
public class ScatterSplineAreaSeries : ScatterAreaSeries
1213
{
14+
/// <summary>
15+
/// Identifies the <see cref="SplineTension"/> property.
16+
/// </summary>
17+
public static readonly DependencyProperty SplineTensionProperty =
18+
DependencyProperty.Register("SplineTension", typeof(double), typeof(ScatterSplineAreaSeries), new PropertyMetadata(SplineHelper.DefaultTension, OnSplineTensionChanged));
19+
1320
/// <summary>
1421
/// Initializes a new instance of the <see cref="ScatterSplineAreaSeries"/> class.
1522
/// </summary>
@@ -18,15 +25,37 @@ public ScatterSplineAreaSeries()
1825
this.DefaultStyleKey = typeof(ScatterSplineAreaSeries);
1926
}
2027

28+
/// <summary>
29+
/// Gets or sets the <see cref="SplineTension"/> that is used to determine the tension of the additional spline points.
30+
/// The default value is 0.5d. The tension works with relative values between 0 and 1.
31+
/// Values outside this range will be coerced internally.
32+
/// </summary>
33+
public double SplineTension
34+
{
35+
get { return (double)this.GetValue(SplineTensionProperty); }
36+
set { this.SetValue(SplineTensionProperty, value); }
37+
}
38+
2139
internal override LineRenderer CreateRenderer()
2240
{
23-
return new SplineAreaRenderer();
41+
return new SplineAreaRenderer()
42+
{
43+
splineTension = this.SplineTension
44+
};
2445
}
2546

2647
/// <inheritdoc/>
2748
protected override AutomationPeer OnCreateAutomationPeer()
2849
{
2950
return new ScatterSplineAreaSeriesAutomationPeer(this);
3051
}
52+
53+
private static void OnSplineTensionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
54+
{
55+
ScatterSplineAreaSeries series = (ScatterSplineAreaSeries)d;
56+
SplineAreaRenderer renderer = (SplineAreaRenderer)series.renderer;
57+
renderer.splineTension = RadMath.CoerceValue((double)e.NewValue, SplineHelper.MinTension, SplineHelper.MaxTension);
58+
series.InvalidateCore();
59+
}
3160
}
3261
}
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using System;
2-
using Telerik.Charting;
1+
using Telerik.Charting;
2+
using Telerik.Core;
33
using Telerik.UI.Automation.Peers;
4+
using Windows.UI.Xaml;
45
using Windows.UI.Xaml.Automation.Peers;
56

67
namespace Telerik.UI.Xaml.Controls.Chart
@@ -10,6 +11,12 @@ namespace Telerik.UI.Xaml.Controls.Chart
1011
/// </summary>
1112
public class ScatterSplineSeries : ScatterLineSeries
1213
{
14+
/// <summary>
15+
/// Identifies the <see cref="SplineTension"/> property.
16+
/// </summary>
17+
public static readonly DependencyProperty SplineTensionProperty =
18+
DependencyProperty.Register("SplineTension", typeof(double), typeof(ScatterSplineSeries), new PropertyMetadata(SplineHelper.DefaultTension, OnSplineTensionChanged));
19+
1320
/// <summary>
1421
/// Initializes a new instance of the <see cref="ScatterSplineSeries"/> class.
1522
/// </summary>
@@ -18,15 +25,37 @@ public ScatterSplineSeries()
1825
this.DefaultStyleKey = typeof(ScatterSplineSeries);
1926
}
2027

28+
/// <summary>
29+
/// Gets or sets the <see cref="SplineTension"/> that is used to determine the tension of the additional spline points.
30+
/// The default value is 0.5d. The tension works with relative values between 0 and 1.
31+
/// Values outside this range will be coerced internally.
32+
/// </summary>
33+
public double SplineTension
34+
{
35+
get { return (double)this.GetValue(SplineTensionProperty); }
36+
set { this.SetValue(SplineTensionProperty, value); }
37+
}
38+
2139
internal override LineRenderer CreateRenderer()
2240
{
23-
return new SplineRenderer();
41+
return new SplineRenderer()
42+
{
43+
splineTension = this.SplineTension
44+
};
2445
}
2546

2647
/// <inheritdoc/>
2748
protected override AutomationPeer OnCreateAutomationPeer()
2849
{
2950
return new ScatterSplineSeriesAutomationPeer(this);
3051
}
52+
53+
private static void OnSplineTensionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
54+
{
55+
ScatterSplineSeries series = (ScatterSplineSeries)d;
56+
SplineRenderer renderer = (SplineRenderer)series.renderer;
57+
renderer.splineTension = RadMath.CoerceValue((double)e.NewValue, SplineHelper.MinTension, SplineHelper.MaxTension);
58+
series.InvalidateCore();
59+
}
3160
}
3261
}

Controls/Chart/Chart.UWP/Visualization/Common/Renderers/Cartesian/Spline/SplineAreaRenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Telerik.UI.Xaml.Controls.Chart
77
{
88
internal class SplineAreaRenderer : AreaRenderer
99
{
10+
internal double splineTension;
11+
1012
protected override IEnumerable<Point> GetTopPoints(DataPointSegment segment)
1113
{
1214
// return the first point since spline segmentation skips it
@@ -15,7 +17,7 @@ protected override IEnumerable<Point> GetTopPoints(DataPointSegment segment)
1517
IChartView view = this.model.GetChartArea().view;
1618
double scaleFactor = Math.Abs(view.ZoomWidth - view.ZoomHeight) / 2;
1719

18-
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor))
20+
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor, this.splineTension))
1921
{
2022
yield return point;
2123
}

Controls/Chart/Chart.UWP/Visualization/Common/Renderers/Cartesian/Spline/SplineRenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace Telerik.UI.Xaml.Controls.Chart
77
{
88
internal class SplineRenderer : LineRenderer
99
{
10+
internal double splineTension;
11+
1012
protected internal override IEnumerable<Point> GetPoints(DataPointSegment segment)
1113
{
1214
// return the first point since spline segmentation skips it
@@ -15,7 +17,7 @@ protected internal override IEnumerable<Point> GetPoints(DataPointSegment segmen
1517
IChartView view = this.model.GetChartArea().view;
1618
double scaleFactor = Math.Abs(view.ZoomWidth - view.ZoomHeight) / 2;
1719

18-
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor))
20+
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor, this.splineTension))
1921
{
2022
yield return point;
2123
}

Controls/Chart/Chart.UWP/Visualization/Common/Renderers/Polar/Polar/PolarSplineRenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Telerik.UI.Xaml.Controls.Chart
88
{
99
internal class PolarSplineRenderer : PolarLineRenderer
1010
{
11+
internal double splineTension;
12+
1113
protected internal override IEnumerable<Point> GetPoints(DataPointSegment segment)
1214
{
1315
// return the first point since spline segmentation skips it
@@ -16,7 +18,7 @@ protected internal override IEnumerable<Point> GetPoints(DataPointSegment segmen
1618
IChartView view = this.model.GetChartArea().view;
1719
double scaleFactor = Math.Abs(view.ZoomWidth - view.ZoomHeight) / 2;
1820

19-
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor, this.isClosed))
21+
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor, this.splineTension, this.isClosed))
2022
{
2123
yield return point;
2224
}

Controls/Chart/Chart.UWP/Visualization/Common/Renderers/Polar/Radar/RadarSplineRenderer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Telerik.UI.Xaml.Controls.Chart
88
{
99
internal class RadarSplineRenderer : RadarLineRenderer
1010
{
11+
internal double splineTension;
12+
1113
protected internal override IEnumerable<Point> GetPoints(DataPointSegment segment)
1214
{
1315
// return the first point since spline segmentation skips it
@@ -16,7 +18,7 @@ protected internal override IEnumerable<Point> GetPoints(DataPointSegment segmen
1618
IChartView view = this.model.GetChartArea().view;
1719
double scaleFactor = Math.Abs(view.ZoomWidth - view.ZoomHeight) / 2;
1820

19-
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor, this.isClosed))
21+
foreach (Point point in SplineHelper.GetSplinePoints(this.renderPoints, segment, scaleFactor, this.splineTension, this.isClosed))
2022
{
2123
yield return point;
2224
}

0 commit comments

Comments
 (0)