Skip to content

Commit

Permalink
Merge pull request #91 from TechGuard/patch-1
Browse files Browse the repository at this point in the history
Add 'disable' property to TimeSeries for filtering
  • Loading branch information
drewnoakes authored Nov 30, 2017
2 parents 525e805 + 4cf2125 commit 7ae1ab2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions smoothie.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export declare class TimeSeries {
* Adjust or inspect the upper y-axis for this <code>TimeSeries</code> object.
*/
maxValue: number;

/**
* Hide this <code>TimeSeries</code> object in the chart.
*/
disabled: boolean;

/**
* Clears all data and state from this TimeSeries object.
Expand Down
24 changes: 18 additions & 6 deletions smoothie.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
*/
function TimeSeries(options) {
this.options = Util.extend({}, TimeSeries.defaultOptions, options);
this.disabled = false;
this.clear();
}

Expand Down Expand Up @@ -521,10 +522,13 @@

// For each data set...
for (var d = 0; d < this.seriesSet.length; d++) {
var timeSeries = this.seriesSet[d].timeSeries,
// find datapoint closest to time 't'
closeIdx = Util.binarySearch(timeSeries.data, t);

var timeSeries = this.seriesSet[d].timeSeries;
if (timeSeries.disabled) {
continue;
}

// find datapoint closest to time 't'
var closeIdx = Util.binarySearch(timeSeries.data, t);
if (closeIdx > 0 && closeIdx < timeSeries.data.length) {
data.push({ series: this.seriesSet[d], index: closeIdx, value: timeSeries.data[closeIdx][1] });
}
Expand Down Expand Up @@ -644,6 +648,10 @@
for (var d = 0; d < this.seriesSet.length; d++) {
// TODO(ndunn): We could calculate / track these values as they stream in.
var timeSeries = this.seriesSet[d].timeSeries;
if (timeSeries.disabled) {
continue;
}

if (!isNaN(timeSeries.maxValue)) {
chartMaxValue = !isNaN(chartMaxValue) ? Math.max(chartMaxValue, timeSeries.maxValue) : timeSeries.maxValue;
}
Expand Down Expand Up @@ -819,8 +827,12 @@
// For each data set...
for (var d = 0; d < this.seriesSet.length; d++) {
context.save();
var timeSeries = this.seriesSet[d].timeSeries,
dataSet = timeSeries.data,
var timeSeries = this.seriesSet[d].timeSeries;
if (timeSeries.disabled) {
continue;
}

var dataSet = timeSeries.data,
seriesOptions = this.seriesSet[d].options;

// Delete old data that's moved off the left of the chart.
Expand Down

0 comments on commit 7ae1ab2

Please sign in to comment.