isCrossLineLabelTapped method
检测是否点击了十字线标签
Implementation
bool isCrossLineLabelTapped(Offset tapPoint) {
if (!shouldShowCrossLine) return false;
double x = selectX;
double y = selectY;
// 确保Y坐标在主图区域内
if (y < mTopPadding) y = mTopPadding;
if (y > mMainRect.bottom) y = mMainRect.bottom;
// 计算标签位置和大小
double w1 = 8;
double w2 = 6;
double lineSpacing = 2;
double textHeight = 12; // 估算文本高度
double totalTextHeight = textHeight * 2 + lineSpacing;
double r = totalTextHeight / 2 + w2;
double maxWidth = 100; // 估算最大宽度
Rect labelRect;
if (x < mWidth / 2) {
// 左侧标签
labelRect = Rect.fromLTRB(
1,
y - r,
maxWidth + 2 * w1 + w2,
y + r,
);
} else {
// 右侧标签
labelRect = Rect.fromLTRB(
mWidth - maxWidth - 1 - 2 * w1 - w2,
y - r,
mWidth - 2,
y + r,
);
}
return labelRect.contains(tapPoint);
}