From 9faea9a8bb501884ab0deafde9a9cd26601721e4 Mon Sep 17 00:00:00 2001 From: Erik De Bonte Date: Thu, 14 Oct 2021 14:58:55 -0700 Subject: [PATCH] Change hand-generated Chart classes to derive from each other --- samples/Microcharts/Charts/BarChart.cs | 4 +-- samples/Microcharts/Charts/PointChart.cs | 11 ++++-- samples/WpfSamplesHost/BarChart.cs | 39 ++------------------- samples/WpfSamplesHost/Chart.cs | 44 ++++++++++++++++++++++++ samples/WpfSamplesHost/PointChart.cs | 39 ++------------------- 5 files changed, 58 insertions(+), 79 deletions(-) create mode 100644 samples/WpfSamplesHost/Chart.cs diff --git a/samples/Microcharts/Charts/BarChart.cs b/samples/Microcharts/Charts/BarChart.cs index 8db3ded..b9f5e66 100644 --- a/samples/Microcharts/Charts/BarChart.cs +++ b/samples/Microcharts/Charts/BarChart.cs @@ -20,12 +20,12 @@ namespace Microcharts /// /// A bar chart. /// - public class BarChartImplementation : PointChartImplementation where T : IBarChart + public class BarChartImplementation : PointChartImplementation { /// /// Initializes a new instance of the class. /// - public BarChartImplementation(T control) : base(control) + public BarChartImplementation(IBarChart control) : base(control) { PointSize = 0; } diff --git a/samples/Microcharts/Charts/PointChart.cs b/samples/Microcharts/Charts/PointChart.cs index ea15831..387ab01 100644 --- a/samples/Microcharts/Charts/PointChart.cs +++ b/samples/Microcharts/Charts/PointChart.cs @@ -7,11 +7,9 @@ using System.Globalization; using System.Linq; using Microsoft.StandardUI; using Microsoft.StandardUI.Controls; +using Microsoft.StandardUI.Media; using Microsoft.StandardUI.Shapes; using static Microsoft.StandardUI.FactoryStatics; -using SkiaSharp; -using SkiaSharp.HarfBuzz; -using Microsoft.StandardUI.Media; namespace Microcharts { @@ -19,6 +17,13 @@ namespace Microcharts { } + public class PointChartImplementation : PointChartImplementation + { + public PointChartImplementation(IPointChart control) : base(control) + { + } + } + /// /// ![chart](../images/Point.png) /// diff --git a/samples/WpfSamplesHost/BarChart.cs b/samples/WpfSamplesHost/BarChart.cs index efce316..4c6bd35 100644 --- a/samples/WpfSamplesHost/BarChart.cs +++ b/samples/WpfSamplesHost/BarChart.cs @@ -1,49 +1,14 @@ // This code will eventually be generated. -using Microsoft.StandardUI.Wpf; using Microcharts; -using System.Collections.Generic; -using Microsoft.StandardUI; namespace SimpleControls.Wpf { - public class BarChart : StandardControl, IBarChart + public class BarChart : PointChart, IBarChart { - public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable), typeof(BarChart), null); - public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(BarChart), ColorWpf.Default); - public static readonly System.Windows.DependencyProperty LabelColorProperty = PropertyUtils.Register(nameof(LabelColor), typeof(ColorWpf), typeof(BarChart), ColorWpf.Default); - public BarChart() { - InitImplementation(new BarChartImplementation(this)); - } - - public IEnumerable Entries - { - get => (IEnumerable)GetValue(EntriesProperty); - set => SetValue(EntriesProperty, value); - } - - public ColorWpf BackgroundColor - { - get => (ColorWpf)GetValue(BackgroundColorProperty); - set => SetValue(BackgroundColorProperty, value); - } - Color IChart.BackgroundColor - { - get => BackgroundColor.Color; - set => BackgroundColor = new ColorWpf(value); - } - - public ColorWpf LabelColor - { - get => (ColorWpf)GetValue(LabelColorProperty); - set => SetValue(LabelColorProperty, value); - } - Color IChart.LabelColor - { - get => LabelColor.Color; - set => LabelColor = new ColorWpf(value); + InitImplementation(new BarChartImplementation(this)); } } } diff --git a/samples/WpfSamplesHost/Chart.cs b/samples/WpfSamplesHost/Chart.cs new file mode 100644 index 0000000..f5de03f --- /dev/null +++ b/samples/WpfSamplesHost/Chart.cs @@ -0,0 +1,44 @@ +// This code will eventually be generated. + +using Microsoft.StandardUI.Wpf; +using Microcharts; +using System.Collections.Generic; +using Microsoft.StandardUI; + +namespace SimpleControls.Wpf +{ + public abstract class Chart : StandardControl, IChart + { + public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable), typeof(Chart), null); + public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(Chart), ColorWpf.Default); + public static readonly System.Windows.DependencyProperty LabelColorProperty = PropertyUtils.Register(nameof(LabelColor), typeof(ColorWpf), typeof(Chart), ColorWpf.Default); + + public IEnumerable Entries + { + get => (IEnumerable)GetValue(EntriesProperty); + set => SetValue(EntriesProperty, value); + } + + public ColorWpf BackgroundColor + { + get => (ColorWpf)GetValue(BackgroundColorProperty); + set => SetValue(BackgroundColorProperty, value); + } + Color IChart.BackgroundColor + { + get => BackgroundColor.Color; + set => BackgroundColor = new ColorWpf(value); + } + + public ColorWpf LabelColor + { + get => (ColorWpf)GetValue(LabelColorProperty); + set => SetValue(LabelColorProperty, value); + } + Color IChart.LabelColor + { + get => LabelColor.Color; + set => LabelColor = new ColorWpf(value); + } + } +} diff --git a/samples/WpfSamplesHost/PointChart.cs b/samples/WpfSamplesHost/PointChart.cs index d47e695..3301a48 100644 --- a/samples/WpfSamplesHost/PointChart.cs +++ b/samples/WpfSamplesHost/PointChart.cs @@ -1,49 +1,14 @@ // This code will eventually be generated. -using Microsoft.StandardUI.Wpf; using Microcharts; -using System.Collections.Generic; -using Microsoft.StandardUI; namespace SimpleControls.Wpf { - public class PointChart : StandardControl, IPointChart + public class PointChart : Chart, IPointChart { - public static readonly System.Windows.DependencyProperty EntriesProperty = PropertyUtils.Register(nameof(Entries), typeof(IEnumerable), typeof(PointChart), null); - public static readonly System.Windows.DependencyProperty BackgroundColorProperty = PropertyUtils.Register(nameof(BackgroundColor), typeof(ColorWpf), typeof(PointChart), ColorWpf.Default); - public static readonly System.Windows.DependencyProperty LabelColorProperty = PropertyUtils.Register(nameof(LabelColor), typeof(ColorWpf), typeof(PointChart), ColorWpf.Default); - public PointChart() { - InitImplementation(new PointChartImplementation(this)); - } - - public IEnumerable Entries - { - get => (IEnumerable)GetValue(EntriesProperty); - set => SetValue(EntriesProperty, value); - } - - public ColorWpf BackgroundColor - { - get => (ColorWpf)GetValue(BackgroundColorProperty); - set => SetValue(BackgroundColorProperty, value); - } - Color IChart.BackgroundColor - { - get => BackgroundColor.Color; - set => BackgroundColor = new ColorWpf(value); - } - - public ColorWpf LabelColor - { - get => (ColorWpf)GetValue(LabelColorProperty); - set => SetValue(LabelColorProperty, value); - } - Color IChart.LabelColor - { - get => LabelColor.Color; - set => LabelColor = new ColorWpf(value); + InitImplementation(new PointChartImplementation(this)); } } }