From fdd03e3b3a33cd75d5fef94f350bf1af83a495ca Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Wed, 21 Aug 2019 16:07:01 +0200 Subject: [PATCH] Fix #273 --- .../results-graph/results-graph.component.ts | 29 ++++++---- src/app/results/calculator-results.ts | 33 ++++++++--- src/app/results/var-results.ts | 55 ++++++++++++------- 3 files changed, 79 insertions(+), 38 deletions(-) diff --git a/src/app/components/results-graph/results-graph.component.ts b/src/app/components/results-graph/results-graph.component.ts index 16224f9ff..7c1ae074f 100644 --- a/src/app/components/results-graph/results-graph.component.ts +++ b/src/app/components/results-graph/results-graph.component.ts @@ -360,20 +360,27 @@ export class ResultsGraphComponent extends ResultsComponent implements AfterCont return this.chartY + " = " + Number(tooltipItems[0].yLabel).toFixed(nDigits); }, label: (tooltipItem, data) => { - const lines: string[] = []; - const nbLines = that._results.getVariatingParametersSymbols().length; + let lines: string[] = []; + // 1. X if different from Y + if (this.chartX !== this.chartY) { + const xseries = that._results.getValuesSeries(this.chartX); + const xline = this.chartX + " = " + xseries[tooltipItem.index].toFixed(nDigits); + lines.push(xline); + } + // 2. variated parameters other than X or Y + const varLines: string[] = []; for (const v of that._results.getVariatingParametersSymbols()) { - const series = that._results.getValuesSeries(v); - const line = v + " = " + series[tooltipItem.index].toFixed(nDigits); - if (v === this.chartX) { - if (nbLines > 1) { - lines.unshift(""); - } - lines.unshift(line); - } else { - lines.push(line); + if (v !== this.chartX && v !== this.chartY) { + const series = that._results.getValuesSeries(v); + const line = v + " = " + series[tooltipItem.index].toFixed(nDigits); + varLines.push(line); } } + // blank line ? + if (varLines.length > 0) { + lines.push(""); + lines = lines.concat(varLines); + } return lines; } } diff --git a/src/app/results/calculator-results.ts b/src/app/results/calculator-results.ts index 935a23035..36f23984c 100644 --- a/src/app/results/calculator-results.ts +++ b/src/app/results/calculator-results.ts @@ -1,18 +1,37 @@ import { NgParameter } from "../formulaire/ngparam"; +import { Nub } from "jalhyd"; +import { ServiceFactory } from "../services/service-factory"; export abstract class CalculatorResults { - public static paramLabel(p: NgParameter, displaySymbol: boolean): string { + + /** + * + * @param p parameter to generate label for + * @param displaySymbol if true, will prefix label with parameter symbol (ex: "ZDV") + * @param referenceNub if given, will detect if parameter belongs to a child of this reference Nub, and + * if so will add a number prefix (ex: "0_") before the label + */ + public static paramLabel(p: NgParameter, displaySymbol: boolean, referenceNub?: Nub): string { let res = ""; - if (displaySymbol) { + // detect child parameter + let isChildParam = false; + if (referenceNub) { + const children = referenceNub.getChildren(); + const parameterNub = p.paramDefinition.parentNub; + if (children.includes(parameterNub)) { + isChildParam = true; + const pos = parameterNub.findPositionInParent() + 1; + res = ServiceFactory.instance.i18nService.localizeText("INFO_OUVRAGE_N") + pos + " : "; + } + } + if (displaySymbol && ! isChildParam) { res += p.symbol; } if (p.label !== undefined && p.label !== "") { - if (p.symbol !== p.label || !displaySymbol) { - if (res.length > 0) { - res += " : "; - } - res += p.label; + if (displaySymbol && ! isChildParam) { + res += " : "; } + res += p.label; } if (p.unit !== undefined && p.unit !== "") { res += " (" + p.unit + ")"; diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts index ef4ff3302..a3823065c 100644 --- a/src/app/results/var-results.ts +++ b/src/app/results/var-results.ts @@ -72,9 +72,6 @@ export class VarResults extends CalculatedParamResults implements PlottableData public set variatedParameters(p: NgParameter[]) { this._variatedParams = p; - this._variableParamHeaders = this._variatedParams.map((v) => { - return CalculatorResults.paramLabel(v, true); - }); } public get variableParamHeaders() { @@ -148,11 +145,26 @@ export class VarResults extends CalculatedParamResults implements PlottableData public getValuesSeries(symbol: string): number[] { let found = false; const series: number[] = []; + // detect children results + const isChildResult = /^([0-9]+)_(.+)$/.exec(symbol); + // 1. variated param ? for (let i = 0; i < this.variatedParameters.length; i++) { - if (this._variatedParams[i].symbol === symbol) { + const vp = this._variatedParams[i]; + let isTheGoodChild = false; + // are we looking for a child variated param ? + if (isChildResult !== null) { + const children = this.result.sourceNub.getChildren(); + const parameterNub = vp.paramDefinition.parentNub; + if (children.includes(parameterNub)) { // current var param is a child param ! + const pos = parameterNub.findPositionInParent(); + isTheGoodChild = (pos === +isChildResult[1] && vp.symbol === isChildResult[2]); + } + } + // in any case + if (isTheGoodChild || vp.symbol === symbol) { found = true; - const iter = this.variatedParameters[i].getExtendedValuesIterator(this.size); + const iter = vp.getExtendedValuesIterator(this.size); for (const v of iter) { series.push(v); } @@ -171,13 +183,11 @@ export class VarResults extends CalculatedParamResults implements PlottableData } // 3. Child result element ? if (! found) { - // detect children results - const match = /^([0-9]+)_(.+)$/.exec(symbol); - if (match !== null) { + if (isChildResult !== null) { found = true; const sn = this.result.sourceNub; - const pos = +match[1]; - symbol = match[2]; + const pos = +isChildResult[1]; + symbol = isChildResult[2]; const child = sn.getChildren()[pos]; for (const r of child.result.resultElements) { series.push(r.getValue(symbol)); @@ -193,10 +203,8 @@ export class VarResults extends CalculatedParamResults implements PlottableData * as X chart axis */ public getAvailableXAxis(): string[] { - const res: string[] = []; - for (const v of this._variatedParams) { - res.push(v.symbol); - } + let res: string[] = []; + res = res.concat(this.getVariatingParametersSymbols()); for (const erk of this.resultKeys) { if (erk.indexOf("ENUM_") === -1) { // ENUM variables are not plottable res.push(erk); @@ -285,17 +293,24 @@ export class VarResults extends CalculatedParamResults implements PlottableData * (used by tooltip functions) */ public getVariatingParametersSymbols(): string[] { + const sn = this.result.sourceNub; return this._variatedParams.map((vp) => { - return vp.symbol; + // detect if variated param is a children param + const parameterNub = vp.paramDefinition.parentNub; + const children = sn.getChildren(); + let symb = vp.symbol; + if (children.includes(parameterNub)) { + symb = parameterNub.findPositionInParent() + "_" + symb; + } + return symb; }); } public update() { - if (this._variableParamHeaders.length === 0) { - this._variableParamHeaders = this._variatedParams.map((v) => { - return CalculatorResults.paramLabel(v, true); - }); - } + // refresh param headers + this._variableParamHeaders = this._variatedParams.map((v) => { + return CalculatorResults.paramLabel(v, true, this.result.sourceNub); + }); // liste la plus longue this.size = 0; -- GitLab