drawCrossLineText method
draw the cross line. when user focus
Implementation
@override
void drawCrossLineText(Canvas canvas, Size size) {
var index = calculateSelectedX(selectX);
KLineEntity point = getItem(index);
TextPainter tp = getTextPainter(point.close, chartColors.crossTextColor);
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));
}
TextPainter dateTp =
getTextPainter(getDate(point.time), chartColors.crossTextColor);
textWidth = dateTp.width;
r = textHeight / 2;
x = translateXtoX(getX(index));
y = size.height - mBottomPadding;
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));
//Long press to display the details of this data
sink.add(InfoWindowEntity(point, isLeft: isLeft));
}