transformValues method

  1. @override
void transformValues()
override

Transforms the x and y values to screen coordinates.

Implementation

@override
void transformValues() {
  points.clear();

  final double marginSpace = (isExploded
          ? percentToValue(series.explodeOffset, _plotAreaBounds.width)!
          : 0) +
      (_plotAreaBounds.width - _triangleSize.width) / 2;
  final double pyramidTop = _plotAreaBounds.top +
      (_plotAreaBounds.height - _triangleSize.height) / 2;
  final double pyramidLeft = marginSpace + _plotAreaBounds.left;
  final double heightRatio = pyramidTop / _triangleSize.height;

  double top = y;
  double bottom = y + _height;

  final double topRadius = (1 - top) / 2;
  final double bottomRadius = (1 - bottom) / 2;

  top += heightRatio;
  bottom += heightRatio;

  final double topX1 = pyramidLeft + topRadius * _triangleSize.width;
  final double topX2 = pyramidLeft + (1 - topRadius) * _triangleSize.width;
  final double bottomX1 =
      pyramidLeft + (1 - bottomRadius) * _triangleSize.width;
  final double bottomX2 = pyramidLeft + bottomRadius * _triangleSize.width;
  final double topY = top * _triangleSize.height;
  final double bottomY = bottom * _triangleSize.height;

  path
    ..reset()
    ..moveTo(topX1, topY)
    ..lineTo(topX2, topY)
    ..lineTo(bottomX1, bottomY)
    ..lineTo(bottomX2, bottomY)
    ..close();

  points
    ..add(Offset(topX1, topY))
    ..add(Offset(topX2, topY))
    ..add(Offset(bottomX1, bottomY))
    ..add(Offset(bottomX2, bottomY));
}