diff --git a/src/app/components/fixedvar-results/fixedvar-results.component.ts b/src/app/components/fixedvar-results/fixedvar-results.component.ts index 802f668258a13a75d18f1b80a2c98ae8cf5583a0..f1774af3957c294a26dd00e8e4ebe85a8a5ec3c1 100644 --- a/src/app/components/fixedvar-results/fixedvar-results.component.ts +++ b/src/app/components/fixedvar-results/fixedvar-results.component.ts @@ -4,7 +4,7 @@ import { InternationalisationService } from "../../services/internationalisation import { ApplicationSetupService } from '../../services/app-setup/app-setup.service'; import { LogComponent } from '../../components/log/log.component'; import { cLog } from "jalhyd"; -import { FixedVarResults } from "../../results/fixed-var-results"; +import { FixedVarResults, GraphType } from "../../results/fixed-var-results"; @Component({ selector: "fixedvar-results", @@ -48,7 +48,7 @@ export class FixedVarResultsComponent { /* * config du graphe */ - private graph_type = "line"; + private graph_type: string; private graph_data = {}; private graph_options = { responsive: true, @@ -62,7 +62,8 @@ export class FixedVarResultsComponent { title: { display: true, text: "" - } + }, + scales: {} }; /** @@ -102,7 +103,23 @@ export class FixedVarResultsComponent { this._varResults.push({ "param": r["param"].toFixed(nDigits), "result": r["result"].toFixed(nDigits) }); this.logComponent.log = this._results.log; - this.generateGraph(); + + switch (this._results.graphType) { + case GraphType.Histogram: + this.graph_type = "bar"; + this.generateBarGraph(); + break; + + case GraphType.HistoLine: + this.graph_type = "line"; + this.generateLineGraph(); + break; + + default: + this.graph_type = "scatter"; + this.generateScatterGraph(); + break; + } } /** * affichage de la table des résultats fixés @@ -139,7 +156,35 @@ export class FixedVarResultsComponent { // this.logComponent.addLogEntries(l); // } - private generateGraph() { + /** + * génère les données d'un graphe de type "line" + */ + private generateLineGraph() { + let labs = []; + let dat = []; + for (let i in this._results.varResults) { + let r = this._results.varResults[i]; + labs.push(r["param"]); + dat.push(this._results.varGraph[i]); + } + + this.graph_options.title.text = this._results.graphTitle; + + this.graph_data = { + labels: labs, + datasets: [ + { + label: "", + data: dat + } + ] + }; + } + + /** + * génère les données d'un graphe de type "bar" + */ + private generateBarGraph() { let labs = []; let dat = []; for (let i in this._results.varResults) { @@ -149,6 +194,13 @@ export class FixedVarResultsComponent { } this.graph_options.title.text = this._results.graphTitle; + this.graph_options.scales = { + xAxes: [{ + gridLines: { + offsetGridLines: true + } + }] + }; this.graph_data = { labels: labs, @@ -161,6 +213,35 @@ export class FixedVarResultsComponent { }; } + /** + * génère les données d'un graphe de type "scatter" + */ + private generateScatterGraph() { + let dat = []; + for (let i in this._results.varResults) { + let r = this._results.varResults[i]; + dat.push({ x: r["param"], y: this._results.varGraph[i] }); + + } + + this.graph_options.title.text = this._results.graphTitle; + this.graph_options.scales = { + xAxes: [{ + type: 'linear', + position: 'bottom' + }] + }; + + this.graph_data = { + datasets: [ + { + label: "", + data: dat + } + ] + }; + } + // public reset(fixed: boolean) { // this._results.reset(); // this.logComponent.reset(); diff --git a/src/app/components/param-values/param-values.component.html b/src/app/components/param-values/param-values.component.html index 40b434a6e221c4892c25c124c3c27d4e29afbd2b..23191187771fcdea5cdd5909ea70127a37f24c98 100644 --- a/src/app/components/param-values/param-values.component.html +++ b/src/app/components/param-values/param-values.component.html @@ -1,5 +1,5 @@ <div class="row"> - <div class="btn-group col-12 col-sm-3" dropdown (click)="onSelect($event)"> + <div class="btn-group col-12 col-sm-3" dropdown (click)="onSelectValueMode($event)"> <button dropdownToggle class="btn btn-primary dropdown-toggle waves-light my-1" type="button" mdbRippleRadius> {{currentLabel}} </button> @@ -18,7 +18,12 @@ <ngparam-step [title]="uitextPasVariation" (onChange)="onStepChanged($event)"></ngparam-step> </div> - <div *ngIf="isList" class="col-12 col-sm-9"> + <div *ngIf="isList" class="col-12 col-sm-6"> <value-list title="valeurs séparées par ';'" (onChange)="onListChanged($event)"></value-list> </div> + + <div *ngIf="isList" class="col-12 col-sm-3"> + <input type="checkbox" name="histogram" [(ngModel)]="_param.histogramMode">Histogramme + <br/> + </div> </div> \ No newline at end of file diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index 46a24c0457f1b7ca8993bbc3ef8bd572f615e271..5bfea4209c9dcfe15e78f45e49dfe899932f9b0c 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -303,19 +303,10 @@ export class ParamValuesComponent implements DoCheck { * valeur courante affichée dans le select */ private get currentLabel(): string { - // return this._list ? "Liste" : "Min/max/pas"; return ParamValueMode[this._param.valueMode]; } - private onSelect(event: any) { - // for (let a of event.target.attributes) - // if (a.name == "value") { - // var val = a.value; - // break; - // } - - // // this._currentLabel = event.target.text; - // this._list = val == "list"; + private onSelectValueMode(event: any) { this._param.valueMode = event.target.value; } } diff --git a/src/app/formulaire/formulaire-definition.ts b/src/app/formulaire/formulaire-definition.ts index fc847e626d90a80098409fcdea8ef52d0ae580d7..a83a912876aa258407808539b7f366871aedd230 100644 --- a/src/app/formulaire/formulaire-definition.ts +++ b/src/app/formulaire/formulaire-definition.ts @@ -19,7 +19,7 @@ import { FormulaireElement } from "./formulaire-element"; import { ValueDependency } from "./value-dependency"; import { ValueDependencyCondition } from "./value-dependency-condition"; import { ExistenceDependency } from "./existence-dependency"; -import { FixedVarResults } from "../results/fixed-var-results"; +import { FixedVarResults, GraphType } from "../results/fixed-var-results"; import { SectionResults } from "../results/section-results"; import { RemousResults } from "../results/remous-results"; import { StringMap } from "../stringmap"; @@ -1119,6 +1119,8 @@ export class FormulaireDefinition extends Observable { switch (varParam.valueMode) { case ParamValueMode.MINMAX: + this._fixVarResults.graphType = GraphType.Scatter; + let min: number = +varParam.minValue; let max: number = +varParam.maxValue; let step: number = +varParam.stepValue; @@ -1137,6 +1139,8 @@ export class FormulaireDefinition extends Observable { break; case ParamValueMode.LISTE: + this._fixVarResults.graphType = varParam.histogramMode ? GraphType.Histogram : GraphType.Scatter; + for (let val of varParam.valueList) { prms[varParam.symbol].v = val; diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index 703ac0696c00b2a276bcabf95c7d39818a15e9bd..a662906dea97c86615dc8651260abe57466df3b6 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -52,6 +52,7 @@ export class NgParameter extends InputField { public stepValue: number; // pas de progression dans le cas ParamRadioConfig.VAR public valueList: number[]; public valueMode: ParamValueMode = ParamValueMode.MINMAX; + public histogramMode: boolean = false; // A VIRER et deplacer dans FixVarResults constructor(private _paramDef: ParamDefinition, formId: number) { super(_paramDef.computeNodeType, _paramDef.symbol, formId); diff --git a/src/app/results/fixed-var-results.ts b/src/app/results/fixed-var-results.ts index 33b49bb07985460136114bf4455a5f2ecc5bcff1..97d16be54d613650eb983d9ccb41279b5a629303 100644 --- a/src/app/results/fixed-var-results.ts +++ b/src/app/results/fixed-var-results.ts @@ -3,6 +3,26 @@ import { cLog } from "jalhyd"; import { NgParameter } from "../formulaire/ngparam"; import { CalculatorResults } from "./calculator-results"; +/** + * type de graphe + */ +export enum GraphType { + /** + * histogramme + */ + Histogram, + + /** + * points indépendants reliés par une courbe + */ + HistoLine, + + /** + * graphe XY classique + */ + Scatter, +} + export class FixedVarResults extends CalculatorResults { /** * résultats fixed (true) ou variés (false) @@ -34,6 +54,11 @@ export class FixedVarResults extends CalculatorResults { */ private _graphTitle: string; + /** + * type de graphe + */ + public graphType: GraphType = GraphType.Scatter; + /** * tableau de valeurs du graphe des résultats variés */