Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsqadmin: fix counter view #1467

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nsqadmin/static/build/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nsqadmin/static/build/main.js.map

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions nsqadmin/static/js/views/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ var CounterView = BaseView.extend({

initialize: function() {
BaseView.prototype.initialize.apply(this, arguments);
this.listenTo(AppState, 'change:graph_interval', this.render);
this.listenTo(AppState, 'change:graph_interval', function() {
clearTimeout(this.poller);
clearTimeout(this.animator);
this.render();
this.start();
});
this.start();
},

Expand All @@ -29,6 +34,7 @@ var CounterView = BaseView.extend({
this.looping = false;
this.targetPollInterval = 10000;
this.currentNum = -1;
this.lastNum = 0;
this.interval = 100;
this.graphUrl = null;
this.updateStats();
Expand All @@ -52,16 +58,17 @@ var CounterView = BaseView.extend({
if (this.currentNum === -1) {
// seed the display
this.currentNum = num;
this.lastNum = num;
this.writeCounts(this.currentNum);
} else if (num > this.lastNum) {
var delta = num - this.lastNum;
this.delta = (delta / (this.interval / 1000)) / 50;
this.lastNum = num;

if (!this.animator) {
this.displayFrame();
}
}
this.currentNum = this.lastNum;
this.lastNum = num;

var newInterval = this.interval;
if (newInterval < this.targetPollInterval) {
Expand Down Expand Up @@ -97,9 +104,13 @@ var CounterView = BaseView.extend({
},

displayFrame: function() {
this.currentNum += this.delta;
this.currentNum = Math.min(this.currentNum + this.delta, this.lastNum)
this.writeCounts(this.currentNum);
this.animator = setTimeout(this.displayFrame.bind(this), 1000 / 60);
if (this.currentNum < this.lastNum) {
this.animator = setTimeout(this.displayFrame.bind(this), 1000 / 60);
} else {
this.animator = null;
}
},

writeCounts: function(c) {
Expand Down