项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,162 @@
//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.Controls;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class CandlePointView : PointView, IOhlcPointView
{
public Line HighToLowLine { get; set; }
public Rectangle OpenToCloseRectangle { get; set; }
public double Open { get; set; }
public double High { get; set; }
public double Close { get; set; }
public double Low { get; set; }
public double Width { get; set; }
public double Left { get; set; }
public double StartReference { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
var center = Left + Width / 2;
if (IsNew)
{
HighToLowLine.X1 = center;
HighToLowLine.X2 = center;
HighToLowLine.Y1 = StartReference;
HighToLowLine.Y2 = StartReference;
Canvas.SetTop(OpenToCloseRectangle, (Open+Close)/2);
Canvas.SetLeft(OpenToCloseRectangle, Left);
OpenToCloseRectangle.Width = Width;
OpenToCloseRectangle.Height = 0;
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X);
}
if (HoverShape != null)
{
var h = Math.Abs(High - Low);
HoverShape.Width = Width;
HoverShape.Height = h > 10 ? h : 10;
Canvas.SetLeft(HoverShape, Left);
Canvas.SetTop(HoverShape, High);
}
if (chart.View.DisableAnimations)
{
HighToLowLine.Y1 = High;
HighToLowLine.Y2 = Low;
HighToLowLine.X1 = center;
HighToLowLine.X2 = center;
OpenToCloseRectangle.Width = Width;
OpenToCloseRectangle.Height = Math.Abs(Open - Close);
Canvas.SetTop(OpenToCloseRectangle, Math.Min(Open, Close));
Canvas.SetLeft(OpenToCloseRectangle, Left);
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualHeight*.5, chart);
var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualWidth*.5, chart);
Canvas.SetTop(DataLabel, cy);
Canvas.SetLeft(DataLabel, cx);
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth*.5, chart);
var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight*.5, chart);
DataLabel.CreateCanvasStoryBoardAndBegin(cx, cy, animSpeed);
}
var x1Animation = AnimationsHelper.CreateDouble(center, animSpeed, "Line.X1");
var x2Animation = AnimationsHelper.CreateDouble(center, animSpeed, "Line.X2");
AnimationsHelper.CreateStoryBoard(HighToLowLine, x1Animation, x2Animation);
var y1Animation = AnimationsHelper.CreateDouble(High, animSpeed, "Line.Y1");
var y2Animation = AnimationsHelper.CreateDouble(Low, animSpeed, "Line.Y2");
AnimationsHelper.CreateStoryBoardAndBegin(HighToLowLine, y1Animation, y2Animation);
OpenToCloseRectangle.BeginDoubleAnimation("(Canvas.Left)", Left, animSpeed);
OpenToCloseRectangle.BeginDoubleAnimation("(Canvas.Top)", Math.Min(Open, Close), animSpeed);
OpenToCloseRectangle.BeginDoubleAnimation("Width", Width, animSpeed);
OpenToCloseRectangle.BeginDoubleAnimation("Height", Math.Max(Math.Abs(Open - Close), OpenToCloseRectangle.StrokeThickness), animSpeed);
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(OpenToCloseRectangle);
chart.View.RemoveFromDrawMargin(HighToLowLine);
chart.View.RemoveFromDrawMargin(DataLabel);
}
protected double CorrectXLabel(double desiredPosition, ChartCore chart)
{
if (desiredPosition + DataLabel.ActualWidth > chart.DrawMargin.Width)
desiredPosition -= desiredPosition + DataLabel.ActualWidth - chart.DrawMargin.Width + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
protected double CorrectYLabel(double desiredPosition, ChartCore chart)
{
//desiredPosition -= Ellipse.ActualHeight * .5 + DataLabel.ActualHeight * .5 + 2;
if (desiredPosition + DataLabel.ActualHeight > chart.DrawMargin.Height)
desiredPosition -= desiredPosition + DataLabel.ActualHeight - chart.DrawMargin.Height + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
}
}

View File

@@ -0,0 +1,205 @@
//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.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class ColumnPointView : PointView, IRectanglePointView
{
public Rectangle Rectangle { get; set; }
public CoreRectangle Data { get; set; }
public double ZeroReference { get; set; }
public BarLabelPosition LabelPosition { get; set; }
private RotateTransform Transform { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
if (IsNew)
{
Canvas.SetTop(Rectangle, ZeroReference);
Canvas.SetLeft(Rectangle, Data.Left);
Rectangle.Width = Data.Width;
Rectangle.Height = 0;
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, ZeroReference);
Canvas.SetLeft(DataLabel, current.ChartLocation.X);
}
Func<double> getY = () =>
{
double y;
#pragma warning disable 618
if (LabelPosition == BarLabelPosition.Parallel || LabelPosition == BarLabelPosition.Merged)
#pragma warning restore 618
{
if (Transform == null)
Transform = new RotateTransform {Angle = 270};
y = Data.Top + Data.Height / 2 + DataLabel.ActualWidth * .5;
DataLabel.RenderTransform = Transform;
}
else if (LabelPosition == BarLabelPosition.Perpendicular)
{
y = Data.Top + Data.Height / 2 - DataLabel.ActualHeight * .5;
}
else
{
if (ZeroReference > Data.Top)
{
y = Data.Top - DataLabel.ActualHeight;
if (y < 0) y = Data.Top;
}
else
{
y = Data.Top + Data.Height;
if (y + DataLabel.ActualHeight > chart.DrawMargin.Height) y -= DataLabel.ActualHeight;
}
}
return y;
};
Func<double> getX = () =>
{
double x;
#pragma warning disable 618
if (LabelPosition == BarLabelPosition.Parallel || LabelPosition == BarLabelPosition.Merged)
#pragma warning restore 618
{
x = Data.Left + Data.Width / 2 - DataLabel.ActualHeight / 2;
}
else if (LabelPosition == BarLabelPosition.Perpendicular)
{
x = Data.Left + Data.Width / 2 - DataLabel.ActualWidth / 2;
}
else
{
x = Data.Left + Data.Width / 2 - DataLabel.ActualWidth / 2;
if (x < 0)
x = 2;
if (x + DataLabel.ActualWidth > chart.DrawMargin.Width)
x -= x + DataLabel.ActualWidth - chart.DrawMargin.Width + 2;
}
return x;
};
if (chart.View.DisableAnimations)
{
Rectangle.Width = Data.Width;
Rectangle.Height = Data.Height;
Canvas.SetTop(Rectangle, Data.Top);
Canvas.SetLeft(Rectangle, Data.Left);
if (DataLabel != null)
{
DataLabel.UpdateLayout();
Canvas.SetTop(DataLabel, getY());
Canvas.SetLeft(DataLabel, getX());
}
if (HoverShape != null)
{
Canvas.SetTop(HoverShape, Data.Top);
Canvas.SetLeft(HoverShape, Data.Left);
HoverShape.Height = Data.Height;
HoverShape.Width = Data.Width;
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
DataLabel.CreateCanvasStoryBoardAndBegin(getX(), getY(), animSpeed);
}
Rectangle.BeginDoubleAnimation("(Canvas.Left)", Data.Left, animSpeed);
Rectangle.BeginDoubleAnimation("(Canvas.Top)", Data.Top, animSpeed);
Rectangle.BeginDoubleAnimation("(Canvas.Height)", Data.Width, animSpeed);
Rectangle.BeginDoubleAnimation(nameof(FrameworkElement.Height), Data.Height, animSpeed);
if (HoverShape != null)
{
Canvas.SetTop(HoverShape, Data.Top);
Canvas.SetLeft(HoverShape, Data.Left);
HoverShape.Height = Data.Height;
HoverShape.Width = Data.Width;
}
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Rectangle);
chart.View.RemoveFromDrawMargin(DataLabel);
}
public override void OnHover(ChartPoint point)
{
var copy = Rectangle.Fill.Clone();
if (copy == null) return;
copy.Opacity -= .15;
Rectangle.Fill = copy;
}
public override void OnHoverLeave(ChartPoint point)
{
if (Rectangle?.Fill == null) return;
Rectangle.Fill.Opacity += .15;
if (point.Fill != null)
{
Rectangle.Fill = (Brush) point.Fill;
}
else
{
Rectangle.Fill = ((Series) point.SeriesView).Fill;
}
}
}
}

