show method

void show(
  1. dynamic x,
  2. double y, [
  3. String? xAxisName,
  4. String? yAxisName,
])

Displays the tooltip at the specified x and y-values.

*x & y - x & y point values at which the tooltip needs to be shown.

  • xAxisName - name of the x axis the given point must be bind to.

  • yAxisName - name of the y axis the given point must be bind to.

Implementation

// shouldInsidePointRegion - determines if whether the given pixel values remains within point region.
// Defaults to true.
///
/// * xAxisName - name of the x axis the given point must be bind to.
///
/// * yAxisName - name of the y axis the given point must be bind to.
void show(dynamic x, double y, [String? xAxisName, String? yAxisName]) {
  if (_chartState._chart is SfCartesianChart) {
    final dynamic chart = _chartState._chart;
    final TooltipBehaviorRenderer tooltipBehaviorRenderer =
        _chartState._tooltipBehaviorRenderer;
    bool? isInsidePointRegion = false;
    ChartAxisRenderer? xAxisRenderer, yAxisRenderer;
    if (xAxisName != null && yAxisName != null) {
      for (final ChartAxisRenderer axisRenderer
          in _chartState._chartAxis._axisRenderersCollection) {
        if (axisRenderer._name == xAxisName) {
          xAxisRenderer = axisRenderer;
        } else if (axisRenderer._name == yAxisName) {
          yAxisRenderer = axisRenderer;
        }
      }
    } else {
      xAxisRenderer = _chartState._chartAxis._primaryXAxisRenderer;
      yAxisRenderer = _chartState._chartAxis._primaryYAxisRenderer;
    }
    final _ChartLocation position = _calculatePoint(
        (x is DateTime && xAxisRenderer! is! DateTimeCategoryAxisRenderer)
            ? x.millisecondsSinceEpoch
            : ((x is DateTime &&
                    xAxisRenderer! is DateTimeCategoryAxisRenderer)
                ? (xAxisRenderer as DateTimeCategoryAxisRenderer)
                    ._labels
                    .indexOf(xAxisRenderer._dateFormat.format(x))
                : ((x is String && xAxisRenderer is CategoryAxisRenderer)
                    ? xAxisRenderer._labels.indexOf(x)
                    : x)),
        y,
        xAxisRenderer!,
        yAxisRenderer!,
        _chartState._requireInvertedAxis,
        null,
        _chartState._chartAxis._axisClipRect);
    for (int i = 0;
        i < _chartState._chartSeries.visibleSeriesRenderers.length;
        i++) {
      final CartesianSeriesRenderer seriesRenderer =
          _chartState._chartSeries.visibleSeriesRenderers[i];
      if (seriesRenderer._visible! &&
          seriesRenderer._series.enableTooltip &&
          seriesRenderer._regionalData != null) {
        final double padding = (seriesRenderer._seriesType == 'bubble' ||
                seriesRenderer._seriesType == 'scatter' ||
                seriesRenderer._seriesType.contains('column') ||
                seriesRenderer._seriesType.contains('bar'))
            ? 0
            : 15; // regional padding to detect smooth touch
        seriesRenderer._regionalData!
            .forEach((dynamic regionRect, dynamic values) {
          final Rect region = regionRect[0];
          final Rect paddedRegion = Rect.fromLTRB(
              region.left - padding,
              region.top - padding,
              region.right + padding,
              region.bottom + padding);
          if (paddedRegion.contains(Offset(position.x, position.y))) {
            isInsidePointRegion = true;
          }
        });
      }
    }
    if (_chartState._tooltipBehaviorRenderer._tooltipTemplate == null) {
      final SfTooltipState? tooltipState =
          tooltipBehaviorRenderer._chartTooltipState;
      if (isInsidePointRegion ?? false) {
        tooltipState?.needMarker = chart is SfCartesianChart;
        tooltipBehaviorRenderer._showTooltip(position.x, position.y);
      } else {
        //to show tooltip when the position is out of point region
        tooltipBehaviorRenderer._show = true;
        tooltipState?.needMarker = false;
        _chartState._tooltipBehaviorRenderer._showChartAreaTooltip(
            Offset(position.x, position.y),
            xAxisRenderer,
            yAxisRenderer,
            chart);
      }
    }
    tooltipBehaviorRenderer._isInteraction = false;
  }
}