From e1079146251c1725285ba670b3085bfe11ae6a13 Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Wed, 27 Jan 2021 09:48:59 +0530 Subject: [PATCH] horizontal bar tootltip updated --- .../report/project_budget_hrs_analysis.py | 24 ++++++- .../static/src/js/graph_renderer.js | 63 +++++++++++++++++-- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/project_report/report/project_budget_hrs_analysis.py b/project_report/report/project_budget_hrs_analysis.py index 460e94a..994a394 100755 --- a/project_report/report/project_budget_hrs_analysis.py +++ b/project_report/report/project_budget_hrs_analysis.py @@ -33,9 +33,9 @@ class BudgetHrsAnalysis(models.Model): """@api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): - if 'hours_type' not in groupby: - groupby.append('hours_type') res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) + for a in res: + print("A",a) return res""" def init(self): @@ -61,7 +61,25 @@ class BudgetHrsAnalysis(models.Model): Left JOIN project_sale_line_employee_map pro_emp ON pro_emp.project_id = pro.id Where pro.active = 't' - and PRO.pricing_type = 'employee_rate' + and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_in_consultant' + Union + SELECT + pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_date, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + pro.partner_id AS partner_id, + null::int AS employee_id, + 'Budgeted Hours' as hours_type, + null::date AS timesheet_date, + pro.budgeted_hours2 as hours + FROM + project_project PRO + --Left JOIN project_sale_line_employee_map pro_emp ON pro_emp.project_id = pro.id + Where + pro.active = 't' + and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_no_limit' Union SELECT pro.id AS project_id, diff --git a/project_report/static/src/js/graph_renderer.js b/project_report/static/src/js/graph_renderer.js index 5fa61c9..e4bdbfb 100755 --- a/project_report/static/src/js/graph_renderer.js +++ b/project_report/static/src/js/graph_renderer.js @@ -250,6 +250,61 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); return legendOptions; }, + /** + * Extracts the important information from a tooltipItem generated by Charts.js + * (a tooltip item corresponds to a line (different from measure name) of a tooltip) + * + * @private + * @param {Object} item + * @param {Object} data + * @returns {Object} + */ + _getTooltipItemContent: function (item, data) { + var dataset = data.datasets[item.datasetIndex]; + var label = data.labels[item.index]; + var value; + var boxColor; + if (this.state.mode === 'bar') { + label = this._relabelling(label, dataset.originIndex); + if (this.state.processedGroupBy.length > 1 || this.state.origins.length > 1) { + label = label + "/" + dataset.label; + } + value = this._formatValue(item.yLabel); + boxColor = dataset.backgroundColor; + } else if (this.state.mode === 'horizontalBar') { + label = this._relabelling(label, dataset.originIndex); + if (this.state.processedGroupBy.length > 1 || this.state.origins.length > 1) { + label = label + "/" + dataset.label; + } + value = this._formatValue(item.xLabel); + boxColor = dataset.backgroundColor; + } + else if (this.state.mode === 'line') { + label = this._relabelling(label, dataset.originIndex); + if (this.state.processedGroupBy.length > 1 || this.state.origins.length > 1) { + label = label + "/" + dataset.label; + } + value = this._formatValue(item.yLabel); + boxColor = dataset.borderColor; + } else { + if (label.isNoData) { + value = this._formatValue(0); + } else { + value = this._formatValue(dataset.data[item.index]); + } + label = this._relabelling(label, dataset.originIndex); + if (this.state.origins.length > 1) { + label = dataset.label + "/" + label; + } + boxColor = dataset.backgroundColor[item.index]; + } + return { + label: label, + value: value, + boxColor: boxColor, + }; + }, + _isRedirectionEnabled: function () { return !this.disableLinking && (this.state.mode === 'bar' || this.state.mode === 'horizontalBar' || this.state.mode === 'pie'); @@ -394,7 +449,7 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); duration: "1", "onComplete": function() { var chartInstance = this.chart, - ctx = chartInstance.ctx; + ctx = chartInstance.ctx; ctx.font = Chart.helpers.fontString(12, 'bold', "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"); ctx.textAlign = 'center'; ctx.textBaseline = 'bottom'; @@ -403,7 +458,7 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); meta.data.forEach(function(bar, index) { var data = dataset.data[index]; var value; - if(!!data){ + if(!!data && chartInstance.isDatasetVisible(i)){ value = GraphVal._formatValue(data); ctx.fillText(value, bar._model.x, bar._model.y - 5); } @@ -431,9 +486,9 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); var meta = chartInstance.controller.getDatasetMeta(i); meta.data.forEach(function(bar, index) { var data = dataset.data[index]; - //console.log("data", JSON.stringify(data)) + //console.log("data", JSON.stringify(data), chartInstance.isDatasetVisible(i), !chartInstance.isDatasetVisible(i)) var value; - if(!!data){ + if(!!data && chartInstance.isDatasetVisible(i)){ value = GraphVal._formatValue(data); ctx.fillText(value, bar._model.x, bar._model.y + 5); }