extract SparklineCanvas component from 5 applets
This commit is contained in:
parent
732a14e5cb
commit
8d76df6ef5
8 changed files with 178 additions and 233 deletions
|
|
@ -104,72 +104,28 @@ Column {
|
|||
}
|
||||
|
||||
// History sparkline
|
||||
Canvas {
|
||||
id: _sparkline
|
||||
SparklineCanvas {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 12
|
||||
height: 40
|
||||
|
||||
property var _hist: root.history
|
||||
property color _col: root.stateColor
|
||||
|
||||
on_HistChanged: if (root.active)
|
||||
requestPaint()
|
||||
on_ColChanged: if (root.active)
|
||||
requestPaint()
|
||||
|
||||
onVisibleChanged: if (visible)
|
||||
requestPaint()
|
||||
|
||||
onPaint: {
|
||||
const ctx = getContext("2d");
|
||||
if (!ctx)
|
||||
return;
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
const d = _hist;
|
||||
if (!d.length)
|
||||
return;
|
||||
|
||||
const maxSamples = 150;
|
||||
const bw = width / maxSamples;
|
||||
|
||||
// Background tint
|
||||
ctx.fillStyle = Qt.rgba(_col.r, _col.g, _col.b, 0.08).toString();
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
// Warm threshold line
|
||||
const warmY = height - height * (root.warm / 100);
|
||||
ctx.strokeStyle = S.Theme.base0A.toString();
|
||||
ctx.globalAlpha = 0.3;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([3, 3]);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, warmY);
|
||||
ctx.lineTo(width, warmY);
|
||||
ctx.stroke();
|
||||
|
||||
// Hot threshold line
|
||||
const hotY = height - height * (root.hot / 100);
|
||||
ctx.strokeStyle = S.Theme.base08.toString();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, hotY);
|
||||
ctx.lineTo(width, hotY);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.setLineDash([]);
|
||||
ctx.globalAlpha = 1.0;
|
||||
|
||||
// Bars
|
||||
const offset = maxSamples - d.length;
|
||||
for (let i = 0; i < d.length; i++) {
|
||||
const barH = Math.max(1, height * d[i] / 100);
|
||||
const barColor = d[i] > root.hot ? S.Theme.base08 : d[i] > root.warm ? S.Theme.base0A : _col;
|
||||
ctx.fillStyle = barColor.toString();
|
||||
ctx.fillRect((offset + i) * bw, height - barH, Math.max(1, bw - 0.5), barH);
|
||||
history: root.history
|
||||
color: root.stateColor
|
||||
active: root.active
|
||||
maxSamples: 150
|
||||
backgroundTint: 0.08
|
||||
thresholds: [
|
||||
{
|
||||
value: root.warm,
|
||||
color: S.Theme.base0A
|
||||
},
|
||||
{
|
||||
value: root.hot,
|
||||
color: S.Theme.base08
|
||||
}
|
||||
}
|
||||
]
|
||||
colorFunction: v => v > root.hot ? S.Theme.base08 : v > root.warm ? S.Theme.base0A : root.stateColor
|
||||
}
|
||||
|
||||
// Threshold labels
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue