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

Handle pie-chart colours #137

Merged
merged 1 commit into from
Jul 8, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.powrc
tmp
_site
.sass-cache
8 changes: 7 additions & 1 deletion lib/metrics-api/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def get_settings(params, data)
@plotly_modebar = params.fetch('plotly_modebar', 'false')
@font_size = params.fetch('font_size', '9vh')
@metric = params.fetch('metric', '')
@pie_colours = fix_pie_colours(params.fetch('pie_colours', ''))
end

def fix_pie_colours list
list.split(':').map { |c| "##{c}" }.to_s.gsub('"', "'")
end

def get_title(metadata, params)
Expand Down Expand Up @@ -154,7 +159,8 @@ def keep_params qs
'barcolour',
'autorefresh',
'with_path',
'font_size'
'font_size',
'pie_colours'
]

good_params = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/views/pie.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function pie(json) {
type: 'pie',
textinfo: 'label+percent',
marker: {
colors: ['#FF6700', '#D60303']
colors: <%= @pie_colours %>
}
}];

Expand Down
10 changes: 10 additions & 0 deletions spec/helpers/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,14 @@ def request

end

it 'turns a list of colours into a JS array' do
expect(helpers.fix_pie_colours '1d91a1:8cdbe6:faa2c7:').to eq (
"['#1d91a1', '#8cdbe6', '#faa2c7']"
)
end

it 'is fine with no pie colours' do
expect(helpers.fix_pie_colours '').to eq '[]'
end

end