Skip to content

Commit

Permalink
Load nvd3 plugins into bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Feb 11, 2018
1 parent 49618cf commit a0ad054
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 524 deletions.
19 changes: 1 addition & 18 deletions client/galaxy/scripts/mvc/visualization/chart/chart-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,20 @@ export default Backbone.View.extend({
this.dataset = dataset;
this.chart = new Chart({}, options);
this.chart.plugin = options.visualization_plugin;
this.chart_func = options.chart_func;
this.deferred = new Deferred();
this.viewer = new Viewer(this);
this.editor = new Editor(this);
this.$el.append(this.viewer.$el);
this.$el.append(this.editor.$el);
this.go(this.chart.load() ? "viewer" : "editor");
this.render();
})
.fail(response => {
let message = response.responseJSON && response.responseJSON.err_msg;
this.errormessage = message || "Import failed for unkown reason.";
});
},

/** Build client ui */
render: function() {
//let plugin_path = this.visualization.plugin.static_url + '/' + this.visualization.type;
//import Plugin from plugin_path;
/*require(["repository/build/" + chart.get("type")], function(ChartView) {
new ChartView({ process: process, chart: chart, dataset: self.app.dataset, targets: self.targets });
}, function(err) {
chart.state(
"failed",
"Please verify that your internet connection works properly. This visualization could not be accessed in the repository. Please contact the Galaxy Team if this error persists."
);
console.debug(err);
process.resolve();
});
*/
},

