protected override string OnTooltipAtPoint(double a_Value, Range a_Range, System.Windows.Media.Transform a_Transform, AxisDrawingArgs args) { //Get the number of significant figures to display on each axis Point sigFigs = a_Transform.GetSignificantFigures(); if (args.AxisOrientation == System.Windows.Controls.Orientation.Horizontal) return string.Format("{0}", a_Value.ToString("F"+((int)sigFigs.X))); else return string.Format("{0}", a_Value.ToString("F"+((int)sigFigs.Y))); }
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 override string OnRangeToString(Range a_Range) { return ""; }
protected Range TransformRange(Range a_RangeToTransform) { return new Range( SingleAxisTransform.Transform(a_RangeToTransform.Start, this.Offset, this.Scale), SingleAxisTransform.Transform(a_RangeToTransform.End, this.Offset, this.Scale)); }
/// <summary> /// Returns a string representation of a Range's Size, in the format of the AxisProvider. /// </summary> protected abstract string OnRangeToString(Range a_Range);
/// <summary> /// Calculates an appropriate tooltip for the given value to be displayed at the cursor. /// </summary> /// <param name="a_Value">Value of the desired label</param> /// <param name="a_Range">Currently displayed range</param> /// <param name="a_Transform">Host charts transform. Included in order to support significant figure calculations.</param> /// <param name="a_Orientation">Orientation of the axis</param> /// <returns>String label.</returns> protected abstract string OnTooltipAtPoint(double a_Value, Range a_Range, Transform a_Transform, AxisDrawingArgs args);
/// <summary> /// Calculates an appropriate tooltip for the given value to be displayed at the cursor. /// </summary> /// <param name="a_Value">Value of the desired label</param> /// <param name="a_Range">Currently displayed range</param> /// <param name="a_Transform">Host charts transform. Included in order to support significant figure calculations.</param> /// <param name="a_Orientation">Orientation of the axis</param> /// <returns>String label.</returns> public string TooltipAtPoint(double a_Value, Range a_Range, Transform a_Transform, AxisDrawingArgs args) { return OnTooltipAtPoint(a_Value, TransformRange(a_Range), a_Transform, args); }
protected abstract void OnCalculateTicks(TickList a_Ticks, Range a_Range, AxisDrawingArgs a_Options);
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; }
/// <summary> /// Returns a string representation of a Range's Size, in the format of the AxisProvider. /// </summary> public string RangeToString(Range a_Range) { return OnRangeToString(TransformRange(a_Range)); }
protected override string OnRangeToString(Range a_Range) { return a_Range.Start + " - " + a_Range.End; }
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; } } } }
protected override string OnTooltipAtPoint(double a_Value, Range a_Range, Transform a_Transform, AxisDrawingArgs args) { if (LabelFormat == null) return string.Empty; DateTime value = m_ZeroValue.AddDays(a_Value); return value.ToString(LabelFormat); }
protected override string OnRangeToString(Range a_Range) { DateTime XStart = this.DoubleToDateTime(a_Range.Start); DateTime XEnd = this.DoubleToDateTime(a_Range.End); return string.Format("{0} {1} - {2} {3}", XStart.ToShortDateString(), XStart.ToShortTimeString(), XEnd.ToShortDateString(), XEnd.ToShortTimeString()); }
//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. //} }