From 83a4732e64ea8998da1dd0ac867701b77b6ce915 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Mon, 27 May 2019 15:02:59 +0200
Subject: [PATCH] =?UTF-8?q?Axes=20des=20graphiques:=20nom=20complet=20avec?=
 =?UTF-8?q?=20unit=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../results-graph/results-graph.component.ts  | 23 +++++++++++++++----
 src/app/results/plottable-data.ts             |  8 ++++++-
 src/app/results/plottable-pab-results.ts      |  6 ++++-
 src/app/results/var-results.ts                | 13 +++++++++--
 4 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/src/app/components/results-graph/results-graph.component.ts b/src/app/components/results-graph/results-graph.component.ts
index efd025288..9cc50d8e7 100644
--- a/src/app/components/results-graph/results-graph.component.ts
+++ b/src/app/components/results-graph/results-graph.component.ts
@@ -104,7 +104,7 @@ export class ResultsGraphComponent extends ResultsComponent implements AfterCont
     /**
      * Returns a human readable description of any param / result symbol
      */
-    public getChartAxisLabel(symbol: string) {
+    public getChartAxisLabel(symbol: string): string {
         return this._results.getChartAxisLabel(symbol);
     }
 
@@ -135,6 +135,19 @@ export class ResultsGraphComponent extends ResultsComponent implements AfterCont
         this._graphTypeComponent.addObserver(this);
     }
 
+    /**
+     * Calls getChartAxisLabel() and removes the symbol prefix
+     * (cannot rebuild a clean label here)
+     */
+    private axisLabelWithoutSymbol(symbol: string) {
+        let l = this._results.getChartAxisLabel(symbol);
+        const i = l.indexOf(": ");
+        if (i !== -1) {
+            l = l.substring(i + 2);
+        }
+        return l;
+    }
+
     /** forces Angular to rebuild the chart @see bug #137 */
     private forceRebuild() {
         this.displayChart = false;
@@ -172,13 +185,13 @@ export class ResultsGraphComponent extends ResultsComponent implements AfterCont
                 },
                 scaleLabel: {
                     display: true,
-                    labelString: this.chartX
+                    labelString: this.axisLabelWithoutSymbol(this.chartX)
                 }
             }],
             yAxes: [{
                 scaleLabel: {
                     display: true,
-                    labelString: this.chartY
+                    labelString: this.axisLabelWithoutSymbol(this.chartY)
                 }
             }]
         };
@@ -224,7 +237,7 @@ export class ResultsGraphComponent extends ResultsComponent implements AfterCont
                 },
                 scaleLabel: {
                     display: true,
-                    labelString: this.chartX
+                    labelString: this.axisLabelWithoutSymbol(this.chartX)
                 }
             }],
             yAxes: [{
@@ -235,7 +248,7 @@ export class ResultsGraphComponent extends ResultsComponent implements AfterCont
                 },
                 scaleLabel: {
                     display: true,
-                    labelString: this.chartY
+                    labelString: this.axisLabelWithoutSymbol(this.chartY)
                 }
             }]
         };
diff --git a/src/app/results/plottable-data.ts b/src/app/results/plottable-data.ts
index 609c388aa..d750529b7 100644
--- a/src/app/results/plottable-data.ts
+++ b/src/app/results/plottable-data.ts
@@ -14,7 +14,13 @@ export interface PlottableData {
      * (usually a variable symbol like "Q", "Z1"…)
      * @param symbol parameter / result symbol (ex: "Q")
      */
-    getChartAxisLabel(symbol: string);
+    getChartAxisLabel(symbol: string): string;
+
+    /**
+     * Returns the translated name of the given symbol (usually an extraResult)
+     * if available, with its unit, but without the symbol itself
+     */
+    expandLabelFromSymbol(symbol: string): string;
 
     /**
      * Returns a list of plottable parameters / result elements, that can be defined
diff --git a/src/app/results/plottable-pab-results.ts b/src/app/results/plottable-pab-results.ts
index c8cdd2964..b8bfe90c9 100644
--- a/src/app/results/plottable-pab-results.ts
+++ b/src/app/results/plottable-pab-results.ts
@@ -29,10 +29,14 @@ export class PlottablePabResults implements PlottableData {
      * Returns the label to display, for an element of getAvailableChartAxis()
      * @param symbol parameter / result symbol (ex: "Q")
      */
-    public getChartAxisLabel(symbol: string) {
+    public getChartAxisLabel(symbol: string): string {
         return this.pabResults.headers[this.pabResults.columns.indexOf(symbol)];
     }
 
+    public expandLabelFromSymbol(symbol: string): string {
+        return symbol;
+    }
+
     /**
      * Returns a list of plottable parameters / result elements, that can be defined
      * as X or Y chart axis
diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts
index 4f7fcf28a..95898befc 100644
--- a/src/app/results/var-results.ts
+++ b/src/app/results/var-results.ts
@@ -93,7 +93,7 @@ export class VarResults extends CalculatedParamResults implements PlottableData
         return this._extraResultHeaders;
     }
 
-    public getChartAxisLabel(symbol: string) {
+    public getChartAxisLabel(symbol: string): string {
         // 1. calculated param ?
         if (this.calculatedParameter && this.calculatedParameter.symbol === symbol) {
             return this.calculatedParameterHeader;
@@ -104,7 +104,16 @@ export class VarResults extends CalculatedParamResults implements PlottableData
                 return this.variableParamHeaders[i];
             }
         }
-        // 3. Result element ?
+        // 3. Result element
+        return this.expandLabelFromSymbol(symbol);
+
+    }
+
+    /**
+     * Returns the translated name of the given symbol (usually an extraResult) with
+     * its unit, but without the symbol itself
+     */
+    public expandLabelFromSymbol(symbol: string): string {
         // calculator type for translation
         const sn = this.result.sourceNub;
         let ct = sn.calcType;
-- 
GitLab