View File

@@ -0,0 +1,105 @@
//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.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class HeatPoint : PointView, IHeatPointView
{
public Rectangle Rectangle { get; set; }
public CoreColor ColorComponents { get; set; }
public double Width { get; set; }
public double Height { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
Canvas.SetTop(Rectangle, current.ChartLocation.Y);
Canvas.SetLeft(Rectangle, current.ChartLocation.X);
Rectangle.Width = Width;
Rectangle.Height = Height;
if (IsNew)
{
Rectangle.Fill = new SolidColorBrush(Colors.Transparent);
}
if (HoverShape != null)
{
HoverShape.Width = Width;
HoverShape.Height = Height;
Canvas.SetLeft(HoverShape, current.ChartLocation.X);
Canvas.SetTop(HoverShape, current.ChartLocation.Y);
}
if (DataLabel != null)
{
DataLabel.UpdateLayout();
Canvas.SetTop(DataLabel, current.ChartLocation.Y + (Height/2) - DataLabel.ActualHeight*.5);
Canvas.SetLeft(DataLabel, current.ChartLocation.X + (Width/2) - DataLabel.ActualWidth*.5);
}
var targetColor = new Color
{
A = ColorComponents.A,
R = ColorComponents.R,
G = ColorComponents.G,
B = ColorComponents.B
};
if (chart.View.DisableAnimations)
{
Rectangle.Fill = new SolidColorBrush(targetColor);
return;
}
var animSpeed = chart.View.AnimationsSpeed;
Rectangle.Fill.BeginColorAnimation(nameof(SolidColorBrush.Color), targetColor, animSpeed);
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Rectangle);
chart.View.RemoveFromDrawMargin(DataLabel);
}
public override void OnHover(ChartPoint point)
{
Rectangle.StrokeThickness++;
}
public override void OnHoverLeave(ChartPoint point)
{
Rectangle.StrokeThickness = ((Series) point.SeriesView).StrokeThickness;
}
}
}

View File

