Display gauges with no benchmarks as "Insufficient Data" with no key benchmark indicator

pull/1/head
Liam Morley 4 years ago
parent aeb6a45a45
commit 0af26e25f2

@ -27,7 +27,7 @@ class GaugePresenter
end
def percentage_for(number)
return 0 if number.nil?
return nil if number.nil?
scale_minimum = @scale.warning_zone.low_benchmark
scale_maximum = @scale.ideal_zone.high_benchmark

@ -35,6 +35,8 @@ class Scale
def zone_for_score(score)
case score
when nil
insufficient_data
when ideal_zone.low_benchmark..ideal_zone.high_benchmark
ideal_zone
when approval_zone.low_benchmark..approval_zone.high_benchmark

@ -3,16 +3,18 @@
viewBox="<%= viewbox.x %> <%= viewbox.y %> <%= viewbox.width %> <%= viewbox.height %>"
class="<%= gauge_class %>"
>
<path
class="gauge-fill <%= gauge.color_class %>"
d="<%= move_to(point: arc_start_point) %>
<%= draw_arc(radius: outer_radius, percentage: gauge.score_percentage, clockwise: true) %>
<%= draw_line_to(point: arc_end_line_destination(radius: inner_radius, percentage: gauge.score_percentage)) %>
<%= draw_arc(radius: inner_radius, percentage: 0, clockwise: false) %>
<%= draw_line_to(point: arc_end_line_destination(radius: outer_radius, percentage: 0)) %>"
fill="none"
stroke="none"
/>
<% if gauge.score_percentage.present? %>
<path
class="gauge-fill <%= gauge.color_class %>"
d="<%= move_to(point: arc_start_point) %>
<%= draw_arc(radius: outer_radius, percentage: gauge.score_percentage, clockwise: true) %>
<%= draw_line_to(point: arc_end_line_destination(radius: inner_radius, percentage: gauge.score_percentage)) %>
<%= draw_arc(radius: inner_radius, percentage: 0, clockwise: false) %>
<%= draw_line_to(point: arc_end_line_destination(radius: outer_radius, percentage: 0)) %>"
fill="none"
stroke="none"
/>
<% end %>
<path
@ -26,24 +28,26 @@
stroke-width="<%= stroke_width %>"
/>
<line
class="zone-benchmark stroke-black"
x1="<%= benchmark_line_point(outer_radius, angle_for(percentage: gauge.key_benchmark_percentage)).x %>"
y1="<%= benchmark_line_point(outer_radius, angle_for(percentage: gauge.key_benchmark_percentage)).y %>"
x2="<%= benchmark_line_point(inner_radius, angle_for(percentage: gauge.key_benchmark_percentage)).x %>"
y2="<%= benchmark_line_point(inner_radius, angle_for(percentage: gauge.key_benchmark_percentage)).y %>"
stroke-width="<%= stroke_width %>"
/>
<% if gauge.key_benchmark_percentage.present? %>
<line
class="zone-benchmark stroke-black"
x1="<%= benchmark_line_point(outer_radius, angle_for(percentage: gauge.key_benchmark_percentage)).x %>"
y1="<%= benchmark_line_point(outer_radius, angle_for(percentage: gauge.key_benchmark_percentage)).y %>"
x2="<%= benchmark_line_point(inner_radius, angle_for(percentage: gauge.key_benchmark_percentage)).x %>"
y2="<%= benchmark_line_point(inner_radius, angle_for(percentage: gauge.key_benchmark_percentage)).y %>"
stroke-width="<%= stroke_width %>"
/>
<path
class="key-benchmark-indicator fill-black"
d="<%= move_to(point: indicator_tip) %>
<%= draw_line_to(point: indicator_right_corner) %>
<%= draw_line_to(point: indicator_left_corner) %>
<%= draw_line_to(point: indicator_tip) %>"
transform="rotate(<%= rotation_angle_for(percentage: gauge.key_benchmark_percentage) %> <%= arc_center.x %> <%= arc_center.y %>)"
stroke="none"
/>
<path
class="key-benchmark-indicator fill-black"
d="<%= move_to(point: indicator_tip) %>
<%= draw_line_to(point: indicator_right_corner) %>
<%= draw_line_to(point: indicator_left_corner) %>
<%= draw_line_to(point: indicator_tip) %>"
transform="rotate(<%= rotation_angle_for(percentage: gauge.key_benchmark_percentage) %> <%= arc_center.x %> <%= arc_center.y %>)"
stroke="none"
/>
<% end %>
</svg>
<span class="gauge-title <%= font_class %> fill-black"><%= gauge.title %></span>

@ -1,25 +1,6 @@
require 'rails_helper'
describe GaugePresenter do
# let(:academic_year) { create(:academic_year, range: '1989-90') }
# let(:school) { create(:school, name: 'Best School') }
# let(:subcategory_presenter) do
# subcategory = create(:subcategory, name: 'A great subcategory')
# measure1 = create(:measure, watch_low_benchmark: 4, growth_low_benchmark: 4.25, approval_low_benchmark: 4.5, ideal_low_benchmark: 4.75, subcategory: subcategory)
# survey_item1 = create(:survey_item, measure: measure1)
# create(:survey_item_response, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 1)
# create(:survey_item_response, survey_item: survey_item1, academic_year: academic_year, school: school, likert_score: 5)
# measure2 = create(:measure, watch_low_benchmark: 1.25, growth_low_benchmark: 1.5, approval_low_benchmark: 1.75, ideal_low_benchmark: 2.0, subcategory: subcategory)
# survey_item2 = create(:survey_item, measure: measure2)
# create(:survey_item_response, survey_item: survey_item2, academic_year: academic_year, school: school, likert_score: 1)
# create(:survey_item_response, survey_item: survey_item2, academic_year: academic_year, school: school, likert_score: 5)
# create_survey_item_responses_for_different_years_and_schools(survey_item1)
# return SubcategoryPresenter.new(subcategory: subcategory, academic_year: academic_year, school: school)
# end
let(:scale) do
Scale.new(
watch_low_benchmark: 1.5,
@ -30,7 +11,6 @@ describe GaugePresenter do
end
let(:score) { 3 }
let(:gauge_presenter) { GaugePresenter.new(scale: scale, score: score) }
it 'returns the key benchmark percentage for the gauge' do
@ -117,4 +97,28 @@ describe GaugePresenter do
end
end
context 'when there are no benchmarks or score for the gauge' do
let(:scale) do
Scale.new(
watch_low_benchmark: nil,
growth_low_benchmark: nil,
approval_low_benchmark: nil,
ideal_low_benchmark: nil,
)
end
let(:score) { nil }
it 'returns the title of the zone' do
expect(gauge_presenter.title).to eq 'Insufficient Data'
end
it 'returns the color class for the gauge' do
expect(gauge_presenter.color_class).to eq 'fill-insufficient_data'
end
it 'returns the score percentage for the gauge' do
expect(gauge_presenter.score_percentage).to be_nil
end
end
end

Loading…
Cancel
Save