public override bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) { return(true); } var from = obj as LinearTickSpacing; if (null == from) { return(false); } using (var suspendToken = SuspendGetToken()) { CopyHelper.Copy(ref _cachedMajorMinor, from._cachedMajorMinor); _userDefinedMajorSpan = from._userDefinedMajorSpan; _userDefinedMinorTicks = from._userDefinedMinorTicks; _targetNumberOfMajorTicks = from._targetNumberOfMajorTicks; _targetNumberOfMinorTicks = from._targetNumberOfMinorTicks; _zeroLever = from._zeroLever; _orgGrace = from._orgGrace; _endGrace = from._endGrace; _snapOrgToTick = from._snapOrgToTick; _snapEndToTick = from._snapEndToTick; ChildCopyToMember(ref _suppressedMajorTicks, from._suppressedMajorTicks); ChildCopyToMember(ref _suppressedMinorTicks, from._suppressedMinorTicks); ChildCopyToMember(ref _additionalMajorTicks, from._additionalMajorTicks); ChildCopyToMember(ref _additionalMinorTicks, from._additionalMinorTicks); _transformationOffset = from._transformationOffset; _transformationDivider = from._transformationDivider; _transformationOperationIsMultiply = from._transformationOperationIsMultiply; _majorTicks = new List <double>(from._majorTicks); _minorTicks = new List <double>(from._minorTicks); EhSelfChanged(); suspendToken.Resume(); } return(true); }
public override bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) { return(true); } var from = obj as DateTimeTickSpacing; if (null == from) { return(false); } using (var suspendToken = SuspendGetToken()) { CopyHelper.Copy(ref _cachedMajorMinor, from._cachedMajorMinor); _userDefinedMajorSpan = from._userDefinedMajorSpan; _userDefinedMinorTicks = from._userDefinedMinorTicks; _targetNumberOfMajorTicks = from._targetNumberOfMajorTicks; _targetNumberOfMinorTicks = from._targetNumberOfMinorTicks; _orgGrace = from._orgGrace; _endGrace = from._endGrace; _snapOrgToTick = from._snapOrgToTick; _snapEndToTick = from._snapEndToTick; ChildCopyToMember(ref _suppressedMajorTicks, from._suppressedMajorTicks); ChildCopyToMember(ref _suppressedMinorTicks, from._suppressedMinorTicks); ChildCopyToMember(ref _additionalMajorTicks, from._additionalMajorTicks); ChildCopyToMember(ref _additionalMinorTicks, from._additionalMinorTicks); _majorTicks = new List <AltaxoVariant>(from._majorTicks); _minorTicks = new List <AltaxoVariant>(from._minorTicks); EhSelfChanged(); suspendToken.Resume(); } return(true); }
private DateTime GetOrgOrEndSnappedToTick(DateTime x, TimeSpanEx majorSpan, TimeSpanEx minorTicks, BoundaryTickSnapping snapping, bool upwards) { switch (snapping) { default: case BoundaryTickSnapping.SnapToNothing: { return(x); } case BoundaryTickSnapping.SnapToMajorOnly: { if (upwards) { return(majorSpan.RoundUp(x)); } else { return(majorSpan.RoundDown(x)); } } case BoundaryTickSnapping.SnapToMinorOnly: { DateTime resultMinor, resultMajor; if (upwards) { resultMinor = minorTicks.RoundUp(x); resultMajor = majorSpan.RoundUp(x); return(resultMinor == resultMajor?TimeSpanEx.Add(resultMinor, minorTicks) : resultMinor); } else { resultMinor = minorTicks.RoundDown(x); resultMajor = majorSpan.RoundDown(x); return(resultMinor == resultMajor?TimeSpanEx.Subtract(resultMinor, minorTicks) : resultMinor); } } case BoundaryTickSnapping.SnapToMinorOrMajor: { DateTime resultMinor, resultMajor; if (upwards) { resultMinor = minorTicks.RoundUp(x); resultMajor = majorSpan.RoundUp(x); return(resultMinor < resultMajor ? resultMinor : resultMajor); } else { resultMinor = minorTicks.RoundDown(x); resultMajor = majorSpan.RoundDown(x); return(resultMinor > resultMajor ? resultMinor : resultMajor); } } } }
/// <summary> /// Adjusts the parameter <paramref name="x"/> so that <paramref name="x"/> snaps to a tick according to the setting of <paramref name="snapping"/>. /// </summary> /// <param name="x">The boundary value to adjust.</param> /// <param name="majorSpan">Value of the major tick span.</param> /// <param name="minorTicks">Number of minor ticks.</param> /// <param name="snapping">Setting of the tick snapping.</param> /// <param name="upwards">If true, the value is towards higher values, if false it is adjusted towards smaller values.</param> /// <returns>The adjusted value of x.</returns> public static double GetOrgOrEndSnappedToTick(double x, double majorSpan, int minorTicks, BoundaryTickSnapping snapping, bool upwards) { switch (snapping) { default: case BoundaryTickSnapping.SnapToNothing: { return(x); } case BoundaryTickSnapping.SnapToMajorOnly: { double rel = x / majorSpan; if (upwards) { return(Math.Ceiling(rel) * majorSpan); } else { return(Math.Floor(rel) * majorSpan); } } case BoundaryTickSnapping.SnapToMinorOnly: { double rel = x * minorTicks / (majorSpan); if (upwards) { rel = Math.Ceiling(rel); } else { rel = Math.Floor(rel); } if (Math.IEEERemainder(rel, 1) != 0 && minorTicks > 1) { rel = upwards ? rel + 1 : rel - 1; } return(rel * majorSpan / minorTicks); } case BoundaryTickSnapping.SnapToMinorOrMajor: { double rel = x * minorTicks / (majorSpan); if (upwards) { return(Math.Ceiling(rel) * majorSpan / minorTicks); } else { return(Math.Floor(rel) * majorSpan / minorTicks); } } } }
/// <summary> /// Adjusts the parameter <paramref name="x"/> so that <paramref name="x"/> snaps to a tick according to the setting of <paramref name="snapping"/>. /// </summary> /// <param name="x">The boundary value to adjust.</param> /// <param name="majorSpan">Value of the major tick span.</param> /// <param name="minorTicks">Number of minor ticks.</param> /// <param name="snapping">Setting of the tick snapping.</param> /// <param name="upwards">If true, the value is towards higher values, if false it is adjusted towards smaller values.</param> /// <returns>The adjusted value of x.</returns> public static double GetOrgOrEndSnappedToTick(double x, double majorSpan, int minorTicks, BoundaryTickSnapping snapping, bool upwards) { switch (snapping) { default: case BoundaryTickSnapping.SnapToNothing: { return x; } case BoundaryTickSnapping.SnapToMajorOnly: { double rel = x / majorSpan; if (upwards) return Math.Ceiling(rel) * majorSpan; else return Math.Floor(rel) * majorSpan; } case BoundaryTickSnapping.SnapToMinorOnly: { double rel = x * minorTicks / (majorSpan); if (upwards) rel = Math.Ceiling(rel); else rel = Math.Floor(rel); if (Math.IEEERemainder(rel, 1) != 0 && minorTicks > 1) rel = upwards ? rel + 1 : rel - 1; return rel * majorSpan / minorTicks; } case BoundaryTickSnapping.SnapToMinorOrMajor: { double rel = x * minorTicks / (majorSpan); if (upwards) return Math.Ceiling(rel) * majorSpan / minorTicks; else return Math.Floor(rel) * majorSpan / minorTicks; } } }
public override bool CopyFrom(object obj) { if (object.ReferenceEquals(this, obj)) return true; var from = obj as LinearTickSpacing; if (null == from) return false; using (var suspendToken = SuspendGetToken()) { CopyHelper.Copy(ref _cachedMajorMinor, from._cachedMajorMinor); _userDefinedMajorSpan = from._userDefinedMajorSpan; _userDefinedMinorTicks = from._userDefinedMinorTicks; _targetNumberOfMajorTicks = from._targetNumberOfMajorTicks; _targetNumberOfMinorTicks = from._targetNumberOfMinorTicks; _zeroLever = from._zeroLever; _orgGrace = from._orgGrace; _endGrace = from._endGrace; _snapOrgToTick = from._snapOrgToTick; _snapEndToTick = from._snapEndToTick; ChildCopyToMember(ref _suppressedMajorTicks, from._suppressedMajorTicks); ChildCopyToMember(ref _suppressedMinorTicks, from._suppressedMinorTicks); ChildCopyToMember(ref _additionalMajorTicks, from._additionalMajorTicks); ChildCopyToMember(ref _additionalMinorTicks, from._additionalMinorTicks); _transformationOffset = from._transformationOffset; _transformationDivider = from._transformationDivider; _transformationOperationIsMultiply = from._transformationOperationIsMultiply; _majorTicks = new List<double>(from._majorTicks); _minorTicks = new List<double>(from._minorTicks); EhSelfChanged(); suspendToken.Resume(); } return true; }
/// <summary> /// Adjusts the parameter <paramref name="x"/> so that <paramref name="x"/> snaps to a tick according to the setting of <paramref name="snapping"/>. /// </summary> /// <param name="x">The boundary value to adjust.</param> /// <param name="decadesPerMajorTick">Number of decades between the major ticks.</param> /// <param name="minorTicks">Number of minor ticks.</param> /// <param name="snapping">Setting of the tick snapping.</param> /// <param name="upwards">If true, the value is towards higher values, if false it is adjusted towards smaller values.</param> /// <returns>The adjusted value of x.</returns> public static double GetOrgOrEndSnappedToTick(double x, int decadesPerMajorTick, int minorTicks, BoundaryTickSnapping snapping, bool upwards) { switch (snapping) { case BoundaryTickSnapping.SnapToMajorOnly: { double rel = Math.Log10(x) / decadesPerMajorTick; if (upwards) return RMath.Pow(10, decadesPerMajorTick * (int)Math.Ceiling(rel)); else return RMath.Pow(10, decadesPerMajorTick * (int)Math.Floor(rel)); } case BoundaryTickSnapping.SnapToMinorOnly: { if (minorTicks > 1) { int decadesPerMinorTick = decadesPerMajorTick / minorTicks; double rel = Math.Log10(x) / decadesPerMinorTick; if (upwards) { int nrel = decadesPerMinorTick * (int)Math.Ceiling(rel); if (0 == (nrel % decadesPerMajorTick)) nrel += decadesPerMinorTick; return RMath.Pow(10, nrel); } else { int nrel = decadesPerMinorTick * (int)Math.Floor(rel); if (0 == (nrel % decadesPerMajorTick)) nrel -= decadesPerMinorTick; return RMath.Pow(10, nrel); } } else if (minorTicks < 0) { int[] mantissa = minorTicks == -1 ? minorTickMantissa3 : minorTickMantissa9; double rel = Math.Log10(x); if (upwards) { int nrel = (int)Math.Floor(rel); for (int i = 0; i < mantissa.Length; ++i) { double result = mantissa[i] * RMath.Pow(10, nrel); if (result >= x && (i != 0 || 0 != (nrel % decadesPerMajorTick))) return result; } } else { int nrel = (int)Math.Ceiling(rel) - 1; for (int i = mantissa.Length - 1; i >= 0; --i) { double result = mantissa[i] * RMath.Pow(10, (int)(rel)); if (result <= x && (i != 0 || 0 != (nrel % decadesPerMajorTick))) return result; } } } else // no minor ticks { double rel = Math.Log10(x) / decadesPerMajorTick; if (upwards) return RMath.Pow(10, decadesPerMajorTick * (int)Math.Ceiling(rel)); else return RMath.Pow(10, decadesPerMajorTick * (int)Math.Floor(rel)); } } break; case BoundaryTickSnapping.SnapToMinorOrMajor: { if (minorTicks > 1) { int decadesPerMinorTick = decadesPerMajorTick / minorTicks; double rel = Math.Log10(x) / decadesPerMinorTick; if (upwards) return RMath.Pow(10, decadesPerMinorTick * (int)Math.Ceiling(rel)); else return RMath.Pow(10, decadesPerMinorTick * (int)Math.Floor(rel)); } else if (minorTicks < 0) { int[] mantissa = minorTicks == -1 ? minorTickMantissa3 : minorTickMantissa9; double rel = Math.Log10(x); if (upwards) { int nrel = (int)Math.Floor(rel); double basis = RMath.Pow(10, nrel); for (int i = 0; i < mantissa.Length; ++i) { double result = mantissa[i] * basis; if (result >= x) return result; } return 10 * basis; } else // downwards { int nrel = (int)Math.Ceiling(rel) - 1; double basis = RMath.Pow(10, nrel); double result = 10 * basis; if (result <= x) return result; for (int i = mantissa.Length - 1; i >= 0; --i) { result = mantissa[i] * basis; if (result <= x) return result; } } } else // no minor ticks { double rel = Math.Log10(x) / decadesPerMajorTick; if (upwards) return RMath.Pow(10, decadesPerMajorTick * (int)Math.Ceiling(rel)); else return RMath.Pow(10, decadesPerMajorTick * (int)Math.Floor(rel)); } } break; } return x; }