transformValues method
Transforms the x and y values to screen coordinates.
Implementation
@override
void transformValues() {
points.clear();
double? leftEnd, neckJoiner;
double rightEnd = 0;
final double neckSizeWidth = _neckSize.width;
final double neckSizeHeight = _neckSize.height;
final double triangleWidth = _triangleSize.width;
final double triangleHeight = _triangleSize.height;
final double funnelHeight = triangleHeight - neckSizeHeight;
final double left = (isExploded
? percentToValue(series.explodeOffset, _plotAreaBounds.width)!
: 0) +
(_plotAreaBounds.width - triangleWidth) / 2;
final double topSpace = (_plotAreaBounds.height - triangleHeight) / 2;
double topY = y * triangleHeight;
double bottomY = topY + _height * triangleHeight;
double funnelWidth = neckSizeWidth +
(triangleWidth - neckSizeWidth) *
((funnelHeight - topY) / funnelHeight);
double topX1 = (triangleWidth / 2) - funnelWidth / 2;
double topX2 = topX1 + funnelWidth;
funnelWidth = (bottomY > funnelHeight || triangleHeight == neckSizeHeight)
? neckSizeWidth
: neckSizeWidth +
(triangleWidth - neckSizeWidth) *
((funnelHeight - bottomY) / funnelHeight);
double bottomX1 = triangleWidth / 2 - funnelWidth / 2;
double bottomX2 = bottomX1 + funnelWidth;
if (topY >= funnelHeight) {
topX1 = bottomX1 = leftEnd = triangleWidth / 2 - neckSizeWidth / 2;
topX2 = bottomX2 = rightEnd = triangleWidth / 2 + neckSizeWidth / 2;
} else if (bottomY > funnelHeight) {
leftEnd = bottomX1 = triangleWidth / 2 - funnelWidth / 2;
rightEnd = bottomX2 = leftEnd + funnelWidth;
neckJoiner = funnelHeight;
}
topY += topSpace;
bottomY += topSpace;
neckJoiner = (neckJoiner != null) ? (neckJoiner + topSpace) : null;
points
..add(Offset(left + topX1, topY))
..add(Offset(left + topX2, topY));
if (neckJoiner != null) {
points
..add(Offset(left + rightEnd, neckJoiner))
..add(Offset(left + bottomX2, bottomY))
..add(Offset(left + bottomX1, bottomY))
..add(Offset(left + ((leftEnd != null) ? leftEnd : 0), neckJoiner));
} else {
points
..add(Offset(left + bottomX2, bottomY))
..add(Offset(left + bottomX1, bottomY));
}
path
..reset()
..moveTo(left + topX1, topY)
..lineTo(left + topX2, topY);
if (neckJoiner != null) {
path
..lineTo(left + rightEnd, neckJoiner)
..lineTo(left + bottomX2, bottomY)
..lineTo(left + bottomX1, bottomY)
..lineTo(left + ((leftEnd != null) ? leftEnd : 0), neckJoiner)
..close();
} else {
path
..lineTo(left + bottomX2, bottomY)
..lineTo(left + bottomX1, bottomY)
..close();
}
}