Essentially what I'm trying to do is have a button .push a line into an array and I want JUMflot to keep redrawing those but not affect the line being pushed in.
What I had done initially was have something like this (the generator ID is my button and options are defined however not relevant to my question so I didn't include them):
var genVector=[[0,1],[6,6]]; //line being pushed in
var data = [];
$("#generator").click(function(){
data.push({data: genVector, editable: true});
var p = $.plot($("#graph"),data,options);
});
$("#graph").bind("datadrop", function(event,pos,item) {
data[item.seriesIndex].data[item.dataIndex] = [Math.round(pos.x1),Math.round(pos.y1)];
p = $.plot($("#graph"), data, options);
};
What I realized would end up happening, is that every time I chose to move the point my genVector coordinates would change. So to work around this I did the following:
var vectorCounter=0;
var genVector=[[0,1],[6,6]];
var data = [];
var vectorArray=[];
$("#generator").click(function(){
vectorArray.push(genVector);
data.push({data: vectorArray[vectorCounter], editable: true});
vectorCounter++;
var p = $.plot($("#graph"),data,options);
});
$("#graph").bind("datadrop", function(event,pos,item) {
data[item.seriesIndex].data[item.dataIndex] = [Math.round(pos.x1),Math.round(pos.y1)];
p = $.plot($("#graph"), data, options);
};
I thought adding the vector to a separate array and modifying it from there would leave the genVector alone. It did not.
I'm assuming this has something to do with how the JUMflot code is written? Even if it does not, how can I achieve what I'm doing? Thanks in advance!