import QtQuick import "../theme" // Filled line graph of the last samples; `max` 0 scales to the largest value. Canvas { id: root property var values: [] property real max: 100 property color color: Theme.accentVivid property int samples: 60 onValuesChanged: requestPaint() onColorChanged: requestPaint() onWidthChanged: requestPaint() onHeightChanged: requestPaint() onPaint: { const c = getContext("2d"); c.reset(); const v = values.filter(x => x !== null && x !== undefined && Number.isFinite(x)); if (v.length < 2) return; const top = root.max > 0 ? root.max : Math.max(1, ...v) * 1.15, step = width / (root.samples - 1), offset = width - (v.length - 1) * step; const y = x => height - 2 - (height - 4) * Math.min(1, x / top); c.beginPath(); c.moveTo(offset, height); v.forEach((x, i) => c.lineTo(offset + i * step, y(x))); c.lineTo(offset + (v.length - 1) * step, height); c.closePath(); const g = c.createLinearGradient(0, 0, 0, height); g.addColorStop(0, Qt.alpha(root.color, 0.35)); g.addColorStop(1, Qt.alpha(root.color, 0)); c.fillStyle = g; c.fill(); c.beginPath(); v.forEach((x, i) => i ? c.lineTo(offset + i * step, y(x)) : c.moveTo(offset, y(x))); c.strokeStyle = root.color; c.lineWidth = 1.6; c.stroke(); } }