Skip to content

Commit 6095287

Browse files
committed
Proper fix for the ' ──' issue
1 parent 5d1c98a commit 6095287

File tree

1 file changed

+75
-12
lines changed

1 file changed

+75
-12
lines changed

lib/renderer/chart_painter.dart

+75-12
Original file line numberDiff line numberDiff line change
@@ -339,34 +339,97 @@ class ChartPainter extends BaseChartPainter {
339339
@override
340340
void drawMaxAndMin(Canvas canvas) {
341341
if (isLine == true) return;
342+
double lineSize = 20;
343+
double lineToTextOffset = 5;
344+
345+
Paint linePaint = Paint()
346+
..strokeWidth = 1
347+
..color = chartColors.minColor;
348+
342349
//绘制最大值和最小值
343350
double x = translateXtoX(getX(mMainMinIndex));
344351
double y = getMainY(mMainLowMinValue);
345352
if (x < mWidth / 2) {
346353
//画右边
347354
TextPainter tp = getTextPainter(
348-
"── " + mMainLowMinValue.toStringAsFixed(fixedLength),
349-
chartColors.minColor);
350-
tp.paint(canvas, Offset(x, y - tp.height / 2));
355+
mMainLowMinValue.toStringAsFixed(fixedLength),
356+
chartColors.minColor,
357+
);
358+
359+
canvas.drawLine(
360+
Offset(x, y),
361+
Offset(x + lineSize, y),
362+
linePaint,
363+
);
364+
365+
tp.paint(
366+
canvas,
367+
Offset(
368+
x + lineSize + lineToTextOffset,
369+
y - tp.height / 2,
370+
),
371+
);
351372
} else {
352373
TextPainter tp = getTextPainter(
353-
mMainLowMinValue.toStringAsFixed(fixedLength) + " ──",
354-
chartColors.minColor);
355-
tp.paint(canvas, Offset(x - tp.width, y - tp.height / 2));
374+
mMainLowMinValue.toStringAsFixed(fixedLength),
375+
chartColors.minColor,
376+
);
377+
378+
canvas.drawLine(
379+
Offset(x, y),
380+
Offset(x - lineSize, y),
381+
linePaint,
382+
);
383+
384+
tp.paint(
385+
canvas,
386+
Offset(
387+
x - tp.width - lineSize - lineToTextOffset,
388+
y - tp.height / 2,
389+
),
390+
);
356391
}
357392
x = translateXtoX(getX(mMainMaxIndex));
358393
y = getMainY(mMainHighMaxValue);
359394
if (x < mWidth / 2) {
360395
//画右边
361396
TextPainter tp = getTextPainter(
362-
"── " + mMainHighMaxValue.toStringAsFixed(fixedLength),
363-
chartColors.maxColor);
364-
tp.paint(canvas, Offset(x, y - tp.height / 2));
397+
mMainHighMaxValue.toStringAsFixed(fixedLength),
398+
chartColors.maxColor,
399+
);
400+
401+
canvas.drawLine(
402+
Offset(x, y),
403+
Offset(x + lineSize, y),
404+
linePaint,
405+
);
406+
407+
tp.paint(
408+
canvas,
409+
Offset(
410+
x + lineSize + lineToTextOffset,
411+
y - tp.height / 2,
412+
),
413+
);
365414
} else {
366415
TextPainter tp = getTextPainter(
367-
mMainHighMaxValue.toStringAsFixed(fixedLength) + " ──",
368-
chartColors.maxColor);
369-
tp.paint(canvas, Offset(x - tp.width, y - tp.height / 2));
416+
mMainHighMaxValue.toStringAsFixed(fixedLength),
417+
chartColors.maxColor,
418+
);
419+
420+
canvas.drawLine(
421+
Offset(x, y),
422+
Offset(x - lineSize, y),
423+
linePaint,
424+
);
425+
426+
tp.paint(
427+
canvas,
428+
Offset(
429+
x - tp.width - lineSize - lineToTextOffset,
430+
y - tp.height / 2,
431+
),
432+
);
370433
}
371434
}
372435

0 commit comments

Comments
 (0)