Explorar el Código

Fix bug in formatting of data for graph

Lee Morgan hace 6 años
padre
commit
cca10c8593
Se han modificado 1 ficheros con 2 adiciones y 2 borrados
  1. 2 2
      views/dataPage/ingredient.js

+ 2 - 2
views/dataPage/ingredient.js

@@ -65,7 +65,7 @@ window.ingredientObj = {
     },
 
     formatData: function(id, startDate, endDate){
-        let dateRange = Math.floor((Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()) - Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate())) / (1000 * 60 * 60 * 24));
+        let dateRange = Math.floor((Date.UTC(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()) - Date.UTC(startDate.getFullYear(), startDate.getMonth(), startDate.getDate())) / (1000 * 60 * 60 * 24)) + 1;
         let dataList = new Array(Math.abs(dateRange)).fill(0);
 
         for(let transaction of data.transactions){
@@ -78,7 +78,7 @@ window.ingredientObj = {
                         if(merchRecipe._id === recipe.recipe){
                             for(let ingredient of merchRecipe.ingredients){
                                 if(ingredient.ingredient === id){
-                                    dataList[dateRange - Math.abs(diff)] += ingredient.quantity;
+                                    dataList[dateRange - Math.abs(diff) - 1] += ingredient.quantity * recipe.quantity;
                                 }
                             }
                             break;