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(
NumberUtil.formatFixed(point.close, fixedLength),
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;
double space = 4.0;
bool isLeft = false;
if (translateXtoX(getX(index)) < mWidth / 2) {
isLeft = false;
x = space;
RRect rect = RRect.fromLTRBR(
x,
y - r,
x + textWidth + 2 * w1,
y + r,
Radius.circular(2.0),
);
canvas.drawRRect(rect, selectPointPaint);
canvas.drawRRect(rect, selectorBorderPaint);
tp.paint(canvas, Offset(x + w1, y - textHeight / 2));
} else {
isLeft = true;
x = mWidth - textWidth - 2 * w1 - space;
RRect rect = RRect.fromLTRBR(
x,
y - r,
mWidth - space,
y + r,
Radius.circular(2.0),
);
canvas.drawRRect(rect, selectPointPaint);
canvas.drawRRect(rect, selectorBorderPaint);
tp.paint(canvas, Offset(x + w1, y - textHeight / 2));
}
TextPainter dateTp =
getTextPainter(getDate(point.time), chartColors.crossTextColor);
textWidth = dateTp.width;
r = textHeight / 2;
x = translateXtoX(getX(index));
y = mDateRect.top;
if (x < textWidth + 2 * w1) {
x = 1 + textWidth / 2 + w1;
} else if (mWidth - x < textWidth + 2 * w1) {
x = mWidth - 1 - textWidth / 2 - w1;
}
RRect rectBox = RRect.fromLTRBR(
x - textWidth / 2 - w1,
y,
x + textWidth / 2 + w1,
mDateRect.bottom,
Radius.circular(2.0),
);
// double baseLine = textHeight / 2;
canvas.drawRRect(
rectBox,
selectPointPaint,
);
canvas.drawRRect(
rectBox,
selectorBorderPaint,
);
dateTp.paint(
canvas,
Offset(
x - textWidth / 2,
mDateRect.top + (mDateRect.height - dateTp.height) / 2,
),
);
//Long press to display the details of this data
sink.add(InfoWindowEntity(point, isLeft: isLeft));
}