Răsfoiți Sursa

Small changes to update visuals of graph

Lee Morgan 6 ani în urmă
părinte
comite
e85978ab10
2 a modificat fișierele cu 5 adăugiri și 3 ștergeri
  1. 1 1
      routes.js
  2. 4 2
      views/shared/graphs.js

+ 1 - 1
routes.js

@@ -46,5 +46,5 @@ module.exports = function(app){
     app.post("/transactions", transactionData.getTransactions);
     app.get("/purchases", transactionData.getPurchases);
     app.post("/transactions/create", transactionData.createTransaction);  //Creates transaction for non-pos merchant
-    app.get("/populate", transactionData.populate);
+    app.get("/populatesometransactions", transactionData.populate);
 }

+ 4 - 2
views/shared/graphs.js

@@ -52,7 +52,7 @@ class LineGraph{
             if(point > this.max){
                 this.max = point;
                 this.verticalMultiplier = (this.bottom - this.top) / this.max;
-                this.horizontalMultiplier = (this.right - this.left) / data.set.length;
+                this.horizontalMultiplier = (this.right - this.left) / (data.set.length - 1);
                 isChange = true;
             }
         }
@@ -127,6 +127,8 @@ class LineGraph{
     }
 
     drawXAxis(){
+        console.log(this.data);
+
         this.context.beginPath();
         this.context.moveTo(this.left, this.bottom);
         this.context.lineTo(this.right, this.bottom);
@@ -141,7 +143,7 @@ class LineGraph{
         this.context.lineWidth = 1;
 
         if(Object.prototype.toString.call(this.xRange[0]) === '[object Date]'){
-            let diff = Math.abs(Math.floor((Date.UTC(this.xRange[0].getFullYear(), this.xRange[0].getMonth(), this.xRange[0].getDate()) - Date.UTC(this.xRange[1].getFullYear(), this.xRange[1].getMonth(), this.xRange[1].getDate())) / (1000 * 60 * 60 * 24)));
+            let diff = Math.abs(Math.floor((Date.UTC(this.xRange[0].getFullYear(), this.xRange[0].getMonth(), this.xRange[0].getDate()) - Date.UTC(this.xRange[1].getFullYear(), this.xRange[1].getMonth(), this.xRange[1].getDate())) / (1000 * 60 * 60 * 24))) + 1;
             let showDate = new Date(this.xRange[0]);
             
             for(let i = 0; i < diff; i += Math.floor(diff / 10)){