protected override void OnCalculateTicks(TickList a_Ticks, Range a_Range, AxisDrawingArgs a_Options) { if (a_Range.Start <= 0 && a_Range.End >= 0) { //Get the fractional position double pos = (0 - a_Range.Start) / a_Range.Size; //add 1 as a tick a_Ticks.MajorTicks.Add(new TickList.Tick(m_Flipped ? "On" : "Off", pos)); } //Only add 2 ticks - off and on. if (a_Range.Start <= 1 && a_Range.End >= 1) { //Get the fractional position double pos = (1 - a_Range.Start) / a_Range.Size; //add 1 as a tick a_Ticks.MajorTicks.Add(new TickList.Tick(m_Flipped ? "Off" : "On", pos)); } }
protected abstract void OnCalculateTicks(TickList a_Ticks, Range a_Range, AxisDrawingArgs a_Options);
protected override void OnCalculateTicks(TickList a_Tick, Range a_Range, AxisDrawingArgs a_Options) { double smallestInterval = 0.00001; //double valueInterval = CalculateInterval(a_Range.Size); double valueInterval = Math.Pow(10, Math.Floor(Math.Log10(a_Range.Size/10))) * 5.0; double positionInterval = (valueInterval / a_Range.Size); if (valueInterval < smallestInterval) return; //Snap to the smallest interval allowed if under it. //if (positionInterval < smallestInterval) //{ // double percentage = positionInterval / smallestInterval; // valueInterval = valueInterval / percentage; // positionInterval = smallestInterval; //} //Round start down starting tick to nearest interval. double tickStart = a_Range.Start - (a_Range.Start % valueInterval) - valueInterval; //Create ticks until beyond the range double tickValue = tickStart; while (tickValue < a_Range.End) { double tickPosition = (tickValue - a_Range.Start) / a_Range.Size; //Round tickvalue to 10 decimal places //Fix for Issue # PW-573 tickValue = Math.Round(tickValue, 10); a_Tick.MajorTicks.Add(new TickList.Tick(tickValue, tickPosition)); tickValue += valueInterval; } //MINOR TICKS if (a_Options.MinorTickCount > 0) { //Calculate the tick interval double minorTickPositionInterval = positionInterval / (a_Options.MinorTickCount + 1); double minorTickValueInterval = valueInterval / (a_Options.MinorTickCount + 1); //Create minor ticks foreach (TickList.Tick currentMajorTick in a_Tick.MajorTicks) { double tickPosition = currentMajorTick.AxisPosition + minorTickPositionInterval; tickValue = (double)currentMajorTick.Value + minorTickValueInterval; //Only add the required number of ticks for (int i = 1; i <= a_Options.MinorTickCount; i++) { a_Tick.MinorTicks.Add(new TickList.Tick(tickValue.ToString(), tickPosition)); tickPosition += minorTickPositionInterval; tickValue += minorTickValueInterval; } } } }
public void CalculateTicks(Range a_Range, AxisDrawingArgs args) { TickList ticks = new TickList(); //Prevent divide-by-zero exceptions. if (a_Range.Size > 0) { //Transform the range OnCalculateTicks(ticks, TransformRange(a_Range), args); } Ticks = ticks; }
//internal override void CalculateTicks(TickList a_Ticks, Range a_Range, AxisDrawOptions args) //{ // //Find the start value (left or bottom ) of the axis by // //adding the range start to the zerovalue. // DateTime rangeStartDate = m_ZeroValue.AddDays(a_Range.Start); // //Get the rounding interval in order to normalise the start value // double intervalSize = 0.0; // TimeUnit tickInterval = this.GetInterval(a_Range.Size, out intervalSize); // //Round the datetime // DateTime roundedStartDate = rangeStartDate.Round(tickInterval, false); // //Adjust range start value so that it reflects the rounded value // double roundedStartValue = roundedStartDate.Subtract(m_ZeroValue).TotalDays; // double cumulativeValue = roundedStartValue; // //Build the ticks // while (true) // { // //Determine the tick's position // double tickPos = (cumulativeValue - a_Range.Start) / a_Range.Size; // //Break loop if current tick is placed > 1 // if (tickPos > 1) // break; // //Assemble the tick's label value // DateTime tickDate = m_ZeroValue.AddDays(cumulativeValue); // string tickValue = string.Empty; // switch (m_DisplayType) // { // case DateDisplay.TimeOnly: // tickValue = tickDate.ToShortTimeString(); // break; // case DateDisplay.DateOnly: // tickValue = tickDate.ToShortDateString(); // break; // case DateDisplay.Both: // tickValue = tickDate.ToShortDateString() + " " + tickDate.ToShortTimeString(); // break; // } // //Add the tick // a_Ticks.MajorTicks.Add(new TickList.Tick(tickValue, tickPos)); // //Increment the cumulative value by the interval amount // cumulativeValue += intervalSize; // } //} protected override void OnCalculateTicks(TickList a_Ticks, Range a_Range, AxisDrawingArgs args) { try { int minorTickCount = args.MinorTickCount; //Find the start value (left or bottom ) of the axis by //adding the range start to the zerovalue. string autoFormat = ""; //Get the rounding interval in order to normalise the start value TimeSpan intervalDuration = GetInterval(a_Range.Size, out autoFormat); double intervalSize = Math.Abs(intervalDuration.TotalDays); //Break if zoom is too small if (intervalSize == 0) return; //Round down to snap to interval using datetime ticks (using raw double value did not work correctly due to rounding) DateTime rangeStartTime = this.DoubleToDateTime(a_Range.Start); DateTime roundedStartTime = new DateTime(rangeStartTime.Ticks - (rangeStartTime.Ticks % intervalDuration.Ticks) - intervalDuration.Ticks); //double startValue = a_Range.Start - (Math.Abs(a_Range.Start) % intervalSize); double startValue = this.DateTimeToDouble(roundedStartTime); if (double.IsNaN(startValue)) startValue = 0.0; double cumulativeValue = startValue; double majorTickPosInterval = intervalSize / a_Range.Size; bool firstTick = true; //Build the ticks while (true) { //Determine the tick's position double tickPos = (cumulativeValue - a_Range.Start) / a_Range.Size; //Break loop if current tick is placed >= 1 if (tickPos >= 1) break; //Assemble the tick's label value DateTime tickDate = m_ZeroValue.AddDays(cumulativeValue); string tickValue = GetString(tickDate, autoFormat); //Add the tick a_Ticks.MajorTicks.Add(new TickList.Tick(tickValue, tickPos)); //Increment the cumulative value by the interval amount cumulativeValue += intervalSize; if (args.MinorTickCount > 0) { double minorPosInterval = majorTickPosInterval / (minorTickCount + 1); //Add minor ticks after this major tick for (int i = 0; i < minorTickCount; i++) { a_Ticks.MinorTicks.Add(new TickList.Tick(null, tickPos + (minorPosInterval * (i + 1)))); } if (firstTick) { //Add minor ticks after this major tick for (int i = 0; i < minorTickCount; i++) { a_Ticks.MinorTicks.Add(new TickList.Tick(null, (tickPos - majorTickPosInterval) + (minorPosInterval * (i + 1)))); } } } firstTick = false; } } catch// (DivideByZeroException ex) { //zoom too small. } //catch (ArgumentOutOfRangeException ex) //{ // //zoom too large. //} }