Skip to content

Commit

Permalink
nvd3 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon authored and guerler committed Feb 11, 2018
1 parent 04c71f3 commit 65590f1
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions config/plugins/visualizations/nvd3_bar/static/nvd3.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,84 @@
/** This is the common wrapper for nvd3 based visualizations. */
define( [ 'utilities/tabular-utilities', 'plugin/nv.d3', 'style!css!plugin/nv.d3.css' ], function( Utilities ) {
define(["utilities/tabular-utilities", "plugin/nv.d3", "style!css!plugin/nv.d3.css"], function(Utilities) {
var CommonWrapper = Backbone.View.extend({
initialize: function( options ) {
initialize: function(options) {
var self = this;
this.options = options;
options.render = function( canvas_id, groups ) {
return self.render( canvas_id, groups )
options.render = function(canvas_id, groups) {
return self.render(canvas_id, groups);
};
Utilities.panelHelper( options );
Utilities.panelHelper(options);
},
render: function( canvas_id, groups ) {
render: function(canvas_id, groups) {
var self = this;
var chart = this.options.chart;
var type = this.options.type;
var makeConfig = this.options.makeConfig;
var d3chart = nv.models[ type ]();
nv.addGraph( function() {
var chart = this.options.chart;
var type = this.options.type;
var makeConfig = this.options.makeConfig;
var d3chart = nv.models[type]();
nv.addGraph(function() {
try {
d3chart.xAxis.axisLabel( chart.settings.get( 'x_axis_label' ) );
d3chart.yAxis.axisLabel( chart.settings.get( 'y_axis_label' ) ).axisLabelDistance( 30 );
d3chart.options( { showControls: false } );
d3chart.showLegend && d3chart.showLegend(chart.settings.get('show_legend') == 'true');
self._makeAxes( d3chart, groups, chart.settings );
makeConfig && makeConfig( d3chart );
chart.settings.get( '__use_panels' ) === 'true' && d3chart.options( { showControls: false } );
d3chart.xAxis.showMaxMin( false );
d3chart.yAxis.showMaxMin( chart.definition.showmaxmin );
d3chart.tooltipContent( function( key, x, y, graph ) {
return '<h3>' + ( graph.point.tooltip || key ) + '</h3>';
d3chart.xAxis.axisLabel(chart.settings.get("x_axis_label"));
d3chart.yAxis.axisLabel(chart.settings.get("y_axis_label")).axisLabelDistance(30);
d3chart.options({ showControls: false });
d3chart.showLegend && d3chart.showLegend(chart.settings.get("show_legend") == "true");
self._makeAxes(d3chart, groups, chart.settings);
makeConfig && makeConfig(d3chart);
chart.settings.get("__use_panels") === "true" && d3chart.options({ showControls: false });
d3chart.xAxis.showMaxMin(false);
d3chart.yAxis.showMaxMin(chart.definition.showmaxmin);
d3chart.tooltipContent(function(key, x, y, graph) {
return "<h3>" + (graph.point.tooltip || key) + "</h3>";
});
if ( $( '#' + canvas_id ).length > 0 ) {
var canvas = d3.select( '#' + canvas_id );
canvas.datum( groups ).call( d3chart );
if ( chart.definition.zoomable && chart.definition.zoomable != 'native' ) {
d3chart.clipEdge && d3chart.clipEdge( true );
if ($("#" + canvas_id).length > 0) {
var canvas = d3.select("#" + canvas_id);
canvas.datum(groups).call(d3chart);
if (chart.definition.zoomable && chart.definition.zoomable != "native") {
d3chart.clipEdge && d3chart.clipEdge(true);
Utilities.addZoom({
xAxis : d3chart.xAxis,
yAxis : d3chart.yAxis,
xAxis: d3chart.xAxis,
yAxis: d3chart.yAxis,
yDomain: d3chart.yDomain,
xDomain: d3chart.xDomain,
redraw : function() { d3chart.update() },
svg : canvas
redraw: function() {
d3chart.update();
},
svg: canvas
});
}
nv.utils.windowResize( d3chart.update );
nv.utils.windowResize(d3chart.update);
}
} catch ( err ) {
chart.state( 'failed', err );
} catch (err) {
chart.state("failed", err);
}
});
return true;
},

/** Format axes ticks */
_makeAxes: function( d3chart, groups, settings ) {
var categories = Utilities.makeCategories( groups, [ 'x', 'y' ] );
function makeTickFormat( id ) {
_makeAxes: function(d3chart, groups, settings) {
var categories = Utilities.makeCategories(groups, ["x", "y"]);
function makeTickFormat(id) {
Utilities.makeTickFormat({
categories : categories.array[ id ],
type : settings.get( id + '_axis_type|type' ),
precision : settings.get( id + '_axis_type|precision' ),
formatter : function( formatter ) {
formatter && d3chart[ id + 'Axis' ].tickFormat( function( value ) {
return formatter( value );
});
categories: categories.array[id],
type: settings.get(id + "_axis_type|type"),
precision: settings.get(id + "_axis_type|precision"),
formatter: function(formatter) {
formatter &&
d3chart[id + "Axis"].tickFormat(function(value) {
return formatter(value);
});
}
});
};
makeTickFormat( 'x' );
makeTickFormat( 'y' );
}
makeTickFormat("x");
makeTickFormat("y");
}
});

return {
nvd3_bar: function(options) {
options.type = 'multiBarChart';
new CommonWrapper( options );
options.type = "multiBarChart";
new CommonWrapper(options);
}
}
});
};
});

0 comments on commit 65590f1

Please sign in to comment.