Skip to content

Commit

Permalink
Use regular form definitions for all nvd3 charts
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 19, 2016
1 parent b1fb1cf commit fb075e1
Show file tree
Hide file tree
Showing 24 changed files with 315 additions and 384 deletions.
10 changes: 1 addition & 9 deletions client/galaxy/scripts/mvc/form/form-data.js
Expand Up @@ -2,7 +2,7 @@
This class maps the form dom to an api compatible javascript dictionary.
*/
define([ 'utils/utils' ], function( Utils ) {
var Manager = Backbone.Model.extend({
var Manager = Backbone.View.extend({
initialize: function( app ) {
this.app = app;
},
Expand All @@ -21,14 +21,6 @@ define([ 'utils/utils' ], function( Utils ) {
return sum;
},

/** Set parameter values from model */
set: function( model ) {
for ( var attr in model.attributes ) {
var index = this.match( attr );
index && this.app.field_list[ index ].value( model.get( attr ) );
}
},

/** Convert dom into a dictionary of flat id/value pairs used e.g. on job submission. */
create: function() {
var self = this;
Expand Down
14 changes: 13 additions & 1 deletion client/galaxy/scripts/mvc/form/form-view.js
Expand Up @@ -9,12 +9,24 @@ function( Utils, Portlet, Ui, FormSection, FormData ) {
initial_errors : false,
cls : 'ui-portlet-limited',
icon : null,
always_refresh : true
always_refresh : true,
values : null,
inputs : []
});
this.setElement( '<div/>' );
this.options.inputs = $.extend( {}, this.options.inputs, true );
this.options.values && this.set( this.options.values );
this.render();
},

/** Set parameter values from value dictionary */
set: function( values ) {
var self = this;
FormData.visitInputs( this.options.inputs, function( input, name, prefix ) {
input.value = values[ name ] !== undefined ? values[ name ] : input.value;
});
},

/** Update available options */
update: function( new_model ){
var self = this;
Expand Down
@@ -1,77 +1,18 @@
define([], function() {

var axis_label_inputs = function( prefix ) {
return {
name : prefix + '_axis_label',
label : prefix.toUpperCase() + '-Axis label',
help : 'Provide a label for the axis.',
type : 'text',
value : prefix.toUpperCase() + '-axis',
placeholder : 'Axis label'
}
}

var axis_precision_inputs = [ { name : 'precision',
label : 'Axis tick format',
help : 'Select the tick format for the axis.',
type : 'select',
value : '1',
data : [ { label : '0.00001', value : '5' },
{ label : '0.0001', value : '4' },
{ label : '0.001', value : '3' },
{ label : '0.01', value : '2' },
{ label : '0.1', value : '1' },
{ label : '1', value : '0' } ] } ];

var axis_type_inputs = function( prefix ) {
return {
type : 'conditional',
name : prefix + '_axis_type',
test_param : {
name : 'type',
label : prefix.toUpperCase() + '-Axis value type',
type : 'select',
value : 'auto',
help : 'Select the value type of the axis.',
data : [ { value : 'hide', label : '-- Do not show values --' },
{ value : 'auto', label : 'Auto' },
{ value : 'f', label : 'Float' },
{ value : 'd', label : 'Integer' },
{ value : 'e', label : 'Exponent' },
{ value : 'p', label : 'Percent' },
{ value : 's', label : 'SI-prefix' } ]
},
cases : [ { value : 'hide' },
{ value : 'auto' },
{ value : 'f', inputs: axis_precision_inputs },
{ value : 'd' },
{ value : 'e', inputs: axis_precision_inputs },
{ value : 'p', inputs: axis_precision_inputs },
{ value : 's' } ]
}
}

var boolean_inputs = function( name, label, help ) {
return { name : name,
label : label,
help : help,
type : 'select',
display : 'radiobutton',
value : 'true',
data : [ { label : 'Yes', value : 'true' },
{ label : 'No', value : 'false' } ] }
}

define( [ 'plugin/charts/forms/inputs' ], function( Inputs ) {
return {
title : '',
category : '',
library : '',
tag : '',
keywords : '',
settings : [ axis_label_inputs( 'x' ), axis_type_inputs( 'x' ),
axis_label_inputs( 'y' ), axis_type_inputs( 'y' ),
boolean_inputs( 'show_legend', 'Show legend', 'Would you like to add a legend?' ),
boolean_inputs( 'use_panels', 'Use multi-panels', 'Would you like to separate your data into individual panels?' ) ],
settings : {
x_axis_label : Inputs.axisLabel( 'x' ),
x_axis_type : Inputs.axisType( 'x' ),
y_axis_label : Inputs.axisLabel( 'y' ),
y_axis_type : Inputs.axisType( 'y' ),
show_legend : Inputs.boolean( 'Show legend', 'Would you like to add a legend?' ),
use_panels : Inputs.boolean( 'Use multi-panels', 'Would you like to separate your data into individual panels?' )
},
series : [{
name : 'key',
label : 'Provide a label',
Expand Down
63 changes: 63 additions & 0 deletions config/plugins/visualizations/charts/static/charts/forms/inputs.js
@@ -0,0 +1,63 @@
define( [], function() {
return {
axisLabel : function( prefix ) {
return {
name : 'label',
label : prefix.toUpperCase() + '-Axis label',
help : 'Provide a label for the axis.',
type : 'text',
value : prefix.toUpperCase() + '-axis',
placeholder : 'Axis label'
}
},
axisPrecision : function() {
return { name : 'precision',
label : 'Axis tick format',
help : 'Select the tick format for the axis.',
type : 'select',
value : '1',
data : [ { label : '0.00001', value : '5' },
{ label : '0.0001', value : '4' },
{ label : '0.001', value : '3' },
{ label : '0.01', value : '2' },
{ label : '0.1', value : '1' },
{ label : '1', value : '0' } ] }
},
axisType : function( prefix, options ) {
options = options || {};
return {
type : 'conditional',
test_param : {
name : 'type',
label : prefix.toUpperCase() + '-Axis value type',
type : 'select',
value : options.value || 'auto',
help : 'Select the value type of the axis.',
data : [ { value : 'hide', label : '-- Do not show values --' },
{ value : 'auto', label : 'Auto' },
{ value : 'f', label : 'Float' },
{ value : 'd', label : 'Integer' },
{ value : 'e', label : 'Exponent' },
{ value : 'p', label : 'Percent' },
{ value : 's', label : 'SI-prefix' } ]
},
cases : [ { value : 'hide' },
{ value : 'auto' },
{ value : 'f', inputs: [ this.axisPrecision() ] },
{ value : 'd' },
{ value : 'e', inputs: [ this.axisPrecision() ] },
{ value : 'p', inputs: [ this.axisPrecision() ] },
{ value : 's' } ]
}
},
boolean : function( label, help, value ) {
return { label : label,
help : help,
type : 'select',
display : 'radiobutton',
value : value || 'true',
data : [ { label : 'Yes', value : 'true' },
{ label : 'No', value : 'false' } ] }
}
}
});
@@ -1,25 +1,21 @@
define(['plugin/charts/nvd3/common/config'], function(nvd3_config) {

return $.extend(true, {}, nvd3_config, {
title : 'Horizontal',
category : 'Bar diagrams',
settings : {
x_axis_type : {
init : 'hide'
}
},
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
define( [ 'plugin/charts/nvd3/common/config', 'plugin/charts/forms/inputs' ], function( nvd3_config, Inputs ) {
return $.extend( true, {}, nvd3_config, {
title : 'Horizontal',
category : 'Bar diagrams',
settings : {
x_axis_type : Inputs.axisType( 'x', { value: 'hide' } )
},
y : {
title : 'Values for y-axis',
is_numeric : true
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
},
y : {
title : 'Values for y-axis',
is_numeric : true
}
}
}
});

});
});
@@ -1,25 +1,21 @@
define(['plugin/charts/nvd3/common/config'], function(nvd3_config) {

return $.extend(true, {}, nvd3_config, {
title : 'Stacked horizontal',
category : 'Bar diagrams',
settings : {
x_axis_type : {
init : 'hide'
}
},
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
define( [ 'plugin/charts/nvd3/common/config', 'plugin/charts/forms/inputs' ], function( nvd3_config, Inputs ) {
return $.extend( true, {}, nvd3_config, {
title : 'Stacked horizontal',
category : 'Bar diagrams',
settings : {
x_axis_type : Inputs.axisType( 'x', { value: 'hide' } )
},
y : {
title : 'Values for y-axis',
is_numeric : true
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
},
y : {
title : 'Values for y-axis',
is_numeric : true
}
}
}
});

});
});
@@ -1,21 +1,19 @@
define(['plugin/charts/nvd3/common/config'], function(nvd3_config) {

return $.extend(true, {}, nvd3_config, {
title : 'Line chart',
category : 'Others',
zoomable : true,
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
},
y : {
title : 'Values for y-axis',
is_numeric : true
define( [ 'plugin/charts/nvd3/common/config' ], function( nvd3_config ) {
return $.extend( true, {}, nvd3_config, {
title : 'Line chart',
category : 'Others',
zoomable : true,
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
},
y : {
title : 'Values for y-axis',
is_numeric : true
}
}
}
});

});
});
@@ -1,21 +1,19 @@
define(['plugin/charts/nvd3/common/config'], function(nvd3_config) {

return $.extend(true, {}, nvd3_config, {
title : 'Line with focus',
category : 'Others',
zoomable : 'native',
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
},
y : {
title : 'Values for y-axis',
is_numeric : true
define( [ 'plugin/charts/nvd3/common/config' ], function( nvd3_config ) {
return $.extend( true, {}, nvd3_config, {
title : 'Line with focus',
category : 'Others',
zoomable : 'native',
columns : {
x : {
title : 'Values for x-axis',
is_label : true,
is_auto : true,
is_unique : true
},
y : {
title : 'Values for y-axis',
is_numeric : true
}
}
}
});

});
});

0 comments on commit fb075e1

Please sign in to comment.