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);
        }
Example #2
0
        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 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);
        }