Chart background on dark theme
This commit is contained in:
@@ -11,11 +11,15 @@ class ChartPainter extends CustomPainter {
|
||||
required this.channel,
|
||||
required this.session,
|
||||
required this.layout,
|
||||
required this.isDark,
|
||||
this.hoverLocalPos,
|
||||
});
|
||||
|
||||
final int channel;
|
||||
final SessionController session;
|
||||
final LayoutController layout;
|
||||
final bool isDark;
|
||||
final Offset? hoverLocalPos;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
@@ -24,8 +28,19 @@ class ChartPainter extends CustomPainter {
|
||||
final plotH = size.height - padTop - padBottom;
|
||||
if (plotW <= 0 || plotH <= 0) return;
|
||||
|
||||
// Theme-dependent palette.
|
||||
final bgColor = isDark ? const Color(0xFF1E1F22) : const Color(0xFFF7F7F4);
|
||||
final lineColor =
|
||||
isDark ? const Color(0xFF5EA8FF) : const Color(0xFF185FA5);
|
||||
final hatchColor =
|
||||
isDark ? const Color(0x66D17050) : const Color(0x55993C1D);
|
||||
final markerColor =
|
||||
isDark ? const Color(0xCCD17050) : const Color(0xAA993C1D);
|
||||
final cursorColor =
|
||||
isDark ? const Color(0xCCBBBBBB) : const Color(0xAA444444);
|
||||
|
||||
// Background.
|
||||
final bgPaint = Paint()..color = const Color(0xFFF7F7F4);
|
||||
final bgPaint = Paint()..color = bgColor;
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(padLeft, padTop, plotW, plotH),
|
||||
bgPaint,
|
||||
@@ -86,7 +101,7 @@ class ChartPainter extends CustomPainter {
|
||||
|
||||
// Hatched gap rectangles.
|
||||
final hatchPaint = Paint()
|
||||
..color = const Color(0x55993C1D)
|
||||
..color = hatchColor
|
||||
..style = PaintingStyle.fill;
|
||||
for (final g in gaps.hatchedRanges) {
|
||||
final x0 = xForCol(g.startPx);
|
||||
@@ -99,7 +114,7 @@ class ChartPainter extends CustomPainter {
|
||||
|
||||
// Polyline.
|
||||
final linePaint = Paint()
|
||||
..color = const Color(0xFF185FA5)
|
||||
..color = lineColor
|
||||
..strokeWidth = 1.2
|
||||
..style = PaintingStyle.stroke;
|
||||
final path = Path();
|
||||
@@ -132,7 +147,7 @@ class ChartPainter extends CustomPainter {
|
||||
|
||||
// Sub-pixel marker lines.
|
||||
final markerPaint = Paint()
|
||||
..color = const Color(0xAA993C1D)
|
||||
..color = markerColor
|
||||
..strokeWidth = 1;
|
||||
for (final px in gaps.markerPixels) {
|
||||
final x = xForCol(px);
|
||||
@@ -143,8 +158,56 @@ class ChartPainter extends CustomPainter {
|
||||
);
|
||||
}
|
||||
|
||||
// Cursor crosshair + data dot (still inside the plot clip).
|
||||
int? hoverCol;
|
||||
double? hoverY;
|
||||
int? hoverTsUs;
|
||||
if (hoverLocalPos != null) {
|
||||
final hx = hoverLocalPos!.dx;
|
||||
final hy = hoverLocalPos!.dy;
|
||||
if (hx >= padLeft &&
|
||||
hx <= padLeft + plotW &&
|
||||
hy >= padTop &&
|
||||
hy <= padTop + plotH) {
|
||||
final col = (hx - padLeft).floor().clamp(0, cols.length - 1);
|
||||
hoverCol = col;
|
||||
hoverTsUs = win.startUs +
|
||||
(((col + 0.5) / plotW) * (win.endUs - win.startUs)).round();
|
||||
final cursorPaint = Paint()
|
||||
..color = cursorColor
|
||||
..strokeWidth = 1;
|
||||
canvas.drawLine(
|
||||
Offset(xForCol(col), padTop),
|
||||
Offset(xForCol(col), padTop + plotH),
|
||||
cursorPaint,
|
||||
);
|
||||
if (cols[col].hasData) {
|
||||
hoverY = (cols[col].min + cols[col].max) / 2;
|
||||
final yPx = yForVal(hoverY);
|
||||
canvas.drawLine(
|
||||
Offset(padLeft, yPx),
|
||||
Offset(padLeft + plotW, yPx),
|
||||
cursorPaint,
|
||||
);
|
||||
canvas.drawCircle(
|
||||
Offset(xForCol(col), yPx),
|
||||
3,
|
||||
Paint()..color = lineColor,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
canvas.restore();
|
||||
|
||||
// Cursor readout box (outside the clip so it can overlay labels).
|
||||
if (hoverCol != null) {
|
||||
final tStr = hoverTsUs != null ? _fmtTime(hoverTsUs) : '—';
|
||||
final yStr = hoverY != null ? hoverY.toStringAsFixed(3) : '—';
|
||||
_drawReadout(canvas, 'x=$tStr y=$yStr',
|
||||
Offset(padLeft + 4, padTop + 2));
|
||||
}
|
||||
|
||||
// Axes labels.
|
||||
_drawText(canvas, '${yMax.toStringAsFixed(2)}',
|
||||
Offset(padLeft - 4, padTop), align: TextAlign.right);
|
||||
@@ -157,6 +220,44 @@ class ChartPainter extends CustomPainter {
|
||||
align: TextAlign.right);
|
||||
}
|
||||
|
||||
void _drawReadout(Canvas c, String s, Offset where) {
|
||||
final textColor =
|
||||
isDark ? const Color(0xFFEEEEEE) : const Color(0xFF222222);
|
||||
final bgColor =
|
||||
isDark ? const Color(0xCC2A2B2E) : const Color(0xCCFFFFFF);
|
||||
final borderColor =
|
||||
isDark ? const Color(0x66FFFFFF) : const Color(0x44000000);
|
||||
final tp = TextPainter(
|
||||
text: TextSpan(
|
||||
text: s,
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 10,
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
textDirection: TextDirection.ltr,
|
||||
)..layout();
|
||||
final bgRect = Rect.fromLTWH(
|
||||
where.dx,
|
||||
where.dy,
|
||||
tp.width + 8,
|
||||
tp.height + 4,
|
||||
);
|
||||
c.drawRRect(
|
||||
RRect.fromRectAndRadius(bgRect, const Radius.circular(3)),
|
||||
Paint()..color = bgColor,
|
||||
);
|
||||
c.drawRRect(
|
||||
RRect.fromRectAndRadius(bgRect, const Radius.circular(3)),
|
||||
Paint()
|
||||
..color = borderColor
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 0.5,
|
||||
);
|
||||
tp.paint(c, Offset(where.dx + 4, where.dy + 2));
|
||||
}
|
||||
|
||||
void _drawText(Canvas c, String s, Offset where,
|
||||
{TextAlign align = TextAlign.left}) {
|
||||
final tp = TextPainter(
|
||||
|
||||
Reference in New Issue
Block a user