private void PointAway(out double xMax, out double yMax, out double xMin, out double yMin) { xMax = XRange.Max(); yMax = YValues.Max(); xMin = XRange.Min(); yMin = YValues.Min(); }
private void CalcGridSize() { var xmax = XValues.Max(); var ymax = YValues.Max(); var xmin = XValues.Min(); var ymin = YValues.Min(); // Calculate axis range var xrange = Math.Abs(xmax - xmin); var yrange = Math.Abs(ymax - ymin); if (xrange > yrange) { // Determine spacing with nx points grid Nx = 200; Dx = xrange / (Nx - 1); // Determine number of y grid so that the space is equal Ny = Convert.ToInt32(Math.Ceiling(yrange / Dx)); Dy = yrange / (Ny - 1); } else { Ny = 200; Dy = yrange / (Ny - 1); Nx = Convert.ToInt32(Math.Ceiling(xrange / Dy)); Dx = xrange / (Nx - 1); } }
public void ReadyControl() { ChartArea.Children.Clear(); Legend.Children.Clear(); _maxValue = YValues.Max(x => x.Max) > 0 ? CanvasHelper.GetGridLineMax(YValues.Max(x => x.Max)) : 10; _xLabelsCount = XLabels.Count > 0 ? XLabels.Count : 1; _helper = new CanvasHelper(new Point(0, 0), new Point(_margin, ChartGridHeight), new Point(_xLabelsCount, _maxValue), new Point(ChartAreaWidth, 0)); DrawBackground(); DrawGridLines(); DrawDataPoint(); DrawXAxis(); DrawYAxis(); DrawLegend(); }
/// <summary> /// Animates the series. /// </summary> internal override void Animate() { int i = 0; // WPF-25124 Animation not working properly when resize the window. if (this.AnimationStoryboard != null) { AnimationStoryboard.Stop(); if (!this.canAnimate) { this.ResetAdornmentAnimationState(); return; } } this.AnimationStoryboard = new Storyboard(); foreach (LineSegment3D segment in this.Segments) { var dblAnimationKeyFrames = new DoubleAnimationUsingKeyFrames(); var min = YValues.Min(); var keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)), Value = double.IsNaN(min) ? YValues.Where(e => !double.IsNaN(e)).Min() : min }; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); keyFrame = new SplineDoubleKeyFrame { KeyTime = KeyTime.FromTimeSpan(AnimationDuration), Value = YValues.Max() }; var keySpline = new KeySpline { ControlPoint1 = new Point(0.64, 0.84), ControlPoint2 = new Point(0.67, 0.95) }; keyFrame.KeySpline = keySpline; dblAnimationKeyFrames.KeyFrames.Add(keyFrame); Storyboard.SetTargetProperty(dblAnimationKeyFrames, "LineSegment3D.Y"); dblAnimationKeyFrames.EnableDependentAnimation = true; Storyboard.SetTarget(dblAnimationKeyFrames, segment); AnimationStoryboard.Children.Add(dblAnimationKeyFrames); if (this.AdornmentsInfo != null) { double secondsPerPoint = AnimationDuration.TotalSeconds / YValues.Count; secondsPerPoint *= 2; foreach (FrameworkElement label in this.AdornmentsInfo.LabelPresenters) { DoubleAnimation keyFrames1 = new DoubleAnimation() { From = 0.5, To = 1, Duration = TimeSpan.FromSeconds(AnimationDuration.TotalSeconds / 2), BeginTime = TimeSpan.FromSeconds(i * secondsPerPoint) }; Storyboard.SetTargetProperty(keyFrames1, "(UIElement.Opacity)"); Storyboard.SetTarget(keyFrames1, label); AnimationStoryboard.Children.Add(keyFrames1); i++; } } } AnimationStoryboard.Begin(); }
private void UpdateSample(TimeSpan sampleTime, TimeSpan sampleBackFor) { var sampleLimit = DateTimeOffset.Now - sampleBackFor; XMinimum = sampleLimit.ToUnixTimeMilliseconds(); var values = _history.SelectTimeSampleBackwards( x => x.Date, x => x.Balance, sampleTime, sampleLimit, DateTime.Now); XValues.Clear(); YValues.Clear(); foreach (var(timestamp, balance) in values.Reverse()) { YValues.Add((double)balance.ToDecimal(MoneyUnit.BTC)); XValues.Add(timestamp.ToUnixTimeMilliseconds()); } if (YValues.Any()) { var maxY = YValues.Max(); YLabels = new List <string> { "0", (maxY / 2).ToString("F2"), maxY.ToString("F2") }; } else { YLabels = null; } if (XValues.Any()) { var minX = XValues.Min(); var maxX = XValues.Max(); var halfX = minX + ((maxX - minX) / 2); var range = DateTimeOffset.FromUnixTimeMilliseconds((long)maxX) - DateTimeOffset.FromUnixTimeMilliseconds((long)minX); if (range <= TimeSpan.FromDays(1)) { XLabels = new List <string> { DateTimeOffset.FromUnixTimeMilliseconds((long)minX).DateTime.ToString("t"), DateTimeOffset.FromUnixTimeMilliseconds((long)halfX).DateTime.ToString("t"), DateTimeOffset.FromUnixTimeMilliseconds((long)maxX).DateTime.ToString("t"), }; } else if (range <= TimeSpan.FromDays(7)) { XLabels = new List <string> { DateTimeOffset.FromUnixTimeMilliseconds((long)minX).DateTime.ToString("ddd MMM-d"), DateTimeOffset.FromUnixTimeMilliseconds((long)halfX).DateTime.ToString("ddd MMM-d"), DateTimeOffset.FromUnixTimeMilliseconds((long)maxX).DateTime.ToString("ddd MMM-d"), }; } else { XLabels = new List <string> { DateTimeOffset.FromUnixTimeMilliseconds((long)minX).DateTime.ToString("MMM-d"), DateTimeOffset.FromUnixTimeMilliseconds((long)halfX).DateTime.ToString("MMM-d"), DateTimeOffset.FromUnixTimeMilliseconds((long)maxX).DateTime.ToString("MMM-d"), }; } } else { XLabels = null; } }