public MinorTickInfo <double>[] CreateTicks(Range <double> range)
        {
            double step = (range.Max - range.Min) / (Coeffs.Length + 1);

            MinorTickInfo <double>[] res = new MinorTickInfo <double> [Coeffs.Length];
            for (int i = 0; i < Coeffs.Length; i++)
            {
                res[i] = new MinorTickInfo <double>(Coeffs[i], range.Min + step * (i + 1));
            }
            return(res);
        }
        private void DoDrawMinorTicks(GeometryGroup geomGroup)
        {
            ITicksProvider <T> minorTicksProvider = ticksProvider.MinorProvider;

            if (minorTicksProvider != null)
            {
                int            minorTicksCount      = DefaultTicksProvider.DefaultTicksCount;
                int            prevActualTicksCount = -1;
                ITicksInfo <T> minorTicks;
                TickChange     result = TickChange.OK;
                TickChange     prevResult;
                int            iteration = 0;
                //PerformanceCounter.startStopwatch("Minor ticks: computing tickCounts");
                do
                {
                    Verify.IsTrue(++iteration < maxTickArrangeIterations);

                    minorTicks = minorTicksProvider.GetTicks(range, minorTicksCount);

                    prevActualTicksCount = minorTicks.Ticks.Length;
                    prevResult           = result;
                    result = CheckMinorTicksArrangement(minorTicks);
                    if (prevResult == TickChange.Decrease && result == TickChange.Increase)
                    {
                        // stop tick number oscillating
                        result = TickChange.OK;
                    }
                    if (result == TickChange.Decrease)
                    {
                        int newMinorTicksCount = minorTicksProvider.DecreaseTickCount(minorTicksCount);
                        if (newMinorTicksCount == minorTicksCount)
                        {
                            result = TickChange.OK;
                        }
                        minorTicksCount = newMinorTicksCount;
                    }
                    else if (result == TickChange.Increase)
                    {
                        int newCount = minorTicksProvider.IncreaseTickCount(minorTicksCount);
                        if (newCount == minorTicksCount)
                        {
                            result = TickChange.OK;
                        }
                        minorTicksCount = newCount;
                    }
                } while (result != TickChange.OK);
                //PerformanceCounter.stopStopwatch("Minor ticks: computing tickCounts");

                minorTicks = minorTicksProvider.GetTicks(range, minorTicksCount);


                double[] sizes = minorTicks.TickSizes;

                double[] screenCoords = minorTicks.Ticks.Select(
                    coord => getCoordinate(createDataPoint(convertToDouble(coord)).
                                           ToScreen(converter))).ToArray();

                minorScreenTicks = new MinorTickInfo <double> [screenCoords.Length];
                for (int i = 0; i < screenCoords.Length; i++)
                {
                    minorScreenTicks[i] = new MinorTickInfo <double>(sizes[i], screenCoords[i]);
                }

                for (int i = 0; i < screenCoords.Length; i++)
                {
                    double screenCoord = screenCoords[i];
                    if (i + usedTicks < allocatedTicks)
                    {
                        //PerformanceCounter.startStopwatch("Minor ticks: getting allocated lines");
                        LineGeometry line = allocatedTicksList[i + usedTicks];
                        //PerformanceCounter.stopStopwatch("Minor ticks: getting allocated lines");
                        //PerformanceCounter.startStopwatch("Minor ticks: renewing allocated lines");
                        line.StartPoint = createScreenPoint1(screenCoord);;
                        line.EndPoint   = createScreenPoint2(screenCoord, sizes[i]);
                        //PerformanceCounter.stopStopwatch("Minor ticks: renewing allocated lines");
                    }
                    else
                    {
                        //PerformanceCounter.startStopwatch("Minor ticks: creating new lines");
                        LineGeometry line = new LineGeometry();
                        line.StartPoint = createScreenPoint1(screenCoord);;
                        line.EndPoint   = createScreenPoint2(screenCoord, sizes[i]);
                        geomGroup.Children.Add(line);
                        allocatedTicksList.Add(line);
                        //PerformanceCounter.stopStopwatch("Minor ticks: creating new lines");
                    }
                }
                usedTicks += screenCoords.Length;
            }
        }
Example #3
0
        private void DoDrawMinorTicks(GeometryGroup geomGroup)
        {
            ITicksProvider <T> minorTicksProvider = ticksProvider.MinorProvider;

            if (minorTicksProvider != null)
            {
                int             minorTicksCount      = prevMinorTicksCount;
                int             prevActualTicksCount = -1;
                ITicksInfo <T>  minorTicks;
                TickCountChange result = TickCountChange.OK;
                TickCountChange prevResult;
                int             iteration = 0;
                do
                {
                    Verify.IsTrue(++iteration < maxTickArrangeIterations);

                    minorTicks = minorTicksProvider.GetTicks(range, minorTicksCount);

                    prevActualTicksCount = minorTicks.Ticks.Length;
                    prevResult           = result;
                    result = CheckMinorTicksArrangement(minorTicks);
                    if (prevResult == TickCountChange.Decrease && result == TickCountChange.Increase)
                    {
                        // stop tick number oscillating
                        result = TickCountChange.OK;
                    }
                    if (result == TickCountChange.Decrease)
                    {
                        int newMinorTicksCount = minorTicksProvider.DecreaseTickCount(minorTicksCount);
                        if (newMinorTicksCount == minorTicksCount)
                        {
                            result = TickCountChange.OK;
                        }
                        minorTicksCount = newMinorTicksCount;
                    }
                    else if (result == TickCountChange.Increase)
                    {
                        int newCount = minorTicksProvider.IncreaseTickCount(minorTicksCount);
                        if (newCount == minorTicksCount)
                        {
                            result = TickCountChange.OK;
                        }
                        minorTicksCount = newCount;
                    }
                } while (result != TickCountChange.OK);
                prevMinorTicksCount = minorTicksCount;

                double[] sizes = minorTicks.TickSizes;

                double[] screenCoords = minorTicks.Ticks.Select(
                    coord => getCoordinate(createDataPoint(convertToDouble(coord)).
                                           DataToScreen(transform))).ToArray();

                minorScreenTicks = new MinorTickInfo <double> [screenCoords.Length];
                for (int i = 0; i < screenCoords.Length; i++)
                {
                    minorScreenTicks[i] = new MinorTickInfo <double>(sizes[i], screenCoords[i]);
                }

                for (int i = 0; i < screenCoords.Length; i++)
                {
                    double screenCoord = screenCoords[i];

                    Point p1 = createScreenPoint1(screenCoord);
                    Point p2 = createScreenPoint2(screenCoord, sizes[i]);

                    LineGeometry line = new LineGeometry(p1, p2);
                    geomGroup.Children.Add(line);
                }
            }
        }