@@ -0,0 +1,216 @@
//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.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class HorizontalBezierPointView : PointView, IBezierPointView
{
public BezierSegment Segment { get; set; }
public Path Shape { get; set; }
public PathFigure Container { get; set; }
public BezierData Data { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
var previosPbv = previousDrawn == null
? null
: (HorizontalBezierPointView) previousDrawn.View;
var y = chart.DrawMargin.Top + chart.DrawMargin.Height;
Container.Segments.Remove(Segment);
Container.Segments.Insert(index, Segment);
if (IsNew)
{
if (previosPbv != null && !previosPbv.IsNew)
{
Segment.Point1 = previosPbv.Segment.Point3;
Segment.Point2 = previosPbv.Segment.Point3;
Segment.Point3 = previosPbv.Segment.Point3;
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, Canvas.GetTop(previosPbv.DataLabel));
Canvas.SetLeft(DataLabel, Canvas.GetLeft(previosPbv.DataLabel));
}
if (Shape != null)
{
Canvas.SetTop(Shape, Canvas.GetTop(previosPbv.Shape));
Canvas.SetLeft(Shape, Canvas.GetLeft(previosPbv.Shape));
}
}
else
{
Segment.Point1 = new Point(Data.Point1.X, y);
Segment.Point2 = new Point(Data.Point2.X, y);
Segment.Point3 = new Point(Data.Point3.X, y);
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X - DataLabel.ActualWidth * .5);
}
if (Shape != null)
{
Canvas.SetTop(Shape, y);
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width*.5);
}
}
}
else if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X - DataLabel.ActualWidth*.5);
}
#region No Animated
if (chart.View.DisableAnimations)
{
Segment.Point1 = Data.Point1.AsPoint();
Segment.Point2 = Data.Point2.AsPoint();
Segment.Point3 = Data.Point3.AsPoint();
if (HoverShape != null)
{
Canvas.SetLeft(HoverShape, current.ChartLocation.X - HoverShape.Width*.5);
Canvas.SetTop(HoverShape, current.ChartLocation.Y - HoverShape.Height*.5);
}
if (Shape != null)
{
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width*.5);
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height*.5);
}
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
Canvas.SetLeft(DataLabel, xl);
Canvas.SetTop(DataLabel, yl);
}
return;
}
#endregion
var animSpeed = chart.View.AnimationsSpeed;
Segment.BeginPointAnimation(nameof(BezierSegment.Point1), Data.Point1.AsPoint(), animSpeed);
Segment.BeginPointAnimation(nameof(BezierSegment.Point2), Data.Point2.AsPoint(), animSpeed);
Segment.BeginPointAnimation(nameof(BezierSegment.Point3), Data.Point3.AsPoint(), animSpeed);
if (Shape != null)
{
if (double.IsNaN(Canvas.GetLeft(Shape)))
{
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width * .5);
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height * .5);
}
else
{
Shape.CreateCanvasStoryBoardAndBegin(current.ChartLocation.X - Shape.Width*.5,
current.ChartLocation.Y - Shape.Height*.5, chart.View.AnimationsSpeed);
}
}
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth*.5, chart);
var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight*.5, chart);
DataLabel.CreateCanvasStoryBoardAndBegin(xl, yl, chart.View.AnimationsSpeed);
}
if (HoverShape != null)
{
Canvas.SetLeft(HoverShape, current.ChartLocation.X - HoverShape.Width*.5);
Canvas.SetTop(HoverShape, current.ChartLocation.Y - HoverShape.Height*.5);
}
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Shape);
chart.View.RemoveFromDrawMargin(DataLabel);
Container.Segments.Remove(Segment);
}
protected double CorrectXLabel(double desiredPosition, ChartCore chart)
{
if (desiredPosition + DataLabel.ActualWidth * .5 < -0.1) return -DataLabel.ActualWidth;
if (desiredPosition + DataLabel.ActualWidth > chart.DrawMargin.Width)
desiredPosition -= desiredPosition + DataLabel.ActualWidth - chart.DrawMargin.Width + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
protected double CorrectYLabel(double desiredPosition, ChartCore chart)
{
desiredPosition -= (Shape == null ? 0 : Shape.ActualHeight*.5) + DataLabel.ActualHeight*.5 + 2;
if (desiredPosition + DataLabel.ActualHeight > chart.DrawMargin.Height)
desiredPosition -= desiredPosition + DataLabel.ActualHeight - chart.DrawMargin.Height + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
public override void OnHover(ChartPoint point)
{
var lineSeries = (LineSeries)point.SeriesView;
if (Shape != null) Shape.Fill = Shape.Stroke;
lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness + 1;
}
public override void OnHoverLeave(ChartPoint point)
{
var lineSeries = (LineSeries) point.SeriesView;
if (Shape != null)
Shape.Fill = point.Fill == null
? lineSeries.PointForeround
: (Brush) point.Fill;
lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness;
}
}
}

View File

@@ -0,0 +1,171 @@
//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.Controls;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class OhlcPointView : PointView, IOhlcPointView
{
public Line HighToLowLine { get; set; }
public Line OpenLine { get; set; }
public Line CloseLine { get; set; }
public double Open { get; set; }
public double High { get; set; }
public double Close { get; set; }
public double Low { get; set; }
public double Width { get; set; }
public double Left { get; set; }
public double StartReference { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
var center = Left + Width / 2;
if (IsNew)
{
HighToLowLine.X1 = center;
HighToLowLine.X2 = center;
HighToLowLine.Y1 = StartReference;
HighToLowLine.Y2 = StartReference;
OpenLine.X1 = Left;
OpenLine.X2 = center;
OpenLine.Y1 = StartReference;
OpenLine.Y2 = StartReference;
CloseLine.X1 = center;
CloseLine.X2 = Left + Width;
CloseLine.Y1 = StartReference;
CloseLine.Y2 = StartReference;
}
if (HoverShape != null)
{
var h = Math.Abs(High - Low);
HoverShape.Width = Width;
HoverShape.Height = h > 10 ? h : 10;
Canvas.SetLeft(HoverShape, Left);
Canvas.SetTop(HoverShape, High);
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X);
}
if (chart.View.DisableAnimations)
{
HighToLowLine.Y1 = High;
HighToLowLine.Y2 = Low;
HighToLowLine.X1 = center;
HighToLowLine.X2 = center;
OpenLine.Y1 = Open;
OpenLine.Y2 = Open;
OpenLine.X1 = Left;
OpenLine.X2 = center;
CloseLine.Y1 = Close;
CloseLine.Y2 = Close;
CloseLine.X1 = center;
CloseLine.X2 = Left;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualHeight*.5, chart);
var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualWidth*.5, chart);
Canvas.SetTop(DataLabel, cy);
Canvas.SetLeft(DataLabel, cx);
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth*.5, chart);
var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight*.5, chart);
DataLabel.CreateCanvasStoryBoardAndBegin(cx, cy, animSpeed);
}
HighToLowLine.BeginDoubleAnimation("Line.X1", center, animSpeed);
HighToLowLine.BeginDoubleAnimation("Line.X2", center, animSpeed);
OpenLine.BeginDoubleAnimation("Line.X1", Left, animSpeed);
OpenLine.BeginDoubleAnimation("Line.X2", center, animSpeed);
CloseLine.BeginDoubleAnimation("Line.X1", center, animSpeed);
CloseLine.BeginDoubleAnimation("Line.X2", center, animSpeed);
HighToLowLine.CreateY1Y2StoryBoardAndBegin(High, Low, animSpeed);
OpenLine.CreateY1Y2StoryBoardAndBegin(Open, Open, animSpeed);
CloseLine.CreateY1Y2StoryBoardAndBegin(Close, Close, animSpeed);
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(OpenLine);
chart.View.RemoveFromDrawMargin(CloseLine);
chart.View.RemoveFromDrawMargin(HighToLowLine);
chart.View.RemoveFromDrawMargin(DataLabel);
}
protected double CorrectXLabel(double desiredPosition, ChartCore chart)
{
if (desiredPosition + DataLabel.ActualWidth * .5 < -0.1) return -DataLabel.ActualWidth;
if (desiredPosition + DataLabel.ActualWidth > chart.DrawMargin.Width)
desiredPosition -= desiredPosition + DataLabel.ActualWidth - chart.DrawMargin.Width + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
protected double CorrectYLabel(double desiredPosition, ChartCore chart)
{
//desiredPosition -= Ellipse.ActualHeight * .5 + DataLabel.ActualHeight * .5 + 2;
if (desiredPosition + DataLabel.ActualHeight > chart.DrawMargin.Height)
desiredPosition -= desiredPosition + DataLabel.ActualHeight - chart.DrawMargin.Height + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
}
}

View File

