Skip to content

Commit

Permalink
Improved start/stop behaviour, so the Cubism chart is in sync with th…
Browse files Browse the repository at this point in the history
…e rest of the application
  • Loading branch information
karmi committed Jun 3, 2012
1 parent 48f55e9 commit 1e73c1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
22 changes: 16 additions & 6 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ var App = Em.Application.create({

ready: function() {
l(App.name + ' (re)loaded.')
App.cluster.__perform_refresh()
App.nodes.__perform_refresh()
App.indices.__perform_refresh()
App.Cubism.setup();
App.__perform_refresh()
App.__initialize_cubism()
return this._super()
},

Expand All @@ -28,7 +26,17 @@ var App = Em.Application.create({
]
}),

refresh_allowed: true
refresh_allowed: true,

__perform_refresh: function() {
App.cluster.__perform_refresh()
App.nodes.__perform_refresh()
App.indices.__perform_refresh()
},

__initialize_cubism: function() {
App.Cubism.setup()
}
});

App.refresh_interval = App.refresh_intervals.toArray()[1]
Expand Down Expand Up @@ -393,6 +401,7 @@ App.toggleChart = Ember.View.create({
toggle: function(event) {
var chart = $("#chart"),
visible = chart.is(":visible")

this.set("text", visible ? 'Show' : 'Hide')
visible ? chart.hide('fast') : chart.show('fast')
}
Expand All @@ -416,7 +425,8 @@ App.addObserver('refresh_interval', function() {
});

App.addObserver('refresh_allowed', function() {
App.ready()
App.refresh_allowed ? App.Cubism.start() : App.Cubism.stop()
App.__perform_refresh()
});

App.nodes.addObserver('@each.name', function() {
Expand Down
19 changes: 14 additions & 5 deletions js/cubism.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,28 @@ App.Cubism = Ember.Object.create({
reset: function() {
var self = this

// Setup context
self.context.stop()
self.__setup_context()
// Stop old context
self.stop()

// Re-insert the chart element
d3.select("#chart-inner").remove()
self.chart = d3.select("#chart").append("div").attr("id", "chart-inner")

// Re-draw the chart(s)
self.__draw()
// Re-initialize everything
self.setup()
return self
},

// Start the polling/animation
start: function() {
if (this.context.start) this.context.start()
},

// Stop the polling/animation
stop: function() {
if (this.context.stop) this.context.stop()
},

// Draw the metrics
__draw: function() {
var self = this
Expand Down

0 comments on commit 1e73c1f

Please sign in to comment.