Пример #1
0
        private void CreateTicks()
        {
            TickCountChange result = TickCountChange.OK;
            TickCountChange prevResult;

            int prevActualTickCount = -1;

            int tickCount = previousTickCount;
            int iteration = 0;

            do
            {
                Verify.IsTrue(++iteration < maxTickArrangeIterations);

                ticksInfo = ticksProvider.GetTicks(range, tickCount);
                ticks     = ticksInfo.Ticks;

                if (ticks.Length == prevActualTickCount)
                {
                    result = TickCountChange.OK;
                    break;
                }

                prevActualTickCount = ticks.Length;

                labels = labelProvider.CreateLabels(ticksInfo);

                prevResult = result;
                result     = CheckLabelsArrangement(labels, ticks);

                if (prevResult == TickCountChange.Decrease && result == TickCountChange.Increase)
                {
                    // stop tick number oscillating
                    result = TickCountChange.OK;
                }

                if (result != TickCountChange.OK)
                {
                    int prevTickCount = tickCount;
                    if (result == TickCountChange.Decrease)
                    {
                        tickCount = ticksProvider.DecreaseTickCount(tickCount);
                    }
                    else
                    {
                        tickCount = ticksProvider.IncreaseTickCount(tickCount);
                        //DebugVerify.Is(tickCount >= prevTickCount);
                    }

                    // ticks provider could not create less ticks or tick number didn't change
                    if (tickCount == 0 || prevTickCount == tickCount)
                    {
                        tickCount = prevTickCount;
                        result    = TickCountChange.OK;
                    }
                }
            } while (result != TickCountChange.OK);

            previousTickCount = tickCount;
        }
Пример #2
0
		private TickCountChange CheckLabelsArrangement(UIElement[] labels, T[] ticks)
		{
			var actualLabels = labels.Select((label, i) => new { Label = label, Index = i })
				.Where(el => el.Label != null)
				.Select(el => new { Label = el.Label, Tick = ticks[el.Index] })
				.ToList();

			actualLabels.ForEach(item => item.Label.Measure(RenderSize));

			var sizeInfos = actualLabels.Select(item =>
				new { X = GetCoordinateFromTick(item.Tick), Size = getSize(item.Label.DesiredSize) })
				.OrderBy(item => item.X).ToArray();

			TickCountChange res = TickCountChange.OK;

			int increaseCount = 0;
			for (int i = 0; i < sizeInfos.Length - 1; i++)
			{
				if ((sizeInfos[i].X + sizeInfos[i].Size * decreaseRatio) > sizeInfos[i + 1].X)
				{
					res = TickCountChange.Decrease;
					break;
				}
				if ((sizeInfos[i].X + sizeInfos[i].Size * increaseRatio) < sizeInfos[i + 1].X)
				{
					increaseCount++;
				}
			}
			if (increaseCount > sizeInfos.Length / 2)
				res = TickCountChange.Increase;

			return res;
		}
Пример #3
0
		private TickCountChange CheckMinorTicksArrangement(ITicksInfo<T> minorTicks)
		{
			Size renderSize = RenderSize;
			TickCountChange result = TickCountChange.OK;
			if (minorTicks.Ticks.Length * 3 > getSize(renderSize))
				result = TickCountChange.Decrease;
			else if (minorTicks.Ticks.Length * 6 < getSize(renderSize))
				result = TickCountChange.Increase;
			return result;
		}
Пример #4
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);
                }
            }
        }