Changeset View
Changeset View
Standalone View
Standalone View
Modules/energy/package/contents/ui/Graph.qml
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 33 | { | |||
---|---|---|---|---|---|
61 | property real plotHeight: height - yPadding * 2 | 61 | property real plotHeight: height - yPadding * 2 | ||
62 | 62 | | |||
63 | onDataChanged: { | 63 | onDataChanged: { | ||
64 | canvas.requestPaint(); | 64 | canvas.requestPaint(); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | //take a QPointF | 67 | //take a QPointF | ||
68 | function scalePoint(plot, currentUnixTime) { | 68 | function scalePoint(plot, currentUnixTime) { | ||
69 | var scaledX = (plot.x - (currentUnixTime / 1000 - xDuration)) / xDuration * plotWidth | 69 | var scaledX = (plot.x - (currentUnixTime / 1000 - xDuration)) / xDuration * plotWidth; | ||
70 | var scaledY = (plot.y - yMin) * plotHeight / (yMax - yMin); | 70 | var scaledY = (plot.y - yMin) * plotHeight / (yMax - yMin); | ||
71 | 71 | | |||
72 | return Qt.point(xPadding + scaledX, | 72 | return Qt.point(xPadding + scaledX, | ||
73 | height - yPadding - scaledY); | 73 | height - yPadding - scaledY); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | SystemPalette { | 76 | SystemPalette { | ||
77 | id: palette; | 77 | id: palette; | ||
Show All 28 Lines | 82 | onPaint: { | |||
106 | var currentUnixTime = Date.now() | 106 | var currentUnixTime = Date.now() | ||
107 | var xMinUnixTime = currentUnixTime - xDuration * 1000 | 107 | var xMinUnixTime = currentUnixTime - xDuration * 1000 | ||
108 | 108 | | |||
109 | // Draw the line graph | 109 | // Draw the line graph | ||
110 | c.beginPath(); | 110 | c.beginPath(); | ||
111 | 111 | | |||
112 | var index = 0 | 112 | var index = 0 | ||
113 | 113 | | |||
114 | while (data[index].x < (xMinUnixTime / 1000)) { | 114 | while ((index < data.length - 1) && (data[index].x < (xMinUnixTime / 1000))) { | ||
115 | index++ | 115 | index++ | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | var firstPoint = scalePoint(data[index], currentUnixTime) | 118 | var firstPoint = scalePoint(data[index], currentUnixTime) | ||
119 | c.moveTo(firstPoint.x, firstPoint.y) | 119 | c.moveTo(firstPoint.x, firstPoint.y) | ||
120 | 120 | | |||
121 | var point | 121 | var point | ||
122 | for (var i = index + 1; i < data.length; i++) { | 122 | for (var i = index + 1; i < data.length; i++) { | ||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |