- expand_row: function (row_id, field_id) {
- var self = this;
- var row = this.get_row(row_id);
-
- if (row.path.length == this.data.row_groupby.length) {
- this.data.row_groupby.push(field_id);
- }
- row.expanded = true;
- row.html.find('.icon-plus-sign')
- .removeClass('icon-plus-sign')
- .addClass('icon-minus-sign');
-
- var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure);
- query_groups_data(this.data.model, visible_fields, row.domain, this.data.col_groupby, field_id)
- .then(function (groups) {
- _.each(groups.reverse(), function (group) {
- var new_row = self.make_row(group, row_id);
- row.html.after(new_row.html);
+/******************************************************************************
+ * Drawing charts methods...
+ ******************************************************************************/
+ bar_chart: function () {
+ var self = this,
+ dim_x = this.pivot.rows.groupby.length,
+ dim_y = this.pivot.cols.groupby.length,
+ data;
+
+ // No groupby **************************************************************
+ if ((dim_x === 0) && (dim_y === 0)) {
+ data = [{key: 'Total', values:[{
+ x: 'Total',
+ y: this.pivot.get_value(this.pivot.rows.main.id, this.pivot.cols.main.id),
+ }]}];
+ // Only column groupbys ****************************************************
+ } else if ((dim_x === 0) && (dim_y >= 1)){
+ data = _.map(this.pivot.get_columns_depth(1), function (header) {
+ return {
+ key: header.title,
+ values: [{x:header.root.main.title, y: self.pivot.get_total(header)}]
+ };
+ });
+ // Just 1 row groupby ******************************************************
+ } else if ((dim_x === 1) && (dim_y === 0)) {
+ data = _.map(this.pivot.rows.main.children, function (pt) {
+ var value = self.pivot.get_value(pt.id, self.pivot.cols.main.id),
+ title = (pt.title !== undefined) ? pt.title : 'Undefined';
+ return {x: title, y: value};
+ });
+ data = [{key: this.measure_label(), values:data}];
+ // 1 row groupby and some col groupbys**************************************
+ } else if ((dim_x === 1) && (dim_y >= 1)) {
+ data = _.map(this.pivot.get_columns_depth(1), function (colhdr) {
+ var values = _.map(self.pivot.get_rows_depth(1), function (header) {
+ return {
+ x: header.title || 'Undefined',
+ y: self.pivot.get_value(header.id, colhdr.id, 0)
+ };