public override List<FrameworkElement> CreateLabels(ITicksInfo<double> ticksInfo) { tickInfo.Info = ticksInfo.Info; var ticks = ticksInfo.Ticks; Init(ticks); int numOfTicks=ticks.Length; for (int i = 0; i < numOfTicks; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string label = GetString(tickInfo); if (i < allocatedTextBlocksCount) { allocatedTextBlocksList[i].Text=label; } else { TextBlock t = new TextBlock() { Text = label }; allocatedTextBlocksList.Add(t); allocatedFrameworkElementsList.Add(t); } ApplyCustomView(tickInfo, allocatedTextBlocksList[i]); } if (allocatedTextBlocksCount > numOfTicks) { allocatedTextBlocksList.RemoveRange(ticks.Length, allocatedTextBlocksCount - numOfTicks); allocatedFrameworkElementsList.RemoveRange(ticks.Length, allocatedTextBlocksCount - numOfTicks); } allocatedTextBlocksCount = numOfTicks; return allocatedFrameworkElementsList; }
public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string labelText = GetString(tickInfo); TextBlock label = (TextBlock)GetResourceFromPool(); if (label == null) { label = new TextBlock(); } label.Text = labelText; label.ToolTip = ticks[i].ToString(); res[i] = label; ApplyCustomView(tickInfo, label); } return res; }
public override UIElement[] CreateLabels(ITicksInfo<DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; if (info is DifferenceIn) { DifferenceIn diff = (DifferenceIn)info; DateFormat = GetDateFormat(diff); } LabelTickInfo<DateTime> tickInfo = new LabelTickInfo<DateTime> { Info = info }; UIElement[] res = new UIElement[ticks.Length]; for (int i = 0; i < ticks.Length; i++) { tickInfo.Tick = ticks[i]; string tickText = GetString(tickInfo); UIElement label = new TextBlock { Text = tickText, ToolTip = ticks[i] }; ApplyCustomView(tickInfo, label); res[i] = label; } return res; }
private void CreateTicks() { TickCountChange result = TickCountChange.OK; TickCountChange prevResult; int prevActualTickCount = -1; int tickCount = previousTickCount; int iteration = 0; do { Verify.IsTrue(++iteration < maxTickArrangeIterations); ticksInfo = ticksProvider.GetTicks(range, tickCount); ticks = ticksInfo.Ticks; if (ticks.Length == prevActualTickCount) { result = TickCountChange.OK; break; } prevActualTickCount = ticks.Length; labels = labelProvider.CreateLabels(ticksInfo); prevResult = result; result = CheckLabelsArrangement(labels, ticks); if (prevResult == TickCountChange.Decrease && result == TickCountChange.Increase) { // stop tick number oscillating result = TickCountChange.OK; } if (result != TickCountChange.OK) { int prevTickCount = tickCount; if (result == TickCountChange.Decrease) tickCount = ticksProvider.DecreaseTickCount(tickCount); else { tickCount = ticksProvider.IncreaseTickCount(tickCount); //DebugVerify.Is(tickCount >= prevTickCount); } // ticks provider could not create less ticks or tick number didn't change if (tickCount == 0 || prevTickCount == tickCount) { tickCount = prevTickCount; result = TickCountChange.OK; } } } while (result != TickCountChange.OK); previousTickCount = tickCount; }
private TickCountChange CheckMinorTicksArrangement(ITicksInfo<T> minorTicks) { Size renderSize = RenderSize; TickCountChange result = TickCountChange.OK; if (minorTicks.Ticks.Length * 3 > getSize(renderSize)) result = TickCountChange.Decrease; else if (minorTicks.Ticks.Length * 6 < getSize(renderSize)) result = TickCountChange.Increase; return result; }
public MinorTickInfo <DateTime>[] CreateTicks(Range <DateTime> range) { int tickCount = tickCounts[1]; ITicksInfo <DateTime> ticks = GetTicks(range, tickCount); MinorTickInfo <DateTime>[] res = ticks.Ticks. Select(dt => new MinorTickInfo <DateTime>(0.5, dt)).ToArray(); return(res); }
/// <summary> /// Creates labels by given ticks info. /// Is not intended to be called from your code. /// </summary> /// <param name="ticksInfo">The ticks info.</param> /// <returns> /// Array of <see cref="UIElement"/>s, which are axis labels for specified axis ticks. /// </returns> public override UIElement[] CreateLabels(ITicksInfo <double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo <double> tickInfo = new LabelTickInfo <double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { var tick = ticks[i]; tickInfo.Tick = tick; tickInfo.Index = i; string labelText = GetString(tickInfo); TextBlock label; if (labelText.Contains('E')) { string[] substrs = labelText.Split('E'); string mantissa = substrs[0]; string exponenta = substrs[1]; exponenta = exponenta.TrimStart('+'); Span span = new Span(); span.Inlines.Add(String.Format(CultureInfo.CurrentCulture, "{0}·10", mantissa)); Span exponentaSpan = new Span(new Run(exponenta)); exponentaSpan.BaselineAlignment = BaselineAlignment.Superscript; exponentaSpan.FontSize = 8; span.Inlines.Add(exponentaSpan); label = new TextBlock(span); LabelProviderProperties.SetExponentialIsCommonLabel(label, false); } else { label = (TextBlock)GetResourceFromPool(); if (label == null) { label = new TextBlock(); } label.Text = labelText; } res[i] = label; label.ToolTip = tick.ToString(CultureInfo.CurrentCulture); ApplyCustomView(tickInfo, label); } return(res); }
public override UIElement[] CreateLabels(ITicksInfo <T> ticksInfo) { UIElement[] res = base.CreateLabels(ticksInfo); foreach (var e in res) { e.Visibility = Visibility.Collapsed; } return(res); }
/// <summary> /// Creates labels by given ticks info. /// Is not intended to be called from your code. /// </summary> /// <param name="ticksInfo">The ticks info.</param> /// <returns> /// Array of <see cref="UIElement"/>s, which are axis labels for specified axis ticks. /// </returns> public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { var tick = ticks[i]; tickInfo.Tick = tick; tickInfo.Index = i; string labelText = GetString(tickInfo); TextBlock label; if (labelText.Contains('E')) { string[] substrs = labelText.Split('E'); string mantissa = substrs[0]; string exponenta = substrs[1]; exponenta = exponenta.TrimStart('+'); Span span = new Span(); span.Inlines.Add(String.Format(CultureInfo.CurrentCulture, "{0}·10", mantissa)); Span exponentaSpan = new Span(new Run(exponenta)); exponentaSpan.BaselineAlignment = BaselineAlignment.Superscript; exponentaSpan.FontSize = 8; span.Inlines.Add(exponentaSpan); label = new TextBlock(span); LabelProviderProperties.SetExponentialIsCommonLabel(label, false); } else { label = (TextBlock)GetResourceFromPool(); if (label == null) { label = new TextBlock(); } label.Text = labelText; } res[i] = label; label.ToolTip = tick.ToString(CultureInfo.CurrentCulture); ApplyCustomView(tickInfo, label); } return res; }
private TickChange CheckMinorTicksArrangement(ITicksInfo <T> minorTicks) { Size renderSize = DesiredSize; TickChange result = TickChange.OK; if (minorTicks.Ticks.Length * 3 > getSize(DesiredSize)) { result = TickChange.Decrease; } else if (minorTicks.Ticks.Length * 6 < getSize(DesiredSize)) { result = TickChange.Increase; } return(result); }
public override UIElement[] CreateLabels(ITicksInfo <double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo <double> tickInfo = new LabelTickInfo <double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string label = GetString(tickInfo); if (label.Contains('E')) { string[] substrs = label.Split('E'); string mantissa = substrs[0]; string exponenta = substrs[1]; exponenta = exponenta.TrimStart('+'); Span span = new Span(); span.Inlines.Add(String.Format(CultureInfo.CurrentCulture, "{0}·10", mantissa)); Span exponentaSpan = new Span(new Run(exponenta)); exponentaSpan.BaselineAlignment = BaselineAlignment.Superscript; exponentaSpan.FontSize = 8; span.Inlines.Add(exponentaSpan); res[i] = new TextBlock(span); } else { res[i] = new TextBlock { Text = label }; } ((TextBlock)res[i]).ToolTip = ticks[i].ToString(CultureInfo.CurrentCulture); ApplyCustomView(tickInfo, res[i]); } return(res); }
public override List<FrameworkElement> CreateLabels(ITicksInfo<DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; if (info is DifferenceIn) { DifferenceIn diff = (DifferenceIn)info; DateFormat = GetDateFormat(diff); } tickInfo.Info = info; int ticksNum = ticks.Length; for (int i = 0; i < ticksNum; i++) { tickInfo.Tick = ticks[i]; string tickText = GetString(tickInfo); TextBlock label; if (i < allocatedCount) { label = allocatedTextBlocksList[i]; } else { label = new TextBlock(); allocatedFrameworkElementList.Add(label); allocatedTextBlocksList.Add(label); } label.Text = tickText; ApplyCustomView(tickInfo, label); } if (allocatedCount > ticksNum) { allocatedFrameworkElementList.RemoveRange(ticksNum, allocatedCount - ticksNum); allocatedTextBlocksList.RemoveRange(ticksNum, allocatedCount - ticksNum); } allocatedCount = ticksNum; return allocatedFrameworkElementList; }
public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string label = GetString(tickInfo); if (label.Contains('E')) { string[] substrs = label.Split('E'); string mantissa = substrs[0]; string exponenta = substrs[1]; exponenta = exponenta.TrimStart('+'); Span span = new Span(); span.Inlines.Add(String.Format(CultureInfo.CurrentCulture, "{0}·10", mantissa)); Span exponentaSpan = new Span(new Run(exponenta)); exponentaSpan.BaselineAlignment = BaselineAlignment.Superscript; exponentaSpan.FontSize = 8; span.Inlines.Add(exponentaSpan); res[i] = new TextBlock(span); } else { res[i] = new TextBlock { Text = label }; } ((TextBlock)res[i]).ToolTip = ticks[i].ToString(CultureInfo.CurrentCulture); ApplyCustomView(tickInfo, res[i]); } return res; }
public override List <FrameworkElement> CreateLabels(ITicksInfo <DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; if (info is DifferenceIn) { DifferenceIn diff = (DifferenceIn)info; DateFormat = GetDateFormat(diff); } tickInfo.Info = info; int ticksNum = ticks.Length; for (int i = 0; i < ticksNum; i++) { tickInfo.Tick = ticks[i]; string tickText = GetString(tickInfo); TextBlock label; if (i < allocatedCount) { label = allocatedTextBlocksList[i]; } else { label = new TextBlock(); allocatedFrameworkElementList.Add(label); allocatedTextBlocksList.Add(label); } label.Text = tickText; ApplyCustomView(tickInfo, label); } if (allocatedCount > ticksNum) { allocatedFrameworkElementList.RemoveRange(ticksNum, allocatedCount - ticksNum); allocatedTextBlocksList.RemoveRange(ticksNum, allocatedCount - ticksNum); } allocatedCount = ticksNum; return(allocatedFrameworkElementList); }
public override List <FrameworkElement> CreateLabels(ITicksInfo <double> ticksInfo) { tickInfo.Info = ticksInfo.Info; var ticks = ticksInfo.Ticks; Init(ticks); int numOfTicks = ticks.Length; for (int i = 0; i < numOfTicks; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string label = GetString(tickInfo); if (i < allocatedTextBlocksCount) { allocatedTextBlocksList[i].Text = label; } else { TextBlock t = new TextBlock() { Text = label }; allocatedTextBlocksList.Add(t); allocatedFrameworkElementsList.Add(t); } ApplyCustomView(tickInfo, allocatedTextBlocksList[i]); } if (allocatedTextBlocksCount > numOfTicks) { allocatedTextBlocksList.RemoveRange(ticks.Length, allocatedTextBlocksCount - numOfTicks); allocatedFrameworkElementsList.RemoveRange(ticks.Length, allocatedTextBlocksCount - numOfTicks); } allocatedTextBlocksCount = numOfTicks; return(allocatedFrameworkElementsList); }
public override UIElement[] CreateLabels(ITicksInfo <TimeSpan> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; LabelTickInfo <TimeSpan> tickInfo = new LabelTickInfo <TimeSpan>(); UIElement[] res = new UIElement[ticks.Length]; for (int i = 0; i < ticks.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Info = info; string tickText = GetString(tickInfo); UIElement label = new TextBlock { Text = tickText, ToolTip = ticks[i] }; res[i] = label; } return(res); }
private ITicksInfo <T> Clip(ITicksInfo <T> ticks, Range <T> range) { var newTicks = new List <T>(ticks.Ticks.Length); var newSizes = new List <double>(ticks.TickSizes.Length); for (int i = 0; i < ticks.Ticks.Length; i++) { T tick = ticks.Ticks[i]; if (IsInside(tick, range)) { newTicks.Add(tick); newSizes.Add(ticks.TickSizes[i]); } } return(new TicksInfo <T> { Ticks = newTicks.ToArray(), TickSizes = newSizes.ToArray(), Info = ticks.Info }); }
public override UIElement[] CreateLabels(ITicksInfo <T> ticksInfo) { var ticks = ticksInfo.Ticks; var info = ticksInfo.Info; LabelTickInfo <T> tickInfo = new LabelTickInfo <T>(); UIElement[] res = new UIElement[ticks.Length]; for (int i = 0; i < res.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Info = info; string text = GetString(tickInfo); res[i] = new TextBlock { Text = text, ToolTip = ticks[i].ToString() }; } return(res); }
public override UIElement[] CreateLabels(ITicksInfo <TAxis> ticksInfo) { var ticks = ticksInfo.Ticks; if (ticks.Length == 0) { return(EmptyLabelsArray); } startIndex = (int)ticksInfo.Info; UIElement[] result = new UIElement[ticks.Length]; LabelTickInfo <TAxis> labelInfo = new LabelTickInfo <TAxis> { Info = ticksInfo.Info }; for (int i = 0; i < result.Length; i++) { var tick = ticks[i]; labelInfo.Tick = tick; labelInfo.Index = i; string labelText = GetString(labelInfo); TextBlock label = new TextBlock { Text = labelText }; ApplyCustomView(labelInfo, label); result[i] = label; } return(result); }
public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string label = GetString(tickInfo); res[i] = new TextBlock { Text = label, ToolTip = ticks[i].ToString() }; ApplyCustomView(tickInfo, res[i]); } 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); }
/// <summary> /// Creates the labels by given ticks info. /// </summary> /// <param name="ticksInfo">The ticks info.</param> /// <returns></returns> public abstract List <FrameworkElement> CreateLabels(ITicksInfo <T> ticksInfo);
public override List<FrameworkElement> CreateLabels(ITicksInfo<DateTime> ticksInfo) { object info = ticksInfo.Info; var ticks = ticksInfo.Ticks; FrameworkElement[] res = new FrameworkElement[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 = new SolidColorBrush(Colors.LightGray) }; Rectangle rect = new Rectangle { Stroke = new SolidColorBrush(Colors.DarkGray), 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 new List<FrameworkElement>(res); }
private void CreateTicks() { TickChange result = TickChange.OK; TickChange prevResult; int prevActualTickCount = -1; int tickCount = DefaultTicksProvider.DefaultTicksCount; int iteration = 0; bool stopTicksCountTuning = false; 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; if (tickCount > TicksUpperConstraint) { result = TickChange.Decrease; } else { 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; } } ticksGenNumber = tickCount; } while (result != TickChange.OK && !stopTicksCountTuning); }
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 abstract UIElement[] CreateLabels(ITicksInfo <T> ticksInfo);
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; }
/// <summary> /// Creates labels by given ticks info. /// Is not intended to be called from your code. /// </summary> /// <param name="ticksInfo">The ticks info.</param> /// <returns> /// Array of <see cref="UIElement"/>s, which are axis labels for specified axis ticks. /// </returns> public override UIElement[] CreateLabels(ITicksInfo <double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo <double> tickInfo = new LabelTickInfo <double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { var tick = ticks[i]; tickInfo.Tick = tick; tickInfo.Index = i; string labelText = GetString(tickInfo); TextBlock label; if (labelText.Contains('E')) { string[] substrs = labelText.Split('E'); string mantissa = substrs[0]; string exponenta = substrs[1]; exponenta = exponenta.TrimStart('+'); Span span = new Span(); span.Inlines.Add(string.Format(CultureInfo.CurrentCulture, "{0}·10", mantissa)); Span exponentaSpan = new Span(new Run(exponenta)); exponentaSpan.BaselineAlignment = BaselineAlignment.Superscript; exponentaSpan.FontSize = 8; span.Inlines.Add(exponentaSpan); label = new TextBlock(span); LabelProviderProperties.SetExponentialIsCommonLabel(label, false); } else { label = (TextBlock)GetResourceFromPool(); if (label == null) { label = new TextBlock(); } label.Text = labelText; } res[i] = label; label.ToolTip = tick.ToString(CultureInfo.CurrentCulture); ApplyCustomView(tickInfo, label); } // need to make the number of digits after the decimal point all the same // so fill in between the "." and the "E" with zeros to make all the same var labelsWithDecimal = res.Cast <TextBlock>().Select(tb => tb.Text).Where(t => t.Contains(".")).ToArray(); if (labelsWithDecimal.Length > 0) { int decimalPlaces = 0; foreach (var labelWithDecimal in labelsWithDecimal) { if (labelsWithDecimal.Contains("E")) { decimalPlaces = Math.Max(decimalPlaces, labelWithDecimal.IndexOf("E") - labelWithDecimal.IndexOf(".") - 1); } else { decimalPlaces = Math.Max(decimalPlaces, labelWithDecimal.Length - labelWithDecimal.IndexOf(".") - 1); } } foreach (TextBlock tb in res) { string text = tb.Text; int insertionPoint = text.Contains("E") ? text.IndexOf("E") : text.Length; if (!text.Contains(".")) { text = text.Insert(insertionPoint, "."); insertionPoint++; } int currentPlaces = insertionPoint - text.IndexOf(".") - 1; for (int i = currentPlaces; i < decimalPlaces; ++i) { text = text.Insert(insertionPoint, "0"); } tb.Text = text; } } return(res); }