calculateTooltipRegion method

void calculateTooltipRegion(
  1. SfCartesianChart chart,
  2. int seriesIndex,
  3. CartesianChartPoint point,
  4. int pointIndex,
)

To find the region data of chart tooltip

Implementation

void calculateTooltipRegion(SfCartesianChart chart, int seriesIndex,
    CartesianChartPoint<dynamic> point, int pointIndex) {
  /// For tooltip implementation
  // ignore: unnecessary_null_comparison
  if (_series.enableTooltip != null &&
      _series.enableTooltip &&
      // ignore: unnecessary_null_comparison
      point != null &&
      !point.isGap &&
      !point.isDrop) {
    final List<String> regionData = <String>[];
    String? date;
    final List<dynamic> regionRect = <dynamic>[];
    final dynamic primaryAxisRenderer = _xAxisRenderer;
    if (primaryAxisRenderer is DateTimeAxisRenderer) {
      final DateTimeAxis _axis = primaryAxisRenderer._axis as DateTimeAxis;
      final DateFormat dateFormat =
          _axis.dateFormat ?? _getDateTimeLabelFormat(_xAxisRenderer!);
      date = dateFormat
          .format(DateTime.fromMillisecondsSinceEpoch(point.xValue));
    } else if (primaryAxisRenderer is DateTimeCategoryAxisRenderer) {
      date = primaryAxisRenderer._dateFormat
          .format(DateTime.fromMillisecondsSinceEpoch(point.xValue.floor()));
    }
    _xAxisRenderer is CategoryAxisRenderer
        ? regionData.add(point.x.toString())
        : _xAxisRenderer is DateTimeAxisRenderer ||
                _xAxisRenderer is DateTimeCategoryAxisRenderer
            ? regionData.add(date.toString())
            : regionData.add(_getLabelValue(
                    point.xValue,
                    _xAxisRenderer!._axis,
                    chart.tooltipBehavior.decimalPlaces)
                .toString());
    if (_seriesType.contains('range')) {
      regionData.add(_getLabelValue(point.high, _yAxisRenderer!._axis,
              chart.tooltipBehavior.decimalPlaces)
          .toString());
      regionData.add(_getLabelValue(point.low, _yAxisRenderer!._axis,
              chart.tooltipBehavior.decimalPlaces)
          .toString());
    } else {
      regionData.add(_getLabelValue(point.yValue, _yAxisRenderer!._axis,
              chart.tooltipBehavior.decimalPlaces)
          .toString());
    }
    regionData.add(_series.name ?? 'series $seriesIndex');
    regionRect.add(point.region);
    regionRect.add(_isRectSeries
        ? _seriesType == 'column' || _seriesType.contains('stackedcolumn')
            ? (point.yValue > 0) == true
                ? point.region!.topCenter
                : point.region!.bottomCenter
            : point.region!.topCenter
        : (_seriesType == 'rangearea'
            ? Offset(point.markerPoint!.x,
                (point.markerPoint!.y + point.markerPoint2!.y) / 2)
            : point.region!.center));
    regionRect.add(point.pointColorMapper);
    regionRect.add(point.bubbleSize);
    if (_seriesType.contains('stacked')) {
      regionData.add((point.cumulativeValue).toString());
    }
    _regionalData![regionRect] = regionData;
  }
}