diff --git a/app/helpers/analyze_helper.rb b/app/helpers/analyze_helper.rb index 03cd001f..af340f54 100644 --- a/app/helpers/analyze_helper.rb +++ b/app/helpers/analyze_helper.rb @@ -68,7 +68,7 @@ module AnalyzeHelper end def colors - @colors ||= ['#49416D', '#FFC857', '#920020', '#00B0B3', '#B2D236', '#595959'] + @colors ||= ['#49416D', '#FFC857', '#920020', '#00B0B3', '#B2D236', '#004D61'] end def empty_dataset?(measures:, school:, academic_year:) diff --git a/app/presenters/analyze_bar_presenter.rb b/app/presenters/analyze_bar_presenter.rb index aeef2908..329e68a9 100644 --- a/app/presenters/analyze_bar_presenter.rb +++ b/app/presenters/analyze_bar_presenter.rb @@ -2,6 +2,8 @@ class AnalyzeBarPresenter include AnalyzeHelper attr_reader :score, :x_position, :academic_year, :measure_id, :measure, :color + MINIMUM_BAR_HEIGHT = 2 + def initialize(measure:, academic_year:, score:, x_position:, color:) @score = score @x_position = x_position @@ -25,20 +27,21 @@ class AnalyzeBarPresenter end def bar_height_percentage - case zone.type - when :ideal - (percentage * zone_height_percentage + zone_height_percentage) * 100 - when :approval - (percentage * zone_height_percentage) * 100 - when :growth - ((1 - percentage) * zone_height_percentage) * 100 - when :watch - ((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100 - when :warning - ((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100 - else - 0.0 - end + bar_height = case zone.type + when :ideal + (percentage * zone_height_percentage + zone_height_percentage) * 100 + when :approval + (percentage * zone_height_percentage) * 100 + when :growth + ((1 - percentage) * zone_height_percentage) * 100 + when :watch + ((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100 + when :warning + ((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100 + else + 0.0 + end + bar_height < MINIMUM_BAR_HEIGHT ? MINIMUM_BAR_HEIGHT : bar_height end def percentage diff --git a/spec/presenters/grouped_bar_column_presenter_spec.rb b/spec/presenters/grouped_bar_column_presenter_spec.rb index 23d02572..206215e0 100644 --- a/spec/presenters/grouped_bar_column_presenter_spec.rb +++ b/spec/presenters/grouped_bar_column_presenter_spec.rb @@ -172,7 +172,7 @@ describe GroupedBarColumnPresenter do it_behaves_like 'column_midpoint' it_behaves_like 'bar_color' - it 'returns a bar width equal to the approval zone width plus the proportionate ideal zone width' do + it 'returns a bar width equal to the approval zone width plus the proportionate ideal zone height' do expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(17) end @@ -223,15 +223,15 @@ describe GroupedBarColumnPresenter do it_behaves_like 'measure_name' it_behaves_like 'column_midpoint' it_behaves_like 'bar_color' - it_behaves_like 'y_offset' + # it_behaves_like 'y_offset' context 'and the score is right at the approval low benchmark' do - it 'bar will have a height of 0' do - expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(0) + it "where bar would normally have a height of 0, we inflate the height to be at least the minimum bar height of #{AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT}" do + expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT) end - it 'bar will be based on the approval low benchmark boundary' do - expect(student_presenter.bars[year_index].y_offset).to be_within(0.01).of(34) + it "where the bar would normally start at the approval low benchmark, it shifts up to accomodate it being grown to the minimum bar height of #{AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT}" do + expect(student_presenter.bars[year_index].y_offset).to be_within(0.01).of(analyze_zone_height * 2 - AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT) end end end @@ -249,6 +249,17 @@ describe GroupedBarColumnPresenter do it 'returns a bar width equal to the proportionate growth zone width' do expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(17) end + + context 'when the score is less than 5 percent away from the approval low benchmark line' do + before do + create_list(:survey_item_response, 40, survey_item: student_survey_item, school:, + academic_year:, likert_score: 4) + end + + it "it rounds to the the minimum bar height of #{AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT} " do + expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT) + end + end end context 'when the score is in the Watch zone' do