showByPixel method
Displays the tooltip at the specified x and y-positions.
- x & y - logical pixel values to position the tooltip.
Implementation
// shouldInsidePointRegion - determines if whether the given pixel values remains within point region.
// Defaults to true.
void showByPixel(double x, double y) {
//, [bool shouldInsidePointRegion]) {
final dynamic chartState = _chartState;
final dynamic chart = chartState._chart;
final TooltipBehaviorRenderer tooltipBehaviorRenderer =
_chartState._tooltipBehaviorRenderer;
bool? isInsidePointRegion;
String text = '';
String trimmedText = '';
Offset? axisLabelPosition;
if (chart is SfCartesianChart) {
_chartState._requireAxisTooltip = false;
for (int i = 0;
i < _chartState._chartAxis._axisRenderersCollection.length;
i++) {
final List<AxisLabel> labels =
_chartState._chartAxis._axisRenderersCollection[i]._visibleLabels;
for (int k = 0; k < labels.length; k++) {
if (_chartState
._chartAxis._axisRenderersCollection[i]._axis.isVisible ==
true &&
labels[k]._labelRegion != null &&
labels[k]._labelRegion!.contains(Offset(x, y))) {
_chartState._requireAxisTooltip = true;
text = labels[k].text;
trimmedText = labels[k].renderText ?? '';
tooltipBehaviorRenderer._prevTooltipValue =
tooltipBehaviorRenderer._currentTooltipValue;
axisLabelPosition = labels[k]._labelRegion!.center;
// -3 to indicte axis tooltip
tooltipBehaviorRenderer._currentTooltipValue =
TooltipValue(null, k, 0);
}
}
}
}
if (chart is SfCartesianChart &&
!(_chartState._requireAxisTooltip == true)) {
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 String seriesType = seriesRenderer._seriesType;
final double padding = (seriesType == 'bubble' ||
seriesType == 'scatter' ||
seriesType.contains('column') ||
seriesType.contains('bar'))
? 0
: _chartState._tooltipBehaviorRenderer._isHovering == true
? 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);
bool outlierTooltip = false;
if (seriesRenderer._seriesType == 'boxandwhisker') {
final List<Rect>? outlierRegion = regionRect[5];
if (outlierRegion != null) {
for (int rectIndex = 0;
rectIndex < outlierRegion.length;
rectIndex++) {
if (outlierRegion[rectIndex].contains(Offset(x, y))) {
outlierTooltip = true;
break;
}
}
}
}
if (paddedRegion.contains(Offset(x, y)) || outlierTooltip) {
isInsidePointRegion = true;
}
});
}
}
}
if (chart is SfCartesianChart &&
activationMode != ActivationMode.none &&
// ignore: unnecessary_null_comparison
x != null &&
// ignore: unnecessary_null_comparison
y != null &&
_chartState._requireAxisTooltip == true) {
final SfTooltipState? tooltipState =
tooltipBehaviorRenderer._chartTooltipState;
if (trimmedText.contains('...')) {
tooltipBehaviorRenderer._show = true;
tooltipState?.needMarker = false;
tooltipBehaviorRenderer._showAxisTooltip(
axisLabelPosition!, chart, text);
} else {
tooltipBehaviorRenderer._show = false;
if (chart.tooltipBehavior.shouldAlwaysShow == false) {
hide();
}
}
} else if (tooltipBehaviorRenderer._chartTooltip != null &&
activationMode != ActivationMode.none &&
// ignore: unnecessary_null_comparison
x != null &&
// ignore: unnecessary_null_comparison
y != null) {
final SfTooltipState? tooltipState =
tooltipBehaviorRenderer._chartTooltipState;
if (chart is! SfCartesianChart ||
tooltipBehaviorRenderer._isInteraction ||
(isInsidePointRegion ?? false)) {
tooltipState?.needMarker = chart is SfCartesianChart;
if (isInsidePointRegion == true ||
_chartState._tooltipBehaviorRenderer._isHovering == true ||
chart is! SfCartesianChart) {
tooltipBehaviorRenderer._showTooltip(x, y);
} else {
tooltipBehaviorRenderer._show = false;
if (chart.tooltipBehavior.shouldAlwaysShow == false) {
hide();
}
}
} else if (tooltipBehaviorRenderer._renderBox != null) {
tooltipBehaviorRenderer._show = true;
tooltipState?.needMarker = false;
tooltipBehaviorRenderer._showChartAreaTooltip(
Offset(x, y),
_chartState._chartAxis._primaryXAxisRenderer,
_chartState._chartAxis._primaryYAxisRenderer,
chart);
}
}
if (chart is SfCartesianChart &&
chart.tooltipBehavior.builder != null &&
x != null && // ignore: unnecessary_null_comparison
// ignore: unnecessary_null_comparison
y != null) {
tooltipBehaviorRenderer._showTemplateTooltip(Offset(x, y));
}
// ignore: unnecessary_null_comparison
if (tooltipBehaviorRenderer != null) {
tooltipBehaviorRenderer._isInteraction = false;
}
}