Exemplo n.º 1
0
        private void DoDrawMayorLabels()
        {
            additionalLabelsCanvas.Children.Clear();
            ITicksProvider <T> mayorTicksProvider = ticksProvider.MayorProvider;

            if (mayorTicksProvider != null && MayorLabelProvider != null)
            {
                Size renderSize = RenderSize;
                var  mayorTicks = mayorTicksProvider.GetTicks(range, DefaultTicksProvider.DefaultTicksCount);

                double[] screenCoords = mayorTicks.Ticks.Select(tick => createDataPoint(convertToDouble(tick))).
                                        Select(p => p.DataToScreen(transform)).Select(p => getCoordinate(p)).ToArray();

                // todo this is not the best decision - when displaying, for example,
                // milliseconds, it causes to create hundreds and thousands of textBlocks.
                double rangesRatio = GetRangesRatio(mayorTicks.Ticks.GetPairs().ToArray()[0], range);

                object          info    = mayorTicks.Info;
                MayorLabelsInfo newInfo = new MayorLabelsInfo
                {
                    Info             = info,
                    MayorLabelsCount = (int)Math.Ceiling(rangesRatio)
                };

                var newMayorTicks = new TicksInfo <T>
                {
                    Info      = newInfo,
                    Ticks     = mayorTicks.Ticks,
                    TickSizes = mayorTicks.TickSizes
                };

                UIElement[] additionalLabels = MayorLabelProvider.CreateLabels(newMayorTicks);

                for (int i = 0; i < additionalLabels.Length; i++)
                {
                    if (screenCoords[i].IsNaN())
                    {
                        continue;
                    }

                    UIElement tickLabel = additionalLabels[i];

                    tickLabel.Measure(renderSize);

                    StackCanvas.SetCoordinate(tickLabel, screenCoords[i]);
                    StackCanvas.SetEndCoordinate(tickLabel, screenCoords[i + 1]);

                    if (tickLabel is FrameworkElement)
                    {
                        ((FrameworkElement)tickLabel).LayoutTransform = additionalLabelTransform;
                    }

                    additionalLabelsCanvas.Children.Add(tickLabel);
                }
            }
        }
Exemplo n.º 2
0
        private void DoDrawMayorLabels()
        {
            AdditionalLabelsCanvas.Children.Clear();
            ITicksProvider <T> mayorTicksProvider = ticksProvider.MayorProvider;

            if (mayorTicksProvider != null && MayorLabelProvider != null)
            {
                Size renderSize = RenderSize;
                //if (renderSize.Width == 0 || renderSize.Height == 0) return;
                var mayorTicks = mayorTicksProvider.GetTicks(range, DefaultTicksProvider.DefaultTicksCount);

                double[] screenCoords = mayorTicks.Ticks.Select(tick => createDataPoint(convertToDouble(tick))).
                                        Select(p => p.DataToScreen(transform)).Select(p => getCoordinate(p)).ToArray();

                int expectedMayorLabelsCount = mayorTicks.Ticks.Length;
                // todo this is not the best decision - when displaying, for example,
                // milliseconds, it causes to create hundreds and thousands of textBlocks.
                double rangesRatio = GetRangesRatio(mayorTicks.Ticks.GetPairs().ToArray()[0], range);

                object          info    = mayorTicks.Info;
                MayorLabelsInfo newInfo = new MayorLabelsInfo
                {
                    Info             = info,
                    MayorLabelsCount = (int)Math.Ceiling(rangesRatio)
                };

                var newMayorTicks = new TicksInfo <T>
                {
                    Info      = newInfo,
                    Ticks     = mayorTicks.Ticks,
                    TickSizes = mayorTicks.TickSizes
                };

                IEnumerable <FrameworkElement> additionalLabels = MayorLabelProvider.CreateLabels(newMayorTicks);

                int i = 0;
                foreach (FrameworkElement fe in additionalLabels)
                {
                    fe.Measure(renderSize);

                    StackCanvas.SetCoordinate(fe, screenCoords[i]);
                    if (i + 1 < screenCoords.Length)
                    {
                        StackCanvas.SetEndCoordinate(fe, screenCoords[i + 1]);
                    }

                    AdditionalLabelsCanvas.Children.Add(fe);
                    i++;
                }
            }
        }
Exemplo n.º 3
0
        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);
        }