Files
danbooru/app/components/time_series_component/time_series_component.html.erb
evazion 203067b5ed reports: add non-timeseries charts.
Add bar charts for non-timeseries data. For example, a bar chart of the
top 10 uploaders overall in the last month, rather than a timeseries
chart of the number of uploads per day for the last month.
2022-10-23 04:42:51 -05:00

39 lines
1.1 KiB
Plaintext

<div class="flex justify-end text-xs mb-2">
<% if mode == :table %>
<%= link_to "Chart", current_page_path(search: { **search_params, mode: "chart" }) %>
<% else %>
<%= link_to "Table", current_page_path(search: { **search_params, mode: "table" }) %>
<% end %>
</div>
<% if mode == :chart && x_axis.present? %>
<div class="line-chart" style="width: 100%; height: max(90vh, <%= chart_height.to_i %>px);"></div>
<script type="text/javascript">
var chart = new Danbooru.TimeSeriesComponent({
container: $(".line-chart").get(0),
options: <%= raw chart_options.to_json %>,
});
</script>
<% else %>
<table class="striped autofit" width="100%">
<thead>
<% dataframe.types.keys.each do |column| %>
<%= tag.th(column.to_s.titleize, class: ("col-expand" if column == dataframe.types.keys.last)) %>
<% end %>
</thead>
<tbody>
<% dataframe.each_row do |row| %>
<tr>
<% dataframe.types.keys.each do |column| %>
<td>
<%= row[column] %>
</td>
<% end %>
<tr>
<% end %>
</tbody>
</table>
<% end %>