本文整理汇总了C#中Range.ToComparableRange方法的典型用法代码示例。如果您正苦于以下问题:C# Range.ToComparableRange方法的具体用法?C# Range.ToComparableRange怎么用?C# Range.ToComparableRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Range
的用法示例。
在下文中一共展示了Range.ToComparableRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverrideDataRange
protected override Range<IComparable> OverrideDataRange(Range<IComparable> range)
{
Range<IComparable> overriddenActualRange = range;
if (!overriddenActualRange.HasData)
{
int year = DateTime.Now.Year;
return new Range<IComparable>(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1));
}
// ActualLength of 1.0 or less maps all points to the same coordinate
if (range.HasData && this.ActualLength > 1.0)
{
IList<ValueMarginCoordinateAndOverlap> valueMargins = new List<ValueMarginCoordinateAndOverlap>();
foreach (ValueMargin valueMargin in
this.RegisteredListeners
.OfType<IValueMarginProvider>()
.SelectMany(provider => provider.GetValueMargins(this)))
{
valueMargins.Add(
new ValueMarginCoordinateAndOverlap
{
ValueMargin = valueMargin,
});
}
if (valueMargins.Count > 0)
{
double maximumPixelMarginLength =
valueMargins
.Select(valueMargin => valueMargin.ValueMargin.LowMargin + valueMargin.ValueMargin.HighMargin)
.MaxOrNullable().Value;
// Requested margin is larger than the axis so give up
// trying to find a range that will fit it.
if (maximumPixelMarginLength > this.ActualLength)
{
return range;
}
Range<DateTime> currentRange = range.ToDateTimeRange();
// Ensure range is not empty.
if (currentRange.Minimum == currentRange.Maximum)
{
int year = DateTime.Now.Year;
currentRange = new Range<DateTime>(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1));
}
// priming the loop
double actualLength = this.ActualLength;
ValueMarginCoordinateAndOverlap maxLeftOverlapValueMargin;
ValueMarginCoordinateAndOverlap maxRightOverlapValueMargin;
UpdateValueMargins(valueMargins, currentRange.ToComparableRange());
GetMaxLeftAndRightOverlap(valueMargins, out maxLeftOverlapValueMargin, out maxRightOverlapValueMargin);
while (maxLeftOverlapValueMargin.LeftOverlap > 0 || maxRightOverlapValueMargin.RightOverlap > 0)
{
long unitOverPixels = currentRange.GetLength().Value.Ticks / ((long) actualLength);
DateTime newMinimum = new DateTime(currentRange.Minimum.Ticks - (long)((maxLeftOverlapValueMargin.LeftOverlap + 0.5) * unitOverPixels));
DateTime newMaximum = new DateTime(currentRange.Maximum.Ticks + (long)((maxRightOverlapValueMargin.RightOverlap + 0.5) * unitOverPixels));
currentRange = new Range<DateTime>(newMinimum, newMaximum);
UpdateValueMargins(valueMargins, currentRange.ToComparableRange());
GetMaxLeftAndRightOverlap(valueMargins, out maxLeftOverlapValueMargin, out maxRightOverlapValueMargin);
}
return currentRange.ToComparableRange();
}
}
return range;
}
示例2: OverrideDataRange
/// <summary>
/// Overrides the actual range to ensure that it is never set to an
/// empty range.
/// </summary>
/// <param name="range">The range to override.</param>
/// <returns>Returns the overridden range.</returns>
protected override Range<IComparable> OverrideDataRange(Range<IComparable> range)
{
range = base.OverrideDataRange(range);
if (!range.HasData)
{
return new Range<IComparable>(0.0, 1.0);
}
else if (ValueHelper.Compare(range.Minimum, range.Maximum) == 0)
{
Range<IComparable> outputRange = new Range<IComparable>((ValueHelper.ToDouble(range.Minimum)) - 1, (ValueHelper.ToDouble(range.Maximum)) + 1);
return outputRange;
}
// ActualLength of 1.0 or less maps all points to the same coordinate
if (range.HasData && this.ActualLength > 1.0)
{
bool isDataAnchoredToOrigin = false;
IList<ValueMarginCoordinateAndOverlap> valueMargins = new List<ValueMarginCoordinateAndOverlap>();
foreach (IValueMarginProvider valueMarginProvider in this.RegisteredListeners.OfType<IValueMarginProvider>())
{
foreach (ValueMargin valueMargin in valueMarginProvider.GetValueMargins(this))
{
IAnchoredToOrigin dataAnchoredToOrigin = valueMarginProvider as IAnchoredToOrigin;
isDataAnchoredToOrigin = (dataAnchoredToOrigin != null && dataAnchoredToOrigin.AnchoredAxis == this);
valueMargins.Add(
new ValueMarginCoordinateAndOverlap
{
ValueMargin = valueMargin,
});
}
}
if (valueMargins.Count > 0)
{
double maximumPixelMarginLength =
valueMargins
.Select(valueMargin => valueMargin.ValueMargin.LowMargin + valueMargin.ValueMargin.HighMargin)
.MaxOrNullable().Value;
// Requested margin is larger than the axis so give up
// trying to find a range that will fit it.
if (maximumPixelMarginLength > this.ActualLength)
{
return range;
}
Range<double> originalRange = range.ToDoubleRange();
Range<double> currentRange = range.ToDoubleRange();
// Ensure range is not empty.
if (currentRange.Minimum == currentRange.Maximum)
{
currentRange = new Range<double>(currentRange.Maximum - 1, currentRange.Maximum + 1);
}
// priming the loop
double actualLength = this.ActualLength;
ValueMarginCoordinateAndOverlap maxLeftOverlapValueMargin;
ValueMarginCoordinateAndOverlap maxRightOverlapValueMargin;
UpdateValueMargins(valueMargins, currentRange.ToComparableRange());
GetMaxLeftAndRightOverlap(valueMargins, out maxLeftOverlapValueMargin, out maxRightOverlapValueMargin);
while (maxLeftOverlapValueMargin.LeftOverlap > 0 || maxRightOverlapValueMargin.RightOverlap > 0)
{
double unitOverPixels = currentRange.GetLength().Value / actualLength;
double newMinimum = currentRange.Minimum - ((maxLeftOverlapValueMargin.LeftOverlap + 0.5) * unitOverPixels);
double newMaximum = currentRange.Maximum + ((maxRightOverlapValueMargin.RightOverlap + 0.5) * unitOverPixels);
currentRange = new Range<double>(newMinimum, newMaximum);
UpdateValueMargins(valueMargins, currentRange.ToComparableRange());
GetMaxLeftAndRightOverlap(valueMargins, out maxLeftOverlapValueMargin, out maxRightOverlapValueMargin);
}
if (isDataAnchoredToOrigin)
{
if (originalRange.Minimum >= 0 && currentRange.Minimum < 0)
{
currentRange = new Range<double>(0, currentRange.Maximum);
}
else if (originalRange.Maximum <= 0 && currentRange.Maximum > 0)
{
currentRange = new Range<double>(currentRange.Minimum, 0);
}
}
return currentRange.ToComparableRange();
}
}
return range;
}