customizeSegment method

  1. @override
void customizeSegment(
  1. ChartSegment segment
)
override

To customize each segments.

Implementation

@override
void customizeSegment(ChartSegment segment) {
  final int index = segment.currentSegmentIndex;
  num previousClose = double.negativeInfinity;
  if (index != 0) {
    previousClose = closeValues[index - 1];
  }

  final num open = openValues[index];
  final num close = closeValues[index];
  final bool isHollow = close > open;
  final bool isBull = close > previousClose;

  // TODO(Natrayasf): Comment section is pending.
  //  Naming of colors.
  //  +--------+-----------+
  //  | Color  | colorName |
  //  +--------+-----------+
  //  | Green  | bullColor |
  //  | Red    | bearColor |
  //  +--------+-----------+

  // Set [enableSolidCandles: true].
  //  +--------+--------+----------------+
  //  | Hollow | Color  | Rendering      |
  //  +--------+--------+----------------+
  //  | true   | Green  | Solid, Fill    |
  //  | false  | Red    | Solid, Fill    |
  //  +--------+--------+----------------+

  // Set [enableSolidCandles: false].
  //  +---------+----------+-------------+-------------+
  //  | isBull  | isHollow | FillColor   | StrokeColor |
  //  +---------+----------+-------------+-------------+
  //  | true    | true     | transparent | Green       |
  //  | false   | true     | transparent | Red         |
  //  | true    | false    | Green       | Green       |
  //  | false   | false    | Red         | Red         |
  //  +---------+----------+-------------+-------------+

  late Color color;
  if (enableSolidCandles) {
    color = isHollow ? bullColor : bearColor;
    final Color? segmentColor = pointColorMapper != null &&
            pointColors[segment.currentSegmentIndex] != null
        ? null
        : color;
    updateSegmentColor(segment, segmentColor, borderWidth,
        fillColor: segmentColor, isLineType: true);
  } else {
    color = isBull ? bullColor : bearColor;
    final Color? segmentColor = pointColorMapper != null &&
            pointColors[segment.currentSegmentIndex] != null
        ? null
        : color;
    updateSegmentColor(segment, segmentColor, borderWidth,
        fillColor: isHollow ? Colors.transparent : segmentColor,
        isLineType: true);
  }
  updateSegmentGradient(segment);
}