private void OnPlotterChildrenChanged(object sender, NotifyCollectionChangedEventArgs e) { bool updateVisible = false; if (e.NewItems != null) { foreach (IPlotterElement item in e.NewItems) { if (Viewport2D.GetIsContentBoundsHost(plotter.VisualBindings[item])) { DebugVerify.Is(!contentBoundsHosts.Contains(item)); updateVisible = true; contentBoundsHosts.Add(item); } } } if (e.OldItems != null) { foreach (IPlotterElement item in e.OldItems) { if (contentBoundsHosts.Contains(item)) { updateVisible = true; contentBoundsHosts.Remove(item); } } } if (updateVisible && IsFittedToView) { UpdateVisible(); } }
/// <summary> /// Gets the ticks. /// </summary> /// <param name="range">The range.</param> /// <param name="ticksCount">The ticks count.</param> /// <returns></returns> public override ITicksInfo <DateTime> GetTicks(Range <DateTime> range, int ticksCount) { Verify.Is(ticksCount > 0); DateTime start = range.Min; DateTime end = range.Max; TimeSpan length = end - start; diff = GetDifference(length); TicksInfo <DateTime> res = new TicksInfo <DateTime> { Info = diff }; if (providers.ContainsKey(diff)) { ITicksInfo <DateTime> result = providers[diff].GetTicks(range, ticksCount); DateTime[] mayorTicks = result.Ticks; res.Ticks = mayorTicks; DifferenceIn lowerDiff = DifferenceIn.Year; // todo разобраться с minor ticks bool lowerDiffExists = TryGetLowerDiff(diff, out lowerDiff); if (lowerDiffExists && providers.ContainsKey(lowerDiff)) { var minorTicks = result.Ticks.GetPairs().Select(r => ((IMinorTicksProvider <DateTime>)providers[lowerDiff]).CreateTicks(r)). SelectMany(m => m).ToArray(); res.MinorTicks = minorTicks; } return(res); } DateTime newStart = RoundDown(start, diff); DateTime newEnd = RoundUp(end, diff); DebugVerify.Is(newStart <= start); List <DateTime> resultTicks = new List <DateTime>(); DateTime dt = newStart; do { resultTicks.Add(dt); dt = Shift(dt, diff); } while (dt <= newEnd); while (resultTicks.Count > ticksCount) { var res2 = resultTicks; resultTicks = res2.Where((date, i) => i % 2 == 0).ToList(); } res.Ticks = resultTicks.ToArray(); return(res); }
private void CreateTicks() { TickChange result = TickChange.OK; TickChange prevResult; int prevActualTickCount = -1; int tickCount = DefaultTicksProvider.DefaultTicksCount; int iteration = 0; do { Verify.IsTrue(++iteration < maxTickArrangeIterations); ticksInfo = ticksProvider.GetTicks(range, tickCount); ticks = ticksInfo.Ticks; if (ticks.Length == prevActualTickCount) { result = TickChange.OK; break; } prevActualTickCount = ticks.Length; labels = labelProvider.CreateLabels(ticksInfo); prevResult = result; result = CheckLabelsArrangement(labels, ticks); if (prevResult == TickChange.Decrease && result == TickChange.Increase) { // stop tick number oscillating result = TickChange.OK; } if (result != TickChange.OK) { int prevTickCount = tickCount; if (result == TickChange.Decrease) { tickCount = ticksProvider.DecreaseTickCount(tickCount); } else { tickCount = ticksProvider.IncreaseTickCount(tickCount); DebugVerify.Is(tickCount >= prevTickCount); } // ticks provider cannot create less ticks or tick number didn't change if (tickCount == 0 || prevTickCount == tickCount) { tickCount = prevTickCount; result = TickChange.OK; } } } while (result != TickChange.OK); }
/// <summary> /// Increases the tick count. /// </summary> /// <param name="tickCount">The tick count.</param> /// <returns></returns> public override int IncreaseTickCount(int tickCount) { DebugVerify.Is(tickCount < 2000); if (providers.ContainsKey(diff)) { return(providers[diff].IncreaseTickCount(tickCount)); } return(tickCount * 2); }
public Quad(Point v00, Point v01, Point v11, Point v10) { DebugVerify.IsNotNaN(v00); DebugVerify.IsNotNaN(v01); DebugVerify.IsNotNaN(v11); DebugVerify.IsNotNaN(v10); this.v00 = v00; this.v01 = v01; this.v10 = v10; this.v11 = v11; }
public Range(T min, T max) { this.min = min; this.max = max; #if DEBUG if (min is IComparable) { IComparable c1 = (IComparable)min; IComparable c2 = (IComparable)max; DebugVerify.Is(c1.CompareTo(c2) <= 0); } #endif }
public ValuesInCell(double leftBottom, double rightBottom, double rightTop, double leftTop) { DebugVerify.IsNotNaN(leftBottom); DebugVerify.IsNotNaN(rightBottom); DebugVerify.IsNotNaN(rightTop); DebugVerify.IsNotNaN(leftTop); this.leftTop = leftTop; this.leftBottom = leftBottom; this.rightTop = rightTop; this.rightBottom = rightBottom; left = (leftTop + leftBottom) / 2; right = (rightTop + rightBottom) / 2; top = (leftTop + rightTop) / 2; bottom = (leftBottom + rightBottom) / 2; }
private static int[] CreateTicks(double start, double finish, int step) { DebugVerify.Is(step != 0); int x = (int)(step * Math.Floor(start / (double)step)); List <int> res = new List <int>(); checked { double increasedFinish = finish + step * 1.05; while (x <= increasedFinish) { res.Add(x); x += step; } } return(res.ToArray()); }
private static double[] CreateTicks(double start, double finish, double step) { DebugVerify.Is(step != 0.0); double x = step * Math.Floor(start / step); List <double> res = new List <double>(); double increasedFinish = finish + step * 1.05; //double increasedFinish = finish; while (x <= increasedFinish) { res.Add(x); x += step; } return(res.ToArray()); }
protected sealed override DateTime RoundDown(DateTime time, DifferenceIn diff) { DateTime res = time; switch (diff) { case DifferenceIn.Year: res = new DateTime(time.Year, 1, 1); break; case DifferenceIn.Month: res = new DateTime(time.Year, time.Month, 1); break; case DifferenceIn.Day: res = time.Date; break; case DifferenceIn.Hour: res = time.Date.AddHours(time.Hour); break; case DifferenceIn.Minute: res = time.Date.AddHours(time.Hour).AddMinutes(time.Minute); break; case DifferenceIn.Second: res = time.Date.AddHours(time.Hour).AddMinutes(time.Minute).AddSeconds(time.Second); break; case DifferenceIn.Millisecond: res = time.Date.AddHours(time.Hour).AddMinutes(time.Minute).AddSeconds(time.Second).AddMilliseconds(time.Millisecond); break; default: break; } DebugVerify.Is(res <= time); return(res); }
protected static DateTime RoundDown(DateTime dateTime, DifferenceIn diff) { DateTime res = dateTime; switch (diff) { case DifferenceIn.Year: res = new DateTime(dateTime.Year, 1, 1); break; case DifferenceIn.Month: res = new DateTime(dateTime.Year, dateTime.Month, 1); break; case DifferenceIn.Day: res = dateTime.Date; break; case DifferenceIn.Hour: res = dateTime.Date.AddHours(dateTime.Hour); break; case DifferenceIn.Minute: res = dateTime.Date.AddHours(dateTime.Hour).AddMinutes(dateTime.Minute); break; case DifferenceIn.Second: res = dateTime.Date.AddHours(dateTime.Hour).AddMinutes(dateTime.Minute).AddSeconds(dateTime.Second); break; case DifferenceIn.Millisecond: res = dateTime.Date.AddHours(dateTime.Hour).AddMinutes(dateTime.Minute).AddSeconds(dateTime.Second).AddMilliseconds(dateTime.Millisecond); break; } DebugVerify.Is(res <= dateTime); return(res); }
public override UIElement[] CreateLabels(ITicksInfo <DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; UIElement[] res = new UIElement[ticks.Length - 1]; int labelsNum = 3; if (info is DifferenceIn) { DifferenceIn diff = (DifferenceIn)info; DateFormat = GetDateFormat(diff); } else if (info is MayorLabelsInfo) { MayorLabelsInfo mInfo = (MayorLabelsInfo)info; DifferenceIn diff = (DifferenceIn)mInfo.Info; DateFormat = GetDateFormat(diff); labelsNum = mInfo.MayorLabelsCount + 1; //DebugVerify.Is(labelsNum < 100); } DebugVerify.Is(ticks.Length < 10); LabelTickInfo <DateTime> tickInfo = new LabelTickInfo <DateTime>(); for (int i = 0; i < ticks.Length - 1; i++) { tickInfo.Info = info; tickInfo.Tick = ticks[i]; string tickText = GetString(tickInfo); Grid grid = new Grid { Background = Brushes.Beige }; Rectangle rect = new Rectangle { Stroke = Brushes.Peru, StrokeThickness = 2 }; Grid.SetColumn(rect, 0); Grid.SetColumnSpan(rect, labelsNum); for (int j = 0; j < labelsNum; j++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); } grid.Children.Add(rect); for (int j = 0; j < labelsNum; j++) { var tb = new TextBlock { Text = tickText, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 3, 0, 3) }; Grid.SetColumn(tb, j); grid.Children.Add(tb); } ApplyCustomView(tickInfo, grid); res[i] = grid; } return(res); }
public Point ToData(Point screenPoint) { DebugVerify.Is(inited); return(new Point(screenPoint.X * rxToData - cxToData, cyToData - screenPoint.Y * ryToData)); }
public Point ToScreen(Point dataPoint) { DebugVerify.Is(inited); return(new Point(dataPoint.X * rxToScreen - cxToScreen, cyToScreen - dataPoint.Y * ryToScreen)); }
public override UIElement[] CreateLabels(ITicksInfo <DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; UIElement[] res = new UIElement[ticks.Length - 1]; int labelsNum = 3; if (info is DifferenceIn) { DifferenceIn diff = (DifferenceIn)info; DateFormat = GetDateFormat(diff); } else if (info is MajorLabelsInfo) { MajorLabelsInfo mInfo = (MajorLabelsInfo)info; DifferenceIn diff = (DifferenceIn)mInfo.Info; DateFormat = GetDateFormat(diff); labelsNum = mInfo.MajorLabelsCount + 1; //DebugVerify.Is(labelsNum < 100); } DebugVerify.Is(ticks.Length < 10); LabelTickInfo <DateTime> tickInfo = new LabelTickInfo <DateTime>(); for (int i = 0; i < ticks.Length - 1; i++) { tickInfo.Info = info; tickInfo.Tick = ticks[i]; string tickText = GetString(tickInfo); Grid grid = new Grid { }; // doing binding as described at http://sdolha.spaces.live.com/blog/cns!4121802308C5AB4E!3724.entry?wa=wsignin1.0&sa=835372863 grid.SetBinding(Grid.BackgroundProperty, new Binding { Path = new PropertyPath("(0)", DateTimeAxis.MajorLabelBackgroundBrushProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(AxisControlBase) } }); Rectangle rect = new Rectangle { StrokeThickness = 2 }; rect.SetBinding(Rectangle.StrokeProperty, new Binding { Path = new PropertyPath("(0)", DateTimeAxis.MajorLabelRectangleBorderPropertyProperty), RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(AxisControlBase) } }); Grid.SetColumn(rect, 0); Grid.SetColumnSpan(rect, labelsNum); for (int j = 0; j < labelsNum; j++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); } grid.Children.Add(rect); for (int j = 0; j < labelsNum; j++) { var tb = new TextBlock { Text = tickText, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 3, 0, 3) }; Grid.SetColumn(tb, j); grid.Children.Add(tb); } ApplyCustomView(tickInfo, grid); res[i] = grid; } return(res); }
public ValuesInCell(double leftBottom, double rightBottom, double rightTop, double leftTop, double missingValue) { DebugVerify.IsNotNaN(leftBottom); DebugVerify.IsNotNaN(rightBottom); DebugVerify.IsNotNaN(rightTop); DebugVerify.IsNotNaN(leftTop); // Copy values and find min and max with respect to possible missing values if (leftTop != missingValue) { this.leftTop = leftTop; if (min > leftTop) { min = leftTop; } if (max < leftTop) { max = leftTop; } } else { this.leftTop = Double.NaN; } if (leftBottom != missingValue) { this.leftBottom = leftBottom; if (min > leftBottom) { min = leftBottom; } if (max < leftBottom) { max = leftBottom; } } else { this.leftBottom = Double.NaN; } if (rightTop != missingValue) { this.rightTop = rightTop; if (min > rightTop) { min = rightTop; } if (max < rightTop) { max = rightTop; } } else { this.rightTop = Double.NaN; } if (rightBottom != missingValue) { this.rightBottom = rightBottom; if (min > rightBottom) { min = rightBottom; } if (max < rightBottom) { max = rightBottom; } } else { this.rightBottom = Double.NaN; } left = (this.leftTop + this.leftBottom) / 2; bottom = (this.leftBottom + this.rightBottom) / 2; right = (this.rightTop + this.rightBottom) / 2; top = (this.rightTop + this.leftTop) / 2; /* * if (leftTop != missingValue && ) * { * if (leftBottom != missingValue) * left = (leftTop + leftBottom) / 2; * else * left = Double.NaN; * * if (rightTop != missingValue) * top = (leftTop + rightTop) / 2; * else * top = Double.NaN; * } * * if (rightBottom != missingValue) * { * if (leftBottom != missingValue) * bottom = (leftBottom + rightBottom) / 2; * else * bottom = Double.NaN; * * if (rightTop != missingValue) * right = (rightTop + rightBottom) / 2; * else * right = Double.NaN; * }*/ }