Skip to content

Commit

Permalink
always refresh if the previous rate calc failed
Browse files Browse the repository at this point in the history
  • Loading branch information
castedmo committed Feb 4, 2017
1 parent 7a93d06 commit 02dc1da
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ This panel is based on [FlipClock](http://flipclockjs.com/) and built upon [Graf

#### Changelog

##### v0.0.4
- Always refresh if the previous rate calculation failed

##### v0.0.3
- Throttle refresh frequency

Expand Down
3 changes: 3 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ This panel is based on [FlipClock](http://flipclockjs.com/) and built upon [Graf

#### Changelog

##### v0.0.4
- Always refresh if the previous rate calculation failed

##### v0.0.3
- Throttle refresh frequency

Expand Down
8 changes: 6 additions & 2 deletions dist/ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ctrl.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"name": "Showcase",
"path": "screenshots/counter1.png"
}],
"version": "0.0.2",
"updated": "2017-01-18"
"version": "0.0.4",
"updated": "2017-02-04"
},

"dependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CounterPanelCtrl extends MetricsPanelCtrl {
});
this.statChangeInterval = null;
this.lastRefreshTime = new Date(2016, 1, 1, 1, 1, 1);
this.refreshRate = 0;
this.newData = false;
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
this.events.on('render', this.onRender.bind(this));
Expand Down Expand Up @@ -160,15 +161,18 @@ class CounterPanelCtrl extends MetricsPanelCtrl {
var timeDiff = lastPoint[1] - prevPoint[1];
var rate = Math.floor(timeDiff / lastPoint[0]);
this.statCounter.setTime(whole-lastPoint[0]);
if (this.statChangeInterval)
clearInterval(this.statChangeInterval);
if (rate > 0) {
if (this.statChangeInterval)
clearInterval(this.statChangeInterval);
var sc = this.statCounter;
if (isFinite(rate)){
this.refreshRate = rate;
this.statChangeInterval = setInterval(function () {
//for (var i=0; i<7; i++)
sc.increment();
}, rate);
}else{
this.refreshRate = 0;
}
}
}
Expand Down Expand Up @@ -357,7 +361,7 @@ class CounterPanelCtrl extends MetricsPanelCtrl {
this.data = data;

var now = Date.now();
if (Math.floor(now - this.lastRefreshTime) >= this.panel.refreshMinSec*1000){
if (this.refreshRate === 0 || Math.floor(now - this.lastRefreshTime) >= this.panel.refreshMinSec*1000){
this.newData = true;
this.lastRefreshTime = now;
this.render();
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"name": "Showcase",
"path": "screenshots/counter1.png"
}],
"version": "0.0.2",
"updated": "2017-01-18"
"version": "0.0.4",
"updated": "2017-02-04"
},

"dependencies": {
Expand Down

0 comments on commit 02dc1da

Please sign in to comment.