From 74bb2083639e692598b1e8b0be33f41e55ea3de0 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Wed, 8 Nov 2017 11:56:29 +0100 Subject: [PATCH] =?UTF-8?q?remous=20:=20ajout=20du=20param=C3=A8tre=20supp?= =?UTF-8?q?l=C3=A9mentaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generic/calculator.component.ts | 48 +++++--- .../remous-results.component.html | 17 +-- .../remous-results.component.ts | 115 +++++++++++++----- 3 files changed, 125 insertions(+), 55 deletions(-) diff --git a/src/app/calculators/generic/calculator.component.ts b/src/app/calculators/generic/calculator.component.ts index a2c79e282..37e6aff36 100644 --- a/src/app/calculators/generic/calculator.component.ts +++ b/src/app/calculators/generic/calculator.component.ts @@ -319,9 +319,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { let targetSelect: SelectField = <SelectField>this._formulaire.getFieldById("select_target"); let targetValue: string = targetSelect.getValue(); - let prefix = "select_target_" - let l = prefix.length; - let symbol: string = targetValue.substr(l, targetValue.length - l); + let symbol: string = this.removePrefix(targetValue, "select_target_"); let label = targetSelect.getLabel(); return { symbol, label }; @@ -460,10 +458,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { this._showResultsSection = true; } - private addRemousResult(x: string, f: number, t: number, nDigits: number) { + private addRemousResult(x: string, f: number, t: number, e: number, nDigits: number) { let flu = f == undefined ? "" : f.toFixed(nDigits); - let tor = t == undefined ? "" : f.toFixed(nDigits); - this.remousResultsComponent.addResult(x, flu, tor); + let tor = t == undefined ? "" : t.toFixed(nDigits); + let extra = e == undefined ? "" : e.toFixed(nDigits); + this.remousResultsComponent.addResult(x, flu, tor, extra); } private doComputeRemous() { @@ -502,12 +501,16 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { else throw "GenericCalculatorComponent.doComputeRemous() : type de méthode de résolution '" + smeth + "' inconnu"; + // paramètre supplémentaire à calculer + + let dsf: SelectField = <SelectField>this._formulaire.getFormulaireElementById("select_target"); + let extraSymbol: string = this.removePrefix(dsf.getValue(), "select_target_"); + // calcul let prmCR: CourbeRemousParams = new CourbeRemousParams(sect, Yamont, Yaval, Long, Dx, methRes); - let log: cLog = new cLog(); - let cr = new CourbeRemous(prmCR, log); - let res = cr.calculRemous(undefined); + let cr = new CourbeRemous(prmCR); + let res = cr.calculRemous(extraSymbol == "none" ? undefined : extraSymbol); // affichage du graphe @@ -516,10 +519,16 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { this.remousResultsComponent.setHauteurBerge(YB); this.remousResultsComponent.setHauteurNormale(Yn); this.remousResultsComponent.setHauteurCritique(Yc); + if (extraSymbol != "none") { + this.remousResultsComponent.extraParamLabel = dsf.selectedEntry.label; + this.remousResultsComponent.extraGraph = ["Hs", "Hsc", "Yf", "Yt", "Yco"].indexOf(extraSymbol) == -1; + } + else + this.remousResultsComponent.extraGraph = false; // affichage du journal - for (let l of log.messages) + for (let l of cr.log.messages) this.remousResultsComponent.addLogEntry(l, nDigits); // affichage des resultats numériques @@ -528,11 +537,10 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { let kTor = Object.keys(res.tor); for (let i = 0; i < res.trX.length; i++) { let x: string = res.trX[i]; - // let f = i < kFlu.length ? res.flu[kFlu[i]] : undefined; - // let t = i < kTor.length ? res.tor[kTor[i]] : undefined; let f = res.flu[x]; let t = res.tor[x]; - this.addRemousResult(x, f, t, nDigits); + let e = res.tRes[x]; + this.addRemousResult(x, f, t, e, nDigits); } this.remousResultsComponent.generateGraph(); @@ -635,13 +643,19 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { }); } + private removePrefix(s: string, prefix: string): string { + if (s.startsWith(prefix)) { + let l = prefix.length; + return s.substr(l, s.length - l); + } + return undefined; + } + private updateSectionType(val: string) { - let select_prefix: string = "select_section_"; //TODO ici on fait un cas particulier, il faudra sortir ça - if (val.startsWith(select_prefix)) { - let l = select_prefix.length; - let type: string = val.substr(l, val.length - l); + let type: string = this.removePrefix(val, "select_section_"); + if (type != undefined) { switch (this._calculatorType) { case CalculatorType.SectionParametree: switch (type) { diff --git a/src/app/components/remous-results/remous-results.component.html b/src/app/components/remous-results/remous-results.component.html index 3e2d8ad81..5b8eb55f0 100644 --- a/src/app/components/remous-results/remous-results.component.html +++ b/src/app/components/remous-results/remous-results.component.html @@ -1,9 +1,6 @@ -<div style="width:30%; height: 400px"> - <chart [type]="graph_type" [data]="graph_data" [options]="graph_options"></chart> - <!-- - <div> - <chart style="float: left" [type]="graph_type" [data]="graph_data" [options]="graph_options"></chart> ---> +<div style="width:50%"> + <chart [type]="graph1_type" [data]="graph1_data" [options]="graph1_options"></chart> + <chart *ngIf="_extraGraph" [type]="graph2_type" [data]="graph2_data" [options]="graph2_options"></chart> </div> <br/> <div style="text-align:center;"> @@ -25,18 +22,24 @@ <tr> <th></th> <th>Ligne d'eau fluviale</th> + <th></th> <th>Ligne d'eau torrentielle</th> + <th></th> </tr> <tr> - <th>Abscisse</th> + <th>Abscisse (m)</th> <th>Tirant d'eau (m)</th> + <th>{{_extraParamLabel}}</th> <th>Tirant d'eau (m)</th> + <th>{{_extraParamLabel}}</th> </tr> </thead> <tr *ngFor="let r of _results; let i=index" [class]="getResultClass(i)"> <td>{{r.abs}}</td> <td>{{r.flu}}</td> + <td>{{r.extraFlu}}</td> <td>{{r.tor}}</td> + <td>{{r.extraTor}}</td> </tr> </table> </div> \ No newline at end of file diff --git a/src/app/components/remous-results/remous-results.component.ts b/src/app/components/remous-results/remous-results.component.ts index 89358f567..0fd32a475 100644 --- a/src/app/components/remous-results/remous-results.component.ts +++ b/src/app/components/remous-results/remous-results.component.ts @@ -65,17 +65,38 @@ export class RemousResultsComponent { private _results: Object[] = []; /** - * tableau de valeurs du graphe des tirants + * titre de la colonne du paramètre supplémentaire + */ + private _extraParamLabel: string; + + /* + * config du graphe principal */ - private _fluvialGraph: any = {}; - private _torrentGraph: any = {}; + private graph1_type = 'line'; + private graph1_data = {}; + private graph1_options = { + responsive: true, + maintainAspectRatio: true, + animation: { + duration: 0 + }, + legend: { + display: true, + position: "right" + }, + title: { + display: true, + text: "Abscisse (m)", + position: "bottom" + } + }; /* - * config du graphe + * config du graphe secondaire (paramètre supplémentaire sauf Hs, Hsc, Yf, Yt, Yco) */ - private graph_type = 'line'; - private graph_data = {}; - private graph_options = { + private graph2_type = 'line'; + private graph2_data = {}; + private graph2_options = { responsive: true, maintainAspectRatio: true, animation: { @@ -92,14 +113,25 @@ export class RemousResultsComponent { } }; + /** + * le paramètre supplémentaire est affiché dans un graphe séparé + */ + private _extraGraph: boolean; + constructor(private intlService: InternationalisationService) { } public reset() { this._results = []; this._logEntries = []; - this._fluvialGraph = {}; - this._torrentGraph = {}; + this._extraParamLabel = undefined; + this._extraGraph = false; + this.graph1_data = {}; + this.graph2_data = {}; + } + + public set extraParamLabel(l: string) { + this._extraParamLabel = l; } /** @@ -128,50 +160,75 @@ export class RemousResultsComponent { public generateGraph() { // http://www.chartjs.org/docs/latest/charts/line.html - let ds: any = []; + let ds1: any = []; + let ds2: any = []; // abscisses - let labs = []; - for (let r of this._results) - labs.push(+r["abs"]); + let labs1 = []; + let labs2 = []; + for (let r of this._results) { + labs1.push(+r["abs"]); + if (this._extraGraph) + labs2.push(+r["abs"]); + } // ligne de fond - ds.push(this.drawLine(0, 0, "#753F00", "Fond", "#753F00")); + ds1.push(this.drawLine(0, 0, "#753F00", "Fond", "#753F00")); // ligne de berge - ds.push(this.drawLine(this._hautBerge, this._hautBerge, "#C58F50", "Berge")); + ds1.push(this.drawLine(this._hautBerge, this._hautBerge, "#C58F50", "Berge")); // hauteur normale - ds.push(this.drawLine(this._hautNormale, this._hautNormale, "#A4C537", "Tirant d'eau normal")); + ds1.push(this.drawLine(this._hautNormale, this._hautNormale, "#A4C537", "Tirant d'eau normal")); // hauteur critique - ds.push(this.drawLine(this._hautCritique, this._hautCritique, "#FF0000", "Tirant d'eau critique")); + ds1.push(this.drawLine(this._hautCritique, this._hautCritique, "#FF0000", "Tirant d'eau critique")); // lignes d'eau torrentielle et fluviale let dataFlu = []; let dataTor = []; + let dataExtra = []; for (let r of this._results) { let x: number = +r["abs"]; let yFlu: string = r["flu"]; let yTor: string = r["tor"]; + + let yExtra: string = r["extraFlu"]; + if (yExtra == undefined) + yExtra = r["extraTor"]; + if (yFlu != undefined && yFlu != "") dataFlu.push(this.mapY(x, +yFlu)); if (yTor != undefined && yTor != "") dataTor.push(this.mapY(x, +yTor)); + if (yExtra != undefined && yExtra != "") + dataExtra.push(this.mapY(x, +yExtra)); } - ds.push({ label: "Ligne d'eau torrentielle", data: dataTor, tension: 0, borderColor: "#77A3CD", pointRadius: 5, backgroundColor: "#D1D0D4" }); - ds.push({ label: "Ligne d'eau fluviale", data: dataFlu, tension: 0, borderColor: "#0093BD", pointRadius: 5, backgroundColor: "#D1D0D4" }); - - this.graph_data = { - labels: labs, - datasets: ds + if (this._extraGraph) + ds2.push({ label: this._extraParamLabel, data: dataExtra, tension: 0, borderColor: "#0093BD", pointRadius: 5 }); + else + ds1.push({ label: this._extraParamLabel, data: dataExtra, tension: 0, borderColor: "#C17AF0", pointRadius: 5 }); + ds1.push({ label: "Ligne d'eau torrentielle", data: dataTor, tension: 0, borderColor: "#77A3CD", pointRadius: 5, backgroundColor: "#D1D0D4" }); + ds1.push({ label: "Ligne d'eau fluviale", data: dataFlu, tension: 0, borderColor: "#0093BD", pointRadius: 5, backgroundColor: "#D1D0D4" }); + + this.graph1_data = { + labels: labs1, + datasets: ds1 }; + + if (this._extraGraph) + this.graph2_data = { + labels: labs2, + datasets: ds2 + }; } - public addResult(x: string, f: string, t: string) { - this._results.push({ "abs": x, "flu": f, "tor": t }); + public addResult(x: string, flu: string, tor: string, extra: string) { + let extraFlu = (flu == "" ? "" : extra); + let extraTor = (tor == "" ? "" : extra); + this._results.push({ "abs": x, "flu": flu, "extraFlu": extraFlu, "tor": tor, "extraTor": extraTor }); } public addLogEntry(m: Message, nDigits: number) { @@ -198,12 +255,8 @@ export class RemousResultsComponent { this._longBief = v; } - public addXYFluvial(x: number, y: number) { - this._fluvialGraph.push({ x: x, y: y }); - } - - public addXYTorrent(x: number, y: number) { - this._torrentGraph.push({ x: x, y: y }); + public set extraGraph(b: boolean) { + this._extraGraph = b; } private getResultClass(i: number) { -- GitLab