From 8abd50db0121920bba0e549df6ffd37d646fa868 Mon Sep 17 00:00:00 2001
From: Juliana <juliana@le-filament.com>
Date: Tue, 21 Sep 2021 15:56:16 +0200
Subject: [PATCH] [ADD]Add label + Text legend

---
 models/enercoop_operation.py     |  2 +-
 static/src/js/operation_graph.js | 90 +++++++++++++++++++++++++++++---
 2 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/models/enercoop_operation.py b/models/enercoop_operation.py
index 86ddd92..07d76cd 100644
--- a/models/enercoop_operation.py
+++ b/models/enercoop_operation.py
@@ -524,7 +524,7 @@ class EnercoopOperation(models.Model):
             type_date = 'date_slot:hour'
             type_date_abs = 'date_slot:day'
             type_date_histo = 'date_slot:hour'
-        elif type == 'year':
+        elif type == 'year' or 'semestre':
             type_date = 'date_slot:month'
             type_date_abs = 'date_slot:month'
             type_date_histo = 'date_slot:month'
diff --git a/static/src/js/operation_graph.js b/static/src/js/operation_graph.js
index e0c1b71..f698094 100644
--- a/static/src/js/operation_graph.js
+++ b/static/src/js/operation_graph.js
@@ -60,9 +60,46 @@ odoo.define('enercoop_cdc.operation_graph', function (require) {
                             ticks: {
                                 min: result.date_start,
                             },
-                            title: {
+                            gridLines: {
+                                offsetGridLines: true
+                            }
+                        }],
+                        yAxes: [{
+                            scaleLabel: {
+                              display: true,
+                              labelString: 'kW',
+                            }
+                        }]
+                    },
+                elements: {
+                    point:{
+                        radius: 0
+                    }
+                }
+                },
+                };
+
+                var options_line_stacked = { options: {
+                    scales: {
+                        xAxes: [{
+                            stacked: true,
+                            type: 'time',
+                            time: {
+                              // Luxon format string
+                              unit: unit,
+                            },
+                            ticks: {
+                                min: result.date_start,
+                            },
+                            gridLines: {
+                                offsetGridLines: true
+                            }
+                        }],
+                        yAxes: [{
+                            stacked: true,
+                            scaleLabel: {
                               display: true,
-                              text: 'Date'
+                              labelString: 'kW',
                             }
                         }]
                     },
@@ -81,13 +118,22 @@ odoo.define('enercoop_cdc.operation_graph', function (require) {
                     }
                 }
             }};
-            var options_stacked = { options: {
+
+            var options_donuts = { options: {
+                showDatasetLabels : true,
+                cutoutPercentage: 41,
+            }};
+
+            var options_histo_stacked = { options: {
                 interaction: {
                   intersect: false,
                 },
                 scales: {
                     xAxes: [{
                         stacked: true,
+                        gridLines: {
+                            offsetGridLines: true
+                        }
                     }],
                     yAxes: [{
                         stacked: true,
@@ -95,6 +141,33 @@ odoo.define('enercoop_cdc.operation_graph', function (require) {
                           beginAtZero: true,
                         },
                         type: 'linear',
+                        scaleLabel: {
+                          display: true,
+                          labelString: 'kWh',
+                        }
+                    }]
+                }
+            }};
+
+            var options_histo = { options: {
+                interaction: {
+                  intersect: false,
+                },
+                scales: {
+                    xAxes: [{
+                        gridLines: {
+                            offsetGridLines: true
+                        }
+                    }],
+                    yAxes: [{
+                        ticks: {
+                          beginAtZero: true,
+                        },
+                        type: 'linear',
+                        scaleLabel: {
+                          display: true,
+                          labelString: 'kWh',
+                        }
                     }]
                 }
             }};
@@ -117,33 +190,34 @@ odoo.define('enercoop_cdc.operation_graph', function (require) {
                     Object.assign({}, result.line_chart_conso_line, options_line)
                 );
             }
+            console.log(options_line);
             console.log(chart_line_conso);
 
 	    	chart_donuts_conso = new Chart(
 	    		donuts_conso,
-	    		Object.assign({}, result.donuts_chart_conso, options)
+	    		Object.assign({}, result.donuts_chart_conso, options_donuts)
 	    	);
 
 	    	chart_histo_conso = new Chart(
 	    		histo_conso,
-	    		Object.assign({}, result.histo_chart_conso, options_stacked)
+	    		Object.assign({}, result.histo_chart_conso, options_histo_stacked)
 	    	);
 
             if (result.scale == 'week' || result.scale == 'day'){
                 chart_line_prod = new Chart(
                     line_prod,
-                    Object.assign({}, result.line_chart_prod_line, options_line)
+                    Object.assign({}, result.line_chart_prod_line, options_line_stacked)
                 );
             }
 
 	    	chart_donuts_prod = new Chart(
 	    		donuts_prod,
-	    		Object.assign({}, result.donuts_chart_prod, options)
+	    		Object.assign({}, result.donuts_chart_prod, options_donuts)
 	    	);
 
 	    	chart_histo_prod = new Chart(
 	    		histo_prod,
-	    		Object.assign({}, result.histo_chart_prod, options_stacked)
+	    		Object.assign({}, result.histo_chart_prod, options_histo)
 	    	);
             this.$el.find('.o_enercoop_button').removeClass('active');
             if (this.state.scale) {
-- 
GitLab