diff --git a/app/Resources/views/logged/previsionnel.html.twig b/app/Resources/views/logged/previsionnel.html.twig index 2899a554..f10c3a3e 100755 --- a/app/Resources/views/logged/previsionnel.html.twig +++ b/app/Resources/views/logged/previsionnel.html.twig @@ -178,7 +178,8 @@

Simulation sur {{config.lines}} mois

-
+
(graphique)
+
Ce sera la dèche dans {{config.monthsBeforeNoMoney}} mois @@ -201,7 +202,7 @@ - +
@@ -240,5 +241,25 @@
+ + + {% endverbatim %} {% endblock %} \ No newline at end of file diff --git a/assets/js/parts/main.js b/assets/js/parts/main.js index 66005cec..9a553070 100755 --- a/assets/js/parts/main.js +++ b/assets/js/parts/main.js @@ -1,4 +1,4 @@ -// require('../../../node_modules/canvasjs/dist/canvasjs.3'); +require('../../../node_modules/canvasjs/dist/canvasjs.3'); var $ = require('jquery'); // JS is equivalent to the normal "bootstrap" package @@ -266,8 +266,8 @@ angular }) return sum; }; - - $scope.previsionTable = () => { + $scope.previsionTable = []; + $scope.calculatePrevisionTable = () => { let turns = $scope.config.lines; let monthly = $scope.sumMonthlyExpenses(); let available = $scope.config.disponibility; @@ -286,10 +286,29 @@ angular } previsionTable.push(newLine); } + $scope.previsionTable = previsionTable; + $scope.makeGraphPointsOfPrevisionTable(previsionTable); return previsionTable; }; + $scope.graphPointsPrevision = []; + $scope.makeGraphPointsOfPrevisionTable = (previsionTable) => { + console.log("previsionTable", previsionTable); + $scope.graphPointsPrevision = []; + for (let i = 0; i < previsionTable.length; i++) { + $scope.graphPointsPrevision.push({ + label: previsionTable[i].available + " euros restants dans " + i + " mois", + y: previsionTable[i].available, + x: i, + }) + } + + } $scope.updateconf = (rep) => { + // update view calculs + $scope.calculatePrevisionTable(); + $scope.updateCanevas() + // flags $scope.config.loading = false; $scope.config.initialLoadingDone = true; $scope.config.disponibility = rep.data.disponibility; @@ -348,5 +367,22 @@ angular $scope.config.loading = false; } + $scope.updateCanevas = () => { + var dataPoints = $scope.graphPointsPrevision; + var chartContainer = new CanvasJS.Chart("simulationPrevision", { + title: { + text: "Euros disponibles dans le temps" + }, + // animationEnabled: true, + data: [ + { + // Change type to "doughnut", "line", "splineArea", etc. + type: "splineArea", + dataPoints: dataPoints + } + ] + }); + chartContainer.render(); + } $scope.init(); }]);