项目结构调整

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,199 @@
//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 System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
namespace LiveCharts.Wpf.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 candleSeries = (CandleSeries) current.SeriesView;
if (candleSeries.ColoringRules == null)
{
if (current.Open <= current.Close)
{
HighToLowLine.Stroke = candleSeries.IncreaseBrush;
OpenToCloseRectangle.Fill = candleSeries.IncreaseBrush;
OpenToCloseRectangle.Stroke = candleSeries.IncreaseBrush;
}
else
{
HighToLowLine.Stroke = candleSeries.DecreaseBrush;
OpenToCloseRectangle.Fill = candleSeries.DecreaseBrush;
OpenToCloseRectangle.Stroke = candleSeries.DecreaseBrush;
}
}
else
{
foreach (var rule in candleSeries.ColoringRules)
{
if (!rule.Condition(current, previousDrawn)) continue;
HighToLowLine.Stroke = rule.Stroke;
OpenToCloseRectangle.Fill = rule.Fill;
OpenToCloseRectangle.Stroke = rule.Stroke;
break;
}
}
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.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(cx, animSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(cy, animSpeed));
}
HighToLowLine.BeginAnimation(Line.X1Property, new DoubleAnimation(center, animSpeed));
HighToLowLine.BeginAnimation(Line.X2Property, new DoubleAnimation(center, animSpeed));
HighToLowLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(High, animSpeed));
HighToLowLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Low, animSpeed));
OpenToCloseRectangle.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(Left, animSpeed));
OpenToCloseRectangle.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(Math.Min(Open, Close), animSpeed));
OpenToCloseRectangle.BeginAnimation(FrameworkElement.WidthProperty,
new DoubleAnimation(Width, animSpeed));
OpenToCloseRectangle.BeginAnimation(FrameworkElement.HeightProperty,
new DoubleAnimation(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 * .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,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 System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
namespace LiveCharts.Wpf.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(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.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(getX(), animSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(getY(), animSpeed));
}
Rectangle.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(Data.Left, animSpeed));
Rectangle.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(Data.Top, animSpeed));
Rectangle.BeginAnimation(FrameworkElement.WidthProperty,
new DoubleAnimation(Data.Width, animSpeed));
Rectangle.BeginAnimation(FrameworkElement.HeightProperty,
new DoubleAnimation(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();
copy.Opacity -= .15;
Rectangle.Fill = copy;
}
public override void OnHoverLeave(ChartPoint point)
{
if (Rectangle == null) return;
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 System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
namespace LiveCharts.Wpf.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.BeginAnimation(SolidColorBrush.ColorProperty,
new ColorAnimation(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,246 @@
//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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
namespace LiveCharts.Wpf.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);
ValidArea = new CoreRectangle(current.ChartLocation.X - 7.5, current.ChartLocation.Y - 7.5, 15, 15);
if (IsNew)
{
if (previosPbv != null && !previosPbv.IsNew)
{
Segment.Point1 = previosPbv.Segment.Point3;
Segment.Point2 = previosPbv.Segment.Point3;
Segment.Point3 = previosPbv.Segment.Point3;
if (Shape != null)
{
Canvas.SetTop(Shape, Canvas.GetTop(previosPbv.Shape));
Canvas.SetLeft(Shape, Canvas.GetLeft(previosPbv.Shape));
}
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, Canvas.GetTop(previosPbv.DataLabel));
Canvas.SetLeft(DataLabel, Canvas.GetLeft(previosPbv.DataLabel));
}
}
else
{
if (current.SeriesView.IsFirstDraw)
{
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 (Shape != null)
{
Canvas.SetTop(Shape, y);
Canvas.SetLeft(Shape, current.ChartLocation.X - Shape.Width*.5);
}
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X - DataLabel.ActualWidth * .5);
}
}
else
{
var startPoint = ((LineSeries)current.SeriesView).Splitters[0].Left.Point;
Segment.Point1 = startPoint;
Segment.Point2 = startPoint;
Segment.Point3 = startPoint;
if (Shape != null)
{
Canvas.SetTop(Shape, y);
Canvas.SetLeft(Shape, startPoint.X - Shape.Width * .5);
}
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, y);
Canvas.SetLeft(DataLabel, startPoint.X - DataLabel.ActualWidth * .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
Segment.BeginAnimation(BezierSegment.Point1Property,
new PointAnimation(Segment.Point1, Data.Point1.AsPoint(), chart.View.AnimationsSpeed));
Segment.BeginAnimation(BezierSegment.Point2Property,
new PointAnimation(Segment.Point2, Data.Point2.AsPoint(), chart.View.AnimationsSpeed));
Segment.BeginAnimation(BezierSegment.Point3Property,
new PointAnimation(Segment.Point3, Data.Point3.AsPoint(), chart.View.AnimationsSpeed));
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.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(current.ChartLocation.X - Shape.Width*.5, chart.View.AnimationsSpeed));
Shape.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(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.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(xl, chart.View.AnimationsSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(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.PointForeground
: (Brush) point.Fill;
lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness;
}
}
}

View File

@@ -0,0 +1,179 @@
//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 System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
namespace LiveCharts.Wpf.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 (DataLabel != null)
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y);
Canvas.SetLeft(DataLabel, current.ChartLocation.X);
}
}
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;
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.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(cx, animSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(cy, animSpeed));
}
HighToLowLine.BeginAnimation(Line.X1Property, new DoubleAnimation(center, animSpeed));
HighToLowLine.BeginAnimation(Line.X2Property, new DoubleAnimation(center, animSpeed));
OpenLine.BeginAnimation(Line.X1Property, new DoubleAnimation(Left, animSpeed));
OpenLine.BeginAnimation(Line.X2Property, new DoubleAnimation(center, animSpeed));
CloseLine.BeginAnimation(Line.X1Property, new DoubleAnimation(center, animSpeed));
CloseLine.BeginAnimation(Line.X2Property, new DoubleAnimation(Left + Width, animSpeed));
HighToLowLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(High, animSpeed));
HighToLowLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Low, animSpeed));
OpenLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(Open, animSpeed));
OpenLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Open, animSpeed));
CloseLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(Close, animSpeed));
CloseLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(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)
{
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,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 System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
namespace LiveCharts.Wpf.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)
{
Canvas.SetTop(Slice, chart.DrawMargin.Height/2);
Canvas.SetLeft(Slice, chart.DrawMargin.Width/2);
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;
Canvas.SetTop(hs, chart.DrawMargin.Height/2);
Canvas.SetLeft(hs, chart.DrawMargin.Width/2);
hs.WedgeAngle = Wedge;
hs.RotationAngle = Rotation;
hs.InnerRadius = InnerRadius;
hs.Radius = Radius;
}
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)
{
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.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(lx, animSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(ly, animSpeed));
}
Slice.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(chart.DrawMargin.Width / 2, animSpeed));
Slice.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(chart.DrawMargin.Height/2, animSpeed));
Slice.BeginAnimation(PieSlice.InnerRadiusProperty, new DoubleAnimation(InnerRadius, animSpeed));
Slice.BeginAnimation(PieSlice.RadiusProperty, new DoubleAnimation(Radius, animSpeed));
Slice.BeginAnimation(PieSlice.WedgeAngleProperty, new DoubleAnimation(Wedge, animSpeed));
Slice.BeginAnimation(PieSlice.RotationAngleProperty, new DoubleAnimation(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)
{
var copy = Slice.Fill.Clone();
copy.Opacity -= .15;
Slice.Fill = copy;
var pieChart = (PieChart) point.SeriesView.Model.Chart.View;
Slice.BeginAnimation(PieSlice.PushOutProperty,
new DoubleAnimation(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.BeginAnimation(PieSlice.PushOutProperty,
new DoubleAnimation(OriginalPushOut, point.SeriesView.Model.Chart.View.AnimationsSpeed));
}
}
}

View File

@@ -0,0 +1,266 @@
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace LiveCharts.Wpf.Points
{
//special thanks to Colin Eberhardt for the article.
//http://www.codeproject.com/Articles/28098/A-WPF-Pie-Chart-with-Data-Binding-Support
/// <summary>
///
/// </summary>
/// <seealso cref="System.Windows.Shapes.Shape" />
public class PieSlice : Shape
{
#region dependency properties
/// <summary>
/// The radius property
/// </summary>
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("RadiusProperty", typeof(double), typeof(PieSlice),
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("PushOutProperty", typeof(double), typeof(PieSlice),
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("InnerRadiusProperty", typeof(double), typeof(PieSlice),
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("WedgeAngleProperty", typeof(double), typeof(PieSlice),
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("RotationAngleProperty", typeof(double), typeof(PieSlice),
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 centre x property
/// </summary>
public static readonly DependencyProperty CentreXProperty =
DependencyProperty.Register("CentreXProperty", typeof(double), typeof(PieSlice),
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 CentreX
{
get { return (double)GetValue(CentreXProperty); }
set { SetValue(CentreXProperty, value); }
}
/// <summary>
/// The centre y property
/// </summary>
public static readonly DependencyProperty CentreYProperty =
DependencyProperty.Register("CentreYProperty", typeof(double), typeof(PieSlice),
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 CentreY
{
get { return (double)GetValue(CentreYProperty); }
set { SetValue(CentreYProperty, value); }
}
/// <summary>
/// The percentage property
/// </summary>
public static readonly DependencyProperty PercentageProperty =
DependencyProperty.Register("PercentageProperty", typeof(double), typeof(PieSlice),
new FrameworkPropertyMetadata(0.0));
/// <summary>
/// The percentage of a full pie that this piece occupies.
/// </summary>
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("PieceValueProperty", typeof(double), typeof(PieSlice),
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
/// <summary>
/// Gets a value that represents the <see cref="T:System.Windows.Media.Geometry" /> of the <see cref="T:System.Windows.Shapes.Shape" />.
/// </summary>
protected override Geometry DefiningGeometry
{
get
{
// Create a StreamGeometry for describing the shape
var geometry = new StreamGeometry { FillRule = FillRule.EvenOdd };
using (var context = geometry.Open())
{
DrawGeometry(context);
}
// Freeze the geometry for performance benefits
geometry.Freeze();
return geometry;
}
}
/// <summary>
/// Draws the pie piece
/// </summary>
private void DrawGeometry(StreamGeometryContext context)
{
var innerArcStartPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle, InnerRadius);
innerArcStartPoint.Offset(CentreX, CentreY);
var innerArcEndPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);
innerArcEndPoint.Offset(CentreX, CentreY);
var outerArcStartPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle, Radius);
outerArcStartPoint.Offset(CentreX, CentreY);
var outerArcEndPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);
outerArcEndPoint.Offset(CentreX, CentreY);
var innerArcMidPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle * .5, InnerRadius);
innerArcMidPoint.Offset(CentreX, CentreY);
var outerArcMidPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle * .5, Radius);
outerArcMidPoint.Offset(CentreX, CentreY);
var largeArc = WedgeAngle > 180.0d;
var requiresMidPoint = Math.Abs(WedgeAngle - 360) < .01;
if (PushOut > 0 && !requiresMidPoint)
{
var offset = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut);
innerArcStartPoint.Offset(offset.X, offset.Y);
innerArcEndPoint.Offset(offset.X, offset.Y);
outerArcStartPoint.Offset(offset.X, offset.Y);
outerArcEndPoint.Offset(offset.X, offset.Y);
}
var outerArcSize = new Size(Radius, Radius);
var innerArcSize = new Size(InnerRadius, InnerRadius);
if (requiresMidPoint)
{
context.BeginFigure(innerArcStartPoint, true, true);
context.LineTo(outerArcStartPoint, true, true);
context.ArcTo(outerArcMidPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true);
context.ArcTo(outerArcEndPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true);
context.LineTo(innerArcEndPoint, true, true);
context.ArcTo(innerArcMidPoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true);
context.ArcTo(innerArcStartPoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true);
return;
}
context.BeginFigure(innerArcStartPoint, true, true);
context.LineTo(outerArcStartPoint, true, true);
context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
context.LineTo(innerArcEndPoint, true, true);
context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
}
}
/// <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>
/// <returns></returns>
public static Point ComputeCartesianCoordinate(double angle, double radius)
{
// 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, y);
}
}
}

View File

@@ -0,0 +1,58 @@
//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 System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
namespace LiveCharts.Wpf.Points
{
internal class PointView : IChartPointView
{
public Shape HoverShape { get; set; }
public ContentControl DataLabel { get; set; }
public bool IsNew { get; set; }
public CoreRectangle ValidArea { get; internal set; }
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,196 @@
//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 System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
using LiveCharts.Dtos;
namespace LiveCharts.Wpf.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(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.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(getX(), animSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(getY(), animSpeed));
}
Rectangle.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(Data.Top, animSpeed));
Rectangle.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(Data.Left, animSpeed));
Rectangle.BeginAnimation(FrameworkElement.HeightProperty,
new DoubleAnimation(Data.Height, animSpeed));
Rectangle.BeginAnimation(FrameworkElement.WidthProperty,
new DoubleAnimation(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();
copy.Opacity -= .15;
Rectangle.Fill = copy;
}
public override void OnHoverLeave(ChartPoint point)
{
if (Rectangle == null) return;
if (point.Fill != null)
{
Rectangle.Fill = (Brush)point.Fill;
}
else
{
Rectangle.Fill = ((Series) point.SeriesView).Fill;
}
}
}
}

