Explorar el Código

limit the number of series on line plot

Daniel Sheffield hace 8 meses
padre
commit
d63788af4a
Se han modificado 1 ficheros con 25 adiciones y 3 borrados
  1. 25 3
      sqlpage/sqlpage/pages/Trend.sql

+ 25 - 3
sqlpage/sqlpage/pages/Trend.sql

@@ -1,6 +1,7 @@
 SET height = '750';
 SET type = 'line';
 SET marker = 4;
+SET max_line_series = 50;
 
 SET unit_count_chart = (SELECT v#>>'{}' FROM json_array_elements($unit_count::json) j(v) LIMIT 1);
 SET display_by_count = (SELECT count(*) FROM json_array_elements($unit_count::json) j(v)) == 1
@@ -12,7 +13,14 @@ SELECT 'chart' AS component
 , 'Cost by Weight' AS title
 , $height AS height
 , '$/'||$unit_mass AS ytitle
-, $type AS type
+, CASE
+    WHEN (
+      SELECT count(DISTINCT product)
+      FROM sqlpage_txn
+      WHERE unit = $unit_mass
+    ) > $max_line_series::numeric
+    THEN 'scatter' ELSE $type
+  END AS type
 , $log_scale = 'true' AS logarithmic
 , TRUE AS time
 , 0 AS ymin
@@ -30,7 +38,14 @@ SELECT 'chart' AS component
 , 'Cost by Volume' AS title
 , $height AS height
 , '$/'||$unit_volume AS ytitle
-, $type AS type
+, CASE
+    WHEN (
+      SELECT count(DISTINCT product)
+      FROM sqlpage_txn
+      WHERE unit = $unit_volume
+    ) > $max_line_series::numeric
+    THEN 'scatter' ELSE $type
+  END AS type
 , $log_scale::bool AS logarithmic
 , TRUE AS time
 , 0 AS ymin
@@ -48,7 +63,14 @@ SELECT 'chart' AS component
 , 'Cost by Count' AS title
 , $height AS height
 , '$/'||$unit_count_chart AS ytitle
-, $type AS type
+, CASE
+    WHEN (
+      SELECT count(DISTINCT product)
+      FROM sqlpage_txn
+      WHERE unit = $unit_count_chart
+    ) > $max_line_series::numeric
+    THEN 'scatter' ELSE $type
+  END AS type
 , $log_scale::bool AS logarithmic
 , TRUE AS time
 , 0 AS ymin