Skip to content

Commit

Permalink
Fix remaining nvd3 plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Feb 11, 2018
1 parent 055e0fa commit 83467ca
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 12 deletions.
162 changes: 160 additions & 2 deletions config/plugins/visualizations/nvd3/nvd3_bar/src/nvd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "../node_modules/nvd3/build/nv.d3.css";

var Series = window.bundleEntries.chartUtilities.Series;
var Datasets = window.bundleEntries.chartUtilities.Datasets;
var Jobs = window.bundleEntries.chartUtilities.Jobs;

var CommonWrapper = Backbone.View.extend({
initialize: function(options) {
Expand Down Expand Up @@ -91,18 +92,175 @@ var CommonWrapper = Backbone.View.extend({
}
});

var PieWrapper = Backbone.View.extend({
initialize: function(options) {
var self = this;
var chart = options.chart;
var targets = options.targets;
var process = options.process;
Datasets.request({
dataset_id: chart.get('dataset_id'),
dataset_groups: chart.groups,
success: function(groups) {
window.console.log(groups);
for (var group_index in groups) {
var group = groups[group_index];
self._drawGroup(chart, group, targets[group_index]);
}
chart.state('ok', 'Pie chart has been drawn.');
process.resolve();
}
});
},

/** Draw group */
_drawGroup: function(chart, group, canvas_id) {
try {
var self = this;
var canvas = d3.select('#' + canvas_id);
var title = canvas.append('text');
this._fixTitle(chart, canvas, title, group.key);
var pie_data = [];
_.each( group.values, function( value ) {
pie_data.push({y : value.y, x : value.label});
});
nv.addGraph(function() {
var legend_visible = chart.settings.get('show_legend') == 'true';
var label_outside = chart.settings.get('label_outside') == 'true';
var label_type = chart.settings.get('label_type');
var donut_ratio = parseFloat(chart.settings.get('donut_ratio'));
var chart_3d = nv.models.pieChart()
.donut( true )
.labelThreshold(.05)
.showLegend(legend_visible)
.labelType(label_type)
.donutRatio(donut_ratio)
.donutLabelsOutside(label_outside);
canvas.datum(pie_data).call(chart_3d);
nv.utils.windowResize(function() {
chart_3d.update();
self._fixTitle(chart, canvas, title, group.key);
});
});
} catch (err) {
console.log(err);
}
},

/** Fix title */
_fixTitle: function(chart, canvas, title_element, title_text) {
var width = parseInt(canvas.style('width'));
var height = parseInt(canvas.style('height'));
title_element.attr('x', width / 2)
.attr('y', height - 10)
.attr('text-anchor', 'middle')
.text(title_text);
}
});

_.extend(window.bundleEntries || {}, {
nvd3_bar: function(options) {
options.type = "multiBarChart";
return new CommonWrapper(options);
},
nvd3_bar_stacked: function(options) {
options.type = "multiBarChart";
options.makeConfig = function(nvd3_model) {
nvd3_model.stacked(true);
};
return new CommonWrapper(options);
},
nvd3_horizontal: function(options) {
options.type = "multiBarHorizontalChart";
return new CommonWrapper(options);
},
nvd3_horizontal_stacked: function(options) {
options.type = "multiBarHorizontalChart";
options.makeConfig = function(nvd3_model) {
nvd3_model.stacked(true);
};
return new CommonWrapper(options);
},
nvd3_histogram: function(options) {
Jobs.request(options.chart, Jobs.requestCharts(options.chart, "histogram"), function(dataset) {
var dataset_groups = new Backbone.Collection();
options.chart.groups.each( function( group, index ) {
dataset_groups.add({
__data_columns: { x: { is_numeric: true }, y: { is_numeric: true } },
x : 0,
y : index + 1,
key : group.get("key")
});
});
options.dataset_id = dataset.id;
options.dataset_groups = dataset_groups;
options.type = "multiBarChart";
options.makeConfig = function( nvd3_model ) {
nvd3_model.options( { showControls: true } );
};
new CommonWrapper(options);
}, function() {options.process.reject()} );
},
nvd3_histogram_discrete: function(options) {
Jobs.request(options.chart, Jobs.requestCharts(options.chart, "histogramdiscrete"), function(dataset) {
var dataset_groups = new Backbone.Collection();
options.chart.groups.each( function( group, index ) {
dataset_groups.add({
__data_columns: { x: { is_label: true }, y: { is_numeric: true } },
x : 0,
y : index + 1,
key : group.get("key")
});
});
options.dataset_id = dataset.id;
options.dataset_groups = dataset_groups;
options.type = "multiBarChart";
options.makeConfig = function( nvd3_model ) {
nvd3_model.options( { showControls: true } );
};
new CommonWrapper(options);
}, function() {options.process.reject()} );
},
nvd3_line: function(options) {
options.type = "lineChart";
return new CommonWrapper(options);
},
nvd3_line_focus: function(options) {
options.type = "lineWithFocusChart";
return new CommonWrapper(options);
},
nvd3_line: function(options) {
options.type = "lineChart";
return new CommonWrapper(options);
},
nvd3_pie: function(options) {
return new PieWrapper(options);
},
nvd3_scatter: function(options) {
options.type = 'scatterChart';
options.type = "scatterChart";
options.makeConfig = function( nvd3_model ) {
nvd3_model.showDistX( true )
.showDistY( true )
.color( d3.scale.category10().range() );
};
return new CommonWrapper(options);
}
},
nvd3_stackedarea: function(options) {
options.type = "stackedAreaChart";
return new CommonWrapper(options);
},
nvd3_stackedarea_full: function(options) {
options.type = "stackedAreaChart";
options.makeConfig = function( nvd3_model ) {
nvd3_model.style("expand");
};
return new CommonWrapper(options);
},
nvd3_stackedarea_stream: function(options) {
options.type = "stackedAreaChart";
options.makeConfig = function( nvd3_model ) {
nvd3_model.style("stream");
};
return new CommonWrapper(options);
},
});
14 changes: 9 additions & 5 deletions config/plugins/visualizations/nvd3/nvd3_bar/static/nvd3.js

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions config/plugins/visualizations/nvd3/nvd3_pie/config/nvd3_pie.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@
<use_panels>yes</use_panels>
</specs>
<groups>
<expand macro="groups"/>
<label>
<input>
<name>key</name>
<label>Provide a label</label>
<type>text</type>
<placeholder>Data label</placeholder>
<value>Data label</value>
</input>
<input>
<name>label</name>
<label>Labels</label>
<type>data_column</type>
<is_label>true</is_label>
<is_auto>true</is_auto>
</label>
<y>
</input>
<input>
<name>y</name>
<label>Values</label>
<type>data_column</type>
<is_numeric>true</is_numeric>
</y>
</input>
</groups>
<settings>
<donut_ratio>
Expand Down

0 comments on commit 83467ca

Please sign in to comment.