protected virtual Point GetTooltipPosition(ChartPoint senderPoint) { var xt = senderPoint.ChartLocation.X; var yt = senderPoint.ChartLocation.Y; xt = xt > DrawMargin.Width / 2 ? xt - DataTooltip.ActualWidth - 5 : xt + 5; yt = yt > DrawMargin.Height / 2 ? yt - DataTooltip.ActualHeight - 5 : yt + 5; return new Point(xt, yt); }
protected override CorePoint GetStackedPoint(ChartPoint chartPoint) { if (_stackModelable.StackMode == StackMode.Values) return new CorePoint( ChartFunctions.ToDrawMargin(chartPoint.To, AxisOrientation.X, Chart, View.ScalesXAt), ChartFunctions.ToDrawMargin(chartPoint.Y, AxisOrientation.Y, Chart, View.ScalesYAt)); return new CorePoint( ChartFunctions.ToDrawMargin(chartPoint.StackedParticipation, AxisOrientation.X, Chart, View.ScalesXAt), ChartFunctions.ToDrawMargin(chartPoint.Y, AxisOrientation.Y, Chart, View.ScalesYAt)); }
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 void CreateRandomChart() { var random = new Random(); var minX = random.Next(-10, -5); var maxX = random.Next(5, 10); var minY = random.Next(-10, -5); var maxY = random.Next(5, 10); var count = random.Next(10, 20); var step = (maxX - minX)/(double) count; var points = new List<ChartPoint>(); for (var i = 0; i < count; i++) { var x = minX + step*i; var y = random.NextDouble()*(maxY - minY) + minY; var point = new ChartPoint(x, y); points.Add(point); } ChartDataList.Add(new ChartData(points)); }
public static List<ChartPoint> LoadFromFile(string path) { var points = new List<ChartPoint>(); using (var reader = new StreamReader(path)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); if (line != null) { var values = line.Split(' '); var valueX = Convert.ToDouble(values[0], CultureInfo.InvariantCulture); var valueY = Convert.ToDouble(values[1], CultureInfo.InvariantCulture); var point = new ChartPoint(valueX, valueY); points.Add(point); } } } return points; }
/// <summary> /// Gets the point view. /// </summary> /// <param name="point">The point.</param> /// <param name="label">The label.</param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (OhlcPointView)point.View; if (pbv == null) { pbv = new OhlcPointView { IsNew = true, HighToLowLine = new Line(), OpenLine = new Line(), CloseLine = new Line() }; Model.Chart.View.AddToDrawMargin(pbv.HighToLowLine); Model.Chart.View.AddToDrawMargin(pbv.OpenLine); Model.Chart.View.AddToDrawMargin(pbv.CloseLine); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HighToLowLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.OpenLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.CloseLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.HighToLowLine.StrokeThickness = StrokeThickness; pbv.CloseLine.StrokeThickness = StrokeThickness; pbv.OpenLine.StrokeThickness = StrokeThickness; pbv.HighToLowLine.StrokeDashArray = StrokeDashArray; pbv.CloseLine.StrokeDashArray = StrokeDashArray; pbv.OpenLine.StrokeDashArray = StrokeDashArray; pbv.HighToLowLine.Visibility = Visibility; pbv.CloseLine.Visibility = Visibility; pbv.OpenLine.Visibility = Visibility; var i = Panel.GetZIndex(this); Panel.SetZIndex(pbv.HighToLowLine, i); Panel.SetZIndex(pbv.CloseLine, i); Panel.SetZIndex(pbv.OpenLine, i); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0 }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels) { pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel { FormattedText = label, Point = point }, pbv.DataLabel); } if (!DataLabels && pbv.DataLabel != null) { Model.Chart.View.RemoveFromDrawMargin(pbv.DataLabel); pbv.DataLabel = null; } if (point.Open < point.Close) { pbv.HighToLowLine.Stroke = IncreaseBrush; pbv.CloseLine.Stroke = IncreaseBrush; pbv.OpenLine.Stroke = IncreaseBrush; } else { pbv.HighToLowLine.Stroke = DecreaseBrush; pbv.CloseLine.Stroke = DecreaseBrush; pbv.OpenLine.Stroke = DecreaseBrush; } return(pbv); }
public override void OnHover(ChartPoint point) { Rectangle.StrokeThickness++; }
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) { 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.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 OnHover(ChartPoint point) { var lineSeries = (LineSeries)point.SeriesView; if (Shape != null) Shape.Fill = Shape.Stroke; lineSeries.Path.StrokeThickness = lineSeries.StrokeThickness + 1; }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="view"></param> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public virtual IChartPointView GetPointView(IChartPointView view, ChartPoint point, string label) { throw new NotImplementedException(); }
private void AddToCanvas(VisualHelper visual, ChartPoint point) { Chart.ShapesMapper.Add(new ShapeMap { Series = this, HoverShape = visual.HoverShape, Shape = visual.PointShape, ChartPoint = point }); Chart.DrawMargin.Children.Add(visual.PointShape); Chart.DrawMargin.Children.Add(visual.HoverShape); Shapes.Add(visual.PointShape); Shapes.Add(visual.HoverShape); Panel.SetZIndex(visual.HoverShape, int.MaxValue); Panel.SetZIndex(visual.PointShape, int.MaxValue - 2); visual.HoverShape.MouseDown += Chart.DataMouseDown; visual.HoverShape.MouseEnter += Chart.DataMouseEnter; visual.HoverShape.MouseLeave += Chart.DataMouseLeave; }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (OhlcPointView) point.View; if (pbv == null) { pbv = new OhlcPointView { IsNew = true, HighToLowLine = new Line(), OpenLine = new Line(), CloseLine = new Line() }; Model.Chart.View.AddToDrawMargin(pbv.HighToLowLine); Model.Chart.View.AddToDrawMargin(pbv.OpenLine); Model.Chart.View.AddToDrawMargin(pbv.CloseLine); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HighToLowLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.OpenLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.CloseLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.HighToLowLine.StrokeThickness = StrokeThickness; pbv.CloseLine.StrokeThickness = StrokeThickness; pbv.OpenLine.StrokeThickness = StrokeThickness; pbv.HighToLowLine.StrokeDashArray = StrokeDashArray; pbv.CloseLine.StrokeDashArray = StrokeDashArray; pbv.OpenLine.StrokeDashArray = StrokeDashArray; pbv.HighToLowLine.Visibility = Visibility; pbv.CloseLine.Visibility = Visibility; pbv.OpenLine.Visibility = Visibility; var i = Canvas.GetZIndex(this); Canvas.SetZIndex(pbv.HighToLowLine, i); Canvas.SetZIndex(pbv.CloseLine, i); Canvas.SetZIndex(pbv.OpenLine, i); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) pbv.HoverShape.Visibility = Visibility; if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) pbv.DataLabel.Text = label; if (point.Open < point.Close) { pbv.HighToLowLine.Stroke = IncreaseBrush; pbv.CloseLine.Stroke = IncreaseBrush; pbv.OpenLine.Stroke = IncreaseBrush; } else { pbv.HighToLowLine.Stroke = DecreaseBrush; pbv.CloseLine.Stroke = DecreaseBrush; pbv.OpenLine.Stroke = DecreaseBrush; } return pbv; }
private void companyGraph_DataClick(object sender, ChartPoint chartPoint) { }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (StepLinePointView)point.View; if (pbv == null) { pbv = new StepLinePointView { IsNew = true, HorizontalLine = new Line(), VerticalLine = new Line() }; Model.Chart.View.AddToDrawMargin(pbv.HorizontalLine); Model.Chart.View.AddToDrawMargin(pbv.VerticalLine); Model.Chart.View.AddToDrawMargin(pbv.Shape); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Shape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HorizontalLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.VerticalLine); } pbv.VerticalLine.StrokeThickness = StrokeThickness; pbv.VerticalLine.Stroke = AlternativeStroke; pbv.VerticalLine.StrokeDashArray = StrokeDashArray; pbv.VerticalLine.Visibility = Visibility; Canvas.SetZIndex(pbv.VerticalLine, Canvas.GetZIndex(this)); pbv.HorizontalLine.StrokeThickness = StrokeThickness; pbv.HorizontalLine.Stroke = Stroke; pbv.HorizontalLine.StrokeDashArray = StrokeDashArray; pbv.HorizontalLine.Visibility = Visibility; Canvas.SetZIndex(pbv.HorizontalLine, Canvas.GetZIndex(this)); if (Math.Abs(PointGeometrySize) > 0.1 && pbv.Shape == null) { pbv.Shape = new Path { Stretch = Stretch.Fill, StrokeThickness = StrokeThickness }; Model.Chart.View.AddToDrawMargin(pbv.Shape); } if (pbv.Shape != null) { pbv.Shape.Fill = PointForeround; pbv.Shape.StrokeThickness = StrokeThickness; pbv.Shape.Stroke = Stroke; pbv.Shape.StrokeDashArray = StrokeDashArray; pbv.Shape.Visibility = Visibility; pbv.Shape.Width = PointGeometrySize; pbv.Shape.Height = PointGeometrySize; pbv.Shape.Data = PointGeometry.Parse(); Canvas.SetZIndex(pbv.Shape, Canvas.GetZIndex(this) + 1); if (point.Stroke != null) { pbv.Shape.Stroke = (Brush)point.Stroke; } if (point.Fill != null) { pbv.Shape.Fill = (Brush)point.Fill; } } if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Windows.UI.Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } return(pbv); }
public override IChartPointView GetPointView(IChartPointView view, ChartPoint point, string label) { var mhr = PointGeometrySize < 10 ? 10 : PointGeometrySize; var pbv = (HBezierPointView)view; if (pbv == null) { pbv = new HBezierPointView { Segment = new BezierSegment(), Container = Figure, IsNew = true }; } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Shape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0, Width = mhr, Height = mhr }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); BindingOperations.SetBinding(pbv.HoverShape, VisibilityProperty, new Binding { Path = new PropertyPath(VisibilityProperty), Source = this }); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (PointGeometry != null && Math.Abs(PointGeometrySize) > 0.1 && pbv.Shape == null) { if (PointGeometry != null) { pbv.Shape = new Path { Stretch = Stretch.Fill, ClipToBounds = true, StrokeThickness = StrokeThickness }; BindingOperations.SetBinding(pbv.Shape, Path.DataProperty, new Binding { Path = new PropertyPath(PointGeometryProperty), Source = this }); } else { pbv.Shape = new Ellipse(); } BindingOperations.SetBinding(pbv.Shape, Shape.FillProperty, new Binding { Path = new PropertyPath(PointForeroundProperty), Source = this }); BindingOperations.SetBinding(pbv.Shape, Shape.StrokeProperty, new Binding { Path = new PropertyPath(StrokeProperty), Source = this }); BindingOperations.SetBinding(pbv.Shape, Shape.StrokeThicknessProperty, new Binding { Path = new PropertyPath(StrokeThicknessProperty), Source = this }); BindingOperations.SetBinding(pbv.Shape, WidthProperty, new Binding { Path = new PropertyPath(PointGeometrySizeProperty), Source = this }); BindingOperations.SetBinding(pbv.Shape, HeightProperty, new Binding { Path = new PropertyPath(PointGeometrySizeProperty), Source = this }); BindingOperations.SetBinding(pbv.Shape, VisibilityProperty, new Binding { Path = new PropertyPath(VisibilityProperty), Source = this }); Panel.SetZIndex(pbv.Shape, int.MaxValue - 2); Model.Chart.View.AddToDrawMargin(pbv.Shape); } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Panel.SetZIndex(pbv.DataLabel, int.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } return(pbv); }
public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (OhlcPointView)point.View; if (pbv == null) { pbv = new OhlcPointView { IsNew = true, HighToLowLine = new Line(), OpenLine = new Line(), CloseLine = new Line() }; Model.Chart.View.AddToDrawMargin(pbv.HighToLowLine); Model.Chart.View.AddToDrawMargin(pbv.OpenLine); Model.Chart.View.AddToDrawMargin(pbv.CloseLine); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HighToLowLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.OpenLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.CloseLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.HighToLowLine.StrokeThickness = StrokeThickness; pbv.CloseLine.StrokeThickness = StrokeThickness; pbv.OpenLine.StrokeThickness = StrokeThickness; pbv.HighToLowLine.StrokeDashArray = StrokeDashArray; pbv.CloseLine.StrokeDashArray = StrokeDashArray; pbv.OpenLine.StrokeDashArray = StrokeDashArray; pbv.HighToLowLine.Visibility = Visibility; pbv.CloseLine.Visibility = Visibility; pbv.OpenLine.Visibility = Visibility; var i = Canvas.GetZIndex(this); Canvas.SetZIndex(pbv.HighToLowLine, i); Canvas.SetZIndex(pbv.CloseLine, i); Canvas.SetZIndex(pbv.OpenLine, i); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } if (point.Open < point.Close) { pbv.HighToLowLine.Stroke = IncreaseBrush; pbv.CloseLine.Stroke = IncreaseBrush; pbv.OpenLine.Stroke = IncreaseBrush; } else { pbv.HighToLowLine.Stroke = DecreaseBrush; pbv.CloseLine.Stroke = DecreaseBrush; pbv.OpenLine.Stroke = DecreaseBrush; } return(pbv); }
/// <summary> /// Initializes a new instance of the <see cref="BezierData"/> class. /// </summary> /// <param name="chartPoint">The chart point.</param> public BezierData(ChartPoint chartPoint) { TargetPoint = chartPoint; }
/// <summary> /// Updates this instance. /// </summary> public override void Update() { var points = View.ActualValues.GetPoints(View).ToArray(); var segmentPosition = 0; var lineView = (ILineSeriesView)View; var smoothness = lineView.LineSmoothness; smoothness = smoothness > 1 ? 1 : smoothness < 0 ? 0 : smoothness; foreach (var segment in points.SplitEachNaN()) { var p0 = segment.Count > 0 ? ChartFunctions.ToDrawMargin(segment[0], View.ScalesXAt, View.ScalesYAt, Chart) : new CorePoint(0, 0); var p1 = segment.Count > 0 ? ChartFunctions.ToDrawMargin(segment[0], View.ScalesXAt, View.ScalesYAt, Chart) : p0; var p2 = segment.Count > 1 ? ChartFunctions.ToDrawMargin(segment[1], View.ScalesXAt, View.ScalesYAt, Chart) : p1; var p3 = segment.Count > 2 ? ChartFunctions.ToDrawMargin(segment[2], View.ScalesXAt, View.ScalesYAt, Chart) : p2; var uw = new CorePoint( CurrentXAxis.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(AxisOrientation.X, Chart, View.ScalesXAt) / 2 : 0, CurrentYAxis.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(AxisOrientation.Y, Chart, View.ScalesYAt) / 2 : 0); if (SeriesOrientation == SeriesOrientation.Horizontal) { p0 += uw; p1 += uw; p2 += uw; p3 += uw; } else { p0 = new CorePoint(p0.X + uw.X, p0.Y - uw.Y); p1 = new CorePoint(p1.X + uw.X, p1.Y - uw.Y); p2 = new CorePoint(p2.X + uw.X, p2.Y - uw.Y); p3 = new CorePoint(p3.X + uw.X, p3.Y - uw.Y); } ChartPoint previousDrawn = null; var isOpen = false; for (var index = 0; index < segment.Count; index++) { if (!isOpen) { lineView.StartSegment(segmentPosition, p1); segmentPosition += segmentPosition == 0 ? 1 : 2; } var chartPoint = segment[index]; chartPoint.ChartLocation = p1; chartPoint.SeriesView = View; var xc1 = (p0.X + p1.X) / 2.0; var yc1 = (p0.Y + p1.Y) / 2.0; var xc2 = (p1.X + p2.X) / 2.0; var yc2 = (p1.Y + p2.Y) / 2.0; var xc3 = (p2.X + p3.X) / 2.0; var yc3 = (p2.Y + p3.Y) / 2.0; var len1 = Math.Sqrt((p1.X - p0.X) * (p1.X - p0.X) + (p1.Y - p0.Y) * (p1.Y - p0.Y)); var len2 = Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y)); var len3 = Math.Sqrt((p3.X - p2.X) * (p3.X - p2.X) + (p3.Y - p2.Y) * (p3.Y - p2.Y)); var k1 = len1 / (len1 + len2); var k2 = len2 / (len2 + len3); if (double.IsNaN(k1)) { k1 = 0d; } if (double.IsNaN(k2)) { k2 = 0d; } var xm1 = xc1 + (xc2 - xc1) * k1; var ym1 = yc1 + (yc2 - yc1) * k1; var xm2 = xc2 + (xc3 - xc2) * k2; var ym2 = yc2 + (yc3 - yc2) * k2; var c1X = xm1 + (xc2 - xm1) * smoothness + p1.X - xm1; var c1Y = ym1 + (yc2 - ym1) * smoothness + p1.Y - ym1; var c2X = xm2 + (xc2 - xm2) * smoothness + p2.X - xm2; var c2Y = ym2 + (yc2 - ym2) * smoothness + p2.Y - ym2; chartPoint.View = View.GetPointView(chartPoint, View.DataLabels ? View.GetLabelPointFormatter()(chartPoint) : null); var bezierView = chartPoint.View as IBezierPointView; if (bezierView == null) { continue; } bezierView.Data = index == segment.Count - 1 ? new BezierData(new CorePoint(p1.X, p1.Y)) : new BezierData { Point1 = index == 0 ? new CorePoint(p1.X, p1.Y) : new CorePoint(c1X, c1Y), Point2 = new CorePoint(c2X, c2Y), Point3 = new CorePoint(p2.X, p2.Y) }; chartPoint.View.DrawOrMove(previousDrawn, chartPoint, segmentPosition, Chart); segmentPosition++; previousDrawn = chartPoint.View.IsNew ? previousDrawn : chartPoint; p0 = new CorePoint(p1); p1 = new CorePoint(p2); p2 = new CorePoint(p3); p3 = segment.Count > index + 3 ? ChartFunctions.ToDrawMargin(segment[index + 3], View.ScalesXAt, View.ScalesYAt, Chart) : p2; if (SeriesOrientation == SeriesOrientation.Horizontal) { p3 += uw; } else { p3 = new CorePoint(p3.X + uw.X, p3.Y - uw.Y); } isOpen = true; } if (!isOpen) { continue; } lineView.EndSegment(segmentPosition, p1); segmentPosition++; } }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (ColumnPointView)point.View; if (pbv == null) { pbv = new ColumnPointView { IsNew = true, Rectangle = new Rectangle(), Data = new CoreRectangle() }; Model.Chart.View.AddToDrawMargin(pbv.Rectangle); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.Rectangle.Fill = Fill; pbv.Rectangle.StrokeThickness = StrokeThickness; pbv.Rectangle.Stroke = Stroke; pbv.Rectangle.StrokeDashArray = StrokeDashArray; pbv.Rectangle.Visibility = Visibility; var zIndex = Canvas.GetZIndex(this); Canvas.SetZIndex(pbv.Rectangle, zIndex); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Windows.UI.Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels) { pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel { FormattedText = label, Instance = point.Instance }, pbv.DataLabel); } if (point.Stroke != null) { pbv.Rectangle.Stroke = (Brush)point.Stroke; } if (point.Fill != null) { pbv.Rectangle.Fill = (Brush)point.Fill; } pbv.LabelPosition = LabelsPosition; return(pbv); }
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 (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)); }
private void CartesianChart1OnDataClick(object sender, ChartPoint chartPoint) { MessageBox.Show("You clicked (" + chartPoint.X + "," + chartPoint.Y + ")", "Short and Excess", MessageBoxButtons.OK, MessageBoxIcon.Information); }
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) { 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 IChartPointView GetPointView(IChartPointView view, ChartPoint point, string label) { var pbv = (view as RowPointView); if (pbv == null) { pbv = new RowPointView { IsNew = true, Rectangle = new Rectangle(), Data = new CoreRectangle(), LabelPosition = BarLabelPosition.Merged }; BindingOperations.SetBinding(pbv.Rectangle, Shape.FillProperty, new Binding { Path = new PropertyPath(FillProperty), Source = this }); BindingOperations.SetBinding(pbv.Rectangle, Shape.StrokeProperty, new Binding { Path = new PropertyPath(StrokeProperty), Source = this }); BindingOperations.SetBinding(pbv.Rectangle, Shape.StrokeThicknessProperty, new Binding { Path = new PropertyPath(StrokeThicknessProperty), Source = this }); BindingOperations.SetBinding(pbv.Rectangle, Shape.StrokeDashArrayProperty, new Binding { Path = new PropertyPath(StrokeDashArrayProperty), Source = this }); BindingOperations.SetBinding(pbv.Rectangle, Panel.ZIndexProperty, new Binding { Path = new PropertyPath(Panel.ZIndexProperty), Source = this }); BindingOperations.SetBinding(pbv.Rectangle, VisibilityProperty, new Binding { Path = new PropertyPath(VisibilityProperty), Source = this }); Model.Chart.View.AddToDrawMargin(pbv.Rectangle); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0 }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); BindingOperations.SetBinding(pbv.HoverShape, VisibilityProperty, new Binding { Path = new PropertyPath(VisibilityProperty), Source = this }); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Panel.SetZIndex(pbv.DataLabel, int.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } return(pbv); }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public virtual IChartPointView GetPointView(ChartPoint point, string label) { throw new NotImplementedException(); }
private void Chart_OnDataClick(object sender, ChartPoint chartpoint) { _columnController.UpdateValues(); }
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; } }
public override void OnHoverLeave(ChartPoint point) { BindingOperations.SetBinding(Rectangle, Shape.FillProperty, new Binding { Path = new PropertyPath(Series.Series.FillProperty), Source = ((Series.Series)point.SeriesView) }); }
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 (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); } } } #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); } }
private VisualHelper GetVisual(ChartPoint point) { var map = _isPrimitive ? Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) && x.ChartPoint.Key == point.Key) : Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) && x.ChartPoint.Instance == point.Instance); var pChart = Chart as PieChart; if (pChart == null) throw new InvalidCastException("Unexpected error converting chart to pie chart."); if (map == null) { var newSlice = new PieSlice { Fill = Brushes != null && Brushes.Length > point.X ? Brushes[(int) point.X] : new SolidColorBrush(GetColorByIndex((int) point.X)), Stroke = Stroke, StrokeThickness = pChart.SlicePadding, CentreX = 0, CentreY = 0, InnerRadius = pChart.InnerRadius }; return new VisualHelper { HoverShape = newSlice, PointShape = newSlice, IsNew = true }; } return new VisualHelper { PointShape = (PieSlice) map.Shape, HoverShape = (PieSlice) map.HoverShape, IsNew = false }; }
private void CartesianChart1OnDataClick(object sender, ChartPoint chartPoint) { MessageBox.Show("You clicked (" + chartPoint.X + "," + chartPoint.Y + ")"); }
private void Chart_OnDataClick(ChartPoint point) { //point.Instance contains the model var salesData = point.Instance as SalesData; MessageBox.Show("You clicked on (" + point.X + ", " + point.Y); }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (ScatterPointView)point.View; if (pbv == null) { pbv = new ScatterPointView { IsNew = true, Shape = new Path { Stretch = Stretch.Fill, StrokeThickness = StrokeThickness } }; Model.Chart.View.AddToDrawMargin(pbv.Shape); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Shape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } var p = (Path)pbv.Shape; p.Data = PointGeometry.Parse(); p.Fill = Fill; p.Stroke = Stroke; p.StrokeThickness = StrokeThickness; p.Visibility = Visibility; Canvas.SetZIndex(p, Canvas.GetZIndex(this)); p.StrokeDashArray = StrokeDashArray; if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Windows.UI.Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels) { pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel { FormattedText = label, Instance = point.Instance }, pbv.DataLabel); } if (point.Stroke != null) { pbv.Shape.Stroke = (Brush)point.Stroke; } if (point.Fill != null) { pbv.Shape.Fill = (Brush)point.Fill; } return(pbv); }
private VisualHelper GetVisual(ChartPoint point) { var map = _isPrimitive ? Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) && x.ChartPoint.Key == point.Key) : Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) && x.ChartPoint.Instance == point.Instance); if (map == null) { var r = new Rectangle { RenderTransform = new TranslateTransform() }; var hs = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0 }; BindingOperations.SetBinding(r, Shape.StrokeProperty, new Binding { Path = new PropertyPath("Stroke"), Source = this }); BindingOperations.SetBinding(r, Shape.FillProperty, new Binding { Path = new PropertyPath("Fill"), Source = this }); BindingOperations.SetBinding(r, Shape.StrokeThicknessProperty, new Binding { Path = new PropertyPath("StrokeThickness"), Source = this }); BindingOperations.SetBinding(r, VisibilityProperty, new Binding { Path = new PropertyPath("Visibility"), Source = this }); BindingOperations.SetBinding(hs, VisibilityProperty, new Binding { Path = new PropertyPath("Visibility"), Source = this }); return new VisualHelper { PointShape = r, HoverShape = hs, IsNew = true }; } map.ChartPoint.X = point.X; map.ChartPoint.Y = point.Y; return new VisualHelper { PointShape = map.Shape, HoverShape = map.HoverShape, IsNew = false }; }
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); } }
/// <summary> /// Gets the point view. /// </summary> /// <param name="point">The point.</param> /// <param name="label">The label.</param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var mhr = PointGeometrySize < 10 ? 10 : PointGeometrySize; var pbv = (VerticalBezierPointView)point.View; if (pbv == null) { pbv = new VerticalBezierPointView { Segment = new BezierSegment(), Container = Figure, IsNew = true }; } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Shape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Windows.UI.Colors.Transparent), StrokeThickness = 0, Width = mhr, Height = mhr }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (Math.Abs(PointGeometrySize) > 0.1 && pbv.Shape == null) { pbv.Shape = new Path { Stretch = Stretch.Fill, StrokeThickness = StrokeThickness }; Model.Chart.View.AddToDrawMargin(pbv.Shape); } if (pbv.Shape != null) { pbv.Shape.Fill = PointForeround; pbv.Shape.Stroke = Stroke; pbv.Shape.StrokeThickness = StrokeThickness; pbv.Shape.Width = PointGeometrySize; pbv.Shape.Height = PointGeometrySize; pbv.Shape.Data = PointGeometry.Parse(); pbv.Shape.Visibility = Visibility; Canvas.SetZIndex(pbv.Shape, Canvas.GetZIndex(this) + 1); if (point.Stroke != null) { pbv.Shape.Stroke = (Brush)point.Stroke; } if (point.Fill != null) { pbv.Shape.Fill = (Brush)point.Fill; } } if (DataLabels) { pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel { FormattedText = label, Instance = point.Instance }, pbv.DataLabel); } return(pbv); }
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) { Canvas.SetTop(DataLabel, Data.Top); Canvas.SetLeft(DataLabel, ZeroReference); } } Func<double> getY = () => { 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; if (LabelInside) { r = Data.Left + Data.Width/2 - DataLabel.ActualWidth/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)); } Canvas.SetTop(Rectangle, Data.Top); Rectangle.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(Data.Left, animSpeed)); Rectangle.Height = Data.Height; 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; } }
/// <summary> /// Generates the datas. /// </summary> override public void GenerateDatas() { LowPoints.Clear(); HighPoints.Clear(); if (!IsPointsGenerated) { Parts.Clear(); } if (Points != null && SeriesContainer != null) { CalculateMinAndMax(); ChartPoint oldPoint = new ChartPoint { XValue = double.MinValue, YValue = double.MinValue }; IntializePoints(); int index = 0; foreach (ChartPoint point in Points) { if (CheckValuePoint(oldPoint, point)) { Point highPoint = NormalizePoint(new Point(point.XValue, point.YValue)); Point lowPoint = NormalizePoint(new Point(lowPoints[index].XValue, lowPoints[index].YValue)); HighPoints.Add(highPoint); LowPoints.Add(lowPoint); oldPoint = point; } index++; } if (RenderingMode == RenderingMode.Default) { if (!IsPointsGenerated) { for (int i = 0; i < HighPoints.Count; i++) { LinePart linePart = new LinePart(HighPoints[i], LowPoints[i]); SetBindingForStrokeandStrokeThickness(linePart); Parts.Add(linePart); } IsPointsGenerated = true; } else { int i = 0; foreach (LinePart part in Parts) { part.X1 = HighPoints[i].X; part.Y1 = HighPoints[i].Y; part.X2 = LowPoints[i].X; part.Y2 = LowPoints[i].Y; part.Refresh(); i++; } } } } else { Parts.Clear(); } if (this.SeriesContainer != null) { this.SeriesContainer.Invalidate(); } IsRefreshed = false; }
internal BurndownPoint(ChartPoint expected, ChartPoint real) { }
protected static double Pull(ChartPoint point, AxisTags source) { return(source == AxisTags.Y ? point.Y : point.X); }
internal void OnDataClick(object sender, ChartPoint point) { DataClick?.Invoke(sender, point); }
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) { Canvas.SetTop(DataLabel, ZeroReference); Canvas.SetLeft(DataLabel, current.ChartLocation.X); } } Func <double> getY = () => { double y; if (LabelInside) { if (RotateTransform == null) { RotateTransform = new RotateTransform(270); } DataLabel.RenderTransform = RotateTransform; y = Data.Top + Data.Height / 2 + DataLabel.ActualWidth * .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; if (LabelInside) { x = Data.Left + Data.Width / 2 - DataLabel.ActualHeight / 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)); } Canvas.SetLeft(Rectangle, Data.Left); Rectangle.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(Data.Top, animSpeed)); Rectangle.Width = Data.Width; 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; } }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (ScatterPointView) point.View; if (pbv == null) { pbv = new ScatterPointView { IsNew = true, Shape = new Path { Stretch = Stretch.Fill, StrokeThickness = StrokeThickness } }; Model.Chart.View.AddToDrawMargin(pbv.Shape); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Shape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } var p = (Path) pbv.Shape; p.Data = PointGeometry.Parse(); p.Fill = Fill; p.Stroke = Stroke; p.StrokeThickness = StrokeThickness; p.Visibility = Visibility; Canvas.SetZIndex(p, Canvas.GetZIndex(this)); p.StrokeDashArray = StrokeDashArray; if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Windows.UI.Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) pbv.HoverShape.Visibility = Visibility; if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) pbv.DataLabel.Text = label; if (point.Stroke != null) pbv.Shape.Stroke = (Brush)point.Stroke; if (point.Fill != null) pbv.Shape.Fill = (Brush)point.Fill; return pbv; }
public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart) { if (IsNew) { Canvas.SetTop(Ellipse, current.ChartLocation.Y); Canvas.SetLeft(Ellipse, current.ChartLocation.X); Ellipse.Width = 0; Ellipse.Height = 0; if (DataLabel != null) { 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) { Ellipse.Width = Diameter; Ellipse.Height = Diameter; Canvas.SetTop(Ellipse, current.ChartLocation.Y - Ellipse.Width * .5); Canvas.SetLeft(Ellipse, current.ChartLocation.X - Ellipse.Height * .5); if (DataLabel != null) { DataLabel.UpdateLayout(); var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualHeight * .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)); } Ellipse.BeginAnimation(FrameworkElement.WidthProperty, new DoubleAnimation(Diameter, animSpeed)); Ellipse.BeginAnimation(FrameworkElement.HeightProperty, new DoubleAnimation(Diameter, animSpeed)); Ellipse.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(current.ChartLocation.Y - Diameter * .5, animSpeed)); Ellipse.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(current.ChartLocation.X - Diameter * .5, animSpeed)); }
public override void OnHover(ChartPoint point) { var copy = Rectangle.Fill.Clone(); copy.Opacity -= .15; Rectangle.Fill = copy; }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (PiePointView)point.View; if (pbv == null) { pbv = new PiePointView { IsNew = true, Slice = new PieSlice() }; Model.Chart.View.AddToDrawMargin(pbv.Slice); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Slice); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.Slice.Fill = Fill; pbv.Slice.Stroke = Stroke; pbv.Slice.StrokeThickness = StrokeThickness; pbv.Slice.StrokeDashArray = StrokeDashArray; pbv.Slice.PushOut = PushOut; pbv.Slice.Visibility = Visibility; Canvas.SetZIndex(pbv.Slice, Canvas.GetZIndex(this)); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new PieSlice { Fill = new SolidColorBrush(Windows.UI.Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } pbv.OriginalPushOut = PushOut; return(pbv); }
private void Label(ChartPoint point, Func<double, string> f, Point pointLocation) { var tb = BuildATextBlock(0); var te = f(Chart.Invert ? point.X : point.Y); var ft = new FormattedText(te, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize, Brushes.Black); tb.Text = te; var length = pointLocation.X - ft.Width * .5; length = length < 0 ? 0 : (length + ft.Width > Chart.DrawMargin.Width ? Chart.DrawMargin.Width - ft.Width : length); var tp = pointLocation.Y - ft.Height - 5; tp = tp < 0 ? 0 : tp; tb.Text = te; tb.Visibility = Visibility.Hidden; Chart.Canvas.Children.Add(tb); Chart.Shapes.Add(tb); Canvas.SetLeft(tb, length + Canvas.GetLeft(Chart.DrawMargin)); Canvas.SetTop(tb, tp + Canvas.GetTop(Chart.DrawMargin)); Panel.SetZIndex(tb, int.MaxValue - 1); if (!Chart.DisableAnimation) { var t = new DispatcherTimer { Interval = AnimSpeed }; t.Tick += (sender, args) => { tb.Visibility = Visibility.Visible; var fadeIn = new DoubleAnimation(0, 1, AnimSpeed); tb.BeginAnimation(OpacityProperty, fadeIn); t.Stop(); }; t.Start(); } else { tb.Visibility = Visibility.Visible; } }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (RowPointView)point.View; if (pbv == null) { pbv = new RowPointView { IsNew = true, Rectangle = new Rectangle(), Data = new CoreRectangle() }; Model.Chart.View.AddToDrawMargin(pbv.Rectangle); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.Rectangle.Fill = Fill; pbv.Rectangle.StrokeThickness = StrokeThickness; pbv.Rectangle.Stroke = Stroke; pbv.Rectangle.StrokeDashArray = StrokeDashArray; pbv.Rectangle.Visibility = Visibility; Panel.SetZIndex(pbv.Rectangle, Panel.GetZIndex(this)); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0 }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels) { pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel { FormattedText = label, Point = point }, pbv.DataLabel); } if (!DataLabels && pbv.DataLabel != null) { Model.Chart.View.RemoveFromDrawMargin(pbv.DataLabel); pbv.DataLabel = null; } pbv.LabelPosition = LabelsPosition; return(pbv); }
private VisualHelper GetVisual(ChartPoint point) { var map = _isPrimitive ? Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) && x.ChartPoint.Key == point.Key) : Chart.ShapesMapper.FirstOrDefault(x => x.Series.Equals(this) && x.ChartPoint.Instance == point.Instance); if (map == null) { var e = new Ellipse { Width = PointRadius*2, Height = PointRadius*2, Stroke = new SolidColorBrush {Color = Chart.PointHoverColor}, StrokeThickness = 1 }; var hs = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0 }; BindingOperations.SetBinding(e, Shape.FillProperty, new Binding { Path = new PropertyPath("Fill"), Source = this }); BindingOperations.SetBinding(e, VisibilityProperty, new Binding { Path = new PropertyPath("Visibility"), Source = this }); BindingOperations.SetBinding(hs, VisibilityProperty, new Binding { Path = new PropertyPath("Visibility"), Source = this }); return new VisualHelper { PointShape = e, HoverShape = hs, IsNew = true }; } map.ChartPoint.X = point.X; map.ChartPoint.Y = point.Y; return new VisualHelper { PointShape = map.Shape, HoverShape = map.HoverShape, IsNew = false }; }
protected static double Pull(ChartPoint point, AxisOrientation source) { return(source == AxisOrientation.Y ? point.Y : point.X); }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (HeatPoint) point.View; if (pbv == null) { pbv = new HeatPoint { IsNew = true, Rectangle = new Rectangle() }; Model.Chart.View.AddToDrawMargin(pbv.Rectangle); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Rectangle); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.Rectangle.Stroke = Stroke; pbv.Rectangle.StrokeThickness = StrokeThickness; pbv.Rectangle.Visibility = Visibility; pbv.Rectangle.StrokeDashArray = StrokeDashArray; Canvas.SetZIndex(pbv.Rectangle, Canvas.GetZIndex(pbv.Rectangle)); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = new SolidColorBrush(Colors.Transparent), StrokeThickness = 0 }; Canvas.SetZIndex(pbv.HoverShape, short.MaxValue); var uwpfChart = (Chart)Model.Chart.View; uwpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) pbv.HoverShape.Visibility = Visibility; if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Canvas.SetZIndex(pbv.DataLabel, short.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) pbv.DataLabel.Text = label; return pbv; }
/// <summary> /// Converts a ChartPoint to Point /// </summary> /// <param name="chartPoint">point to convert</param> /// <returns></returns> public static Point AsPoint(this ChartPoint chartPoint) { return(new Point(chartPoint.X, chartPoint.Y)); }
public override void OnHover(ChartPoint point) { var copy = Shape.Fill.Clone(); copy.Opacity -= .15; Shape.Fill = copy; }
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 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) { 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 IChartPointView GetPointView(ChartPoint point, string label) { var mhr = PointGeometrySize < 10 ? 10 : PointGeometrySize; var pbv = (HorizontalBezierPointView)point.View; if (pbv == null) { pbv = new HorizontalBezierPointView { Segment = new BezierSegment(), Container = Figure, IsNew = true }; } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Shape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0, Width = mhr, Height = mhr }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (PointGeometry != null && Math.Abs(PointGeometrySize) > 0.1 && pbv.Shape == null) { if (PointGeometry != null) { pbv.Shape = new Path { Stretch = Stretch.Fill, StrokeThickness = StrokeThickness }; } Model.Chart.View.AddToDrawMargin(pbv.Shape); } if (pbv.Shape != null) { pbv.Shape.Fill = PointForeround; pbv.Shape.Stroke = Stroke; pbv.Shape.StrokeThickness = StrokeThickness; pbv.Shape.Width = PointGeometrySize; pbv.Shape.Height = PointGeometrySize; pbv.Shape.Data = PointGeometry; pbv.Shape.Visibility = Visibility; Panel.SetZIndex(pbv.Shape, Panel.GetZIndex(this) + 1); if (point.Stroke != null) { pbv.Shape.Stroke = (Brush)point.Stroke; } if (point.Fill != null) { pbv.Shape.Fill = (Brush)point.Fill; } } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Panel.SetZIndex(pbv.DataLabel, int.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } return(pbv); }
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; }
/// <summary> /// Gets the view of a given point /// </summary> /// <param name="point"></param> /// <param name="label"></param> /// <returns></returns> public override IChartPointView GetPointView(ChartPoint point, string label) { var pbv = (PiePointView)point.View; if (pbv == null) { pbv = new PiePointView { IsNew = true, Slice = new PieSlice() }; Model.Chart.View.AddToDrawMargin(pbv.Slice); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.Slice); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } pbv.Slice.Fill = Fill; pbv.Slice.Stroke = Stroke; pbv.Slice.StrokeThickness = StrokeThickness; pbv.Slice.StrokeDashArray = StrokeDashArray; pbv.Slice.PushOut = PushOut; pbv.Slice.Visibility = Visibility; Panel.SetZIndex(pbv.Slice, Panel.GetZIndex(this)); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new PieSlice { Fill = Brushes.Transparent, StrokeThickness = 0 }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels) { pbv.DataLabel = UpdateLabelContent(new DataLabelViewModel { FormattedText = label, Instance = point.Instance }, pbv.DataLabel); } pbv.OriginalPushOut = PushOut; return(pbv); }
/// <summary> /// Gets the tooltip position. /// </summary> /// <param name="senderPoint">The sender point.</param> /// <returns></returns> protected internal override Point GetTooltipPosition(ChartPoint senderPoint) { var pieSlice = ((PiePointView) senderPoint.View).Slice; var alpha = pieSlice.RotationAngle + pieSlice.WedgeAngle * .5 + 180; var alphaRad = alpha * Math.PI / 180; var sliceMidAngle = alpha - 180; DataTooltip.UpdateLayout(); var y = DrawMargin.ActualHeight*.5 + (sliceMidAngle > 90 && sliceMidAngle < 270 ? -1 : 0)*DataTooltip.ActualHeight - Math.Cos(alphaRad)*15; var x = DrawMargin.ActualWidth*.5 + (sliceMidAngle > 0 && sliceMidAngle < 180 ? -1 : 0)*DataTooltip.ActualWidth + Math.Sin(alphaRad)*15; return new Point(x, y); }
public override IChartPointView GetPointView(IChartPointView view, ChartPoint point, string label) { var pbv = (CandlePointView)view; if (pbv == null) { pbv = new CandlePointView { IsNew = true, HighToLowLine = new Line(), OpenToCloseRectangle = new Rectangle() }; Model.Chart.View.AddToDrawMargin(pbv.HighToLowLine); Model.Chart.View.AddToDrawMargin(pbv.OpenToCloseRectangle); } else { pbv.IsNew = false; point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HighToLowLine); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.OpenToCloseRectangle); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.HoverShape); point.SeriesView.Model.Chart.View .EnsureElementBelongsToCurrentDrawMargin(pbv.DataLabel); } var i = Panel.GetZIndex(this); pbv.HighToLowLine.StrokeThickness = StrokeThickness; pbv.HighToLowLine.StrokeDashArray = StrokeDashArray; pbv.HighToLowLine.Visibility = Visibility; Panel.SetZIndex(pbv.HighToLowLine, i); pbv.OpenToCloseRectangle.Fill = Fill; pbv.OpenToCloseRectangle.StrokeThickness = StrokeThickness; pbv.OpenToCloseRectangle.Stroke = Stroke; pbv.OpenToCloseRectangle.StrokeDashArray = StrokeDashArray; pbv.OpenToCloseRectangle.Visibility = Visibility; Panel.SetZIndex(pbv.HighToLowLine, i); if (Model.Chart.RequiresHoverShape && pbv.HoverShape == null) { pbv.HoverShape = new Rectangle { Fill = Brushes.Transparent, StrokeThickness = 0 }; Panel.SetZIndex(pbv.HoverShape, int.MaxValue); var wpfChart = (Chart)Model.Chart.View; wpfChart.AttachHoverableEventTo(pbv.HoverShape); Model.Chart.View.AddToDrawMargin(pbv.HoverShape); } if (pbv.HoverShape != null) { pbv.HoverShape.Visibility = Visibility; } if (DataLabels && pbv.DataLabel == null) { pbv.DataLabel = BindATextBlock(0); Panel.SetZIndex(pbv.DataLabel, int.MaxValue - 1); Model.Chart.View.AddToDrawMargin(pbv.DataLabel); } if (pbv.DataLabel != null) { pbv.DataLabel.Text = label; } if (point.Open <= point.Close) { pbv.HighToLowLine.Stroke = IncreaseBrush; pbv.OpenToCloseRectangle.Fill = IncreaseBrush; pbv.OpenToCloseRectangle.Stroke = IncreaseBrush; } else { pbv.HighToLowLine.Stroke = DecreaseBrush; pbv.OpenToCloseRectangle.Fill = DecreaseBrush; pbv.OpenToCloseRectangle.Stroke = DecreaseBrush; } return(pbv); }
public ChartLine AttachDataSet(IChart chart, MultiDimensionalPoint point, int pointDimension, object tag) { var chartPoints = new ChartPoint[pointDimension]; var chartLineSegments = new ChartLineSegment[pointDimension - 1]; for (int i = 0; i < pointDimension; i++) { chartPoints[i] = new ChartPoint { Data = point }; chart.Axes[i].Points.Add(chartPoints[i]); chart.Axes[i].Transformation.Transform(chart.Axes[i], chartPoints[i]); } for (int i = 0; i < pointDimension - 1; i++) { chartLineSegments[i] = new ChartLineSegment(chartPoints[i], chartPoints[i + 1]); } foreach (var chartPoint in chartPoints) { chart.Points.Add(chartPoint); } var line = new ChartLine(chartLineSegments) { Tag = tag }; chart.Lines.Add(line); return line; }