Beispiel #1
0
        internal void UpdateSeparators(AxisOrientationNew source, ChartCore chart, int axisIndex)
        {
            foreach (var element in Cache.Values.ToArray())
            {
                if (element.GarbageCollectorIndex < GarbageCollectorIndex)
                {
                    element.State = SeparationState.Remove;
                    Cache.Remove(element.Key);
                }

                var toLine = ChartFunctionsNew.ToPlotArea(element.Value, source, chart, axisIndex);

                var direction = source == AxisOrientationNew.X ? 1 : -1;

                toLine += EvaluatesUnitWidth ? direction * ChartFunctionsNew.GetUnitWidth(source, chart, this) / 2 : 0;
                var toLabel = toLine + element.View.LabelModel.GetOffsetBySource(source);

                if (IsMerged)
                {
                    const double padding = 4;

                    if (source == AxisOrientationNew.Y)
                    {
                        if (toLabel + element.View.LabelModel.ActualHeight >
                            chart.DrawMargin.Top + chart.DrawMargin.Height)
                        {
                            toLabel -= element.View.LabelModel.ActualHeight + padding;
                        }
                    }
                    else
                    {
                        if (toLabel + element.View.LabelModel.ActualWidth >
                            chart.DrawMargin.Left + chart.DrawMargin.Width)
                        {
                            toLabel -= element.View.LabelModel.ActualWidth + padding;
                        }
                    }
                }

                var labelTab = Tab;
                labelTab += element.View.LabelModel.GetOffsetBySource(source.Invert());

                switch (element.State)
                {
                case SeparationState.Remove:
                    if (!chart.View.DisableAnimations && !View.DisableAnimations)
                    {
                        element.View.Move(chart, this, source, axisIndex, toLabel, toLine, labelTab);
                        element.View.FadeOutAndRemove(chart);
                    }
                    else
                    {
                        element.View.Remove(chart);
                    }
                    break;

                case SeparationState.Keep:
                    if (!chart.View.DisableAnimations && !View.DisableAnimations)
                    {
                        if (element.IsNew)
                        {
                            var toLinePrevious = FromPreviousState(element.Value, source, chart);
                            toLinePrevious += EvaluatesUnitWidth ? ChartFunctionsNew.GetUnitWidth(source, chart, this) / 2 : 0;
                            var toLabelPrevious = toLinePrevious + element.View.LabelModel.GetOffsetBySource(source);
                            element.View.Place(chart, this, source, axisIndex, toLabelPrevious,
                                               toLinePrevious, labelTab);
                            element.View.FadeIn(this, chart);
                        }
                        element.View.Move(chart, this, source, axisIndex, toLabel, toLine, labelTab);
                    }
                    else
                    {
                        element.View.Place(chart, this, source, axisIndex, toLabel, toLine, labelTab);
                    }
                    break;

                case SeparationState.InitialAdd:
                    element.View.Place(chart, this, source, axisIndex, toLabel, toLine, labelTab);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            LastAxisMax  = TopLimit;
            LastAxisMin  = BotLimit;
            LastPlotArea = new CoreRectangle(chart.DrawMargin.Left, chart.DrawMargin.Top,
                                             chart.DrawMargin.Width, chart.DrawMargin.Height);
        }
Beispiel #2
0
        private void PlaceLabel(string text, AxisCoreNew axis, AxisOrientationNew source)
        {
            _label.Text = text;

            var formattedText = new FormattedText(
                _label.Text,
                CultureInfo.CurrentUICulture,
                FlowDirection.LeftToRight,
                new Typeface(_label.FontFamily, _label.FontStyle, _label.FontWeight, _label.FontStretch),
                _label.FontSize, Brushes.Black);

            var transform = new LabelEvaluation(axis.View.LabelsRotation,
                                                formattedText.Width + 10, formattedText.Height, axis, source);

            _label.RenderTransform = Math.Abs(transform.LabelAngle) > 1
                ? new RotateTransform(transform.LabelAngle)
                : null;

            var toLine = ChartFunctionsNew.ToPlotArea(Value + SectionOffset + SectionWidth * .5, source, Model.Chart,
                                                      axis);

            var direction = source == AxisOrientationNew.X ? 1 : -1;

            toLine += axis.EvaluatesUnitWidth ? direction * ChartFunctionsNew.GetUnitWidth(source, Model.Chart, axis) / 2 : 0;
            var toLabel = toLine + transform.GetOffsetBySource(source);

            var chart = Model.Chart;

            if (axis.IsMerged)
            {
                const double padding = 4;

                if (source == AxisOrientationNew.Y)
                {
                    if (toLabel + transform.ActualHeight >
                        chart.DrawMargin.Top + chart.DrawMargin.Height)
                    {
                        toLabel -= transform.ActualHeight + padding;
                    }
                }
                else
                {
                    if (toLabel + transform.ActualWidth >
                        chart.DrawMargin.Left + chart.DrawMargin.Width)
                    {
                        toLabel -= transform.ActualWidth + padding;
                    }
                }
            }

            var labelTab = axis.Tab;

            labelTab += transform.GetOffsetBySource(source.Invert());

            if (source == AxisOrientationNew.Y)
            {
                labelTab += 8 * (axis.Position == AxisPositionNew.LeftBottom ? 1 : -1);

                if (Model.View.DisableAnimations || DisableAnimations)
                {
                    Canvas.SetLeft(_label, labelTab);
                    Canvas.SetTop(_label, toLabel);
                    return;
                }

                _label.BeginAnimation(Canvas.TopProperty,
                                      new DoubleAnimation(toLabel, chart.View.AnimationsSpeed));
                _label.BeginAnimation(Canvas.LeftProperty,
                                      new DoubleAnimation(labelTab, chart.View.AnimationsSpeed));
            }
            else
            {
                if (Model.View.DisableAnimations || DisableAnimations)
                {
                    Canvas.SetLeft(_label, toLabel);
                    Canvas.SetTop(_label, labelTab);
                    return;
                }

                _label.BeginAnimation(Canvas.LeftProperty,
                                      new DoubleAnimation(toLabel, chart.View.AnimationsSpeed));
                _label.BeginAnimation(Canvas.TopProperty,
                                      new DoubleAnimation(labelTab, chart.View.AnimationsSpeed));
            }
        }