drawCrossLineText method
void
drawCrossLineText(
- Canvas canvas,
- Size size
)
override
Implementation
@override
void drawCrossLineText(Canvas canvas, Size size) {
final index = calculateSelectedX(selectX);
final point = getItem(index);
final tp = getTextPainter(format(point.close), style.select.colors.text);
double textHeight = tp.height;
double textWidth = tp.width;
double w1 = 5;
double w2 = 3;
double r = textHeight / 2 + w2;
double y = getMainY(point.close);
double x;
bool isLeft = false;
if (translateXtoX(getX(index)) < mWidth / 2) {
isLeft = false;
x = 1;
Path path = new Path();
path.moveTo(x, y - r);
path.lineTo(x, y + r);
path.lineTo(textWidth + 2 * w1, y + r);
path.lineTo(textWidth + 2 * w1 + w2, y);
path.lineTo(textWidth + 2 * w1, y - r);
path.close();
canvas.drawPath(path, selectPointPaint);
canvas.drawPath(path, selectorBorderPaint);
tp.paint(canvas, Offset(x + w1, y - textHeight / 2));
} else {
isLeft = true;
x = mWidth - textWidth - 1 - 2 * w1 - w2;
Path path = new Path();
path.moveTo(x, y);
path.lineTo(x + w2, y + r);
path.lineTo(mWidth - 2, y + r);
path.lineTo(mWidth - 2, y - r);
path.lineTo(x + w2, y - r);
path.close();
canvas.drawPath(path, selectPointPaint);
canvas.drawPath(path, selectorBorderPaint);
tp.paint(canvas, Offset(x + w1 + w2, y - textHeight / 2));
}
final dateTp = getTextPainter(getDate(point.time), style.select.colors.text);
textWidth = dateTp.width;
r = textHeight / 2;
x = translateXtoX(getX(index));
y = size.height - style.main.padding.bottom;
if (x < textWidth + 2 * w1) {
x = 1 + textWidth / 2 + w1;
} else if (mWidth - x < textWidth + 2 * w1) {
x = mWidth - 1 - textWidth / 2 - w1;
}
double baseLine = textHeight / 2;
canvas.drawRect(Rect.fromLTRB(x - textWidth / 2 - w1, y, x + textWidth / 2 + w1, y + baseLine + r), selectPointPaint);
canvas.drawRect(Rect.fromLTRB(x - textWidth / 2 - w1, y, x + textWidth / 2 + w1, y + baseLine + r), selectorBorderPaint);
dateTp.paint(canvas, Offset(x - textWidth / 2, y));
//长按显示这条数据详情
sink?.add(InfoWindowEntity(point, isLeft: isLeft));
}