@@ -0,0 +1,171 @@
//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.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class PiePointView : PointView, IPieSlicePointView
{
public double Rotation { get; set; }
public double InnerRadius { get; set; }
public double Radius { get; set; }
public double Wedge { get; set; }
public PieSlice Slice { get; set; }
public double OriginalPushOut { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
if (IsNew)
{
Slice.Width = chart.DrawMargin.Width;
Slice.Height = chart.DrawMargin.Height;
Slice.WedgeAngle = 0;
Slice.RotationAngle = 0;
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, chart.DrawMargin.Height / 2);
Canvas.SetLeft(DataLabel, chart.DrawMargin.Width / 2);
}
if (HoverShape != null)
{
var hs = (PieSlice) HoverShape;
hs.Width = chart.DrawMargin.Width;
hs.Height = chart.DrawMargin.Height;
hs.WedgeAngle = Wedge;
hs.RotationAngle = Rotation;
hs.InnerRadius = InnerRadius;
hs.Radius = Radius;
}
Slice.Width = chart.DrawMargin.Width;
Slice.Height = chart.DrawMargin.Height;
var lh = 0d;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
lh = DataLabel.ActualHeight;
}
var hypo = ((PieSeries)current.SeriesView).LabelPosition == PieLabelPosition.InsideSlice
? (Radius + InnerRadius) * (Math.Abs(InnerRadius) < 0.01 ? .65 : .5)
: Radius + lh;
var gamma = current.Participation*360/2 + Rotation;
var cp = new Point(hypo * Math.Sin(gamma * (Math.PI / 180)), hypo * Math.Cos(gamma * (Math.PI / 180)));
if (chart.View.DisableAnimations)
{
Slice.InnerRadius = InnerRadius;
Slice.Radius = Radius;
Slice.WedgeAngle = Wedge;
Slice.RotationAngle = Rotation;
Canvas.SetTop(Slice, chart.DrawMargin.Height / 2);
Canvas.SetLeft(Slice, chart.DrawMargin.Width / 2);
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var lx = cp.X + chart.DrawMargin.Width / 2 - DataLabel.ActualWidth * .5;
var ly = chart.DrawMargin.Height/2 - cp.Y - DataLabel.ActualHeight*.5;
Canvas.SetLeft(DataLabel, lx);
Canvas.SetTop(DataLabel, ly);
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var lx = cp.X + chart.DrawMargin.Width / 2 - DataLabel.ActualWidth * .5;
var ly = chart.DrawMargin.Height / 2 - cp.Y - DataLabel.ActualHeight * .5;
DataLabel.CreateCanvasStoryBoardAndBegin(lx, ly, animSpeed);
}
Slice.BeginDoubleAnimation("(Canvas.Left)", chart.DrawMargin.Width / 2, animSpeed);
Slice.BeginDoubleAnimation("(Canvas.Top)", chart.DrawMargin.Height / 2, animSpeed);
Slice.BeginDoubleAnimation(nameof(PieSlice.InnerRadius), InnerRadius, animSpeed);
Slice.BeginDoubleAnimation(nameof(PieSlice.Radius), Radius, animSpeed);
Slice.BeginDoubleAnimation(nameof(PieSlice.WedgeAngle), Wedge, animSpeed);
Slice.BeginDoubleAnimation(nameof(PieSlice.RotationAngle), Rotation, animSpeed);
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Slice);
chart.View.RemoveFromDrawMargin(DataLabel);
}
public override void OnHover(ChartPoint point)
{
Slice.Fill = Slice.Fill.Clone();
if (Slice?.Fill != null)
{
Slice.Fill.Opacity -= .15;
}
if (Slice != null)
{
var pieChart = (PieChart) point.SeriesView.Model.Chart.View;
Slice.BeginDoubleAnimation(nameof(PieSlice.PushOut), Slice.PushOut,
OriginalPushOut + pieChart.HoverPushOut,
point.SeriesView.Model.Chart.View.AnimationsSpeed);
}
}
public override void OnHoverLeave(ChartPoint point)
{
if (point.Fill != null)
{
Slice.Fill = (Brush)point.Fill;
}
else
{
Slice.Fill = ((Series)point.SeriesView).Fill;
}
Slice.BeginDoubleAnimation(nameof(Slice.PushOut), OriginalPushOut,
point.SeriesView.Model.Chart.View.AnimationsSpeed);
}
}
}

View File

