diff --git a/.gitignore b/.gitignore index 3be89333..3b5f40d3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ .powrc tmp _site +.sass-cache diff --git a/lib/metrics-api/helpers.rb b/lib/metrics-api/helpers.rb index 7f0ecc74..254518e3 100644 --- a/lib/metrics-api/helpers.rb +++ b/lib/metrics-api/helpers.rb @@ -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) @@ -154,7 +159,8 @@ def keep_params qs 'barcolour', 'autorefresh', 'with_path', - 'font_size' + 'font_size', + 'pie_colours' ] good_params = {} diff --git a/lib/views/pie.erb b/lib/views/pie.erb index 765c3ea4..5a9b839e 100644 --- a/lib/views/pie.erb +++ b/lib/views/pie.erb @@ -50,7 +50,7 @@ function pie(json) { type: 'pie', textinfo: 'label+percent', marker: { - colors: ['#FF6700', '#D60303'] + colors: <%= @pie_colours %> } }]; diff --git a/spec/helpers/helpers_spec.rb b/spec/helpers/helpers_spec.rb index 2cdc7dc1..138e6a90 100644 --- a/spec/helpers/helpers_spec.rb +++ b/spec/helpers/helpers_spec.rb @@ -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