computeBoundedPointsForElement method
- @protected
- PointRendererElement<
D> pointElement, - Rectangle<
num> drawBounds
Computes end points for the pointElement
's lower and upper data bounds.
This will compute two points representing the end points of the symbol,
from (xLower, yLower) to (xUpper, yUpper). The end points will be clamped
along the line so that it is fully contained within drawBounds
.
Returns null if pointElement
is missing any of the data bounds, or if
the line connecting them is located entirely outside of drawBounds
.
Implementation
@protected
List<Point<double>>? computeBoundedPointsForElement(
PointRendererElement<D> pointElement, Rectangle drawBounds) {
// All bounds points must be defined for a valid comparison point to be
// drawn.
final point = pointElement.point!;
if (point.xLower == null ||
point.xUpper == null ||
point.yLower == null ||
point.yUpper == null) {
return null;
}
// Construct the points that describe our line p1p2.
var p1 = Point<double>(point.xLower!, point.yLower!);
var p2 = Point<double>(point.xUpper!, point.yUpper!);
// First check to see if there is no intersection at all between the line
// p1p2 and [drawBounds].
final dataBoundsRect = Rectangle<num>.fromPoints(p1, p2);
if (!drawBounds.intersects(dataBoundsRect)) {
return null;
}
// Line with end points [p1] and [p2].
final p1p2 = _Line.fromPoints(p1, p2);
// Next, slide p1 along the line p1p2 towards the edge of the draw area if
// the point is located outside of it.
if (!drawBounds.containsPoint(p1)) {
final p = _clampPointAlongLineToBoundingBox(p1, p1p2, drawBounds);
if (p != null) {
p1 = p;
}
}
// Next, slide p2 along the line p1p2 towards the edge of the draw area if
// the point is located outside of it.
if (!drawBounds.containsPoint(p2)) {
final p = _clampPointAlongLineToBoundingBox(p2, p1p2, drawBounds);
if (p != null) {
p2 = p;
}
}
return [p1, p2];
}