Commit 836a1729 authored by Arne Johanson's avatar Arne Johanson

added addDataPoint

parent 5d5b9c08
......@@ -151,13 +151,23 @@ CanvasDataPlot.prototype.setupYScaleAndAxis = function() {
.ticks(Math.round(this.yTicksPerPixel*this.height));
};
CanvasDataPlot.prototype.addDataSet = function(uniqueID, label, dataSet, colorString, updateDomains) {
CanvasDataPlot.prototype.addDataSet = function(uniqueID, label, dataSet, colorString, updateDomains, copyData) {
this.dataIDs.push(uniqueID);
this.dataLabels.push(label);
this.data.push(dataSet);
this.dataColors.push(colorString);
this.displayIndexStart.push(0);
this.displayIndexEnd.push(0);
if(copyData) {
var dataIndex = this.data.length;
this.data.push([]);
var dataSetLength = dataSet.length;
for(var i=0; i<dataSetLength; ++i) {
this.data[dataIndex].push(dataSet[i].slice(0));
}
}
else {
this.data.push(dataSet);
}
this.updateLegend();
......@@ -170,6 +180,22 @@ CanvasDataPlot.prototype.addDataSet = function(uniqueID, label, dataSet, colorSt
}
};
CanvasDataPlot.prototype.addDataPoint = function(uniqueID, dataPoint, updateDomains) {
var i = this.dataIDs.indexOf(uniqueID);
if(i < 0 || (this.data[i].length > 0 && this.data[i][this.data[i].length-1][0] > dataPoint[0])) {
return;
}
this.data[i].push(dataPoint);
if(updateDomains) {
this.updateDomains(this.calculateXDomain(), this.calculateYDomain(), true);
}
else {
this.updateDisplayIndices();
this.drawCanvas();
}
};
CanvasDataPlot.prototype.removeDataSet = function(uniqueID) {
var index = this.dataIDs.indexOf(uniqueID);
if(index >= 0) {
......@@ -525,9 +551,9 @@ function CanvasTimeSeriesPlot(parentElement, canvasDimensions, config) {
}
CanvasTimeSeriesPlot.prototype = Object.create(CanvasDataPlot.prototype);
CanvasTimeSeriesPlot.prototype.addDataSet = function(uniqueID, label, dataSet, colorString, updateDomains) {
CanvasTimeSeriesPlot.prototype.addDataSet = function(uniqueID, label, dataSet, colorString, updateDomains, copyData) {
this.informationDensity.push(1);
CanvasDataPlot.prototype.addDataSet.call(this, uniqueID, label, dataSet, colorString, updateDomains);
CanvasDataPlot.prototype.addDataSet.call(this, uniqueID, label, dataSet, colorString, updateDomains, copyData);
};
CanvasTimeSeriesPlot.prototype.removeDataSet = function(uniqueID) {
......
......@@ -28,7 +28,13 @@ $(document).ready(function() {
markerLineWidth: 3,
markerRadius: 5
});
plot1.addDataSet("ds1", "Test 1", data1, "orange", true);
plot1.addDataSet("ds1", "Test 1", data1, "orange", true, false);
plot1.addDataPoint("ds1", [15,0]); // Will not be added! (x values have to be in ascending order)
plot1.addDataPoint("ds1", [20,10]); // Will be added
plot1.addDataPoint("ds1", [21,0]);
plot1.updateDomains([-2,22], [-60,15], true);
// Since we told addDataSet() not to copy our data, data1 is mutated by addDataPoint().
console.log(data1);
var ts1 = [];
......@@ -43,12 +49,17 @@ $(document).ready(function() {
var plot2 = new CanvasTimeSeriesPlot(d3.select("#maincontainer"), getDemoPlotSize(), {
yAxisLabel: "Voltage [V]"
});
plot2.addDataSet("ds1", "Signal 1", ts1, "orange", true);
plot2.addDataSet("ds2", "Signal 2", ts2, "steelblue", true);
plot2.addDataSet("ds1", "Signal 1", ts1, "orange", true, true);
plot2.addDataSet("ds2", "Signal 2", ts2, "steelblue", true, true);
plot2.setZoomYAxis(false);
$(window).resize(function() {
plot2.resize(getDemoPlotSize());
});
var time = new Date(now);
time.setHours(101);
// Since we told addDataSet() to copy our data, ts1 is not mutated by addDataPoint().
// Cf. the plot of ts1 in the plot group below.
plot2.addDataPoint("ds1", [time, 1.5], true);
var tsPlotGroup = new CanvasDataPlotGroup(d3.select("#maincontainer"), [550, 350], true, true, {});
tsPlotGroup.addDataSet("CanvasTimeSeriesPlot", "ds1", "Signal 1", ts1, "orange", {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment