Skip to content

Commit

Permalink
Merge pull request #137 from theodi/pie-colours
Browse files Browse the repository at this point in the history
Handle pie-chart colours
  • Loading branch information
Sam Pikesley authored Jul 8, 2016
2 parents cb31c97 + 7d9ea1e commit 78e2495
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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

0 comments on commit 78e2495

Please sign in to comment.