@@ -0,0 +1,298 @@
using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace LiveCharts.Uwp.Points
{
//special thanks to Colin Eberhardt for the article.
//http://www.codeproject.com/Articles/28098/A-WPF-Pie-Chart-with-Data-Binding-Support
//http://domysee.com/blogposts/Blogpost%207%20-%20Creating%20custom%20Shapes%20for%20UWP%20Apps/
/// <summary>
///
/// </summary>
/// <seealso cref="Windows.UI.Xaml.Shapes.Path" />
[Bindable]
public class PieSlice : Path
{
/// <summary>
/// Initializes a new instance of the <see cref="PieSlice"/> class.
/// </summary>
public PieSlice()
{
RegisterPropertyChangedCallback(WidthProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(RadiusProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(PushOutProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(InnerRadiusProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(WedgeAngleProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(RotationAngleProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(XOffsetProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(YOffsetProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(PieceValueProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(HeightProperty, RenderAffectingPropertyChanged);
RegisterPropertyChangedCallback(WidthProperty, RenderAffectingPropertyChanged);
}
#region dependency properties
/// <summary>
/// The radius property
/// </summary>
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register(nameof(Radius), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The radius of this pie piece
/// </summary>
public double Radius
{
get { return (double)GetValue(RadiusProperty); }
set { SetValue(RadiusProperty, value); }
}
/// <summary>
/// The push out property
/// </summary>
public static readonly DependencyProperty PushOutProperty =
DependencyProperty.Register(nameof(PushOut), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The distance to 'push' this pie piece out from the centre.
/// </summary>
public double PushOut
{
get { return (double)GetValue(PushOutProperty); }
set { SetValue(PushOutProperty, value); }
}
/// <summary>
/// The inner radius property
/// </summary>
public static readonly DependencyProperty InnerRadiusProperty =
DependencyProperty.Register(nameof(InnerRadius), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The inner radius of this pie piece
/// </summary>
public double InnerRadius
{
get { return (double)GetValue(InnerRadiusProperty); }
set { SetValue(InnerRadiusProperty, value); }
}
/// <summary>
/// The wedge angle property
/// </summary>
public static readonly DependencyProperty WedgeAngleProperty =
DependencyProperty.Register(nameof(WedgeAngle), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The wedge angle of this pie piece in degrees
/// </summary>
public double WedgeAngle
{
get { return (double)GetValue(WedgeAngleProperty); }
set
{
SetValue(WedgeAngleProperty, value);
Percentage = (value / 360.0);
}
}
/// <summary>
/// The rotation angle property
/// </summary>
public static readonly DependencyProperty RotationAngleProperty =
DependencyProperty.Register(nameof(RotationAngle), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The rotation, in degrees, from the Y axis vector of this pie piece.
/// </summary>
public double RotationAngle
{
get { return (double)GetValue(RotationAngleProperty); }
set { SetValue(RotationAngleProperty, value); }
}
/// <summary>
/// The x offset property
/// </summary>
public static readonly DependencyProperty XOffsetProperty =
DependencyProperty.Register(nameof(XOffset), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The X coordinate of centre of the circle from which this pie piece is cut.
/// </summary>
public double XOffset
{
get { return (double)GetValue(XOffsetProperty); }
set { SetValue(XOffsetProperty, value); }
}
/// <summary>
/// The y offset property
/// </summary>
public static readonly DependencyProperty YOffsetProperty =
DependencyProperty.Register(nameof(YOffset), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The Y coordinate of centre of the circle from which this pie piece is cut.
/// </summary>
public double YOffset
{
get { return (double)GetValue(YOffsetProperty); }
set { SetValue(YOffsetProperty, value); }
}
/// <summary>
/// The percentage property
/// </summary>
public static readonly DependencyProperty PercentageProperty =
DependencyProperty.Register(nameof(Percentage), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
//new FrameworkPropertyMetadata(0.0));
/// <summary>
/// The percentage of a full pie that this piece occupies.
/// </summary>
/// <value>
/// The percentage.
/// </value>
public double Percentage
{
get { return (double)GetValue(PercentageProperty); }
private set { SetValue(PercentageProperty, value); }
}
/// <summary>
/// The piece value property
/// </summary>
public static readonly DependencyProperty PieceValueProperty =
DependencyProperty.Register(nameof(PieceValue), typeof(double), typeof(PieSlice),
new PropertyMetadata(0.0));
// new FrameworkPropertyMetadata(0.0));
/// <summary>
/// The value that this pie piece represents.
/// </summary>
public double PieceValue
{
get { return (double)GetValue(PieceValueProperty); }
set { SetValue(PieceValueProperty, value); }
}
#endregion
private static void RenderAffectingPropertyChanged(DependencyObject obj, DependencyProperty dp)
{
(obj as PieSlice)?.SetRenderData();
}
/// <summary>
/// Draws the pie piece
/// </summary>
private void SetRenderData()
{
var innerArcStartPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle, InnerRadius, this);
innerArcStartPoint.X += XOffset;
innerArcStartPoint.Y += YOffset;
var innerArcEndPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius, this);
innerArcEndPoint.X += XOffset;
innerArcEndPoint.Y += YOffset;
var outerArcStartPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle, Radius, this);
outerArcStartPoint.X += XOffset;
outerArcStartPoint.Y += YOffset;
var outerArcEndPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius, this);
outerArcEndPoint.X += XOffset;
outerArcEndPoint.Y += YOffset;
var innerArcMidPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle * .5, InnerRadius, this);
innerArcMidPoint.X += XOffset;
innerArcMidPoint.Y += YOffset;
var outerArcMidPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle * .5, Radius, this);
outerArcMidPoint.X += XOffset;
outerArcMidPoint.Y += YOffset;
var largeArc = WedgeAngle > 180.0d;
var requiresMidPoint = Math.Abs(WedgeAngle - 360) < .01;
if (PushOut > 0 && !requiresMidPoint)
{
var offset = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut, this);
offset.X -= Width*.5;
offset.Y -= Height*.5;
innerArcStartPoint.X += offset.X;
innerArcStartPoint.Y += offset.Y;
innerArcEndPoint.X += offset.X;
innerArcEndPoint.Y += offset.Y;
outerArcStartPoint.X += offset.X;
outerArcStartPoint.Y += offset.Y;
outerArcEndPoint.X += offset.X;
outerArcEndPoint.Y += offset.Y;
}
var outerArcSize = new Size(Radius, Radius);
var innerArcSize = new Size(InnerRadius, InnerRadius);
var pathFigure = new PathFigure { IsClosed = true, IsFilled = true, StartPoint = innerArcStartPoint };
if (requiresMidPoint)
{
pathFigure.Segments.Add(new LineSegment { Point = outerArcStartPoint });
pathFigure.Segments.Add(new ArcSegment { Point = outerArcMidPoint, Size = outerArcSize, RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise });
pathFigure.Segments.Add(new ArcSegment { Point = outerArcEndPoint, Size = outerArcSize, RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Clockwise });
pathFigure.Segments.Add(new LineSegment { Point = innerArcEndPoint });
pathFigure.Segments.Add(new ArcSegment { Point = innerArcMidPoint, Size = innerArcSize, RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Counterclockwise });
pathFigure.Segments.Add(new ArcSegment { Point = innerArcStartPoint, Size = innerArcSize, RotationAngle = 0, IsLargeArc = false, SweepDirection = SweepDirection.Counterclockwise });
}
else
{
pathFigure.Segments.Add(new LineSegment { Point = outerArcStartPoint });
pathFigure.Segments.Add(new ArcSegment { Point = outerArcEndPoint, Size = outerArcSize, RotationAngle = 0, IsLargeArc = largeArc, SweepDirection = SweepDirection.Clockwise });
pathFigure.Segments.Add(new LineSegment { Point = innerArcEndPoint });
pathFigure.Segments.Add(new ArcSegment { Point = innerArcStartPoint, Size = innerArcSize, RotationAngle = 0, IsLargeArc = largeArc, SweepDirection = SweepDirection.Counterclockwise });
}
Data = new PathGeometry { Figures = new PathFigureCollection() { pathFigure }, FillRule = FillRule.EvenOdd };
}
}
/// <summary>
///
/// </summary>
public static class PieUtils
{
/// <summary>
/// Converts a coordinate from the polar coordinate system to the cartesian coordinate system.
/// </summary>
/// <param name="angle"></param>
/// <param name="radius"></param>
/// <param name="container"></param>
/// <returns></returns>
public static Point ComputeCartesianCoordinate(double angle, double radius, Path container)
{
// convert to radians
var angleRad = (Math.PI / 180.0) * (angle - 90);
var x = radius * Math.Cos(angleRad);
var y = radius * Math.Sin(angleRad);
return new Point(x + container.Width*.5, y + container.Height*.5);
}
}
}

View File

@@ -0,0 +1,22 @@
using Windows.Foundation;
namespace LiveCharts.Uwp.Points
{
/// <summary>
///
/// </summary>
public static class PointExtensions
{
/// <summary>
/// Offsets the specified x.
/// </summary>
/// <param name="point">The point.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
public static void Offset(this Point point, double x, double y)
{
point.X += x;
point.Y += y;
}
}
}

View File

@@ -0,0 +1,57 @@
//copyright(c) 2016 Alberto Rodriguez
//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.Controls;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
namespace LiveCharts.Uwp.Points
{
internal class PointView : IChartPointView
{
public Shape HoverShape { get; set; }
public ContentControl DataLabel { get; set; }
public bool IsNew { get; set; }
public CoreRectangle ValidArea { get; }
public virtual void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
throw new NotImplementedException();
}
public virtual void RemoveFromView(ChartCore chart)
{
throw new NotImplementedException();
}
public virtual void OnHover(ChartPoint point)
{
}
public virtual void OnHoverLeave(ChartPoint point)
{
}
}
}

View File

@@ -0,0 +1,193 @@
//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.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class RowPointView : PointView, IRectanglePointView
{
public Rectangle Rectangle { get; set; }
public CoreRectangle Data { get; set; }
public double ZeroReference { get; set; }
public BarLabelPosition LabelPosition { get; set; }
private RotateTransform Transform { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
if (IsNew)
{
Canvas.SetTop(Rectangle, Data.Top);
Canvas.SetLeft(Rectangle, ZeroReference);
Rectangle.Width = 0;
Rectangle.Height = Data.Height;
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, Data.Top);
Canvas.SetLeft(DataLabel, ZeroReference);
}
Func<double> getY = () =>
{
if (LabelPosition == BarLabelPosition.Perpendicular)
{
if (Transform == null)
Transform = new RotateTransform {Angle = 270};
DataLabel.RenderTransform = Transform;
return Data.Top + Data.Height / 2 + DataLabel.ActualWidth * .5;
}
var r = Data.Top + Data.Height / 2 - DataLabel.ActualHeight / 2;
if (r < 0) r = 2;
if (r + DataLabel.ActualHeight > chart.DrawMargin.Height)
r -= r + DataLabel.ActualHeight - chart.DrawMargin.Height + 2;
return r;
};
Func<double> getX = () =>
{
double r;
#pragma warning disable 618
if (LabelPosition == BarLabelPosition.Parallel || LabelPosition == BarLabelPosition.Merged)
#pragma warning restore 618
{
r = Data.Left + Data.Width / 2 - DataLabel.ActualWidth / 2;
}
else if (LabelPosition == BarLabelPosition.Perpendicular)
{
r = Data.Left + Data.Width / 2 - DataLabel.ActualHeight / 2;
}
else
{
if (Data.Left < ZeroReference)
{
r = Data.Left - DataLabel.ActualWidth - 5;
if (r < 0) r = Data.Left + 5;
}
else
{
r = Data.Left + Data.Width + 5;
if (r + DataLabel.ActualWidth > chart.DrawMargin.Width)
r -= DataLabel.ActualWidth + 10;
}
}
return r;
};
if (chart.View.DisableAnimations)
{
Rectangle.Width = Data.Width;
Rectangle.Height = Data.Height;
Canvas.SetTop(Rectangle, Data.Top);
Canvas.SetLeft(Rectangle, Data.Left);
if (DataLabel != null)
{
DataLabel.UpdateLayout();
Canvas.SetTop(DataLabel, getY());
Canvas.SetLeft(DataLabel, getX());
}
if (HoverShape != null)
{
Canvas.SetTop(HoverShape, Data.Top);
Canvas.SetLeft(HoverShape, Data.Left);
HoverShape.Height = Data.Height;
HoverShape.Width = Data.Width;
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
DataLabel.CreateCanvasStoryBoardAndBegin(getX(), getY(), animSpeed);
}
Rectangle.BeginDoubleAnimation("(Canvas.Top)", Data.Top, animSpeed);
Rectangle.BeginDoubleAnimation("(Canvas.Left)", Data.Left, animSpeed);
Rectangle.BeginDoubleAnimation("Height", Data.Height, animSpeed);
Rectangle.BeginDoubleAnimation("Width", Data.Width, animSpeed);
if (HoverShape != null)
{
Canvas.SetTop(HoverShape, Data.Top);
Canvas.SetLeft(HoverShape, Data.Left);
HoverShape.Height = Data.Height;
HoverShape.Width = Data.Width;
}
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Rectangle);
chart.View.RemoveFromDrawMargin(DataLabel);
}
public override void OnHover(ChartPoint point)
{
var copy = Rectangle.Fill.Clone();
if (copy == null) return;
copy.Opacity -= .15;
Rectangle.Fill = copy;
}
public override void OnHoverLeave(ChartPoint point)
{
if (Rectangle == null) return;
if (Rectangle?.Fill != null)
Rectangle.Fill.Opacity += .15;
if (point.Fill != null)
{
Rectangle.Fill = (Brush) point.Fill;
}
else
{
Rectangle.Fill = ((Series) point.SeriesView).Fill;
}
}
}
}

View File

@@ -0,0 +1,153 @@
//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.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class ScatterPointView : PointView, IScatterPointView
{
public Shape Shape { get; set; }
public double Diameter { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
if (IsNew)
{
Canvas.SetTop(Shape, current.ChartLocation.Y);
Canvas.SetLeft(Shape, current.ChartLocation.X);
Shape.Width = 0;
Shape.Height = 0;
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X);
}
if (HoverShape != null)
{
HoverShape.Width = Diameter;
HoverShape.Height = Diameter;
Canvas.SetLeft(HoverShape, current.ChartLocation.X - Diameter / 2);
Canvas.SetTop(HoverShape, current.ChartLocation.Y - Diameter / 2);
}
if (chart.View.DisableAnimations)
{
Shape.Width = Diameter;
Shape.Height = Diameter;
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height*.5);
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width*.5);
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth*.5, chart);
var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight*.5, chart);
Canvas.SetTop(DataLabel, cy);
Canvas.SetLeft(DataLabel, cx);
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth*.5, chart);
var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight*.5, chart);
DataLabel.CreateCanvasStoryBoardAndBegin(cx, cy, animSpeed);
}
Shape.BeginDoubleAnimation(nameof(FrameworkElement.Width), Diameter, animSpeed);
Shape.BeginDoubleAnimation(nameof(FrameworkElement.Height), Diameter, animSpeed);
Shape.CreateCanvasStoryBoardAndBegin(current.ChartLocation.X - Diameter*.5,
current.ChartLocation.Y - Diameter*.5, animSpeed);
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Shape);
chart.View.RemoveFromDrawMargin(DataLabel);
}
protected double CorrectXLabel(double desiredPosition, ChartCore chart)
{
if (desiredPosition + DataLabel.ActualWidth > chart.DrawMargin.Width)
desiredPosition -= desiredPosition + DataLabel.ActualWidth - chart.DrawMargin.Width;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
protected double CorrectYLabel(double desiredPosition, ChartCore chart)
{
if (desiredPosition + DataLabel.ActualHeight > chart.DrawMargin.Height)
desiredPosition -= desiredPosition + DataLabel.ActualHeight - chart.DrawMargin.Height;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
public override void OnHover(ChartPoint point)
{
var copy = Shape.Fill.Clone();
if (copy == null) return;
copy.Opacity -= .15;
Shape.Fill = copy;
}
public override void OnHoverLeave(ChartPoint point)
{
if (Shape?.Fill == null) return;
Shape.Fill.Opacity += .15;
if (point.Fill != null)
{
Shape.Fill = (Brush) point.Fill;
}
else
{
Shape.Fill = ((Series) point.SeriesView).Fill;
}
}
}
}

