Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back category bar chart #401

Merged
merged 2 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/helpers/component_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ def line_chart(data, scale: "logarithmic")
scale: scale
end

def bar_chart(data)
def bar_chart(data, small: false)
render "components/bar_chart",
keys: data.keys,
values: data.values
values: data.values,
small: small
end

def landing_hero(title:, image:, &block)
Expand Down
3 changes: 3 additions & 0 deletions app/views/categories/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- else
em This category does not have a description yet. You can <strong><a href="#{@category.catalog_edit_url}">add one on github</a></strong>!

- if current_order.default_direction?
= bar_chart @category.projects.first(10).map {|p| [p.permalink, p.score]}.to_h, small: true

section.section: .container
.level.is-mobile
.level-left
Expand Down
2 changes: 1 addition & 1 deletion app/views/components/_bar_chart.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- element = "bar-chart-#{SecureRandom.hex(8)}"
canvas class=element width="400" height="150"
canvas.bar-chart class=element width="400" height=(small ? 60 : 150)

javascript:
barChart(
Expand Down
3 changes: 3 additions & 0 deletions app/views/pages/components/bar_chart.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

= component_example "A Bar Chart" do
.chart= bar_chart 2014 => 2123, 2015 => 3501, 2016 => 2012

= component_example "A small bar Chart" do
.chart= bar_chart({ 2014 => 2123, 2015 => 3501, 2016 => 2012 }, small: true)
2 changes: 2 additions & 0 deletions spec/features/category_display_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
visit "/categories/widgets"

expect(listed_project_names).to be == %w[acme toolkit widget]
expect(page).to have_selector(".hero canvas.bar-chart")

within ".project-order-dropdown" do
expect(page).to have_text "Order by Project Score"
Expand All @@ -34,6 +35,7 @@
expect(page).to have_text "Order by #{button_label}"
end
expect(listed_project_names).to be == %w[widget acme toolkit]
expect(page).not_to have_selector(".hero canvas.bar-chart")
end

within ".project-order-dropdown" do
Expand Down