mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-26 11:17:56 +08:00
项目结构调整
This commit is contained in:
222
Others/Live-Charts-master/UwpView/StackedRowSeries.cs
Normal file
222
Others/Live-Charts-master/UwpView/StackedRowSeries.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
//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 System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Shapes;
|
||||
using LiveCharts.Definitions.Points;
|
||||
using LiveCharts.Definitions.Series;
|
||||
using LiveCharts.Dtos;
|
||||
using LiveCharts.SeriesAlgorithms;
|
||||
using LiveCharts.Uwp.Charts.Base;
|
||||
using LiveCharts.Uwp.Points;
|
||||
using LiveCharts.Uwp.Components;
|
||||
|
||||
namespace LiveCharts.Uwp
|
||||
{
|
||||
/// <summary>
|
||||
/// The stacked row series compares the proportion of every series in a point
|
||||
/// </summary>
|
||||
public class StackedRowSeries : Series, IStackedRowSeriesView
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of StackedRow series class
|
||||
/// </summary>
|
||||
public StackedRowSeries()
|
||||
{
|
||||
Model = new StackedRowAlgorithm(this);
|
||||
InitializeDefuaults();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of StackedRow series class, with a given mapper
|
||||
/// </summary>
|
||||
public StackedRowSeries(object configuration)
|
||||
{
|
||||
Model = new StackedRowAlgorithm(this);
|
||||
Configuration = configuration;
|
||||
InitializeDefuaults();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The maximum row height property
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty MaxRowHeightProperty = DependencyProperty.Register(
|
||||
"MaxRowHeight", typeof (double), typeof (StackedRowSeries), new PropertyMetadata(35d));
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum height of row, any row height will be capped at this value.
|
||||
/// </summary>
|
||||
public double MaxRowHeight
|
||||
{
|
||||
get { return (double) GetValue(MaxRowHeightProperty); }
|
||||
set { SetValue(MaxRowHeightProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The row padding property
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty RowPaddingProperty = DependencyProperty.Register(
|
||||
"RowPadding", typeof (double), typeof (StackedRowSeries), new PropertyMetadata(2d));
|
||||
/// <summary>
|
||||
/// Gets or sets the padding between each row in the series.
|
||||
/// </summary>
|
||||
public double RowPadding
|
||||
{
|
||||
get { return (double) GetValue(RowPaddingProperty); }
|
||||
set { SetValue(RowPaddingProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The stack mode property
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty StackModeProperty = DependencyProperty.Register(
|
||||
"StackMode", typeof (StackMode), typeof (StackedRowSeries), new PropertyMetadata(default(StackMode)));
|
||||
/// <summary>
|
||||
/// Gets or sets the stacked mode, values or percentage.
|
||||
/// </summary>
|
||||
public StackMode StackMode
|
||||
{
|
||||
get { return (StackMode) GetValue(StackModeProperty); }
|
||||
set { SetValue(StackModeProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The label position property
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty LabelPositionProperty = DependencyProperty.Register(
|
||||
"LabelPosition", typeof(BarLabelPosition), typeof(StackedRowSeries),
|
||||
new PropertyMetadata(BarLabelPosition.Parallel, CallChartUpdater()));
|
||||
/// <summary>
|
||||
/// Gets or sets where the label is placed
|
||||
/// </summary>
|
||||
public BarLabelPosition LabelPosition
|
||||
{
|
||||
get { return (BarLabelPosition)GetValue(LabelPositionProperty); }
|
||||
set { SetValue(LabelPositionProperty, value); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overridden Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the view of a given point
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
/// <param name="label"></param>
|
||||
/// <returns></returns>
|
||||
public override IChartPointView GetPointView(ChartPoint point, string label)
|
||||
{
|
||||
var pbv = (RowPointView) point.View;
|
||||
|
||||
if (pbv == null)
|
||||
{
|
||||
pbv = new RowPointView
|
||||
{
|
||||
IsNew = true,
|
||||
Rectangle = new Rectangle(),
|
||||
Data = new CoreRectangle()
|
||||
};
|
||||
|
||||
Model.Chart.View.AddToDrawMargin(pbv.Rectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
pbv.IsNew = false;
|
||||
point.SeriesView.Model.Chart.View
|
||||
.EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle);
|
||||
point.SeriesView.Model.Chart.View
|
||||
.EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape);
|
||||
point.SeriesView.Model.Chart.View
|
||||
.EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel);
|
||||
}
|
||||
|
||||
pbv.Rectangle.Fill = Fill;
|
||||
pbv.Rectangle.StrokeThickness = StrokeThickness;
|
||||
pbv.Rectangle.Stroke = Stroke;
|
||||
pbv.Rectangle.StrokeDashArray = StrokeDashArray;
|
||||
pbv.Rectangle.Visibility = Visibility;
|
||||
Canvas.SetZIndex(pbv.Rectangle, Canvas.GetZIndex(this));
|
||||
|
||||
if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null)
|
||||
{
|
||||
pbv.HoverShape = new Rectangle
|
||||
{
|
||||
Fill = new SolidColorBrush(Windows.UI.Colors.Transparent),
|
||||
StrokeThickness = 0
|
||||
};
|
||||
|
||||
Canvas.SetZIndex(pbv.HoverShape, short.MaxValue);
|
||||
|
||||
var uwpfChart = (Chart)Model.Chart.View;
|
||||
uwpfChart.AttachHoverableEventTo(pbv.HoverShape);
|
||||
|
||||
Model.Chart.View.AddToDrawMargin(pbv.HoverShape);
|
||||
}
|
||||
|
||||
if (pbv.HoverShape != null) pbv.HoverShape.Visibility = Visibility;
|
||||
|
||||
if (DataLabels)
|
||||
{
|
||||
pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel
|
||||
{
|
||||
FormattedText = label,
|
||||
Instance = point.Instance
|
||||
}, pbv.DataLabel);
|
||||
|
||||
Model.Chart.View.AddToDrawMargin(pbv.DataLabel);
|
||||
}
|
||||
|
||||
pbv.LabelPosition = LabelPosition;
|
||||
|
||||
return pbv;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void InitializeDefuaults()
|
||||
{
|
||||
//this.SetIfNotSet(StrokeThicknessProperty, 0d);
|
||||
//this.SetIfNotSet(ForegroundProperty, new SolidColorBrush(Windows.UI.Colors.White));
|
||||
|
||||
Func<ChartPoint, string> defaultLabel = x => Model.CurrentXAxis.GetFormatter()(x.X);
|
||||
this.SetIfNotSet(LabelPointProperty, defaultLabel);
|
||||
|
||||
DefaultFillOpacity = 1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user