View File

@@ -0,0 +1,181 @@
//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.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class StepLinePointView : PointView, IStepPointView
{
public double DeltaX { get; set; }
public double DeltaY { get; set; }
public Line VerticalLine { get; set; }
public Line HorizontalLine { get; set; }
public Path Shape { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
if (IsNew)
{
VerticalLine.X1 = current.ChartLocation.X;
VerticalLine.X2 = current.ChartLocation.X;
VerticalLine.Y1 = chart.DrawMargin.Height;
VerticalLine.Y2 = chart.DrawMargin.Height;
HorizontalLine.X1 = current.ChartLocation.X - DeltaX;
HorizontalLine.X2 = current.ChartLocation.X;
HorizontalLine.Y1 = chart.DrawMargin.Height;
HorizontalLine.Y2 = chart.DrawMargin.Height;
if (Shape != null)
{
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width/2);
Canvas.SetTop(Shape, chart.DrawMargin.Height);
}
}
if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, chart.DrawMargin.Height);
Canvas.SetLeft(DataLabel, current.ChartLocation.X);
}
if (HoverShape != null)
{
HoverShape.Width = Shape != null ? (Shape.Width > 5 ? Shape.Width : 5) : 5;
HoverShape.Height = Shape != null ? (Shape.Height > 5 ? Shape.Height : 5) : 5;
Canvas.SetLeft(HoverShape, current.ChartLocation.X - HoverShape.Width / 2);
Canvas.SetTop(HoverShape, current.ChartLocation.Y - HoverShape.Height / 2);
}
if (chart.View.DisableAnimations)
{
VerticalLine.X1 = current.ChartLocation.X;
VerticalLine.X2 = current.ChartLocation.X;
VerticalLine.Y1 = current.ChartLocation.Y;
VerticalLine.Y2 = current.ChartLocation.Y - DeltaY;
HorizontalLine.X1 = current.ChartLocation.X - DeltaX;
HorizontalLine.X2 = current.ChartLocation.X;
HorizontalLine.Y1 = current.ChartLocation.Y - DeltaY;
HorizontalLine.Y2 = current.ChartLocation.Y - DeltaY;
if (Shape != null)
{
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width/2);
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height/2);
}
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
Canvas.SetLeft(DataLabel, xl);
Canvas.SetTop(DataLabel, yl);
}
return;
}
var animSpeed = chart.View.AnimationsSpeed;
VerticalLine.BeginDoubleAnimation(nameof(Line.X1), current.ChartLocation.X, animSpeed);
VerticalLine.BeginDoubleAnimation(nameof(Line.X2), current.ChartLocation.X, animSpeed);
VerticalLine.BeginDoubleAnimation(nameof(Line.Y1), current.ChartLocation.Y, animSpeed);
VerticalLine.BeginDoubleAnimation(nameof(Line.Y2), current.ChartLocation.Y - DeltaY, animSpeed);
HorizontalLine.BeginDoubleAnimation(nameof(Line.X1), current.ChartLocation.X - DeltaX, animSpeed);
HorizontalLine.BeginDoubleAnimation(nameof(Line.X2), current.ChartLocation.X, animSpeed);
HorizontalLine.BeginDoubleAnimation(nameof(Line.Y1), current.ChartLocation.Y - DeltaY, animSpeed);
HorizontalLine.BeginDoubleAnimation(nameof(Line.Y2), current.ChartLocation.Y - DeltaY, animSpeed);
Shape?.CreateCanvasStoryBoardAndBegin(current.ChartLocation.X - Shape.Width/2,
current.ChartLocation.Y - Shape.Height/2, animSpeed);
if (DataLabel == null) return;
{
DataLabel.UpdateLayout();
var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
Canvas.SetLeft(DataLabel, xl);
Canvas.SetTop(DataLabel, yl);
}
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Shape);
chart.View.RemoveFromDrawMargin(DataLabel);
chart.View.RemoveFromDrawMargin(VerticalLine);
chart.View.RemoveFromDrawMargin(HorizontalLine);
}
public override void OnHover(ChartPoint point)
{
var lineSeries = (StepLineSeries) point.SeriesView;
if (Shape != null) Shape.Fill = Shape.Stroke;
lineSeries.StrokeThickness = lineSeries.StrokeThickness + 1;
}
public override void OnHoverLeave(ChartPoint point)
{
var lineSeries = (StepLineSeries) point.SeriesView;
if (Shape != null)
Shape.Fill = point.Fill == null
? lineSeries.PointForeround
: (Brush) point.Fill;
lineSeries.StrokeThickness = lineSeries.StrokeThickness - 1;
}
protected double CorrectXLabel(double desiredPosition, ChartCore chart)
{
if (desiredPosition + DataLabel.ActualWidth * .5 < -0.1) return -DataLabel.ActualWidth;
if (desiredPosition + DataLabel.ActualWidth > chart.DrawMargin.Width)
desiredPosition -= desiredPosition + DataLabel.ActualWidth - chart.DrawMargin.Width + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
protected double CorrectYLabel(double desiredPosition, ChartCore chart)
{
desiredPosition -= (Shape?.ActualHeight * .5 ?? 0) + DataLabel.ActualHeight * .5 + 2;
if (desiredPosition + DataLabel.ActualHeight > chart.DrawMargin.Height)
desiredPosition -= desiredPosition + DataLabel.ActualHeight - chart.DrawMargin.Height + 2;
if (desiredPosition < 0) desiredPosition = 0;
return desiredPosition;
}
}
}

