//The MIT License(MIT) //Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors //Permission is hereby granted, free of charge, to any person obtaining a copy //of this software and associated documentation files (the "Software"), to deal //in the Software without restriction, including without limitation the rights //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //copies of the Software, and to permit persons to whom the Software is //furnished to do so, subject to the following conditions: //The above copyright notice and this permission notice shall be included in all //copies or substantial portions of the Software. //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; using LiveCharts.Charts; using LiveCharts.Definitions.Charts; namespace LiveCharts.Uwp { /// /// Defines an Axis.Separator, this class customizes the separator of an axis. /// public class Separator : Control, ISeparatorView { /// /// Initializes a new instance of Separator class /// public Separator() { //this.SetIfNotSet(IsEnabledProperty, true); } /// /// Gets the chart the own the separator /// public ChartCore Chart { get; set; } private AxisCore Axis { get; set; } #region Dependency Properties /// /// The stroke property /// public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register( "Stroke", typeof (Brush), typeof (Separator), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(255, 240, 240, 240)), CallChartUpdater())); /// /// Gets or sets separators color /// public Brush Stroke { get { return (Brush) GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } } /// /// The stroke thickness property /// public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register( "StrokeThickness", typeof (double), typeof (Separator), new PropertyMetadata(1d, CallChartUpdater())); /// /// Gets or sets separators thickness /// public double StrokeThickness { get { return (double) GetValue(StrokeThicknessProperty); } set { SetValue(StrokeThicknessProperty, value); } } /// /// The stroke dash array property /// public static readonly DependencyProperty StrokeDashArrayProperty = DependencyProperty.Register( "StrokeDashArray", typeof (DoubleCollection), typeof (Separator), new PropertyMetadata(default(DoubleCollection), CallChartUpdater())); /// /// Gets or sets the stroke dash array for the current separator. /// public DoubleCollection StrokeDashArray { get { return (DoubleCollection) GetValue(StrokeDashArrayProperty); } set { SetValue(StrokeDashArrayProperty, value); } } /// /// The step property /// public static readonly DependencyProperty StepProperty = DependencyProperty.Register( "Step", typeof (double), typeof (Separator), new PropertyMetadata(double.NaN, CallChartUpdater())); /// /// Gets or sets separators step, this means the value between each line, default is null, when null this value is calculated automatically. /// public double Step { get { return (double) GetValue(StepProperty); } set { SetValue(StepProperty, value); } } /// /// The actual step property /// public static readonly DependencyProperty ActualStepProperty = DependencyProperty.Register( "ActualStep", typeof(double), typeof(Separator), new PropertyMetadata(default(double))); /// /// Gets the actual step. /// /// /// The actual step. /// public double ActualStep { get { return Axis.S; } } /// /// The axis orientation property /// public static readonly DependencyProperty AxisOrientationProperty = DependencyProperty.Register( "AxisOrientation", typeof(AxisOrientation), typeof(Separator), new PropertyMetadata(default(AxisOrientation))); /// /// Gets or sets the element orientation ind the axis /// public AxisOrientation AxisOrientation { get { return (AxisOrientation)GetValue(AxisOrientationProperty); } internal set { SetValue(AxisOrientationProperty, value); } } #endregion /// /// Ases the core element. /// /// The axis. /// The source. /// public SeparatorConfigurationCore AsCoreElement(AxisCore axis, AxisOrientation source) { AxisOrientation = source; Chart = axis.Chart; Axis = axis; return new SeparatorConfigurationCore(axis) { IsEnabled = IsEnabled, Step = Step, Source = source }; } private static PropertyChangedCallback CallChartUpdater(bool animate = false) { return (o, args) => { var wpfSeparator = o as Separator; if (wpfSeparator == null) return; if (wpfSeparator.Chart != null) wpfSeparator.Chart.Updater.Run(animate); }; } } }