public Scaler( PointF drawMaringLocation, SizeF drawMarginSize, AxisOrientation orientation, Bounds axisBounds, bool isInverted) { if (orientation == AxisOrientation.Unknown) { throw new Exception("The axis is not ready to be scaled."); } if (orientation == AxisOrientation.X) { minPx = drawMaringLocation.X; maxPx = drawMarginSize.Width; deltaPx = maxPx - minPx; maxVal = (float)(isInverted ? axisBounds.min : axisBounds.max); minVal = (float)(isInverted ? axisBounds.max : axisBounds.min); deltaVal = maxVal - minVal; } else { minPx = drawMaringLocation.Y; maxPx = drawMarginSize.Height; deltaPx = maxPx - minPx; maxVal = (float)(isInverted ? axisBounds.max : axisBounds.min); minVal = (float)(isInverted ? axisBounds.min : axisBounds.max); deltaVal = maxVal - minVal; } m = deltaPx / deltaVal; mInv = 1 / m; }
public override AxisCore AsCoreElement(ChartCore chart, AxisOrientation source) { if (this.Model == null) { this.Model = (AxisCore) new PrimeDateAxisCore((IWindowAxisView)this); } this.Model.ShowLabels = this.ShowLabels; this.Model.Chart = chart; this.Model.IsMerged = this.IsMerged; this.Model.Labels = this.Labels; this.Model.LabelFormatter = this.LabelFormatter; this.Model.MaxValue = this.MaxValue; this.Model.MinValue = this.MinValue; this.Model.Title = this.Title; this.Model.Position = this.Position; this.Model.Separator = this.Separator.AsCoreElement(this.Model, source); this.Model.DisableAnimations = this.DisableAnimations; this.Model.Sections = this.Sections.Select <AxisSection, AxisSectionCore>((Func <AxisSection, AxisSectionCore>)(x => x.AsCoreElement(this.Model, source))).ToList <AxisSectionCore>(); this.Windows.Clear(); this.Windows.AddRange(DateAxisWindows.GetDateAxisWindows()); ((WindowAxisCore)this.Model).Windows = this.Windows.ToList <AxisWindow>(); ((WindowAxisCore)this.Model).Windows.ForEach((Action <AxisWindow>)(w => ((DateAxisWindow)w).DateAxisCore = (PrimeDateAxisCore)this.Model)); return(this.Model); }
public Axis(Vector x_initial, Vector x_final, AxisOrientation orientation) { x_i = x_initial; x_f = x_final; Orientation = orientation; Scale(1.0D); }
public AxisSectionCore AsCoreElement(AxisCore axis, AxisOrientation source) { var model = new AxisSectionCore(this, axis.Chart); model.View.Model = model; return(model); }
/// <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; }
/// <summary> /// Get or create a linear numeric axis in the correct dimension. /// </summary> /// <param name="orientation">Dimension of the axis to create.</param> /// <param name="oldAxis"> /// Old value of the axis in this dimension. /// </param> /// <returns>New value of the axis in this dimension.</returns> private IRangeAxis GetAxis(AxisOrientation orientation, IRangeAxis oldAxis) { // Check the existing axes for a potential axis IRangeAxis axis = (from IRangeAxis a in SeriesHost.Axes.OfType <IRangeAxis>() where a.Orientation == orientation select a) .FirstOrDefault(); if (axis == null) { // Create a new axis if not found axis = new LinearAxis { Orientation = orientation, }; } if (oldAxis != axis) { // Unregister any existing axis if (oldAxis != null) { oldAxis.RegisteredListeners.Remove(this); } // Register the new axis if (!axis.RegisteredListeners.Contains(this)) { axis.RegisteredListeners.Add(this); } } return(axis); }
public ScaleContext(PointF drawMaringLocation, SizeF drawMarginSize, AxisOrientation orientation, Bounds axisBounds) { if (orientation == AxisOrientation.Unknown) { throw new System.Exception("The axis is not ready to be scaled."); } if (orientation == AxisOrientation.X) { unchecked { o = drawMaringLocation.X; d = drawMarginSize.Width; m = (float)(-(d - 0) / (axisBounds.max - axisBounds.min)); max = (float)axisBounds.max; scaler = ScaleXToUI; } } else { unchecked { o = drawMaringLocation.Y; d = drawMarginSize.Height; m = (float)(-(d - 0) / (axisBounds.max - axisBounds.min)); max = (float)axisBounds.max; scaler = ScaleYToUI; } } }
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> /// Gets two points defining the axis of the object. /// </summary> /// public LineSegment GetAxis(AxisOrientation axis) { double x1, y1; double x2, y2; if (axis == AxisOrientation.Horizontal) { y1 = Math.Cos(-Angle - Math.PI) * Rectangle.Height / 2.0; x1 = Math.Sin(-Angle - Math.PI) * Rectangle.Width / 2.0; y2 = Math.Cos(-Angle) * Rectangle.Height / 2.0; x2 = Math.Sin(-Angle) * Rectangle.Width / 2.0; } else { y1 = Math.Cos(-(Angle + Math.PI / 2) - Math.PI) * Rectangle.Height / 2.0; x1 = Math.Sin(-(Angle + Math.PI / 2) - Math.PI) * Rectangle.Width / 2.0; y2 = Math.Cos(-(Angle + Math.PI / 2)) * Rectangle.Height / 2.0; x2 = Math.Sin(-(Angle + Math.PI / 2)) * Rectangle.Width / 2.0; } Point start = new Point((float)(Center.X + x1), (float)(Center.Y + y1)); Point end = new Point((float)(Center.X + x2), (float)(Center.Y + y2)); if (start.DistanceTo(end) == 0) { return(null); } return(new LineSegment(start, end)); }
/// <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) { var x1 = AnimationsHelper.CreateDouble(chart.DrawMargin.Left, chart.View.AnimationsSpeed, nameof(Line.X1)); var x2 = AnimationsHelper.CreateDouble(chart.DrawMargin.Left + chart.DrawMargin.Width, chart.View.AnimationsSpeed, nameof(Line.X2)); var y1 = AnimationsHelper.CreateDouble(toLine, chart.View.AnimationsSpeed, nameof(Line.Y1)); var y2 = AnimationsHelper.CreateDouble(toLine, chart.View.AnimationsSpeed, nameof(Line.Y2)); AnimationsHelper.CreateStoryBoardAndBegin(Line, x1, x2, y1, y2); var tb1 = AnimationsHelper.CreateDouble(toLabel, chart.View.AnimationsSpeed, "(Canvas.Top)"); var tb2 = AnimationsHelper.CreateDouble(tab, chart.View.AnimationsSpeed, "(Canvas.Left)"); AnimationsHelper.CreateStoryBoardAndBegin(TextBlock, tb1, tb2); } else { var x1 = AnimationsHelper.CreateDouble(toLine, chart.View.AnimationsSpeed, nameof(Line.X1)); var x2 = AnimationsHelper.CreateDouble(toLine, chart.View.AnimationsSpeed, nameof(Line.X2)); var y1 = AnimationsHelper.CreateDouble(chart.DrawMargin.Top, chart.View.AnimationsSpeed, nameof(Line.Y1)); var y2 = AnimationsHelper.CreateDouble(chart.DrawMargin.Top + chart.DrawMargin.Height, chart.View.AnimationsSpeed, nameof(Line.Y2)); AnimationsHelper.CreateStoryBoardAndBegin(Line, x1, x2, y1, y2); var tb1 = AnimationsHelper.CreateDouble(toLabel, chart.View.AnimationsSpeed, "(Canvas.Left)"); var tb2 = AnimationsHelper.CreateDouble(tab, chart.View.AnimationsSpeed, "(Canvas.Top)"); AnimationsHelper.CreateStoryBoardAndBegin(TextBlock, tb1, tb2); } }
internal double FromPreviousState(double value, AxisOrientation source, ChartCore chart) { if (LastAxisMax == null) { return(0); } var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisOrientation.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> /// 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].MaxLimit; p1.Y = chart.DrawMargin.Top; p2.X = chart.AxisY[axis].MinLimit; p2.Y = chart.DrawMargin.Top + chart.DrawMargin.Height; } else { p1.X = chart.AxisX[axis].MaxLimit; p1.Y = chart.DrawMargin.Width + chart.DrawMargin.Left; p2.X = chart.AxisX[axis].MinLimit; 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); }
/// <summary> /// Converts from chart values to chart control size. /// </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 model instance</param> /// <returns></returns> public static double ToPlotArea(double value, AxisOrientation source, ChartCore chart, AxisCore axis) { var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisOrientation.Y) { p1.X = axis.TopLimit; p1.Y = chart.DrawMargin.Top; p2.X = axis.BotLimit; p2.Y = chart.DrawMargin.Top + chart.DrawMargin.Height; } else { p1.X = axis.TopLimit; p1.Y = chart.DrawMargin.Width + chart.DrawMargin.Left; p2.X = 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(m * (value - p1.X) + p1.Y); }
public void InvertAxisDirection(AxisOrientation axisOrient, bool isInvert) { switch (axisOrient) { case AxisOrientation.LeftRight: AxisAndMovePackage pkg = (AxisAndMovePackage)arrowButtonRight.Tag; arrowButtonRight.Tag = CreatePackage(pkg.Axis, pkg.MoveProfile, !isInvert); arrowButtonLeft.Tag = CreatePackage(pkg.Axis, pkg.MoveProfile, isInvert); break; case AxisOrientation.ForwardBackward: AxisAndMovePackage pkg2 = (AxisAndMovePackage)arrowButtonForward.Tag; arrowButtonForward.Tag = CreatePackage(pkg2.Axis, pkg2.MoveProfile, !isInvert); arrowButtonBackward.Tag = CreatePackage(pkg2.Axis, pkg2.MoveProfile, isInvert); break; case AxisOrientation.UpDown: AxisAndMovePackage pkg3 = (AxisAndMovePackage)arrowButtonUp.Tag; arrowButtonUp.Tag = CreatePackage(pkg3.Axis, pkg3.MoveProfile, !isInvert); arrowButtonDown.Tag = CreatePackage(pkg3.Axis, pkg3.MoveProfile, isInvert); break; case AxisOrientation.Rotation: AxisAndMovePackage pkg4 = (AxisAndMovePackage)arrowButtonCCW.Tag; arrowButtonCCW.Tag = CreatePackage(pkg4.Axis, pkg4.MoveProfile, !isInvert); arrowButtonCW.Tag = CreatePackage(pkg4.Axis, pkg4.MoveProfile, isInvert); break; } }
/// <summary> /// /// </summary> internal override CoreMargin PrepareChart(AxisOrientation source, ChartCore chart) { if (!(Math.Abs(TopLimit - BotLimit) > S * .01) || !ShowLabels) { return(new CoreMargin()); } var currentMargin = new CoreMargin(); var tolerance = S / 10; InitializeGarbageCollector(); // Determine which magnitude and unit to use var m = (!double.IsNaN(View.Unit) ? View.Unit : Magnitude); var u = (!double.IsNaN(View.Unit) ? View.Unit : 1); // Calculate the separator indices var indices = CalculateSeparatorIndices(chart, source, u); // Draw the separators foreach (var index in indices) { DrawSeparator(index, tolerance, currentMargin, source); } return(currentMargin); }
public void OrientationChangeValue() { IAxis axis = (IAxis)DefaultControlToTest; AxisOrientation orientation = AxisOrientation.X; axis.Orientation = orientation; Assert.AreEqual(orientation, axis.Orientation); }
/// <summary> /// Calculate internalYValue from mouse pointer position /// </summary> /// <param name="chart">Chart</param> /// <param name="yAxis">y-axis reference</param> /// <param name="e">MouseEventArgs</param> /// <returns>Double internalXValue</returns> internal static Double CalculateInternalXValueFromPixelPos(Chart chart, Axis xAxis, MouseEventArgs e) { AxisOrientation axisOrientation = xAxis.AxisOrientation; Double pixelPosition = (axisOrientation == AxisOrientation.Horizontal) ? e.GetPosition(chart.ChartArea.PlottingCanvas).X : e.GetPosition(chart.ChartArea.PlottingCanvas).Y; Double lengthInPixel = ((axisOrientation == AxisOrientation.Horizontal) ? chart.ChartArea.ChartVisualCanvas.Width : chart.ChartArea.ChartVisualCanvas.Height); return(xAxis.PixelPositionToXValue(lengthInPixel, (axisOrientation == AxisOrientation.Horizontal) ? pixelPosition : lengthInPixel - pixelPosition)); }
/// <summary> /// Calculate internalYValue from mouse pointer position /// </summary> /// <param name="chart">Chart</param> /// <param name="yAxis">y-axis reference</param> /// <param name="e">MouseEventArgs</param> /// <returns>Double internalYValue</returns> internal static Double CalculateInternalYValueFromPixelPos(Chart chart, Axis yAxis, MouseEventArgs e) { AxisOrientation axisOrientation = yAxis.AxisOrientation; Double pixelPosition = (axisOrientation == AxisOrientation.Vertical) ? e.GetPosition(chart.ChartArea.PlottingCanvas).Y : e.GetPosition(chart.ChartArea.PlottingCanvas).X; Double lengthInPixel = ((axisOrientation == AxisOrientation.Vertical) ? chart.ChartArea.ChartVisualCanvas.Height : chart.ChartArea.ChartVisualCanvas.Width); return(yAxis.PixelPositionToYValue(lengthInPixel, (axisOrientation == AxisOrientation.Vertical) ? pixelPosition : lengthInPixel - pixelPosition)); }
internal override CoreMargin PrepareChart(AxisOrientation source, ChartCore chart) { // Get the current configued values from the view _initialDateTime = ((IDateAxisView)View).InitialDateTime; _period = ((IDateAxisView)View).Period; return(base.PrepareChart(source, chart)); }
/// <summary> /// Converts from chart values to chart draw margin size. /// </summary> /// <param name="value">value to scale</param> /// <param name="source">axis orientation</param> /// <param name="chart">chart model to scale the value at</param> /// <param name="axis">axis instance to scale the value at</param> /// <returns></returns> public static double ToDrawMargin(double value, AxisOrientation source, ChartCore chart, AxisCore axis) { var o = source == AxisOrientation.X ? chart.DrawMargin.Left : chart.DrawMargin.Top; return(ToPlotArea(value, source, chart, axis) - o); }
/// <summary> /// OrientationProperty property changed handler. /// </summary> /// <param name="d">Axis that changed its Orientation.</param> /// <param name="e">Event arguments.</param> private static void OnOrientationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Axis source = (Axis)d; AxisOrientation oldValue = (AxisOrientation)e.OldValue; AxisOrientation newValue = (AxisOrientation)e.NewValue; source.OnOrientationPropertyChanged(oldValue, newValue); }
/// <summary> /// OrientationProperty property changed handler. /// </summary> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> protected virtual void OnOrientationPropertyChanged(AxisOrientation oldValue, AxisOrientation newValue) { RoutedPropertyChangedEventHandler <AxisOrientation> handler = OrientationChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs <AxisOrientation>(oldValue, newValue)); } }
public Axis(AxisOrientation orient) { LabelProvider = x => x.ToString(System.Globalization.CultureInfo.InvariantCulture); Orientation = orient; AbsoluteMinimum = Double.NegativeInfinity; AbsoluteMaximum = Double.PositiveInfinity; VisibleMaximum = 1; VisibleMinimum = -1; }
private DateTimeAxis BuildDateTimeAxis(AxisOrientation orientation, double interval, bool showGridLines) { DateTimeAxis axis = new DateTimeAxis(); axis.Orientation = orientation; axis.ShowGridLines = showGridLines; return(axis); }
internal static Axis CreateAxis(string name, AxisOrientation orientation) { Axis axis = new Axis(); axis.IsAutoCreated = true; axis.Name = name; axis.Orientation = orientation; return(axis); }
public SeparatorConfigurationCore AsCoreElement(AxisCore axis, AxisOrientation source) { AxisOrientation = source; return(new SeparatorConfigurationCore(axis) { IsEnabled = IsEnabled, Step = Step, Source = source }); }
public AxisOrientation GetAxisOrientation(string target_key, int iAxis) { AxisOrientation ret = (AxisOrientation)OsrPINVOKE.SpatialReference_GetAxisOrientation(swigCPtr, target_key, iAxis); if (OsrPINVOKE.SWIGPendingException.Pending) { throw OsrPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public AxisInfoView(AxisChart chart, AxisTypes axisType, AxisOrientation orientation) { Chart = chart; AxisType = axisType; Orientation = orientation; FillColor = SolidColor.Transparent; LineColor = SolidColor.Transparent; FontSize *= 0.9f; }
/// <summary> /// Converts from draw margin size to chart values. /// </summary> /// <param name="value">value to scale</param> /// <param name="source">axis orientation</param> /// <param name="chart">chart model to scale the value at</param> /// <param name="axis">axis index in the axes collection</param> /// <returns></returns> public static double FromDrawMargin(double value, AxisOrientation source, ChartCore chart, int axis = 0) { var o = source == AxisOrientation.X ? chart.DrawMargin.Left : chart.DrawMargin.Top; //var of = axis == AxisTags.X ? chart.XOffset : chart.YOffset; return(FromPlotArea(value, source, chart, axis)); //- o; //FromPlotArea(value, axis, chart) - o + of; }
/// <summary> /// Get the axis by name and orientation /// </summary> /// <param name="orientation">orientation type</param> /// <param name="name">orientation name</param> /// <returns>axis</returns> public static Axis GetAxis(AxisOrientation orientation, string name) { Dictionary <string, Axis> map = _axisFromOriAndName[orientation]; if (map == null) { return(null); } return(map[name]); }
private Axis CreateAxis(string axisName, AxisOrientation orientation) { if (string.IsNullOrEmpty(axisName)) { axisName = XamlShims.NewFrameworkElementName(); } Axis axis = Axis.CreateAxis(axisName, orientation); this.Axes.Add(axis); return(axis); }
private Axis CreateAxis(string axisName, AxisOrientation orientation) { if (string.IsNullOrEmpty(axisName)) axisName = XamlShims.NewFrameworkElementName(); Axis axis = Axis.CreateAxis(axisName, orientation); this.Axes.Add(axis); return axis; }
/// <summary> /// Initializes a new instance of the AxisInfo class with a value for the RadiansPerUnit property. /// </summary> /// <param name="name">The name of the new axis.</param> /// <param name="orientation">The orietation of the axis.</param> public AxisInfo(string name, AxisOrientation orientation) { _name = name; _orientation = orientation; }
/// <summary> /// OrientationProperty property changed handler. /// </summary> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> protected virtual void OnOrientationPropertyChanged(AxisOrientation oldValue, AxisOrientation newValue) { RoutedPropertyChangedEventHandler<AxisOrientation> handler = OrientationChanged; if (handler != null) { handler(this, new RoutedPropertyChangedEventArgs<AxisOrientation>(oldValue, newValue)); } }
/// <summary> /// OrientationProperty property changed handler. /// </summary> /// <param name="oldValue">Old value.</param> /// <param name="newValue">New value.</param> protected virtual void OnOrientationPropertyChanged(AxisOrientation oldValue, AxisOrientation newValue) { if (OrintationChanged != null) { this.OrintationChanged(this, (AxisOrientation)newValue); } }
public LabelEvaluation UpdateLabel(string text, AxisCore axis, AxisOrientation source) { TextBlock.Text = text; TextBlock.UpdateLayout(); var transform = new LabelEvaluation(axis.View.LabelsRotation, TextBlock.ActualWidth, TextBlock.ActualHeight, axis, source); TextBlock.RenderTransform = Math.Abs(transform.LabelAngle) > 1 ? new RotateTransform(transform.LabelAngle) : null; LabelModel = transform; return transform; }
/// <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); } }
/// <summary> /// Recalculates a DateTime interval obtained from maximum and minimum DateTime. /// </summary> /// <param name="width">Width of available space</param> /// <param name="height">Height of available space</param> /// <param name="axisOrientation">Axis orientation</param> /// <param name="minDateTime">Minimum DateTime value</param> /// <param name="maxDateTime">Maximum DateTime Value</param> /// <param name="type">Current Interval type</param> /// <param name="maxInterval">Max Interval</param> /// <returns>Calculated auto interval</returns> public static double CalculateAutoInterval(Double width, Double height, AxisOrientation axisOrientation, DateTime minDateTime, DateTime maxDateTime, out IntervalTypes type, Double maxInterval, ChartValueTypes xValueType) { TimeSpan timeSpan = maxDateTime.Subtract(minDateTime); // Algorithm will interval close to 10. // We need to align the time span for PrefferedNumberOfIntervals double maxIntervals = axisOrientation == AxisOrientation.Horizontal ? maxInterval * 0.8 : maxInterval; double rangeMultiplicator = (axisOrientation == AxisOrientation.Horizontal ? width : height) / (200 * 10 / maxIntervals); timeSpan = new TimeSpan((long)((double)timeSpan.Ticks / rangeMultiplicator)); // TotalMinutes double totalMinutes = timeSpan.TotalMinutes; if (xValueType != ChartValueTypes.Date) { // For Range less than 60 seconds interval is 5 sec if (totalMinutes <= 1.0) { // Milli Seconds double milliSeconds = timeSpan.TotalMilliseconds; if (milliSeconds <= 10) { type = IntervalTypes.Milliseconds; return 1; } if (milliSeconds <= 50) { type = IntervalTypes.Milliseconds; return 4; } if (milliSeconds <= 200) { type = IntervalTypes.Milliseconds; return 20; } if (milliSeconds <= 500) { type = IntervalTypes.Milliseconds; return 50; } // Seconds double seconds = timeSpan.TotalSeconds; if (seconds <= 7) { type = IntervalTypes.Seconds; return 1; } else if (seconds <= 15) { type = IntervalTypes.Seconds; return 2; } else if (seconds <= 30) { type = IntervalTypes.Seconds; return 5; } else if (seconds <= 60) { type = IntervalTypes.Seconds; return 10; } } else if (totalMinutes <= 2.0) { // Range less than 120 seconds interval is 10 sec type = IntervalTypes.Seconds; return 20; } else if (totalMinutes <= 3.0) { // Range less than 180 seconds interval is 30 sec type = IntervalTypes.Seconds; return 30; } else if (totalMinutes <= 10) { // Range less than 10 minutes interval is 1 min type = IntervalTypes.Minutes; return 1; } else if (totalMinutes <= 20) { // Range less than 20 minutes interval is 1 min type = IntervalTypes.Minutes; return 2; } else if (totalMinutes <= 60) { // Range less than 60 minutes interval is 5 min type = IntervalTypes.Minutes; return 5; } else if (totalMinutes <= 120) { // Range less than 120 minutes interval is 10 min type = IntervalTypes.Minutes; return 10; } else if (totalMinutes <= 180) { // Range less than 180 minutes interval is 30 min type = IntervalTypes.Minutes; return 30; } else if (totalMinutes <= 60 * 12) { // Range less than 12 hours interval is 1 hour type = IntervalTypes.Hours; return 1; } else if (totalMinutes <= 60 * 24) { // Range less than 24 hours interval is 4 hour type = IntervalTypes.Hours; return 4; } else if (totalMinutes <= 60 * 24 * 2) { // Range less than 2 days interval is 6 hour type = IntervalTypes.Hours; return 6; } else if (totalMinutes <= 60 * 24 * 3) { // Range less than 3 days interval is 12 hour type = IntervalTypes.Hours; return 12; } } if (totalMinutes <= 60 * 24 * 10) { // Range less than 10 days interval is 1 day type = IntervalTypes.Days; return 1; } else if (totalMinutes <= 60 * 24 * 20) { // Range less than 20 days interval is 2 day type = IntervalTypes.Days; return 2; } else if (totalMinutes <= 60 * 24 * 30) { // Range less than 30 days interval is 3 day type = IntervalTypes.Days; return 3; } else if (totalMinutes <= 60 * 24 * 30.5 * 2) { // Range less than 2 months interval is 1 week type = IntervalTypes.Weeks; return 1; } else if (totalMinutes <= 60 * 24 * 30.5 * 5) { // Range less than 5 months interval is 2weeks type = IntervalTypes.Weeks; return 2; } else if (totalMinutes <= 60 * 24 * 30.5 * 12) { // Range less than 12 months interval is 1 month type = IntervalTypes.Months; return 1; } else if (totalMinutes <= 60 * 24 * 30.5 * 24) { // Range less than 24 months interval is 3 month type = IntervalTypes.Months; return 3; } else if (totalMinutes <= 60 * 24 * 30.5 * 48) { // Range less than 48 months interval is 6 months type = IntervalTypes.Months; return 6; } // Range more than 48 months interval is year type = IntervalTypes.Years; double years = totalMinutes / 60 / 24 / 365; if (years < 5) { return 1; } else if (years < 10) { return 2; } // Make a correction of the interval return Math.Floor(years / 5); }
internal Axis GetAxis(string axisName, AxisOrientation orientation) { return this.FindAxis(axisName, orientation) ?? this.CreateAxis(axisName, orientation); }
internal void UpdateSeparators(AxisOrientation 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 == AxisOrientation.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 == AxisOrientation.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 = TopLimit; LastAxisMin = BotLimit; LastPlotArea = new CoreRectangle(chart.DrawMargin.Left, chart.DrawMargin.Top, chart.DrawMargin.Width, chart.DrawMargin.Height); #if DEBUG Debug.WriteLine("Axis.Separations: " + Cache.Count); #endif }
/// <summary> /// Gets two points defining the axis of the object. /// </summary> /// public LineSegment GetAxis(AxisOrientation axis) { double x1, y1; double x2, y2; if (axis == AxisOrientation.Horizontal) { y1 = Math.Cos(-Angle - Math.PI) * Rectangle.Height / 2.0; x1 = Math.Sin(-Angle - Math.PI) * Rectangle.Width / 2.0; y2 = Math.Cos(-Angle) * Rectangle.Height / 2.0; x2 = Math.Sin(-Angle) * Rectangle.Width / 2.0; } else { y1 = Math.Cos(-(Angle + Math.PI / 2) - Math.PI) * Rectangle.Height / 2.0; x1 = Math.Sin(-(Angle + Math.PI / 2) - Math.PI) * Rectangle.Width / 2.0; y2 = Math.Cos(-(Angle + Math.PI / 2)) * Rectangle.Height / 2.0; x2 = Math.Sin(-(Angle + Math.PI / 2)) * Rectangle.Width / 2.0; } Point start = new Point((float)(Center.X + x1), (float)(Center.Y + y1)); Point end = new Point((float)(Center.X + x2), (float)(Center.Y + y2)); if (start.DistanceTo(end) == 0) return null; return new LineSegment(start, end); }
internal CoreMargin PrepareChart(AxisOrientation source, ChartCore chart) { if (!(Math.Abs(TopLimit - BotLimit) > S*.01) || !ShowLabels) return new CoreMargin(); CalculateSeparator(chart, source); var f = GetFormatter(); var currentMargin = new CoreMargin(); var tolerance = S/10; InitializeGarbageCollector(); var bl = Math.Ceiling(BotLimit/Magnitude)*Magnitude; for (var i = bl; i <= TopLimit - (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; }
internal double FromPreviousState(double value, AxisOrientation source, ChartCore chart) { if (LastAxisMax == null) return 0; var p1 = new CorePoint(); var p2 = new CorePoint(); if (source == AxisOrientation.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; }
internal void CalculateSeparator(ChartCore chart, AxisOrientation source) { var range = TopLimit - BotLimit; range = range <= 0 ? 1 : range; //ToDO: Improve this according to current labels! var separations = source == AxisOrientation.Y ? Math.Round(chart.ControlSize.Height/((12)*CleanFactor), 0) // at least 3 font 12 labels per separator. : Math.Round(chart.ControlSize.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 (!double.IsNaN(Separator.Step)) { S = Separator.Step; 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; }
/// <summary> /// Get or create a linear numeric axis in the correct dimension. /// </summary> /// <param name="orientation">Dimension of the axis to create.</param> /// <param name="oldAxis"> /// Old value of the axis in this dimension. /// </param> /// <returns>New value of the axis in this dimension.</returns> private IRangeAxis GetAxis(AxisOrientation orientation, IRangeAxis oldAxis) { // Check the existing axes for a potential axis IRangeAxis axis = (from IRangeAxis a in SeriesHost.Axes.OfType<IRangeAxis>() where a.Orientation == orientation select a) .FirstOrDefault(); if (axis == null) { // Create a new axis if not found axis = new LinearAxis { Orientation = orientation, }; } if (oldAxis != axis) { // Unregister any existing axis if (oldAxis != null) { SeriesHost.UnregisterWithAxis(this, oldAxis); oldAxis.Invalidated -= OnAxisInvalidated; } // Register the new axis SeriesHost.RegisterWithAxis(this, axis); axis.Invalidated += OnAxisInvalidated; } return axis; }
public void SetOrientation(AxisOrientation orientation) { CT_Scaling scaling = GetCTScaling(); ST_Orientation stOrientation = fromAxisOrientation(orientation); if (scaling.IsSetOrientation()) { scaling.orientation.val = stOrientation; } else { GetCTScaling().AddNewOrientation().val= stOrientation; } }
/// <summary> /// Get or create a linear numeric axis in the correct dimension. /// </summary> /// <param name="orientation">Dimension of the axis to create.</param> /// <param name="oldAxis"> /// Old value of the axis in this dimension. /// </param> /// <returns>New value of the axis in this dimension.</returns> private IRangeAxis GetAxis(AxisOrientation orientation, IRangeAxis oldAxis) { // Check the existing axes for a potential axis IRangeAxis axis = (from IRangeAxis a in SeriesHost.Axes.OfType<IRangeAxis>() where a.Orientation == orientation select a) .FirstOrDefault(); if (axis == null) { // Create a new axis if not found axis = new LinearAxis { Orientation = orientation, }; } if (oldAxis != axis) { // Unregister any existing axis if (oldAxis != null) { oldAxis.RegisteredListeners.Remove(this); } // Register the new axis if (!axis.RegisteredListeners.Contains(this)) { axis.RegisteredListeners.Add(this); } } return axis; }
private static ST_Orientation fromAxisOrientation(AxisOrientation orientation) { switch (orientation) { case AxisOrientation.MinToMax: return ST_Orientation.minMax; case AxisOrientation.MaxToMin: return ST_Orientation.maxMin; default: throw new ArgumentException(); } }
/// <summary> /// Reformulates the grid when the orientation is changed. Grid is /// either separated into two columns or two rows. The title is /// inserted with the outermost section from the edge and an oriented /// panel is inserted into the innermost section. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected override void OnOrientationPropertyChanged(AxisOrientation oldValue, AxisOrientation newValue) { ArrangeAxisGrid(); base.OnOrientationPropertyChanged(oldValue, newValue); }
/// <summary> /// Ases the core element. /// </summary> /// <param name="axis">The axis.</param> /// <param name="source">The source.</param> /// <returns></returns> public SeparatorConfigurationCore AsCoreElement(AxisCore axis, AxisOrientation source) { AxisOrientation = source; return new SeparatorConfigurationCore(axis) { IsEnabled = IsEnabled, Step = Step, Source = source }; }
private Axis FindAxis(string axisName, AxisOrientation orientation) { if (string.IsNullOrEmpty(axisName)) { foreach (Axis axis in (Collection<Axis>)this.Axes) { if (axis.Orientation == orientation) return axis; } } else { foreach (Axis axis in (Collection<Axis>)this.Axes) { if (axisName == axis.Name) return axis; } } return (Axis)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)); } }
public AxisSectionCore AsCoreElement(AxisCore axis, AxisOrientation source) { var model = new AxisSectionCore(this, axis.Chart); model.View.Model = model; return model; }
/// <summary> /// Updates the label. /// </summary> /// <param name="text">The text.</param> /// <param name="axis">The axis.</param> /// <param name="source">The source.</param> /// <returns></returns> public LabelEvaluation UpdateLabel(string text, AxisCore axis, AxisOrientation source) { TextBlock.Text = text; var formattedText = new FormattedText( TextBlock.Text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(TextBlock.FontFamily, TextBlock.FontStyle, TextBlock.FontWeight, TextBlock.FontStretch), TextBlock.FontSize, Brushes.Black); var transform = new LabelEvaluation(axis.View.LabelsRotation, formattedText.Width, formattedText.Height, axis, source); TextBlock.RenderTransform = Math.Abs(transform.LabelAngle) > 1 ? new RotateTransform(transform.LabelAngle) : null; LabelModel = transform; return transform; }
public void DrawOrMove(AxisOrientation source, int axis) { 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 from = ChartFunctions.ToDrawMargin(FromValue, source, Model.Chart, axis); var to = ChartFunctions.ToDrawMargin(ToValue, source, Model.Chart, axis); 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); Canvas.SetLeft(_label, (from + to)/2 - _label.ActualWidth/2); } else { _rectangle.BeginAnimation(WidthProperty, new DoubleAnimation(w > 0 ? w : 0, anSpeed)); _rectangle.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(from, anSpeed)); _label.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation((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.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(from, anSpeed)); _rectangle.BeginAnimation(HeightProperty, new DoubleAnimation(h, anSpeed)); _label.BeginAnimation(Canvas.TopProperty, new DoubleAnimation((from + to)/2 - _label.ActualHeight/2, anSpeed)); } }
private Axis FindAxis(DataValueType valueType, AxisOrientation orientation) { foreach (Axis axis in (Collection<Axis>)this.Axes) { if (axis.Orientation == orientation && axis.Scale.ValueType == valueType) return axis; } foreach (Axis axis in (Collection<Axis>)this.Axes) { if (axis.Orientation == orientation && axis.Scale.CanProject(valueType)) return axis; } return (Axis)null; }
/// <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)); 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); } }
/// <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; }
/// <summary> /// Updates the label. /// </summary> /// <param name="text">The text.</param> /// <param name="axis">The axis.</param> /// <param name="source">The source.</param> /// <returns></returns> public LabelEvaluation UpdateLabel(string text, AxisCore axis, AxisOrientation source) { TextBlock.Text = text; TextBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); var transform = new LabelEvaluation(axis.View.LabelsRotation, TextBlock.DesiredSize.Width, TextBlock.DesiredSize.Height, axis, source); TextBlock.RenderTransform = Math.Abs(transform.LabelAngle) > 1 ? new RotateTransform { Angle = transform.LabelAngle } : null; LabelModel = transform; return transform; }