Charts: Add data point labels to all nvd3 charts (without this gene expression analysis using scatter plots is not very useful)

This commit is contained in:
guerler
2015-02-28 12:12:10 -05:00
parent 76a337bd24
commit 5bee11df4c
6 changed files with 40 additions and 26 deletions
File diff suppressed because one or more lines are too long
@@ -4,7 +4,15 @@ return $.extend(true, {}, config_default, {
category : '',
library : 'NVD3',
tag : 'svg',
keywords : 'small'
keywords : 'small',
columns : {
tooltip : {
title : 'Data point labels',
is_text : true,
is_numeric : true,
is_auto : true
}
}
});
});
@@ -15,71 +15,76 @@ return Backbone.View.extend({
options.render = function(canvas_id, groups) {
return self.render(canvas_id, groups)
};
// call panel helper
Tools.panelHelper(app, options);
},
// render
render : function(canvas_id, groups) {
var chart = this.options.chart;
var type = this.options.type;
var makeConfig = this.options.makeConfig;
// create nvd3 model
var d3chart = nv.models[type]()
// request data
var self = this;
nv.addGraph(function() {
try {
// x axis label
d3chart.xAxis.axisLabel(chart.settings.get('x_axis_label'));
// y axis label
d3chart.yAxis.axisLabel(chart.settings.get('y_axis_label'))
.axisLabelDistance(30);
// controls
d3chart.options({showControls: false});
// legend
if (d3chart.showLegend) {
d3chart.showLegend(chart.settings.get('show_legend') == 'true');
}
// make categories
self._makeAxes(d3chart, groups, chart.settings);
// custom callback
if (makeConfig) {
makeConfig(d3chart);
}
// hide controls if in multi-viewer mode
if (chart.settings.get('use_panels') === 'true') {
d3chart.options({showControls: false});
}
// hide min/max values
d3chart.xAxis.showMaxMin(false);
d3chart.yAxis.showMaxMin(chart.definition.showmaxmin);
// configure tooltips
d3chart.tooltipContent(function(key, x, y, graph) {
return '<h3>' + (graph.point.tooltip || key) + '</h3>';
});
// draw chart
if ($('#' + canvas_id).length == 0) {
return;
}
var canvas = d3.select('#' + canvas_id);
canvas.datum(groups)
canvas.datum(groups)
.call(d3chart);
// add zoom/pan handler
if (chart.definition.zoomable && chart.definition.zoomable != 'native') {
// clip edges
if (d3chart.clipEdge) {
d3chart.clipEdge(true);
}
// add zoom
Tools.addZoom({
xAxis : d3chart.xAxis,
@@ -97,16 +102,16 @@ return Backbone.View.extend({
self._handleError(chart, err);
}
});
// return
return true;
},
// create axes formatting
_makeAxes: function(d3chart, groups, settings) {
// result
var categories = Tools.makeCategories(groups);
// make axes
function makeTickFormat (id) {
Tools.makeTickFormat({
@@ -125,7 +130,7 @@ return Backbone.View.extend({
makeTickFormat('x');
makeTickFormat('y');
},
// handle error
_handleError: function(chart, err) {
chart.state('failed', err);
@@ -6,11 +6,11 @@ return $.extend(true, {}, nvd3_config, {
zoomable : true,
columns : {
x : {
title : 'Values for x-axis',
title : 'Values for x-axis',
is_numeric : true
},
y : {
title : 'Values for y-axis',
title : 'Values for y-axis',
is_numeric : true
}
}
@@ -299,7 +299,7 @@ return Backbone.Collection.extend(
// get/fix value
var v = column_data[j];
if (isNaN(v) && !column.is_label) {
if (isNaN(v) && !column.is_label && !column.is_text) {
v = 0;
}
@@ -145,12 +145,13 @@ return Backbone.View.extend({
// link this
var self = this;
// is a numeric number required
// available column options
var is_label = column_definition.is_label;
var is_auto = column_definition.is_auto;
var is_numeric = column_definition.is_numeric;
var is_unique = column_definition.is_unique;
var is_zero = column_definition.is_zero;
var is_text = column_definition.is_text;
// configure columns
var columns = [];
@@ -182,7 +183,7 @@ return Backbone.View.extend({
if (meta[key] == 'int' || meta[key] == 'float') {
valid = is_numeric;
} else {
valid = is_label;
valid = is_text || is_label;
}
// check type