Skip to content

Commit

Permalink
feat: added total count to prop values
Browse files Browse the repository at this point in the history
  • Loading branch information
shafy committed May 20, 2022
1 parent e2f3a8f commit 59eb699
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/javascript/controllers/chart_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class extends Controller {

createDataSet(label, data, index) {
return {
label: htmlDecode(label),
label: `${htmlDecode(label)} (${data["total_count"]})`,
backgroundColor: this.colorPalette[index % this.colorPalette.length],
borderColor: this.colorPalette[index % this.colorPalette.length],
borderJointStyle: "round",
Expand All @@ -86,7 +86,7 @@ export default class extends Controller {
pointHitRadius: 5,
hoverBorderWidth: 4,
data: data["data"],
hidden: index > 5
hidden: !data["visible"]
}
}

Expand Down Expand Up @@ -118,7 +118,6 @@ export default class extends Controller {
e.preventDefault();

this.chart.data.datasets.forEach((dataset, index) => {
//dataset.hidden = true;
this.chart.setDatasetVisibility(index, false);
});
this.chart.update();
Expand Down
7 changes: 7 additions & 0 deletions app/javascript/helpers/chart_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const htmlLegendPlugin = {
propertiesUnselected.firstChild.remove();
}

// this.chart.data.datasets.forEach((dataset, index) => {
// this.chart.setDatasetVisibility(index, true);
// });

//console.log(chart.data.datasets)

items.forEach(item => {
//console.log(item)
const propertyItem = propertyItemTemplate.content.cloneNode(true);
const propertyItemContents = propertyItem.querySelectorAll("div");
const colorBox = propertyItemContents[0];
Expand Down
6 changes: 5 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def self.format_for_chart(events_array)
}
total_count += events_grouped[k][:total_count]
end
[events_grouped.sort_by { |k, v| [-v[:total_count], k] }.to_h, total_count]
events_grouped.sort_by { |k, v| [-v[:total_count], k] }.each_with_index do |e, i|
e[1][:visible] = true
break if i >= 5
end
[events_grouped.sort.to_h, total_count]
end

# rubocop:disable Metrics/ParameterLists
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_chart.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-chart-events-value="<%= events.to_json %>"
data-chart-event-name-value="<%= selected_event.titleize %>"
data-chart-agg-value="<%= @aggregation %>"
data-chart-has-prop-values-value="<%= @property_values.present? %>"
data-chart-has-prop-values-value="<%= property_values.present? %>"
class="flex flex-col w-full p-4 rounded-md shadow-md bg-yellow-50"
>
<div class="text-sm font-medium mb-2>">
Expand Down
3 changes: 2 additions & 1 deletion app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
locals: {
dates: @dates,
events: @events,
selected_event: @selected_event
selected_event: @selected_event,
property_values: @property_values
}
%>
<% end %>
Expand Down

0 comments on commit 59eb699

Please sign in to comment.