2011-04-15 06:42:41 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-09-05 12:28:15 +00:00
|
|
|
* OpenERP web_graph
|
2011-04-15 06:42:41 +00:00
|
|
|
*---------------------------------------------------------*/
|
2013-11-08 15:41:14 +00:00
|
|
|
|
2013-11-12 08:38:27 +00:00
|
|
|
/* jshint undef: false */
|
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
openerp.web_graph = function (instance) {
|
2013-11-13 10:50:59 +00:00
|
|
|
'use strict';
|
2011-06-17 13:25:50 +00:00
|
|
|
|
2012-06-07 14:17:12 +00:00
|
|
|
var _lt = instance.web._lt;
|
2013-01-25 07:02:40 +00:00
|
|
|
var _t = instance.web._t;
|
2013-11-12 13:53:44 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
2012-05-07 08:19:08 +00:00
|
|
|
|
2012-04-17 12:48:30 +00:00
|
|
|
instance.web.views.add('graph', 'instance.web_graph.GraphView');
|
2013-11-08 13:08:06 +00:00
|
|
|
|
2013-11-08 15:20:48 +00:00
|
|
|
/**
|
2013-12-05 10:07:10 +00:00
|
|
|
* GraphView
|
2013-11-08 15:20:48 +00:00
|
|
|
*/
|
2012-04-17 12:48:30 +00:00
|
|
|
instance.web_graph.GraphView = instance.web.View.extend({
|
2013-11-08 13:08:06 +00:00
|
|
|
template: 'GraphView',
|
2011-12-16 13:00:00 +00:00
|
|
|
display_name: _lt('Graph'),
|
2013-11-08 13:08:06 +00:00
|
|
|
view_type: 'graph',
|
2013-11-12 11:31:34 +00:00
|
|
|
|
2013-11-08 13:08:06 +00:00
|
|
|
events: {
|
2013-12-05 10:07:10 +00:00
|
|
|
'click .graph_mode_selection li' : 'mode_selection',
|
|
|
|
'click .graph_measure_selection li' : 'measure_selection',
|
|
|
|
'click .graph_expand_selection li' : 'expand_selection',
|
|
|
|
'click .graph_options_selection li' : 'option_selection',
|
|
|
|
'click .web_graph_click' : 'cell_click_callback',
|
|
|
|
'click a.field-selection' : 'field_selection',
|
2013-11-08 13:08:06 +00:00
|
|
|
},
|
2011-04-15 06:42:41 +00:00
|
|
|
|
2013-11-27 13:04:06 +00:00
|
|
|
init: function(parent, dataset, view_id, options) {
|
|
|
|
this._super(parent);
|
2013-12-05 15:19:45 +00:00
|
|
|
this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true});
|
2013-11-27 13:04:06 +00:00
|
|
|
this.dataset = dataset;
|
2013-12-05 15:19:45 +00:00
|
|
|
this.pivot_table = new openerp.web_graph.PivotTable(this.model, dataset.domain);
|
2013-11-27 13:04:06 +00:00
|
|
|
this.set_default_options(options);
|
|
|
|
this.dropdown = null;
|
2013-12-05 15:19:45 +00:00
|
|
|
this.mode = 'pivot'; // pivot, bar_chart, line_chart, pie_chart, heatmap, row_heatmap, col_heatmap
|
2013-11-28 08:27:54 +00:00
|
|
|
this.measure_list = [];
|
|
|
|
this.important_fields = [];
|
2013-12-05 10:07:10 +00:00
|
|
|
this.search_view = parent.searchview;
|
2013-12-05 15:19:45 +00:00
|
|
|
this.groupby_mode = 'default'; // 'default' or 'manual'
|
|
|
|
this.default_row_groupby = [];
|
2013-12-10 11:16:46 +00:00
|
|
|
this.default_col_groupby = [];
|
2013-12-06 15:43:19 +00:00
|
|
|
this.search_field = {
|
2013-12-09 13:08:58 +00:00
|
|
|
get_context: this.proxy('get_context'),
|
|
|
|
get_domain: function () {},
|
2013-12-06 15:43:19 +00:00
|
|
|
get_groupby: function () { },
|
|
|
|
};
|
2013-11-28 08:27:54 +00:00
|
|
|
},
|
|
|
|
|
2013-12-09 13:08:58 +00:00
|
|
|
get_context: function (facet) {
|
|
|
|
var col_group_by = _.map(facet.values.models, function (model) {
|
|
|
|
return model.attributes.value.attrs.context.col_group_by;
|
|
|
|
});
|
|
|
|
return {col_group_by : col_group_by};
|
|
|
|
},
|
|
|
|
|
2013-11-28 08:27:54 +00:00
|
|
|
start: function () {
|
|
|
|
this.table = $('<table></table>');
|
|
|
|
this.$('.graph_main_content').append(this.table);
|
|
|
|
instance.web.bus.on('click', this, function (ev) {
|
|
|
|
if (this.dropdown) {
|
|
|
|
this.dropdown.remove();
|
|
|
|
this.dropdown = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return this.load_view();
|
2013-11-27 13:04:06 +00:00
|
|
|
},
|
|
|
|
|
2013-11-08 13:08:06 +00:00
|
|
|
view_loading: function (fields_view_get) {
|
2013-11-22 07:43:27 +00:00
|
|
|
var self = this,
|
2013-12-05 15:19:45 +00:00
|
|
|
measure = null;
|
2013-11-22 07:43:27 +00:00
|
|
|
|
2013-11-28 14:51:55 +00:00
|
|
|
if (fields_view_get.arch.attrs.type === 'bar') {
|
|
|
|
this.mode = 'bar_chart';
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:20:48 +00:00
|
|
|
// get the default groupbys and measure defined in the field view
|
|
|
|
_.each(fields_view_get.arch.children, function (field) {
|
|
|
|
if ('name' in field.attrs) {
|
|
|
|
if ('operator' in field.attrs) {
|
2013-12-11 13:11:48 +00:00
|
|
|
measure = field.attrs.name;
|
2013-11-08 15:20:48 +00:00
|
|
|
} else {
|
2013-12-11 13:11:48 +00:00
|
|
|
if (measure) {
|
2013-12-10 11:16:46 +00:00
|
|
|
self.default_col_groupby.push(field.attrs.name);
|
|
|
|
} else {
|
|
|
|
self.default_row_groupby.push(field.attrs.name);
|
|
|
|
}
|
2013-11-08 15:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-12-11 13:11:48 +00:00
|
|
|
this.pivot_table.set_measure(measure);
|
2013-11-08 15:20:48 +00:00
|
|
|
|
2013-11-13 15:47:31 +00:00
|
|
|
// get the most important fields (of the model) by looking at the
|
|
|
|
// groupby filters defined in the search view
|
2013-12-05 15:19:45 +00:00
|
|
|
var options = {model:this.model, view_type: 'search'},
|
2013-11-28 10:49:29 +00:00
|
|
|
deferred1 = instance.web.fields_view_get(options).then(function (search_view) {
|
|
|
|
var groups = _.select(search_view.arch.children, function (c) {
|
|
|
|
return (c.tag == 'group') && (c.attrs.string != 'Display');
|
|
|
|
});
|
|
|
|
_.each(groups, function(g) {
|
|
|
|
_.each(g.children, function (g) {
|
|
|
|
if (g.attrs.context) {
|
|
|
|
var field_id = py.eval(g.attrs.context).group_by;
|
|
|
|
self.important_fields.push(field_id);
|
|
|
|
}
|
|
|
|
});
|
2013-11-13 15:47:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// get the fields descriptions from the model
|
2013-12-05 15:19:45 +00:00
|
|
|
var deferred2 = this.model.call('fields_get', []).then(function (fs) {
|
|
|
|
self.fields = fs;
|
2013-12-11 13:11:48 +00:00
|
|
|
var temp = _.map(fs, function (field, name) {
|
|
|
|
return {name:name, type: field.type};
|
|
|
|
});
|
|
|
|
temp = _.filter(temp, function (field) {
|
|
|
|
return (((field.type === 'integer') || (field.type === 'float')) && (field.name !== 'id'));
|
|
|
|
});
|
|
|
|
self.measure_list = _.map(temp, function (field) {
|
|
|
|
return field.name;
|
|
|
|
});
|
|
|
|
|
2013-11-28 10:54:02 +00:00
|
|
|
var measure_selection = self.$('.graph_measure_selection');
|
|
|
|
_.each(self.measure_list, function (measure) {
|
|
|
|
var choice = $('<a></a>').attr('data-choice', measure)
|
|
|
|
.attr('href', '#')
|
|
|
|
.append(self.fields[measure].string);
|
|
|
|
measure_selection.append($('<li></li>').append(choice));
|
2013-11-12 16:10:34 +00:00
|
|
|
|
2013-11-28 08:27:54 +00:00
|
|
|
});
|
2013-11-28 10:54:02 +00:00
|
|
|
});
|
|
|
|
|
2013-12-05 15:19:45 +00:00
|
|
|
return $.when(deferred1, deferred2);
|
2013-11-13 09:18:07 +00:00
|
|
|
},
|
|
|
|
|
2013-11-08 15:20:48 +00:00
|
|
|
do_search: function (domain, context, group_by) {
|
2013-12-05 15:19:45 +00:00
|
|
|
var self = this,
|
2013-12-09 13:08:58 +00:00
|
|
|
col_groupby = context.col_group_by || []; // get_col_groupby('ColGroupBy');
|
2013-12-05 10:07:10 +00:00
|
|
|
|
2013-12-05 15:19:45 +00:00
|
|
|
if (group_by.length || col_groupby.length) {
|
|
|
|
this.groupby_mode = 'manual';
|
2013-12-05 10:07:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 15:19:45 +00:00
|
|
|
this.pivot_table.set_domain(domain);
|
|
|
|
if (this.groupby_mode === 'manual') {
|
|
|
|
this.pivot_table.set_row_groupby(group_by);
|
|
|
|
this.pivot_table.set_col_groupby(col_groupby);
|
|
|
|
} else {
|
2013-12-06 12:44:37 +00:00
|
|
|
this.pivot_table.set_row_groupby(_.toArray(this.default_row_groupby));
|
2013-12-10 11:16:46 +00:00
|
|
|
this.pivot_table.set_col_groupby(_.toArray(this.default_col_groupby));
|
2013-12-05 10:07:10 +00:00
|
|
|
}
|
2013-12-05 15:19:45 +00:00
|
|
|
this.display_data();
|
2011-05-06 12:41:08 +00:00
|
|
|
},
|
2012-05-07 09:40:59 +00:00
|
|
|
|
2013-11-08 11:32:10 +00:00
|
|
|
do_show: function () {
|
2012-01-03 16:06:50 +00:00
|
|
|
this.do_push_state({});
|
|
|
|
return this._super();
|
2012-05-07 08:19:08 +00:00
|
|
|
},
|
2013-11-08 15:20:48 +00:00
|
|
|
|
2013-11-27 11:05:38 +00:00
|
|
|
display_data: function () {
|
2013-12-05 15:19:45 +00:00
|
|
|
var pivot = this.pivot_table;
|
|
|
|
if (pivot.stale_data) {
|
|
|
|
pivot.update_data().done(this.proxy('display_data'));
|
2013-11-22 16:04:49 +00:00
|
|
|
} else {
|
2013-12-05 15:19:45 +00:00
|
|
|
this.$('.graph_main_content svg').remove();
|
|
|
|
this.table.empty();
|
|
|
|
|
|
|
|
if (pivot.no_data) {
|
|
|
|
var msg = 'No data available. Try to remove any filter or add some data.';
|
|
|
|
this.table.append($('<tr><td>' + msg + '</td></tr>'));
|
2013-11-27 14:07:01 +00:00
|
|
|
} else {
|
2013-12-05 15:19:45 +00:00
|
|
|
var table_modes = ['pivot', 'heatmap', 'row_heatmap', 'col_heatmap'];
|
|
|
|
if (_.contains(table_modes, this.mode)) {
|
|
|
|
this.draw_table();
|
|
|
|
} else {
|
|
|
|
this.$('.graph_main_content').append($('<div><svg></svg></div>'));
|
2013-12-11 14:01:40 +00:00
|
|
|
var options = {
|
|
|
|
svg: this.$('.graph_main_content svg')[0],
|
|
|
|
mode: this.mode,
|
|
|
|
pivot: this.pivot_table,
|
2013-12-11 16:00:11 +00:00
|
|
|
width: this.$el.width(),
|
2013-12-12 08:39:36 +00:00
|
|
|
height: Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width())),
|
2013-12-11 14:01:40 +00:00
|
|
|
measure_label: this.measure_label()
|
|
|
|
};
|
|
|
|
openerp.web_graph.draw_chart(options);
|
2013-12-05 15:19:45 +00:00
|
|
|
}
|
2013-11-27 14:07:01 +00:00
|
|
|
}
|
2013-11-22 16:04:49 +00:00
|
|
|
}
|
|
|
|
},
|
2013-11-22 13:59:27 +00:00
|
|
|
|
2013-12-05 10:07:10 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Event handling methods...
|
|
|
|
******************************************************************************/
|
2013-11-22 13:59:27 +00:00
|
|
|
handle_header_event: function (options) {
|
|
|
|
var pivot = this.pivot_table,
|
2013-11-24 21:48:09 +00:00
|
|
|
id = options.id,
|
2013-12-06 12:44:37 +00:00
|
|
|
header = pivot.get_header(id),
|
|
|
|
dim = header.root.groupby.length;
|
2013-11-22 13:59:27 +00:00
|
|
|
|
|
|
|
if (header.is_expanded) {
|
2013-11-24 15:00:34 +00:00
|
|
|
pivot.fold(header);
|
2013-12-06 15:43:19 +00:00
|
|
|
this.register_groupby();
|
2013-11-22 13:59:27 +00:00
|
|
|
} else {
|
2013-11-24 20:58:55 +00:00
|
|
|
if (header.path.length < header.root.groupby.length) {
|
|
|
|
var field = header.root.groupby[header.path.length];
|
2013-12-06 15:43:19 +00:00
|
|
|
pivot.expand(id, field).then(this.proxy('register_groupby'));
|
2013-11-22 13:59:27 +00:00
|
|
|
} else {
|
2013-11-27 09:20:52 +00:00
|
|
|
this.display_dropdown({id:header.id,
|
|
|
|
target: $(options.event.target),
|
|
|
|
x: options.event.pageX,
|
2013-11-24 21:48:09 +00:00
|
|
|
y: options.event.pageY});
|
2013-11-22 13:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-12-05 10:07:10 +00:00
|
|
|
mode_selection: function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var mode = event.target.attributes['data-mode'].nodeValue;
|
|
|
|
this.mode = mode;
|
|
|
|
this.display_data();
|
|
|
|
},
|
|
|
|
|
2013-12-06 15:43:19 +00:00
|
|
|
register_groupby: function() {
|
2013-12-06 12:44:37 +00:00
|
|
|
var self = this,
|
2013-12-06 15:43:19 +00:00
|
|
|
query = this.search_view.query;
|
|
|
|
this.groupby_mode = 'manual';
|
|
|
|
|
|
|
|
var rows = _.map(this.pivot_table.rows.groupby, function (group) {
|
|
|
|
return make_facet('GroupBy', group);
|
|
|
|
});
|
|
|
|
var cols = _.map(this.pivot_table.cols.groupby, function (group) {
|
|
|
|
return make_facet('ColGroupBy', group);
|
|
|
|
});
|
|
|
|
|
|
|
|
query.reset(rows.concat(cols));
|
|
|
|
|
|
|
|
function make_facet (category, fields) {
|
|
|
|
var values,
|
|
|
|
icon,
|
|
|
|
backbone_field,
|
|
|
|
cat_name;
|
|
|
|
if (!(fields instanceof Array)) { fields = [fields]; }
|
|
|
|
if (category === 'GroupBy') {
|
|
|
|
cat_name = 'group_by';
|
|
|
|
icon = 'w';
|
|
|
|
backbone_field = self.search_view._s_groupby;
|
|
|
|
} else {
|
|
|
|
cat_name = 'col_group_by';
|
|
|
|
icon = 'f';
|
|
|
|
backbone_field = self.search_field;
|
2013-12-06 12:44:37 +00:00
|
|
|
}
|
2013-12-06 15:43:19 +00:00
|
|
|
values = _.map(fields, function (field) {
|
|
|
|
var context = {};
|
|
|
|
context[cat_name] = field;
|
|
|
|
return {label: self.fields[field].string, value: {attrs:{domain: [], context: context}}};
|
2013-12-06 12:44:37 +00:00
|
|
|
});
|
2013-12-06 15:43:19 +00:00
|
|
|
return {category:category, values: values, icon:icon, field: backbone_field};
|
2013-12-05 15:19:45 +00:00
|
|
|
}
|
|
|
|
},
|
2013-12-05 10:07:10 +00:00
|
|
|
|
|
|
|
measure_selection: function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var measure = event.target.attributes['data-choice'].nodeValue;
|
2013-12-06 16:04:11 +00:00
|
|
|
this.pivot_table.set_measure((measure === '__count') ? null : measure);
|
2013-12-05 15:19:45 +00:00
|
|
|
this.display_data();
|
2013-12-05 10:07:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
expand_selection: function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
switch (event.target.attributes['data-choice'].nodeValue) {
|
|
|
|
case 'fold_columns':
|
|
|
|
this.pivot_table.fold_cols();
|
2013-12-06 15:43:19 +00:00
|
|
|
this.register_groupby();
|
2013-12-05 10:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'fold_rows':
|
|
|
|
this.pivot_table.fold_rows();
|
2013-12-06 15:43:19 +00:00
|
|
|
this.register_groupby();
|
2013-12-05 10:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'fold_all':
|
2013-12-06 16:04:11 +00:00
|
|
|
this.pivot_table.fold_cols();
|
|
|
|
this.pivot_table.fold_rows();
|
2013-12-06 15:43:19 +00:00
|
|
|
this.register_groupby();
|
2013-12-05 10:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'expand_all':
|
2013-12-05 15:19:45 +00:00
|
|
|
this.pivot_table.invalidate_data();
|
|
|
|
this.display_data();
|
2013-12-05 10:07:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
option_selection: function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
switch (event.target.attributes['data-choice'].nodeValue) {
|
|
|
|
case 'swap_axis':
|
|
|
|
this.pivot_table.swap_axis();
|
2013-12-06 15:43:19 +00:00
|
|
|
this.register_groupby();
|
2013-12-05 10:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'update_values':
|
2013-12-05 15:19:45 +00:00
|
|
|
this.pivot_table.stale_data = true;
|
|
|
|
this.display_data();
|
2013-12-05 10:07:10 +00:00
|
|
|
break;
|
|
|
|
case 'export_data':
|
|
|
|
// Export code... To do...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
cell_click_callback: function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
var id = event.target.attributes['data-id'].nodeValue;
|
|
|
|
this.handle_header_event({id:id, event:event});
|
|
|
|
},
|
|
|
|
|
|
|
|
field_selection: function (event) {
|
|
|
|
var self = this,
|
|
|
|
id = event.target.attributes['data-id'].nodeValue,
|
|
|
|
field_id = event.target.attributes['data-field-id'].nodeValue;
|
|
|
|
event.preventDefault();
|
|
|
|
this.pivot_table.expand(id, field_id).then(function () {
|
2013-12-06 15:43:19 +00:00
|
|
|
self.register_groupby();
|
2013-12-05 10:07:10 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-11-22 13:59:27 +00:00
|
|
|
display_dropdown: function (options) {
|
|
|
|
var self = this,
|
|
|
|
pivot = this.pivot_table,
|
|
|
|
dropdown_options = {
|
2013-11-24 21:48:09 +00:00
|
|
|
header_id: options.id,
|
2013-12-06 16:25:49 +00:00
|
|
|
fields: _.map(self.important_fields, function (field) {
|
2013-11-28 10:16:25 +00:00
|
|
|
return {id: field, value: self.fields[field].string};
|
2013-11-22 13:59:27 +00:00
|
|
|
})};
|
|
|
|
this.dropdown = $(QWeb.render('field_selection', dropdown_options));
|
|
|
|
options.target.after(this.dropdown);
|
|
|
|
this.dropdown.css({position:'absolute',
|
|
|
|
left:options.x,
|
|
|
|
top:options.y});
|
2013-11-27 13:04:06 +00:00
|
|
|
this.$('.field-selection').next('.dropdown-menu').toggle();
|
2013-11-22 13:59:27 +00:00
|
|
|
},
|
|
|
|
|
2013-12-05 10:07:10 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Drawing pivot table methods...
|
|
|
|
******************************************************************************/
|
2013-11-22 07:43:27 +00:00
|
|
|
draw_table: function () {
|
2013-11-28 08:45:51 +00:00
|
|
|
this.pivot_table.rows.main.title = 'Total';
|
|
|
|
this.pivot_table.cols.main.title = this.measure_label();
|
2013-11-22 07:43:27 +00:00
|
|
|
this.draw_top_headers();
|
2013-11-23 11:42:01 +00:00
|
|
|
_.each(this.pivot_table.rows.headers, this.proxy('draw_row'));
|
2013-11-14 13:17:47 +00:00
|
|
|
},
|
|
|
|
|
2013-12-05 10:07:10 +00:00
|
|
|
measure_label: function () {
|
2013-12-06 16:04:11 +00:00
|
|
|
var pivot = this.pivot_table;
|
|
|
|
return (pivot.measure) ? this.fields[pivot.measure].string : 'Quantity';
|
2013-12-05 10:07:10 +00:00
|
|
|
},
|
|
|
|
|
2013-11-22 09:43:22 +00:00
|
|
|
make_border_cell: function (colspan, rowspan) {
|
|
|
|
return $('<td></td>').addClass('graph_border')
|
|
|
|
.attr('colspan', colspan)
|
|
|
|
.attr('rowspan', rowspan);
|
|
|
|
},
|
2013-11-19 14:52:33 +00:00
|
|
|
|
2013-11-22 09:43:22 +00:00
|
|
|
make_header_title: function (header) {
|
|
|
|
return $('<span> </span>')
|
|
|
|
.addClass('web_graph_click')
|
|
|
|
.attr('href', '#')
|
|
|
|
.addClass((header.is_expanded) ? 'icon-minus-sign' : 'icon-plus-sign')
|
2013-11-26 15:19:06 +00:00
|
|
|
.append((header.title !== undefined) ? header.title : 'Undefined');
|
2013-11-22 09:43:22 +00:00
|
|
|
},
|
2013-11-20 11:08:21 +00:00
|
|
|
|
2013-11-22 09:43:22 +00:00
|
|
|
draw_top_headers: function () {
|
|
|
|
var self = this,
|
|
|
|
pivot = this.pivot_table,
|
2013-11-23 11:42:01 +00:00
|
|
|
height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})),
|
2013-11-22 09:43:22 +00:00
|
|
|
header_cells = [[this.make_border_cell(1, height)]];
|
|
|
|
|
2013-11-22 13:59:27 +00:00
|
|
|
function set_dim (cols) {
|
|
|
|
_.each(cols.children, set_dim);
|
|
|
|
if (cols.children.length === 0) {
|
|
|
|
cols.height = height - cols.path.length + 1;
|
|
|
|
cols.width = 1;
|
|
|
|
} else {
|
|
|
|
cols.height = 1;
|
|
|
|
cols.width = _.reduce(cols.children, function (sum,c) { return sum + c.width;}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 09:43:22 +00:00
|
|
|
function make_col_header (col) {
|
|
|
|
var cell = self.make_border_cell(col.width, col.height);
|
2013-11-24 21:48:09 +00:00
|
|
|
return cell.append(self.make_header_title(col).attr('data-id', col.id));
|
2013-11-14 15:33:48 +00:00
|
|
|
}
|
2013-11-14 13:17:47 +00:00
|
|
|
|
2013-11-22 07:43:27 +00:00
|
|
|
function make_cells (queue, level) {
|
2013-11-22 15:10:25 +00:00
|
|
|
var col = queue[0];
|
|
|
|
queue = _.rest(queue).concat(col.children);
|
2013-11-22 09:43:22 +00:00
|
|
|
if (col.path.length == level) {
|
|
|
|
_.last(header_cells).push(make_col_header(col));
|
2013-11-21 09:07:19 +00:00
|
|
|
} else {
|
2013-11-22 09:43:22 +00:00
|
|
|
level +=1;
|
|
|
|
header_cells.push([make_col_header(col)]);
|
2013-11-21 09:07:19 +00:00
|
|
|
}
|
2013-11-22 07:43:27 +00:00
|
|
|
if (queue.length !== 0) {
|
|
|
|
make_cells(queue, level);
|
2013-11-21 09:07:19 +00:00
|
|
|
}
|
2013-11-20 13:07:48 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 11:42:01 +00:00
|
|
|
set_dim(pivot.cols.main); // add width and height info to columns headers
|
|
|
|
if (pivot.cols.main.children.length === 0) {
|
|
|
|
make_cells(pivot.cols.headers, 0);
|
2013-11-22 09:43:22 +00:00
|
|
|
} else {
|
2013-11-23 11:42:01 +00:00
|
|
|
make_cells(pivot.cols.main.children, 1);
|
2013-11-25 09:15:05 +00:00
|
|
|
header_cells[0].push(self.make_border_cell(1, height).append('Total').css('font-weight', 'bold'));
|
2013-11-22 09:43:22 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 07:43:27 +00:00
|
|
|
_.each(header_cells, function (cells) {
|
2013-11-27 09:20:52 +00:00
|
|
|
self.table.append($('<tr></tr>').append(cells));
|
2013-11-18 15:26:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-12-11 12:43:07 +00:00
|
|
|
get_measure_type: function () {
|
|
|
|
var measure = this.pivot_table.measure;
|
|
|
|
return (measure) ? this.fields[measure].type : 'integer';
|
|
|
|
},
|
|
|
|
|
2013-11-22 07:43:27 +00:00
|
|
|
draw_row: function (row) {
|
2013-11-24 14:52:40 +00:00
|
|
|
var self = this,
|
|
|
|
pivot = this.pivot_table,
|
2013-12-11 12:43:07 +00:00
|
|
|
measure_type = this.get_measure_type(),
|
2013-11-22 07:43:27 +00:00
|
|
|
html_row = $('<tr></tr>'),
|
2013-11-22 13:59:27 +00:00
|
|
|
row_header = this.make_border_cell(1,1)
|
2013-11-24 21:48:09 +00:00
|
|
|
.append(this.make_header_title(row).attr('data-id', row.id))
|
2013-11-22 07:43:27 +00:00
|
|
|
.addClass('graph_border');
|
|
|
|
|
|
|
|
for (var i in _.range(row.path.length)) {
|
|
|
|
row_header.prepend($('<span/>', {class:'web_graph_indent'}));
|
2013-11-14 13:17:47 +00:00
|
|
|
}
|
2013-11-14 10:34:46 +00:00
|
|
|
|
2013-11-22 07:43:27 +00:00
|
|
|
html_row.append(row_header);
|
2013-11-15 09:24:11 +00:00
|
|
|
|
2013-11-23 11:42:01 +00:00
|
|
|
_.each(pivot.cols.headers, function (col) {
|
2013-11-22 15:10:25 +00:00
|
|
|
if (col.children.length === 0) {
|
2013-11-24 14:52:40 +00:00
|
|
|
var value = pivot.get_value(row.id, col.id),
|
2013-11-27 15:06:28 +00:00
|
|
|
cell = make_cell(value, col);
|
2013-11-22 15:10:25 +00:00
|
|
|
html_row.append(cell);
|
|
|
|
}
|
2013-11-14 10:34:46 +00:00
|
|
|
});
|
2013-11-25 09:04:43 +00:00
|
|
|
|
|
|
|
if (pivot.cols.main.children.length > 0) {
|
2013-11-28 09:47:46 +00:00
|
|
|
var cell = make_cell(pivot.get_total(row), pivot.cols.main)
|
2013-11-27 15:06:28 +00:00
|
|
|
.css('font-weight', 'bold');
|
2013-11-25 09:04:43 +00:00
|
|
|
html_row.append(cell);
|
|
|
|
}
|
|
|
|
|
2013-11-22 07:43:27 +00:00
|
|
|
this.table.append(html_row);
|
2013-11-27 14:45:05 +00:00
|
|
|
|
2013-11-27 15:06:28 +00:00
|
|
|
function make_cell (value, col) {
|
2013-11-27 14:45:05 +00:00
|
|
|
var color,
|
2013-11-27 15:06:28 +00:00
|
|
|
total,
|
2013-11-27 14:45:05 +00:00
|
|
|
cell = $('<td></td>');
|
|
|
|
if ((self.mode === 'pivot') && (row.is_expanded) && (row.path.length <=2)) {
|
|
|
|
color = row.path.length * 5 + 240;
|
|
|
|
cell.css('background-color', $.Color(color, color, color));
|
|
|
|
}
|
2013-11-27 15:06:28 +00:00
|
|
|
if (value === undefined) {
|
|
|
|
return cell;
|
|
|
|
}
|
2013-12-11 12:43:07 +00:00
|
|
|
cell.append(instance.web.format_value(value, {type: measure_type}));
|
2013-11-27 14:45:05 +00:00
|
|
|
if (self.mode === 'heatmap') {
|
2013-11-28 09:47:46 +00:00
|
|
|
total = pivot.get_total();
|
|
|
|
color = Math.floor(50 + 205*(total - value)/total);
|
2013-11-27 14:45:05 +00:00
|
|
|
cell.css('background-color', $.Color(255, color, color));
|
|
|
|
}
|
2013-11-27 15:06:28 +00:00
|
|
|
if (self.mode === 'row_heatmap') {
|
2013-11-28 09:47:46 +00:00
|
|
|
total = pivot.get_total(row);
|
2013-11-27 15:06:28 +00:00
|
|
|
color = Math.floor(50 + 205*(total - value)/total);
|
|
|
|
cell.css('background-color', $.Color(255, color, color));
|
|
|
|
}
|
|
|
|
if (self.mode === 'col_heatmap') {
|
2013-11-28 09:47:46 +00:00
|
|
|
total = pivot.get_total(col);
|
2013-11-27 15:06:28 +00:00
|
|
|
color = Math.floor(50 + 205*(total - value)/total);
|
|
|
|
cell.css('background-color', $.Color(255, color, color));
|
|
|
|
}
|
2013-11-27 14:45:05 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
},
|
2013-11-22 07:43:27 +00:00
|
|
|
});
|
2013-11-14 10:34:46 +00:00
|
|
|
|
2011-04-15 06:42:41 +00:00
|
|
|
};
|