示例#1
0
        private double staticAxisMargin = 1;         // px

        private void CreateCommonLabels(double[] screenTicksX)
        {
            Size renderSize = RenderSize;

            commonLabelsCanvas.Children.Clear();
            UIElement[] labels = this.labels.ToArray();

            double minCoordUnsorted = ToScreen(range.Min);
            double maxCoordUnsorted = ToScreen(range.Max);

            double minCoord = Math.Min(minCoordUnsorted, maxCoordUnsorted);
            double maxCoord = Math.Max(minCoordUnsorted, maxCoordUnsorted);

            double maxCoordDiff = (maxCoord - minCoord) / labels.Length / 2.0;

            double minCoordToAdd = minCoord - maxCoordDiff;
            double maxCoordToAdd = maxCoord + maxCoordDiff;

            for (int i = 0; i < ticks.Length; i++)
            {
                UIElement tickLabel = labels[i];
                if (tickLabel == null)
                {
                    continue;
                }

                // getting real size of label
                tickLabel.Measure(renderSize);
                Size tickLabelSize = tickLabel.DesiredSize;

                double screenX = screenTicksX[i];
                double coord   = screenX - getSize(tickLabelSize) / 2;

                if (isStaticAxis)
                {
                    if (Math.Abs(screenX - minCoord) < maxCoordDiff)
                    {
                        coord = screenX + staticAxisMargin;
                    }
                    else if (Math.Abs(screenX - maxCoord) < maxCoordDiff)
                    {
                        coord = screenX - getSize(tickLabelSize) - staticAxisMargin;
                    }
                }

                if (coord < minCoordToAdd || coord > maxCoordToAdd)
                {
                    continue;
                }

                if (coord.IsNaN())
                {
                    continue;
                }

                StackCanvas.SetCoordinate(tickLabel, coord);

                commonLabelsCanvas.Children.Add(tickLabel);
            }
        }
示例#2
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);
                }
            }
        }
示例#3
0
        private static void OnCoordinateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            UIElement reference = d as UIElement;

            if (reference != null)
            {
                StackCanvas parent = VisualTreeHelper.GetParent(reference) as StackCanvas;
                if (parent != null)
                {
                    parent.InvalidateArrange();
                }
            }
        }