[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasma-framework/bshah/plotter-qml] /: Multiple plot support, and various fixes
From: Bhushan Shah <bhush94 () gmail ! com>
Date: 2014-02-03 9:12:03
Message-ID: E1WAFZT-0000v6-Mw () scm ! kde ! org
[Download RAW message or body]
Git commit 068fec82444e719ef3c56f895aeb76e33c82bd9d by Bhushan Shah.
Committed on 01/02/2014 at 19:01.
Pushed by bshah into branch 'bshah/plotter-qml'.
Multiple plot support, and various fixes
M +11 -2 examples/applets/plottertest/contents/ui/main.qml
M +74 -50 src/declarativeimports/plasmaextracomponents/qml/SignalPlotter.qml
http://commits.kde.org/plasma-framework/068fec82444e719ef3c56f895aeb76e33c82bd9d
diff --git a/examples/applets/plottertest/contents/ui/main.qml \
b/examples/applets/plottertest/contents/ui/main.qml index fbefe42..bb28f7c \
100644
--- a/examples/applets/plottertest/contents/ui/main.qml
+++ b/examples/applets/plottertest/contents/ui/main.qml
@@ -29,11 +29,20 @@ PlasmaExtra.SignalPlotter {
Timer {
id: timer
interval: 500
- running: true
+ running: false
repeat: true
onTriggered: {
- plot.addSample(Math.ceil(Math.random()*100));
+ var sample = new Array();
+ sample.push(Math.ceil(Math.random()*100));
+ sample.push(Math.ceil(Math.random()*100));
+ plot.addSample(sample);
}
}
+ Component.onCompleted: {
+ plot.addPlot("red");
+ plot.addPlot("green");
+ timer.running = true;
+ }
+
}
\ No newline at end of file
diff --git a/src/declarativeimports/plasmaextracomponents/qml/SignalPlotter.qml \
b/src/declarativeimports/plasmaextracomponents/qml/SignalPlotter.qml index \
9950e82..697a817 100644
--- a/src/declarativeimports/plasmaextracomponents/qml/SignalPlotter.qml
+++ b/src/declarativeimports/plasmaextracomponents/qml/SignalPlotter.qml
@@ -27,6 +27,7 @@ Canvas {
id: graphCanvas
property variant samples
+ property variant plots
property bool showAxis: true
property bool showHorizontalLines: true
@@ -38,7 +39,7 @@ Canvas {
property color plotColor: theme.highlightColor
property int graphPadding: 10 //Replace with units later
- property int max: 0
+ property int max: 100
QtObject {
id: internal
@@ -52,13 +53,35 @@ Canvas {
anchors.horizontalCenter: graphCanvas.horizontalCenter
}
+ function addPlot(color) {
+ var plotData = plots;
+ var sampleData = samples;
+ if (plotData == undefined || sampleData == undefined) {
+ plotData = new Array();
+ sampleData = new Array();
+ }
+ plotData.push(color);
+ sampleData.push(new Array());
+ plots = plotData;
+ samples = sampleData;
+ }
+
function addSample(sample) {
- var temp = samples;
- if (temp == undefined) {
- temp = new Array();
+ var plotData = plots;
+ var sampleData = samples;
+ if (plotData == undefined) {
+ print("You need to add plot first");
+ return;
+ }
+ if (plotData.length != sample.length) {
+ print("Count of plots and data in sample mismatch, discarding sample");
+ return;
}
- temp.push(sample);
- samples = temp;
+ for(var i=0; i<plotData.length; i++) {
+ sampleData[i].push(sample[i]);
+ }
+ samples = sampleData;
+ plots = plotData;
requestPaint();
}
@@ -70,7 +93,6 @@ Canvas {
function drawGraph(context) {
- //print(internal.sampleCount);
// Draw Axis
if (showAxis) {
context.beginPath();
@@ -83,7 +105,6 @@ Canvas {
context.closePath();
}
- // Draw horizontal lines
if (showHorizontalLines) {
context.beginPath();
context.lineWidth = 1;
@@ -96,54 +117,57 @@ Canvas {
context.closePath();
}
- // Time to draw graph
var graphSamples;
- graphSamples = samples;
- if (graphSamples == undefined)
- graphSamples = new Array();
- if (graphSamples.length != 0) {
-
- var xPos = (graphSamples.length < internal.sampleCount) ? \
(internal.availableHSpace - (graphSamples.length * graphPadding)) : 0 - \
(2*graphPadding);
- if(smooth && graphPadding > 5) {
-
- context.beginPath();
- context.moveTo(xPos, height - graphPadding);
- var loopInit = (graphSamples.length < internal.sampleCount) ? 0 : \
(graphSamples.length - internal.sampleCount) - 3;
- var yPos0 = (getYPos(graphSamples[loopInit]));
- context.lineTo(xPos, yPos0);
- xPos += graphPadding;
-
- for (var i = loopInit; i < graphSamples.length; i ++)
- {
- var xc = ((xPos * 2) + graphPadding ) / 2;
- var yc = (getYPos(graphSamples[i]) + getYPos(graphSamples[i + 1])) / \
2;
- context.quadraticCurveTo(xPos, getYPos(graphSamples[i]), xc, yc);
+ for(var j = 0; j<plots.length; j++) {
+ graphSamples = samples[j];
+
+ if (graphSamples == undefined)
+ graphSamples = new Array();
+ if (graphSamples.length != 0) {
+ var xPos = (graphSamples.length < internal.sampleCount) ? \
(internal.availableHSpace - (graphSamples.length * graphPadding)) : 0 - \
(2*graphPadding); + if(smooth && graphPadding > 5) {
+
+ context.beginPath();
+ context.moveTo(xPos, height - graphPadding);
+ var loopInit = (graphSamples.length < internal.sampleCount) ? 0 : \
(graphSamples.length - internal.sampleCount) - 3; + var yPos0 = \
(getYPos(graphSamples[loopInit])); + print(graphSamples[loopInit]);
+ context.lineTo(xPos, yPos0);
xPos += graphPadding;
+
+ for (var i = loopInit; i < graphSamples.length; i ++)
+ {
+ var xc = ((xPos * 2) + graphPadding ) / 2;
+ var yc = (getYPos(graphSamples[i]) + getYPos(graphSamples[i + 1])) / \
2; + context.quadraticCurveTo(xPos, getYPos(graphSamples[i]), xc, yc);
+ xPos += graphPadding;
+ }
+ context.quadraticCurveTo(width+graphPadding, height-graphPadding, \
width - graphPadding,height -graphPadding); + context.stroke();
+ context.fillStyle = plots[j]
+ context.fill();
}
- context.quadraticCurveTo(width+graphPadding, height-graphPadding, \
width - graphPadding,height -graphPadding);
- context.stroke();
- context.fillStyle = plotColor;
- context.fill();
- }
- else {
- context.beginPath();
- context.moveTo(xPos, height - graphPadding);
- var loopInit = (graphSamples.length < internal.sampleCount) ? 0 : \
(graphSamples.length - internal.sampleCount) - 2;
- var yPos0 = (getYPos(graphSamples[loopInit]));
- context.lineTo(xPos, yPos0);
- xPos += graphPadding;
- for(var i = loopInit; i < graphSamples.length ; i++){
- context.lineTo(xPos, getYPos(graphSamples[i]));
+ else {
+ context.beginPath();
+ context.moveTo(xPos, height - graphPadding);
+ var loopInit = (graphSamples.length < internal.sampleCount) ? 0 : \
(graphSamples.length - internal.sampleCount) - 2; + var yPos0 = \
(getYPos(graphSamples[loopInit])); + context.lineTo(xPos, yPos0);
xPos += graphPadding;
+ for(var i = loopInit; i < graphSamples.length ; i++){
+ context.lineTo(xPos, getYPos(graphSamples[i]));
+ xPos += graphPadding;
+ }
+ context.lineTo(xPos, height-graphPadding);
+ context.stroke();
+ context.fillStyle = plots[j];
+ context.fill();
}
- context.lineTo(xPos, height-graphPadding);
- context.stroke();
- context.fillStyle = plotColor;
- context.fill();
+ //sampleLabel.text = graphSamples[graphSamples.length-3]
+
+ } else {
+ print("No samples yet");
}
- sampleLabel.text = graphSamples[graphSamples.length-3]
- } else {
- print("No samples yet");
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic