Set a minimum bar height for analyze graphs

pull/1/head
rebuilt 4 years ago
parent cb3499de64
commit 1155f74ca9

@ -68,7 +68,7 @@ module AnalyzeHelper
end end
def colors def colors
@colors ||= ['#49416D', '#FFC857', '#920020', '#00B0B3', '#B2D236', '#595959'] @colors ||= ['#49416D', '#FFC857', '#920020', '#00B0B3', '#B2D236', '#004D61']
end end
def empty_dataset?(measures:, school:, academic_year:) def empty_dataset?(measures:, school:, academic_year:)

@ -2,6 +2,8 @@ class AnalyzeBarPresenter
include AnalyzeHelper include AnalyzeHelper
attr_reader :score, :x_position, :academic_year, :measure_id, :measure, :color attr_reader :score, :x_position, :academic_year, :measure_id, :measure, :color
MINIMUM_BAR_HEIGHT = 2
def initialize(measure:, academic_year:, score:, x_position:, color:) def initialize(measure:, academic_year:, score:, x_position:, color:)
@score = score @score = score
@x_position = x_position @x_position = x_position
@ -25,20 +27,21 @@ class AnalyzeBarPresenter
end end
def bar_height_percentage def bar_height_percentage
case zone.type bar_height = case zone.type
when :ideal when :ideal
(percentage * zone_height_percentage + zone_height_percentage) * 100 (percentage * zone_height_percentage + zone_height_percentage) * 100
when :approval when :approval
(percentage * zone_height_percentage) * 100 (percentage * zone_height_percentage) * 100
when :growth when :growth
((1 - percentage) * zone_height_percentage) * 100 ((1 - percentage) * zone_height_percentage) * 100
when :watch when :watch
((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100 ((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100
when :warning when :warning
((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100 ((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100
else else
0.0 0.0
end end
bar_height < MINIMUM_BAR_HEIGHT ? MINIMUM_BAR_HEIGHT : bar_height
end end
def percentage def percentage

@ -172,7 +172,7 @@ describe GroupedBarColumnPresenter do
it_behaves_like 'column_midpoint' it_behaves_like 'column_midpoint'
it_behaves_like 'bar_color' 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) expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(17)
end end
@ -223,15 +223,15 @@ describe GroupedBarColumnPresenter do
it_behaves_like 'measure_name' it_behaves_like 'measure_name'
it_behaves_like 'column_midpoint' it_behaves_like 'column_midpoint'
it_behaves_like 'bar_color' 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 context 'and the score is right at the approval low benchmark' do
it 'bar will have a height of 0' do 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(0) expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(AnalyzeBarPresenter::MINIMUM_BAR_HEIGHT)
end end
it 'bar will be based on the approval low benchmark boundary' do 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(34) 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 end
end end
@ -249,6 +249,17 @@ describe GroupedBarColumnPresenter do
it 'returns a bar width equal to the proportionate growth zone width' 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) expect(student_presenter.bars[year_index].bar_height_percentage).to be_within(0.01).of(17)
end 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 end
context 'when the score is in the Watch zone' do context 'when the score is in the Watch zone' do

Loading…
Cancel
Save