Business intelligence made simple
Added pie charts - closes #181
Andrew Kane9aa2e6c74ee8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9efd7694..25519287 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,7 @@- Added navbar- Added favicon+- Added pie charts- Added Trend anomaly detection- Added forecasting- Added search for checks and schemadiff --git a/README.md b/README.mdindex eae66374..519965e4 100644--- a/README.md+++ b/README.md@@ -324,6 +324,14 @@ SELECT gender, zip_code, COUNT(*) FROM users GROUP BY 1, 2SELECT x, y FROM table```+### Pie Chart [master]++2 columns - string, numeric - and last column named `pie`++```sql+SELECT gender, COUNT(*) AS pie FROM users GROUP BY 1+```+### MapsColumns named `latitude` and `longitude` or `lat` and `lon` or `lat` and `lng` - [Example](https://blazer.dokkuapp.com/queries/15-map)diff --git a/app/views/blazer/queries/docs.html.erb b/app/views/blazer/queries/docs.html.erbindex 52841ac6..503c46a2 100644--- a/app/views/blazer/queries/docs.html.erb+++ b/app/views/blazer/queries/docs.html.erb@@ -111,6 +111,10 @@<td>Scatter</td><td>2 columns - both numeric</td></tr>+ <tr>+ <td>Pie</td>+ <td>2 columns - string, numeric - and last column named <code>pie</code></td>+ </tr><tr><td>Map</td><td>diff --git a/app/views/blazer/queries/run.html.erb b/app/views/blazer/queries/run.html.erbindex 326fd21f..1121b7c9 100644--- a/app/views/blazer/queries/run.html.erb+++ b/app/views/blazer/queries/run.html.erb@@ -52,7 +52,7 @@<% if ["line", "line2"].include?(chart_type) %><% chart_options.merge!(min: nil) %><% end %>- <% if !["scatter"].include?(chart_type) %>+ <% if !["scatter", "pie"].include?(chart_type) %><% chart_options.merge!(library: {tooltips: {mode: "index", intersect: false, position: "nearest"}}) %><% end %><% series_library = {} %>@@ -101,6 +101,8 @@<%= line_chart chart_data, chart_options %><% elsif chart_type == "line2" %><%= line_chart @rows.group_by { |r| v = r[1]; (@boom[@columns[1]] || {})[v.to_s] || v }.each_with_index.map { |(name, v), i| {name: blazer_series_name(name), data: v.map { |v2| [v2[0], v2[2]] }, library: series_library[i]} }, chart_options %>+ <% elsif chart_type == "pie" %>+ <%= pie_chart @rows.map { |r| [(@boom[@columns[0]] || {})[r[0].to_s] || r[0], r[1]] }, chart_options %><% elsif chart_type == "bar" %><%= column_chart (values.size - 1).times.map { |i| name = @columns[i + 1]; {name: blazer_series_name(name), data: @rows.first(20).map { |r| [(@boom[@columns[0]] || {})[r[0].to_s] || r[0], r[i + 1]] } } }, chart_options %><% elsif chart_type == "bar2" %>diff --git a/lib/blazer/result.rb b/lib/blazer/result.rbindex 7edbfd4c..71b8fe02 100644--- a/lib/blazer/result.rb+++ b/lib/blazer/result.rb@@ -69,6 +69,8 @@ module Blazer"line"elsif column_types == ["time", "string", "numeric"]"line2"+ elsif column_types == ["string", "numeric"] && @columns.last == "pie"+ "pie"elsif column_types.compact.size >= 2 && column_types == ["string"] + (column_types.compact.size - 1).times.map { "numeric" }"bar"elsif column_types == ["string", "string", "numeric"]