/// <summary> /// Converts from chart control size to chart values. /// </summary> /// <param name="value">value to scale</param> /// <param name="source">axis orientation to scale value at</param> /// <param name="chart">chart model to scale value at</param> /// <param name="axis">axis index in collection of chart.axis</param> /// <returns></returns> public static double FromPlotArea(double value, AxisOrientation source, ChartCore chart, int axis = 0) { var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisOrientation.Y) { p1.X = chart.AxisY[axis].TopLimit; p1.Y = chart.DrawMargin.Top; p2.X = chart.AxisY[axis].BotLimit; p2.Y = chart.DrawMargin.Top + chart.DrawMargin.Height; } else { p1.X = chart.AxisX[axis].TopLimit; p1.Y = chart.DrawMargin.Width + chart.DrawMargin.Left; p2.X = chart.AxisX[axis].BotLimit; p2.Y = chart.DrawMargin.Left; } var deltaX = p2.X - p1.X; // ReSharper disable once CompareOfFloatsByEqualityOperator var m = (p2.Y - p1.Y) / (deltaX == 0 ? double.MinValue : deltaX); return (value + m * p1.X - p1.Y) / m; }
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)); }
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 RemoveFromView(ChartCore chart) { chart.View.RemoveFromDrawMargin(HoverShape); chart.View.RemoveFromDrawMargin(Shape); chart.View.RemoveFromDrawMargin(DataLabel); Container.Segments.Remove(Segment); }
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; }
/// <summary> /// Removes the specified chart. /// </summary> /// <param name="chart">The chart.</param> public void Remove(ChartCore chart) { chart.View.RemoveFromView(TextBlock); chart.View.RemoveFromView(Line); TextBlock = null; Line = null; }
/// <summary> /// Moves the specified chart. /// </summary> /// <param name="chart">The chart.</param> /// <param name="axis">The axis.</param> /// <param name="direction">The direction.</param> /// <param name="axisIndex">Index of the axis.</param> /// <param name="toLabel">To label.</param> /// <param name="toLine">To line.</param> /// <param name="tab">The tab.</param> public void Move(ChartCore chart, AxisCore axis, AxisOrientation direction, int axisIndex, double toLabel, double toLine, double tab) { if (direction == AxisOrientation.Y) { Line.BeginAnimation(Line.X1Property, new DoubleAnimation(chart.DrawMargin.Left, chart.View.AnimationsSpeed)); Line.BeginAnimation(Line.X2Property, new DoubleAnimation(chart.DrawMargin.Left + chart.DrawMargin.Width, chart.View.AnimationsSpeed)); Line.BeginAnimation(Line.Y1Property, new DoubleAnimation(toLine, chart.View.AnimationsSpeed)); Line.BeginAnimation(Line.Y2Property, new DoubleAnimation(toLine, chart.View.AnimationsSpeed)); TextBlock.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(toLabel, chart.View.AnimationsSpeed)); TextBlock.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(tab, chart.View.AnimationsSpeed)); } else { Line.BeginAnimation(Line.X1Property, new DoubleAnimation(toLine, chart.View.AnimationsSpeed)); Line.BeginAnimation(Line.X2Property, new DoubleAnimation(toLine, chart.View.AnimationsSpeed)); Line.BeginAnimation(Line.Y1Property, new DoubleAnimation(chart.DrawMargin.Top, chart.View.AnimationsSpeed)); Line.BeginAnimation(Line.Y2Property, new DoubleAnimation(chart.DrawMargin.Top + chart.DrawMargin.Height, chart.View.AnimationsSpeed)); TextBlock.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(toLabel, chart.View.AnimationsSpeed)); TextBlock.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(tab, chart.View.AnimationsSpeed)); } }
/// <summary> /// Fades the in. /// </summary> /// <param name="axis">The axis.</param> /// <param name="chart">The chart.</param> public void FadeIn(AxisCore axis, ChartCore chart) { if (TextBlock.Visibility != Visibility.Collapsed) TextBlock.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0, 1, chart.View.AnimationsSpeed)); if (Line.Visibility != Visibility.Collapsed) Line.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(0, 1, chart.View.AnimationsSpeed)); }
internal void CalculateSeparator(ChartCore chart, AxisTags source) { var range = MaxLimit - MinLimit; range = range <= 0 ? 1 : range; //ToDO: Improve this according to current labels! var separations = source == AxisTags.Y ? Math.Round(chart.DrawMargin.Height/((12)*CleanFactor), 0) // at least 3 font 12 labels per separator. : Math.Round(chart.DrawMargin.Width/(50*CleanFactor), 0); // at least 150 pixels per separator. separations = separations < 2 ? 2 : separations; var minimum = range/separations; Magnitude = Math.Pow(10, Math.Floor(Math.Log(minimum)/Math.Log(10))); if (Separator.Step != null) { S = Separator.Step ?? 1; return; } var residual = minimum/Magnitude; double tick; if (residual > 5) tick = 10*Magnitude; else if (residual > 2) tick = 5*Magnitude; else if (residual > 1) tick = 2*Magnitude; else tick = Magnitude; S = tick; if (Labels != null) S = S < 1 ? 1 : S; }
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) { Canvas.SetTop(DataLabel, 0d); Canvas.SetLeft(DataLabel, 0d); } } 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; } Canvas.SetTop(Slice, chart.DrawMargin.Height / 2); Canvas.SetLeft(Slice, chart.DrawMargin.Width / 2); Slice.InnerRadius = InnerRadius; Slice.Radius = Radius; var hypo = (Slice.Radius + Slice.InnerRadius)/2; 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.WedgeAngle = Wedge; Slice.RotationAngle = Rotation; if (DataLabel != null) { DataLabel.UpdateLayout(); var lx = cp.X + chart.DrawMargin.Width / 2 - DataLabel.ActualWidth * .5; var ly = chart.DrawMargin.Height/2 - cp.Y - DataLabel.ActualHeight*.5; Canvas.SetLeft(DataLabel, lx); Canvas.SetTop(DataLabel, ly); } return; } var animSpeed = chart.View.AnimationsSpeed; if (DataLabel != null) { DataLabel.UpdateLayout(); var lx = cp.X + chart.DrawMargin.Width / 2 - DataLabel.ActualWidth * .5; var ly = chart.DrawMargin.Height / 2 - cp.Y - DataLabel.ActualHeight * .5; DataLabel.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(lx, animSpeed)); DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(ly, animSpeed)); } Slice.BeginAnimation(PieSlice.WedgeAngleProperty, new DoubleAnimation(Wedge, animSpeed)); Slice.BeginAnimation(PieSlice.RotationAngleProperty, new DoubleAnimation(Rotation, animSpeed)); }
/// <summary> /// Maps the y axes. /// </summary> /// <param name="chart">The chart.</param> /// <returns></returns> public List<AxisCore> MapYAxes(ChartCore chart) { if (DesignerProperties.GetIsInDesignMode(this) || AxisY == null) AxisY = DefaultAxes.DefaultAxis; //if (AxisY.Count == 0) // AxisY.AddRange(DefaultAxes.DefaultAxis); if (AxisY.Count == 0) AxisY.Add(new Axis {Separator = new Separator()}); return AxisY.Select(y => { if (y.Parent == null) { y.AxisOrientation = AxisOrientation.Y; if (y.Separator != null) chart.View.AddToView(y.Separator); chart.View.AddToView(y); } return y.AsCoreElement(Model, AxisOrientation.Y); }).ToList(); }
/// <summary> /// Maps the x axes. /// </summary> /// <param name="chart">The chart.</param> /// <returns></returns> public List<AxisCore> MapXAxes(ChartCore chart) { if (DesignerProperties.GetIsInDesignMode(this) || AxisX == null) AxisX = DefaultAxes.DefaultAxis; //if (AxisX.Count == 0) // AxisX.AddRange(DefaultAxes.CleanAxis); if (AxisX.Count == 0) AxisX.Add(new Axis {Separator = new Separator()}); return AxisX.Select(x => { if (x.Parent == null) { x.AxisOrientation = AxisOrientation.X; if (x.Separator != null) chart.View.AddToView(x.Separator); chart.View.AddToView(x); } return x.AsCoreElement(Model, AxisOrientation.X); }).ToList(); }
/// <summary> /// Updates the title. /// </summary> /// <param name="chart">The chart.</param> /// <param name="rotationAngle">The rotation angle.</param> /// <returns></returns> public CoreSize UpdateTitle(ChartCore chart, double rotationAngle = 0) { if (TitleBlock.Parent == null) { if (Math.Abs(rotationAngle) > 1) TitleBlock.RenderTransform = new RotateTransform {Angle = rotationAngle}; chart.View.AddToView(TitleBlock); } TitleBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); return string.IsNullOrWhiteSpace(Title) ? new CoreSize() : new CoreSize(TitleBlock.DesiredSize.Width, TitleBlock.DesiredSize.Height); }
/// <summary> /// Renders the separator. /// </summary> /// <param name="model">The model.</param> /// <param name="chart">The chart.</param> public void RenderSeparator(SeparatorElementCore model, ChartCore chart) { AxisSeparatorElement ase; if (model.View == null) { ase = new AxisSeparatorElement(model) { Line = BindALine(), TextBlock = BindATextBlock() }; model.View = ase; chart.View.AddToView(ase.Line); chart.View.AddToView(ase.TextBlock); Canvas.SetZIndex(ase.Line, -1); } else { ase = (AxisSeparatorElement) model.View; } if (!Separator.IsEnabled) ase.Line.Visibility = Visibility.Collapsed; if (!ShowLabels) ase.TextBlock.Visibility = Visibility.Collapsed; }
/// <summary> /// Ases the core element. /// </summary> /// <param name="chart">The chart.</param> /// <param name="source">The source.</param> /// <returns></returns> public AxisCore AsCoreElement(ChartCore chart, AxisOrientation source) { if (Model == null) Model = new AxisCore(this); Model.ShowLabels = ShowLabels; Model.Chart = chart; Model.IsMerged = IsMerged; Model.Labels = Labels; Model.LabelFormatter = LabelFormatter; Model.MaxValue = MaxValue; Model.MinValue = MinValue; Model.Title = Title; Model.Position = Position; Model.Separator = Separator.AsCoreElement(Model, source); Model.DisableAnimations = DisableAnimations; Model.Sections = Sections.Select(x => x.AsCoreElement(Model, source)).ToList(); return Model; }
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)); }
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; } }
internal double FromPreviousState(double value, AxisTags source, ChartCore chart) { if (LastAxisMax == null) return 0; var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisTags.Y) { p1.X = LastAxisMax ?? 0; p1.Y = LastPlotArea.Top; p2.X = LastAxisMin ?? 0; p2.Y = LastPlotArea.Top + LastPlotArea.Height; } else { p1.X = LastAxisMax ?? 0; p1.Y = LastPlotArea.Width + LastPlotArea.Left; p2.X = LastAxisMin ?? 0; p2.Y = LastPlotArea.Left; } var deltaX = p2.X - p1.X; // ReSharper disable once CompareOfFloatsByEqualityOperator var m = (p2.Y - p1.Y) / (deltaX == 0 ? double.MinValue : deltaX); var d = m * (value - p1.X) + p1.Y; return d; }
/// <summary> /// Fades the out and remove. /// </summary> /// <param name="chart">The chart.</param> public void FadeOutAndRemove(ChartCore chart) { if (TextBlock.Visibility == Visibility.Collapsed && Line.Visibility == Visibility.Collapsed) return; var anim = new DoubleAnimation { From = 1, To = 0, Duration = chart.View.AnimationsSpeed }; anim.Completed += (sender, args) => { if (Application.Current == null) { chart.View.RemoveFromView(TextBlock); chart.View.RemoveFromView(Line); return; } Application.Current.Dispatcher.Invoke(new Action(() => { chart.View.RemoveFromView(TextBlock); chart.View.RemoveFromView(Line); })); }; TextBlock.BeginAnimation(UIElement.OpacityProperty, anim); Line.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation(1, 0, chart.View.AnimationsSpeed)); }
internal CoreMargin PrepareChart(AxisTags source, ChartCore chart) { if (!(Math.Abs(MaxLimit - MinLimit) > S*.01) || !ShowLabels) return new CoreMargin(); CalculateSeparator(chart, source); var f = GetFormatter(); var currentMargin = new CoreMargin(); var tolerance = S/10; InitializeGarbageCollector(); for (var i = MinLimit; i <= MaxLimit - (EvaluatesUnitWidth ? 1 : 0); i += S) { SeparatorElementCore asc; var key = Math.Round(i/tolerance)*tolerance; if (!Cache.TryGetValue(key, out asc)) { asc = new SeparatorElementCore {IsNew = true}; Cache[key] = asc; } else { asc.IsNew = false; } View.RenderSeparator(asc, Chart); asc.Key = key; asc.Value = i; asc.GarbageCollectorIndex = GarbageCollectorIndex; var labelsMargin = asc.View.UpdateLabel(f(i), this, source); currentMargin.Width = labelsMargin.TakenWidth > currentMargin.Width ? labelsMargin.TakenWidth : currentMargin.Width; currentMargin.Height = labelsMargin.TakenHeight > currentMargin.Height ? labelsMargin.TakenHeight : currentMargin.Height; currentMargin.Left = labelsMargin.Left > currentMargin.Left ? labelsMargin.Left : currentMargin.Left; currentMargin.Right = labelsMargin.Right > currentMargin.Right ? labelsMargin.Right : currentMargin.Right; currentMargin.Top = labelsMargin.Top > currentMargin.Top ? labelsMargin.Top : currentMargin.Top; currentMargin.Bottom = labelsMargin.Bottom > currentMargin.Bottom ? labelsMargin.Bottom : currentMargin.Bottom; if (LastAxisMax == null) { asc.State = SeparationState.InitialAdd; continue; } asc.State = SeparationState.Keep; } return currentMargin; }
/// <summary> /// Places the specified chart. /// </summary> /// <param name="chart">The chart.</param> /// <param name="axis">The axis.</param> /// <param name="direction">The direction.</param> /// <param name="axisIndex">Index of the axis.</param> /// <param name="toLabel">To label.</param> /// <param name="toLine">To line.</param> /// <param name="tab">The tab.</param> public void Place(ChartCore chart, AxisCore axis, AxisOrientation direction, int axisIndex, double toLabel, double toLine, double tab) { if (direction == AxisOrientation.Y) { Line.X1 = chart.DrawMargin.Left; Line.X2 = chart.DrawMargin.Left + chart.DrawMargin.Width; Line.Y1 = toLine; Line.Y2 = toLine; Canvas.SetLeft(TextBlock, tab); Canvas.SetTop(TextBlock, toLabel); } else { Line.X1 = toLine; Line.X2 = toLine; Line.Y1 = chart.DrawMargin.Top; Line.Y2 = chart.DrawMargin.Top + chart.DrawMargin.Height; Canvas.SetLeft(TextBlock, toLabel); Canvas.SetTop(TextBlock, tab); } }
internal void UpdateSeparators(AxisTags source, ChartCore chart, int axisIndex) { foreach (var element in Cache.Values.ToArray()) { if (element.GarbageCollectorIndex < GarbageCollectorIndex) { element.State = SeparationState.Remove; Cache.Remove(element.Key); } var toLine = ChartFunctions.ToPlotArea(element.Value, source, chart, axisIndex); var direction = source == AxisTags.X ? 1 : -1; toLine += EvaluatesUnitWidth ? direction*ChartFunctions.GetUnitWidth(source, chart, this)/2 : 0; var toLabel = toLine + element.View.LabelModel.GetOffsetBySource(source); if (IsMerged) { const double padding = 4; if (source == AxisTags.Y) { if (toLabel + element.View.LabelModel.ActualHeight > chart.DrawMargin.Top + chart.DrawMargin.Height) toLabel -= element.View.LabelModel.ActualHeight + padding; } else { if (toLabel + element.View.LabelModel.ActualWidth > chart.DrawMargin.Left + chart.DrawMargin.Width) toLabel -= element.View.LabelModel.ActualWidth + padding; } } var labelTab = Tab; labelTab += element.View.LabelModel.GetOffsetBySource(source.Invert()); switch (element.State) { case SeparationState.Remove: if (!chart.View.DisableAnimations && !View.DisableAnimations) { element.View.Move(chart, this, source, axisIndex, toLabel, toLine, labelTab); element.View.FadeOutAndRemove(chart); } else { element.View.Remove(chart); } break; case SeparationState.Keep: if (!chart.View.DisableAnimations && !View.DisableAnimations) { if (element.IsNew) { var toLinePrevious = FromPreviousState(element.Value, source, chart); toLinePrevious += EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(source, chart, this) / 2 : 0; var toLabelPrevious = toLinePrevious + element.View.LabelModel.GetOffsetBySource(source); element.View.Place(chart, this, source, axisIndex, toLabelPrevious, toLinePrevious, labelTab); element.View.FadeIn(this, chart); } element.View.Move(chart, this, source, axisIndex, toLabel, toLine, labelTab); } else { element.View.Place(chart, this, source, axisIndex, toLabel, toLine, labelTab); } break; case SeparationState.InitialAdd: element.View.Place(chart, this, source, axisIndex, toLabel, toLine, labelTab); break; default: throw new ArgumentOutOfRangeException(); } } LastAxisMax = MaxLimit; LastAxisMin = MinLimit; LastPlotArea = new CoreRectangle(chart.DrawMargin.Left, chart.DrawMargin.Top, chart.DrawMargin.Width, chart.DrawMargin.Height); #if DEBUG Debug.WriteLine("Axis.Separations: " + Cache.Count); #endif }
public override void RemoveFromView(ChartCore chart) { chart.View.RemoveFromDrawMargin(HoverShape); chart.View.RemoveFromDrawMargin(Shape); chart.View.RemoveFromDrawMargin(DataLabel); }
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; } }
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)); }
/// <summary> /// Maps the x axes. /// </summary> /// <param name="chart">The chart.</param> /// <returns></returns> public List<AxisCore> MapXAxes(ChartCore chart) { if (Windows.ApplicationModel.DesignMode.DesignModeEnabled && AxisX == null) AxisX = DefaultAxes.DefaultAxis; if (AxisX.Count == 0) AxisX.AddRange(DefaultAxes.CleanAxis); return AxisX.Select(x => { if (x.Parent == null) { if (x.Separator != null) chart.View.AddToView(x.Separator); chart.View.AddToView(x); x.AxisOrientation = AxisOrientation.X; } return x.AsCoreElement(Model, AxisOrientation.X); }).ToList(); }
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; }
/// <summary> /// Maps the y axes. /// </summary> /// <param name="chart">The chart.</param> /// <returns></returns> public List<AxisCore> MapYAxes(ChartCore chart) { if (Windows.ApplicationModel.DesignMode.DesignModeEnabled && AxisY == null) AxisY = DefaultAxes.DefaultAxis; if (AxisY.Count == 0) AxisY.AddRange(DefaultAxes.DefaultAxis); return AxisY.Select(y => { if (y.Parent == null) { if (y.Separator != null) chart.View.AddToView(y.Separator); chart.View.AddToView(y); y.AxisOrientation = AxisOrientation.Y; } return y.AsCoreElement(Model, AxisOrientation.Y); }).ToList(); }
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); } }
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); }