PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Axes/Numeric/MinorNumericTicksProvider.cs

#
C# | 89 lines | 73 code | 16 blank | 0 comment | 5 complexity | 7d5a7dcd2bc071cd2308b255509a188d MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace Microsoft.Research.DynamicDataDisplay.Charts
 8{
 9	public sealed class MinorNumericTicksProvider : ITicksProvider<double>
10	{
11		private readonly ITicksProvider<double> parent;
12		private Range<double>[] ranges;
13		internal void SetRanges(IEnumerable<Range<double>> ranges)
14		{
15			this.ranges = ranges.ToArray();
16		}
17
18		private double[] coeffs;
19		public double[] Coeffs
20		{
21			get { return coeffs; }
22			set
23			{
24				if (value == null)
25					throw new ArgumentNullException("value");
26
27				coeffs = value;
28				Changed.Raise(this);
29			}
30		}
31
32		internal MinorNumericTicksProvider(ITicksProvider<double> parent)
33		{
34			this.parent = parent;
35			Coeffs = new double[] { 0.3, 0.3, 0.3, 0.3, 0.6, 0.3, 0.3, 0.3, 0.3 };
36		}
37
38		#region ITicksProvider<double> Members
39
40		public event EventHandler Changed;
41
42		public ITicksInfo<double> GetTicks(Range<double> range, int ticksCount)
43		{
44			if (Coeffs.Length == 0)
45				return new TicksInfo<double>();
46
47			var minorTicks = ranges.Select(r => CreateTicks(r)).SelectMany(m => m);
48			var res = new TicksInfo<double>();
49			res.TickSizes = minorTicks.Select(m => m.Value).ToArray();
50			res.Ticks = minorTicks.Select(m => m.Tick).ToArray();
51
52			return res;
53		}
54
55		public MinorTickInfo<double>[] CreateTicks(Range<double> range)
56		{
57			double step = (range.Max - range.Min) / (Coeffs.Length + 1);
58
59			MinorTickInfo<double>[] res = new MinorTickInfo<double>[Coeffs.Length];
60			for (int i = 0; i < Coeffs.Length; i++)
61			{
62				res[i] = new MinorTickInfo<double>(Coeffs[i], range.Min + step * (i + 1));
63			}
64			return res;
65		}
66
67		public int DecreaseTickCount(int ticksCount)
68		{
69			return ticksCount;
70		}
71
72		public int IncreaseTickCount(int ticksCount)
73		{
74			return ticksCount;
75		}
76
77		public ITicksProvider<double> MinorProvider
78		{
79			get { return null; }
80		}
81
82		public ITicksProvider<double> MajorProvider
83		{
84			get { return parent; }
85		}
86
87		#endregion
88	}
89}