<% if @error %>
<%= @error %>
<% elsif !@success %> <% if @only_chart %>

Select variables

<% else %>
Can’t preview queries with variables...yet!
<% end %> <% else %> <% unless @only_chart %> <% if @cached_at || @just_cached %>

<% if @cached_at %> Cached <%= time_ago_in_words(@cached_at, include_seconds: true) %> ago <% elsif !params[:data_source] %> Cached just now <% if @data_source.cache_mode == "slow" %> (over <%= "%g" % @data_source.cache_slow_threshold %>s) <% end %> <% end %> <% if @query && !params[:data_source] %> <%= link_to "Refresh", refresh_query_path(@query, variable_params), method: :post %> <% end %>

<% end %>

<%= pluralize(@rows.size, "row") %> <% @checks.select(&:state).each do |check| %> · "><%= link_to check.state.upcase, edit_check_path(check) %> <% if check.try(:message) %> · <%= check.message %> <% end %> <% end %>

<% end %> <% if @rows.any? %> <% values = @rows.first %> <% chart_id = SecureRandom.hex %> <% column_types = @result.column_types %> <% chart_type = @result.chart_type %> <% chart_options = {id: chart_id, min: nil} %> <% series_library = {} %> <% target_index = @columns.index { |k| k.downcase == "target" } %> <% if target_index %> <% series_library[target_index - 1] = {pointStyle: "line", hitRadius: 5, borderColor: "#109618", pointBackgroundColor: "#109618", backgroundColor: "#109618"} %> <% end %> <% if blazer_maps? && @markers.any? %>
<% elsif chart_type == "line" %> <%= line_chart @columns[1..-1].each_with_index.map{ |k, i| {name: k, data: @rows.map{ |r| [r[0], r[i + 1]] }, library: series_library[i]} }, 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: name, data: v.map { |v2| [v2[0], v2[2]] }, library: series_library[i]} }, chart_options %> <% elsif chart_type == "bar" %> <%= column_chart (values.size - 1).times.map { |i| name = @columns[i + 1]; {name: name, data: @rows.first(20).map { |r| [(@boom[@columns[0]] || {})[r[0].to_s] || r[0], r[i + 1]] } } }, id: chart_id %> <% elsif chart_type == "bar2" %> <% first_20 = @rows.group_by { |r| r[0] }.values.first(20).flatten(1) %> <% labels = first_20.map { |r| r[0] }.uniq %> <% series = first_20.map { |r| r[1] }.uniq %> <% labels.each do |l| %> <% series.each do |s| %> <% first_20 << [l, s, 0] unless first_20.find { |r| r[0] == l && r[1] == s } %> <% end %> <% end %> <%= column_chart first_20.group_by { |r| v = r[1]; (@boom[@columns[1]] || {})[v.to_s] || v }.each_with_index.map { |(name, v), i| {name: name, data: v.sort_by { |r2| labels.index(r2[0]) }.map { |v2| v3 = v2[0]; [(@boom[@columns[0]] || {})[v3.to_s] || v3, v2[2]] }} }, id: chart_id %> <% elsif @only_chart %> <% if @rows.size == 1 && @rows.first.size == 1 %> <% v = @rows.first.first %> <% if v.is_a?(String) && v == "" %>
empty string
<% else %>

<%= blazer_format_value(@columns.first, v) %>

<% end %> <% else %> <% @no_chart = true %> <% end %> <% end %> <% unless @only_chart && !@no_chart %> <% header_width = 100 / @columns.size.to_f %>
<% if @columns == ["QUERY PLAN"] %>
<%= @rows.map { |r| r[0] }.join("\n") %>
<% else %> <% @columns.each_with_index do |key, i| %> <% type = @column_types[i] %> <% end %> <% @rows.each do |row| %> <% row.each_with_index do |v, i| %> <% k = @columns[i] %> <% end %> <% end %>
<%= key %>
<% if v.is_a?(Time) %> <% v = blazer_time_value(@data_source, k, v) %> <% end %> <% unless v.nil? %> <% if v.is_a?(String) && v == "" %>
empty string
<% elsif @linked_columns[k] %> <%= link_to blazer_format_value(k, v), @linked_columns[k].gsub("{value}", u(v.to_s)), target: "_blank" %> <% else %> <%= blazer_format_value(k, v) %> <% end %> <% if v2 = (@boom[k] || {})[v.to_s] %>
<%= v2 %>
<% end %> <% end %>
<% end %>
<% end %> <% elsif @only_chart %>

No rows

<% end %> <% end %>