GetUnitWidth() public static method

Gets the width of a unit in the chart
public static GetUnitWidth ( AxisOrientation source, ChartCore chart, AxisCore axis ) : double
source AxisOrientation axis orientation
chart LiveCharts.Charts.ChartCore chart model to get the scale at
axis AxisCore axis instance
return double
コード例 #1
0
ファイル: AxisCore.cs プロジェクト: sung-su/vs-tools-cps
        internal void UpdateSeparators(AxisOrientation 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 = ChartFunctions.ToPlotArea(element.Value, source, chart, axisIndex);

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

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

                if (IsMerged)
                {
                    const double padding = 4;

                    if (source == AxisOrientation.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 ? ChartFunctions.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);
        }