/// <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.BeginDoubleAnimation("Opacity", 0, 1, chart.View.AnimationsSpeed); } if (Line.Visibility != Visibility.Collapsed) { Line.BeginDoubleAnimation("Opacity", 0, 1, chart.View.AnimationsSpeed); } }
/// <summary> /// Draws the or move. /// </summary> /// <param name="source">The source.</param> /// <param name="axis">The axis.</param> public void DrawOrMove(AxisOrientation source, int axis) { _rectangle.Fill = Fill; _rectangle.Stroke = Stroke; _rectangle.StrokeDashArray = StrokeDashArray; _rectangle.StrokeThickness = StrokeThickness; Canvas.SetZIndex(_rectangle, Canvas.GetZIndex(this)); BindingOperations.SetBinding(_rectangle, VisibilityProperty, new Binding { Path = new PropertyPath(nameof(Visibility)), Source = this }); if (Parent == null) { Model.Chart.View.AddToView(this); Model.Chart.View.AddToDrawMargin(_rectangle); Model.Chart.View.AddToDrawMargin(_label); _rectangle.Height = 0; _rectangle.Width = 0; Canvas.SetLeft(_rectangle, 0d); Canvas.SetTop(_rectangle, Model.Chart.DrawMargin.Height); Canvas.SetTop(_label, Model.Chart.DrawMargin.Height); Canvas.SetLeft(_label, 0d); } var ax = source == AxisOrientation.X ? Model.Chart.AxisX[axis] : Model.Chart.AxisY[axis]; var uw = ax.EvaluatesUnitWidth ? ChartFunctions.GetUnitWidth(source, Model.Chart, axis) / 2 : 0; var from = ChartFunctions.ToDrawMargin(Value, source, Model.Chart, axis) + uw; var to = ChartFunctions.ToDrawMargin(Value + SectionWidth, source, Model.Chart, axis) + uw; if (from > to) { var temp = to; to = from; from = temp; } var anSpeed = Model.Chart.View.AnimationsSpeed; _label.UpdateLayout(); if (source == AxisOrientation.X) { var w = to - from; w = StrokeThickness > w ? StrokeThickness : w; Canvas.SetTop(_rectangle, 0); _rectangle.Height = Model.Chart.DrawMargin.Height; if (Model.Chart.View.DisableAnimations) { _rectangle.Width = w > 0 ? w : 0; Canvas.SetLeft(_rectangle, from - StrokeThickness / 2); Canvas.SetLeft(_label, (from + to) / 2 - _label.ActualWidth / 2); } else { _rectangle.BeginDoubleAnimation(nameof(Width), w > 0 ? w : 0, anSpeed); _rectangle.BeginDoubleAnimation("(Canvas.Left)", from - StrokeThickness / 2, anSpeed); _label.BeginDoubleAnimation("(Canvas.Left)", (from + to) / 2 - _label.ActualWidth / 2, anSpeed); } return; } var h = to - from; h = StrokeThickness > h ? StrokeThickness : h; Canvas.SetLeft(_rectangle, 0d); _rectangle.Width = Model.Chart.DrawMargin.Width; if (Model.Chart.View.DisableAnimations) { Canvas.SetTop(_rectangle, from); _rectangle.Height = h > 0 ? h : 0; Canvas.SetTop(_label, (from + to) / 2 - _label.ActualHeight / 2); } else { _rectangle.BeginDoubleAnimation("(Canvas.Top)", from - StrokeThickness / 2, anSpeed); _rectangle.BeginDoubleAnimation(nameof(Height), h > 0 ? h : 0, anSpeed); _label.BeginDoubleAnimation("(Canvas.Top)", (from + to) / 2 - _label.ActualHeight / 2, anSpeed); } }
private void PlaceLabel(string text, AxisCore axis, AxisOrientation source) { _label.Text = text; _label.UpdateLayout(); var transform = new LabelEvaluation(axis.View.LabelsRotation, _label.Width + 10, _label.Height, axis, source); _label.RenderTransform = Math.Abs(transform.LabelAngle) > 1 ? new RotateTransform { Angle = transform.LabelAngle } : null; var toLine = ChartFunctions.ToPlotArea(Value, source, Model.Chart, axis); var direction = source == AxisOrientation.X ? 1 : -1; toLine += axis.EvaluatesUnitWidth ? direction * ChartFunctions.GetUnitWidth(source, Model.Chart, axis) / 2 : 0; var toLabel = toLine + transform.GetOffsetBySource(source); var chart = Model.Chart; if (axis.IsMerged) { const double padding = 4; if (source == AxisOrientation.Y) { if (toLabel + transform.ActualHeight > chart.DrawMargin.Top + chart.DrawMargin.Height) { toLabel -= transform.ActualHeight + padding; } } else { if (toLabel + transform.ActualWidth > chart.DrawMargin.Left + chart.DrawMargin.Width) { toLabel -= transform.ActualWidth + padding; } } } var labelTab = axis.Tab; labelTab += transform.GetOffsetBySource(source.Invert()); if (source == AxisOrientation.Y) { if (Model.View.DisableAnimations || DisableAnimations) { Canvas.SetLeft(_label, labelTab); Canvas.SetTop(_label, toLabel); return; } _label.BeginDoubleAnimation("Canvas.Top", toLabel, chart.View.AnimationsSpeed); _label.BeginDoubleAnimation("Canvas.Left", labelTab, chart.View.AnimationsSpeed); } else { if (Model.View.DisableAnimations || DisableAnimations) { Canvas.SetLeft(_label, toLabel); Canvas.SetTop(_label, labelTab); return; } _label.BeginDoubleAnimation("Canvas.Left", toLabel, chart.View.AnimationsSpeed); _label.BeginDoubleAnimation("Canvas.Top", labelTab, chart.View.AnimationsSpeed); } }