瀏覽代碼

Added graph max width in y axis

Mohidul Islam 3 年之前
父節點
當前提交
ad4d5668d9
共有 2 個文件被更改,包括 11 次插入5 次删除
  1. 2 1
      manager/templates/locations.html
  2. 9 4
      manager/views.py

+ 2 - 1
manager/templates/locations.html

@@ -173,7 +173,8 @@
                   },
                   ticks: {
                       beginAtZero: true,
-                      stepSize: 1
+                      stepSize: 1,
+                      max: data.max_rev_count
                   }
               }],
               xAxes: [{

+ 9 - 4
manager/views.py

@@ -255,6 +255,7 @@ class AllLocationSummary(APIView):
             return Response({'error': 'No location Found'}, status=status.HTTP_400_BAD_REQUEST)
         locations = Location.objects.all()
         review_counts = []
+        max_rev = 0
         for location in locations:
             loc_json = {
                 'name': location.care_name,
@@ -269,9 +270,13 @@ class AllLocationSummary(APIView):
                     location.last_week_neg_yelp_review_count
                 ]
             }
+            _temp_max = max(loc_json['positive']+loc_json['negative'])
+            if _temp_max > max_rev:
+                max_rev = _temp_max
             review_counts.append(loc_json)
-            response = {
-                'labels': ['Google', 'Facebook', 'Yelp'],
-                'review_counts': review_counts,
-            }
+        response = {
+            'labels': ['Google', 'Facebook', 'Yelp'],
+            'review_counts': review_counts,
+            'max_rev_count': max_rev,
+        }
         return Response(response)