/** Loads a view and makes sure that all others are hidden */
go: function(view_id) {
$(".tooltip").hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export default Backbone.View.extend({
/** Draw chart data */
_drawChart: function() {
this.chart.set({
type: this.types.value(),
title: this.title.value(),
date: Utils.time()
});
Expand Down
11 changes: 1 addition & 10 deletions client/galaxy/scripts/mvc/visualization/chart/views/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ export default Backbone.View.extend({
var n_panels = chart.settings.get("__use_panels") == "true" ? chart.groups.length : 1;
this._createContainer(chart.plugin.tag, n_panels);
chart.state("wait", "Please wait...");
/*require(["repository/build/" + chart.get("type")], function(ChartView) {
new ChartView({ process: process, chart: chart, dataset: self.app.dataset, targets: self.targets });
}, function(err) {
chart.state(
"failed",
"Please verify that your internet connection works properly. This visualization could not be accessed in the repository. Please contact the Galaxy Team if this error persists."
);
console.debug(err);
process.resolve();
});*/
this.app.chart_func({ process: process, chart: chart, dataset: this.app.dataset, targets: this.targets });
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'libs/jquery/jquery-ui',
'bundled/libs.bundled',
'bundled/chart.bundled')}
<script type="text/javascript" src="${script_tag_attributes.get("src")}"></script>
<script type="text/javascript" src="${script_attributes.get("src")}"></script>
<script type="text/javascript">
$(function() {
var config = ${h.dumps(config)};
Expand All @@ -27,7 +27,8 @@
visualization_name: ${h.dumps(visualization_name)},
visualization_plugin: ${h.dumps(visualization_plugin)},
dataset_id: config.dataset_id,
chart_dict: config.chart_dict
chart_dict: config.chart_dict,
chart_func: bundleEntries["${script_attributes.get("func")}"]
});
$('body').append(app.$el);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<%def name="stylesheets()"></%def>
## No javascript libraries
<%def name="late_javascripts()">
<% tag_attrs = ' '.join([ '{0}="{1}"'.format( key, attr ) for key, attr in script_tag_attributes.items() ]) %>
<% tag_attrs = ' '.join([ '{0}="{1}"'.format( key, attr ) for key, attr in script_attributes.items() ]) %>
<script type="text/javascript" ${tag_attrs}></script>
</%def>
2 changes: 1 addition & 1 deletion config/plugins/visualizations/nvd3_bar/config/nvd3_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</macros>
<description>Renders a regular bar diagram using NVD3 hosted at http://www.nvd3.org.</description>
<expand macro="data"/>
<entry_point entry_point_type="chart" src="static/dist/nvd3.js" function="nvd3_bar"/>
<entry_point entry_point_type="chart" src="static/dist/nvd3.js" func="nvd3_bar"/>
<specs>
<expand macro="specs"/>
<zoomable>true</zoomable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,121 +1,121 @@
/** This class handles, formats and caches datasets. */
define( [ 'utilities/utils' ], function( Utils ) {
/** Fills request dictionary with data from cache/response */
var _cache = {};
var request = function( options ) {
var groups = options.dataset_groups;
var dataset_id = options.dataset_id;
// identify columns needed to fulfill request
var column_list = [];
groups.each( function( group ) {
_.each( group.get( '__data_columns' ), function( column_def, column_name ) {
var column = group.get( column_name );
var block_id = _block_id( dataset_id, column );
if ( column_list.indexOf( column ) === -1 && !_cache[ block_id ] && column != 'auto' && column != 'zero' && column !== undefined ) {
column_list.push( column );
}
});
import Utils from "./utils";

/** Fills request dictionary with data from cache/response */
var _cache = {};
var request = function( options ) {
var groups = options.dataset_groups;
var dataset_id = options.dataset_id;
// identify columns needed to fulfill request
var column_list = [];
groups.each( function( group ) {
_.each( group.get( '__data_columns' ), function( column_def, column_name ) {
var column = group.get( column_name );
var block_id = _block_id( dataset_id, column );
if ( column_list.indexOf( column ) === -1 && !_cache[ block_id ] && column != 'auto' && column != 'zero' && column !== undefined ) {
column_list.push( column );
}
});
if ( column_list.length == 0 ) {
_fillFromCache( options );
return;
}
// Fetch data columns into dataset object
Utils.get({
url : Galaxy.root + 'api/datasets/' + dataset_id,
data : {
data_type : 'raw_data',
provider : 'dataset-column',
indeces : column_list.toString()
},
success : function( response ) {
var results = new Array( column_list.length );
for ( var i = 0; i < results.length; i++ ) {
results[ i ] = [];
}
for ( var i in response.data ) {
var row = response.data[ i ];
for ( var j in row ) {
var v = row[ j ];
if ( v !== undefined && v != 2147483647 ) {
results[ j ].push( v );
}
});
if ( column_list.length == 0 ) {
_fillFromCache( options );
return;
}
// Fetch data columns into dataset object
Utils.get({
url : Galaxy.root + 'api/datasets/' + dataset_id,
data : {
data_type : 'raw_data',
provider : 'dataset-column',
indeces : column_list.toString()
},
success : function( response ) {
var results = new Array( column_list.length );
for ( var i = 0; i < results.length; i++ ) {
results[ i ] = [];
}
for ( var i in response.data ) {
var row = response.data[ i ];
for ( var j in row ) {
var v = row[ j ];
if ( v !== undefined && v != 2147483647 ) {
results[ j ].push( v );
}
}
console.debug( 'tabular-datasets::_fetch() - Fetching complete.' );
for ( var i in results ) {
var column = column_list[ i ];
var block_id = _block_id( dataset_id, column );
_cache[ block_id ] = results[ i ];
}
_fillFromCache( options );
}
});
};

/** Fill data from cache */
var _fillFromCache = function( options ) {
var groups = options.dataset_groups;
var dataset_id = options.dataset_id;
console.debug( 'tabular-datasets::_fillFromCache() - Filling request from cache.' );
var limit = 0;
groups.each( function( group ) {
_.each( group.get( '__data_columns' ), function( column_def, column_name ) {
var column = group.get( column_name );
console.debug( 'tabular-datasets::_fetch() - Fetching complete.' );
for ( var i in results ) {
var column = column_list[ i ];
var block_id = _block_id( dataset_id, column );
var column_data = _cache[ block_id ];
if ( column_data ) {
limit = Math.max( limit, column_data.length );
}
});
});
if ( limit == 0 ) {
console.debug( 'tabular-datasets::_fillFromCache() - No data available.' );
_cache[ block_id ] = results[ i ];
}
_fillFromCache( options );
}
var results = [];
groups.each( function( group, group_index ) {
var dict = Utils.merge( { key: ( group_index ) + ':' + group.get( 'key' ), values: [] }, group.attributes );
for ( var j = 0; j < limit; j++ ) {
dict.values[ j ] = { x : parseInt( j ) };
});
};

/** Fill data from cache */
var _fillFromCache = function( options ) {
var groups = options.dataset_groups;
var dataset_id = options.dataset_id;
console.debug( 'tabular-datasets::_fillFromCache() - Filling request from cache.' );
var limit = 0;
groups.each( function( group ) {
_.each( group.get( '__data_columns' ), function( column_def, column_name ) {
var column = group.get( column_name );
var block_id = _block_id( dataset_id, column );
var column_data = _cache[ block_id ];
if ( column_data ) {
limit = Math.max( limit, column_data.length );
}
results.push( dict );
});
groups.each( function( group, group_index ) {
var values = results[ group_index ].values;
_.each( group.get( '__data_columns' ), function( column_def, column_name ) {
var column = group.get( column_name );
switch ( column ) {
case 'auto':
for ( var j = 0; j < limit; j++ ) {
values[ j ][ column_name ] = parseInt( j );
}
break;
case 'zero':
for ( var j = 0; j < limit; j++ ) {
values[ j ][ column_name ] = 0;
}
break;
default:
var block_id = _block_id( dataset_id, column );
var column_data = _cache[ block_id ];
for ( var j = 0; j < limit; j++ ) {
var value = values[ j ];
var v = column_data[ j ];
if ( isNaN( v ) && !column_def.is_label ) {
v = 0;
}
value[ column_name ] = v;
});
if ( limit == 0 ) {
console.debug( 'tabular-datasets::_fillFromCache() - No data available.' );
}
var results = [];
groups.each( function( group, group_index ) {
var dict = Utils.merge( { key: ( group_index ) + ':' + group.get( 'key' ), values: [] }, group.attributes );
for ( var j = 0; j < limit; j++ ) {
dict.values[ j ] = { x : parseInt( j ) };
}
results.push( dict );
});
groups.each( function( group, group_index ) {
var values = results[ group_index ].values;
_.each( group.get( '__data_columns' ), function( column_def, column_name ) {
var column = group.get( column_name );
switch ( column ) {
case 'auto':
for ( var j = 0; j < limit; j++ ) {
values[ j ][ column_name ] = parseInt( j );
}
break;
case 'zero':
for ( var j = 0; j < limit; j++ ) {
values[ j ][ column_name ] = 0;
}
break;
default:
var block_id = _block_id( dataset_id, column );
var column_data = _cache[ block_id ];
for ( var j = 0; j < limit; j++ ) {
var value = values[ j ];
var v = column_data[ j ];
if ( isNaN( v ) && !column_def.is_label ) {
v = 0;
}
}
});
value[ column_name ] = v;
}
}
});
options.success( results );
};
});
options.success( results );
};

/** Get block id */
var _block_id = function ( dataset_id, column ) {
return dataset_id + '_' + '_' + column;
};
/** Get block id */
var _block_id = function ( dataset_id, column ) {
return dataset_id + '_' + '_' + column;
};

return { request: request };
});
export default { request: request };

0 comments on commit a0ad054

Please sign in to comment.