Ver código fonte

fix tick spacing on chart

Pi 1 mês atrás
pai
commit
dc64584076
1 arquivos alterados com 21 adições e 12 exclusões
  1. 21 12
      sqlpage/trend/Quantity.sql

+ 21 - 12
sqlpage/trend/Quantity.sql

@@ -2,7 +2,20 @@ SET height = '500';
 SET type = 'line';
 SET marker = 4;
 SET max_line_series = 50;
-
+SET ":unit" = $unit;
+SET ":log_scale" = $log_scale;
+SET ":ymin" = (SELECT
+    min(price/quantity)
+  FROM sqlpage_txn
+  WHERE unit = :unit
+);
+SET ":ymax" = (SELECT
+    max(price/quantity)
+  FROM sqlpage_txn
+  WHERE unit = :unit
+);
+--SELECT 'debug' AS component;
+--SELECT :ymin AS ymin, :ymax AS ymax, :ystep AS ystep;
 
 SELECT 'chart' AS component
 , 'Cost per '||$unit AS title
@@ -12,27 +25,23 @@ SELECT 'chart' AS component
     WHEN (
       SELECT count(DISTINCT product)
       FROM sqlpage_txn
-      WHERE unit = $unit
+      WHERE unit = :unit
     ) > $max_line_series::numeric
     THEN 'scatter' ELSE $type
   END AS type
-, $log_scale = 'true' AS logarithmic
+, :log_scale = 'true' AS logarithmic
 , TRUE AS time
-, CASE
-    WHEN $log_scale = 'true'
-    THEN 1 ELSE 0
+, 5 AS yticks
+, CASE :log_scale
+    WHEN 'true' THEN CAST(:ymin AS NUMERIC)/CAST(:ymax AS NUMERIC)
+    ELSE 0
   END AS ymin
-, ((
-    SELECT max(price/quantity)
-    FROM sqlpage_txn
-    WHERE unit = $unit
-  )/10 + 1)::int AS ystep
 , $marker AS marker
 ;
 SELECT product AS series
 , ts AS x
 , to_char(price/quantity, 'FM999999999.000') AS y
 FROM sqlpage_txn
-WHERE unit = $unit
+WHERE unit = :unit
 ORDER BY ts
 ;