View File

@@ -0,0 +1,157 @@
//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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
namespace LiveCharts.Wpf.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.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(cx, animSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(cy, animSpeed));
}
Shape.BeginAnimation(FrameworkElement.WidthProperty,
new DoubleAnimation(Diameter, animSpeed));
Shape.BeginAnimation(FrameworkElement.HeightProperty,
new DoubleAnimation(Diameter, animSpeed));
Shape.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(current.ChartLocation.Y - Diameter*.5, animSpeed));
Shape.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(current.ChartLocation.X - 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();
copy.Opacity -= .15;
Shape.Fill = copy;
}
public override void OnHoverLeave(ChartPoint point)
{
if (Shape == null) return;
if (point.Fill != null)
{
Shape.Fill = (Brush) point.Fill;
}
else
{
Shape.Fill = ((Series) point.SeriesView).Fill;
}
}
}
}

View File

@@ -0,0 +1,249 @@
//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.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Points;
namespace LiveCharts.Wpf.Points
{
internal class StepLinePointView : PointView, IStepPointView
{
public double DeltaX { get; set; }
public double DeltaY { get; set; }
public Line Line1 { get; set; }
public Line Line2 { get; set; }
public Path Shape { get; set; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
{
var invertedMode = ((StepLineSeries) current.SeriesView).InvertedMode;
if (IsNew)
{
if (invertedMode)
{
Line1.X1 = current.ChartLocation.X;
Line1.X2 = current.ChartLocation.X - DeltaX;
Line1.Y1 = chart.DrawMargin.Height;
Line1.Y2 = chart.DrawMargin.Height;
Line2.X1 = current.ChartLocation.X - DeltaX;
Line2.X2 = current.ChartLocation.X - DeltaX;
Line2.Y1 = chart.DrawMargin.Height;
Line2.Y2 = chart.DrawMargin.Height;
}
else
{
Line1.X1 = current.ChartLocation.X;
Line1.X2 = current.ChartLocation.X;
Line1.Y1 = chart.DrawMargin.Height;
Line1.Y2 = chart.DrawMargin.Height;
Line2.X1 = current.ChartLocation.X - DeltaX;
Line2.X2 = current.ChartLocation.X;
Line2.Y1 = chart.DrawMargin.Height;
Line2.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)
{
if (invertedMode)
{
Line1.X1 = current.ChartLocation.X;
Line1.X2 = current.ChartLocation.X - DeltaX;
Line1.Y1 = current.ChartLocation.Y;
Line1.Y2 = current.ChartLocation.Y;
Line2.X1 = current.ChartLocation.X - DeltaX;
Line2.X2 = current.ChartLocation.X - DeltaX;
Line2.Y1 = current.ChartLocation.Y;
Line2.Y2 = current.ChartLocation.Y - DeltaY;
}
else
{
Line1.X1 = current.ChartLocation.X;
Line1.X2 = current.ChartLocation.X;
Line1.Y1 = current.ChartLocation.Y;
Line1.Y2 = current.ChartLocation.Y - DeltaY;
Line2.X1 = current.ChartLocation.X - DeltaX;
Line2.X2 = current.ChartLocation.X;
Line2.Y1 = current.ChartLocation.Y - DeltaY;
Line2.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;
if (invertedMode)
{
Line1.BeginAnimation(Line.X1Property,
new DoubleAnimation(current.ChartLocation.X, animSpeed));
Line1.BeginAnimation(Line.X2Property,
new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
Line1.BeginAnimation(Line.Y1Property,
new DoubleAnimation(current.ChartLocation.Y, animSpeed));
Line1.BeginAnimation(Line.Y2Property,
new DoubleAnimation(current.ChartLocation.Y, animSpeed));
Line2.BeginAnimation(Line.X1Property,
new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
Line2.BeginAnimation(Line.X2Property,
new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
Line2.BeginAnimation(Line.Y1Property,
new DoubleAnimation(current.ChartLocation.Y, animSpeed));
Line2.BeginAnimation(Line.Y2Property,
new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
}
else
{
Line1.BeginAnimation(Line.X1Property,
new DoubleAnimation(current.ChartLocation.X, animSpeed));
Line1.BeginAnimation(Line.X2Property,
new DoubleAnimation(current.ChartLocation.X, animSpeed));
Line1.BeginAnimation(Line.Y1Property,
new DoubleAnimation(current.ChartLocation.Y, animSpeed));
Line1.BeginAnimation(Line.Y2Property,
new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
Line2.BeginAnimation(Line.X1Property,
new DoubleAnimation(current.ChartLocation.X - DeltaX, animSpeed));
Line2.BeginAnimation(Line.X2Property,
new DoubleAnimation(current.ChartLocation.X, animSpeed));
Line2.BeginAnimation(Line.Y1Property,
new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
Line2.BeginAnimation(Line.Y2Property,
new DoubleAnimation(current.ChartLocation.Y - DeltaY, animSpeed));
}
if (Shape != null)
{
Shape.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(current.ChartLocation.X - Shape.Width/2, animSpeed));
Shape.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(current.ChartLocation.Y - Shape.Height/2, animSpeed));
}
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);
}
}
public override void RemoveFromView(ChartCore chart)
{
chart.View.RemoveFromDrawMargin(HoverShape);
chart.View.RemoveFromDrawMargin(Shape);
chart.View.RemoveFromDrawMargin(DataLabel);
chart.View.RemoveFromDrawMargin(Line1);
chart.View.RemoveFromDrawMargin(Line2);
}
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.PointForeground
: (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 == 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;
}
}
}

View File

@@ -0,0 +1,201 @@
//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.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using LiveCharts.Charts;
using LiveCharts.Dtos;
namespace LiveCharts.Wpf.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);
ValidArea = new CoreRectangle(current.ChartLocation.X - 7.5, current.ChartLocation.Y - 7.5, 15, 15);
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
{
if (current.SeriesView.IsFirstDraw)
{
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 (Shape != null)
{
Canvas.SetTop(Shape, current.ChartLocation.Y - Shape.Height * .5);
Canvas.SetLeft(Shape, 0);
}
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, current.ChartLocation.Y - DataLabel.ActualHeight * .5);
Canvas.SetLeft(DataLabel, 0);
}
}
else
{
var startPoint = ((LineSeries) current.SeriesView).Splitters[0].Left.Point;
Segment.Point1 = startPoint;
Segment.Point2 = startPoint;
Segment.Point3 = startPoint;
if (Shape != null)
{
Canvas.SetTop(Shape, startPoint.Y - Shape.Height * .5);
Canvas.SetLeft(Shape, startPoint.X);
}
if (DataLabel != null)
{
Canvas.SetTop(DataLabel, startPoint.Y - DataLabel.ActualHeight * .5);
Canvas.SetLeft(DataLabel, startPoint.X);
}
}
}
}
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
Segment.BeginAnimation(BezierSegment.Point1Property,
new PointAnimation(Segment.Point1, Data.Point1.AsPoint(), chart.View.AnimationsSpeed));
Segment.BeginAnimation(BezierSegment.Point2Property,
new PointAnimation(Segment.Point2, Data.Point2.AsPoint(), chart.View.AnimationsSpeed));
Segment.BeginAnimation(BezierSegment.Point3Property,
new PointAnimation(Segment.Point3, Data.Point3.AsPoint(), chart.View.AnimationsSpeed));
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.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(current.ChartLocation.X - Shape.Width * .5, chart.View.AnimationsSpeed));
Shape.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(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.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(xl, chart.View.AnimationsSpeed));
DataLabel.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(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 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.PointForeground
: (Brush) point.Fill;
lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness;
}
}
}