View File

@@ -0,0 +1,211 @@
//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.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using LiveCharts.Charts;
using Windows.Foundation;
using LiveCharts.Uwp.Components;
namespace LiveCharts.Uwp.Points
{
internal class VerticalBezierPointView : HorizontalBezierPointView
{
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
var previosPbv = previousDrawn == null ? null : (VerticalBezierPointView) previousDrawn.View;
Container.Segments.Remove(Segment);
Container.Segments.Insert(index, Segment);
if (IsNew)
{
if (previosPbv != null && !previosPbv.IsNew)
{
Segment.Point1 = previosPbv.Segment.Point3;
Segment.Point2 = previosPbv.Segment.Point3;
Segment.Point3 = previosPbv.Segment.Point3;
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, Canvas.GetTop(previosPbv.DataLabel));
Canvas.SetLeft(DataLabel, Canvas.GetLeft(previosPbv.DataLabel));
}
if (Shape != null)
{
Canvas.SetTop(Shape, Canvas.GetTop(previosPbv.Shape));
Canvas.SetLeft(Shape, Canvas.GetLeft(previosPbv.Shape));
}
}
else
{
Segment.Point1 = new Point(0, Data.Point1.Y);
Segment.Point2 = new Point(0, Data.Point2.Y);
Segment.Point3 = new Point(0, Data.Point3.Y);
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y - DataLabel.ActualHeight * .5);
Canvas.SetLeft(DataLabel, 0);
}
if (Shape != null)
{
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height * .5);
Canvas.SetLeft(Shape, 0);
}
}
}
else if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y - DataLabel.ActualHeight*.5);
Canvas.SetLeft(DataLabel, 0);
}
#region No Animated
if (chart.View.DisableAnimations)
{
Segment.Point1 = Data.Point1.AsPoint();
Segment.Point2 = Data.Point2.AsPoint();
Segment.Point3 = Data.Point3.AsPoint();
if (HoverShape != null)
{
Canvas.SetLeft(HoverShape, current.ChartLocation.X - HoverShape.Width * .5);
Canvas.SetTop(HoverShape, current.ChartLocation.Y - HoverShape.Height * .5);
}
if (Shape != null)
{
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width * .5);
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height * .5);
}
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
Canvas.SetLeft(DataLabel, xl);
Canvas.SetTop(DataLabel, yl);
}
return;
}
#endregion
var animSpeed = chart.View.AnimationsSpeed;
Segment.BeginPointAnimation(nameof(BezierSegment.Point1), Data.Point1.AsPoint(), animSpeed);
Segment.BeginPointAnimation(nameof(BezierSegment.Point2), Data.Point2.AsPoint(), animSpeed);
Segment.BeginPointAnimation(nameof(BezierSegment.Point3), Data.Point3.AsPoint(), animSpeed);
if (Shape != null)
{
if (double.IsNaN(Canvas.GetLeft(Shape)))
{
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width * .5);
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height * .5);
}
else
{
var storyBoard = new Storyboard();
var xAnimation = new DoubleAnimation()
{
To = current.ChartLocation.X - Shape.Width * .5,
Duration = chart.View.AnimationsSpeed
};
var yAnimation = new DoubleAnimation()
{
To = current.ChartLocation.Y - Shape.Height * .5,
Duration = chart.View.AnimationsSpeed
};
Storyboard.SetTarget(xAnimation, Shape);
Storyboard.SetTarget(yAnimation, Shape);
Storyboard.SetTargetProperty(xAnimation, "(Canvas.Left)");
Storyboard.SetTargetProperty(yAnimation, "(Canvas.Top)");
storyBoard.Children.Add(xAnimation);
storyBoard.Children.Add(yAnimation);
storyBoard.Begin();
}
}
if (DataLabel != null)
{
DataLabel.UpdateLayout();
var xl = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
var yl = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);
var storyBoard = new Storyboard();
var xAnimation = new DoubleAnimation()
{
To = xl,
Duration = chart.View.AnimationsSpeed
};
var yAnimation = new DoubleAnimation()
{
To = yl,
Duration = chart.View.AnimationsSpeed
};
Storyboard.SetTarget(xAnimation, DataLabel);
Storyboard.SetTarget(yAnimation, DataLabel);
Storyboard.SetTargetProperty(xAnimation, "(Canvas.Left)");
Storyboard.SetTargetProperty(yAnimation, "(Canvas.Top)");
storyBoard.Children.Add(xAnimation);
storyBoard.Children.Add(yAnimation);
storyBoard.Begin();
}
if (HoverShape != null)
{
Canvas.SetLeft(HoverShape, current.ChartLocation.X - HoverShape.Width * .5);
Canvas.SetTop(HoverShape, current.ChartLocation.Y - HoverShape.Height * .5);
}
}
public override void OnHover(ChartPoint point)
{
var lineSeries = (LineSeries)point.SeriesView;
if (Shape != null) Shape.Fill = Shape.Stroke;
lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness + 1;
}
public override void OnHoverLeave(ChartPoint point)
{
var lineSeries = (LineSeries)point.SeriesView;
if (Shape != null)
Shape.Fill = point.Fill == null
? lineSeries.PointForeround
: (Brush) point.Fill;
lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness;
}
}
}