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
def colors
@colors ||= ['#49416D', '#FFC857', '#920020', '#00B0B3', '#B2D236', '#595959']
@colors ||= ['#49416D', '#FFC857', '#920020', '#00B0B3', '#B2D236', '#004D61']
end
def empty_dataset?(measures:, school:, academic_year:)

@ -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

@ -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

Loading…
Cancel
Save