Skip to content
Snippets Groups Projects
Commit fdd03e3b authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #273

parent 2ba6b289
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
......
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 + ")";
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment