Skip to content

Commit

Permalink
Revise chart resetting mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 19, 2016
1 parent 5ea8d03 commit e3bb858
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
27 changes: 10 additions & 17 deletions config/plugins/visualizations/charts/static/models/chart.js
@@ -1,4 +1,4 @@
define( [], function() {
define( [ 'utils/utils' ], function( Utils ) {
var Groups = Backbone.Collection.extend({
model: Backbone.Model.extend({
defaults : {
Expand Down Expand Up @@ -30,23 +30,16 @@ define( [], function() {
this.settings = new Backbone.Model();
},

reset: function() {
this.clear( { silent: true } ).set( this.defaults );
this.groups.reset();
this.settings.clear();
this.trigger( 'reset', this );
},

copy: function( new_chart ) {
var current = this;
current.clear( { silent: true } ).set( this.defaults );
current.set( new_chart.attributes );
current.settings = new_chart.settings.clone();
current.groups.reset();
new_chart.groups.each( function( group ) {
current.groups.add( group.clone() );
reset: function( options ) {
this.set({
'id' : Utils.uid(),
'type' : 'nvd3_bar',
'dataset_id' : options.config.dataset_id,
'title' : 'New Chart'
});
current.trigger( 'change', current );
this.settings.clear();
this.groups.reset();
this.groups.add( { id : Utils.uid() } );
},

state: function( value, info ) {
Expand Down
19 changes: 3 additions & 16 deletions config/plugins/visualizations/charts/static/views/editor.js
Expand Up @@ -87,15 +87,15 @@ define( [ 'mvc/ui/ui-tabs', 'mvc/ui/ui-misc', 'mvc/ui/ui-portlet', 'utils/utils'
// set elements
this.portlet.append( this.message.$el );
this.portlet.append( this.tabs.$el.addClass( 'ui-margin-top-large' ) );
this.portlet.hideOperation( 'back' );
this.setElement( this.portlet.$el );
this.tabs.hideOperation( 'back' );

// chart events
this.chart.on( 'change:title', function( chart ) { self._refreshTitle() } );
this.chart.on( 'change:type', function( chart ) { self.types.value( chart.get( 'type' ) ) } );
this.chart.on( 'reset', function( chart ) { self._resetChart() } );
this.app.chart.on( 'redraw', function( chart ) { self.portlet.showOperation( 'back' ) } );
this._resetChart();
this.chart.on( 'redraw', function( chart ) { self.portlet.showOperation( 'back' ) } );
this.chart.reset( this.app.options );
},

/** Show editor */
Expand All @@ -115,19 +115,6 @@ define( [ 'mvc/ui/ui-tabs', 'mvc/ui/ui-misc', 'mvc/ui/ui-portlet', 'utils/utils'
this.title.value( title );
},

/** Reset entire chart */
_resetChart: function() {
this.chart.set({
'id' : Utils.uid(),
'type' : 'nvd3_bar',
'dataset_id' : this.app.options.config.dataset_id,
'title' : 'New Chart'
});
this.chart.groups.reset();
this.chart.groups.add( { id : Utils.uid() } );
this.portlet.hideOperation( 'back' );
},

/** Save chart data */
_saveChart: function() {
var self = this;
Expand Down

0 comments on commit e3bb858

Please sign in to comment.