Skip to content

Instantly share code, notes, and snippets.

@mrosenberg
Last active August 29, 2015 14:00
Show Gist options
  • Save mrosenberg/11403130 to your computer and use it in GitHub Desktop.
Save mrosenberg/11403130 to your computer and use it in GitHub Desktop.
Responsive D3 charts in an Ember View
App.Chart = Ember.View.extend({
tagName: 'svg',
reScale: function() {
d3.selectAll( this.svg[0][0].childNodes ).remove();
Ember.run.scheduleOnce( 'afterRender', this, 'build' );
},
didInsertElement: function() {
var that = this;
$( window ).on( 'resize', function() {
Ember.run.debounce( that, that.reScale, 1000 );
});
Ember.run.scheduleOnce( 'afterRender', this, 'build' );
},
build: function() {
// D3 magic
}
});
@mrosenberg
Copy link
Author

This destroys the chart and then renders it again. It would be possible to tween the data but that was not needed in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment