joewalnes / smoothie

Smoothie Charts: smooooooth JavaScript charts for realtime streaming data
http://smoothiecharts.org
Other
2.25k stars 232 forks source link

removeTimeSeries always removes the last one #24

Closed davidgaleano closed 11 years ago

davidgaleano commented 12 years ago

removeTimeSeries is broken because it is trying to find the index of the TimeSeries to remove by using indexOf, but the array object is not pointing to the TimeSeries directly so it always returns -1, which deletes the last element on the array.

The array seriesSet stores objects that do point to a TimeSeries, so the correct code should be something like this:

SmoothieChart.prototype.removeTimeSeries = function(timeSeries) {
  var numSeries = this.seriesSet.length;
  for (var i = 0; i < numSeries; i++)
  {
    if (this.seriesSet[i].timeSeries === timeSeries)
    {
      this.seriesSet.splice(i, 1);
      break;
    }
  }
};