move methods from analyze helper to background presenter

pull/1/head
rebuilt 3 years ago
parent 88339c729f
commit c568e8bc06

@ -2,7 +2,7 @@
class AnalyzeController < SqmApplicationController
before_action :assign_categories, :assign_subcategories, :assign_measures, :assign_academic_years,
:response_rate_timestamp, :races, :selected_races, :graph, :graphs, only: [:index]
:response_rate_timestamp, :races, :selected_races, :graph, :graphs, :background, only: [:index]
def index; end
private
@ -66,10 +66,18 @@ class AnalyzeController < SqmApplicationController
end
def graph
@graph ||= params[:graph] || 'students-and-teachers'
graphs.each do |graph|
@graph = graph if graph.value == params[:graph]
end
@graph ||= graphs.first
end
def graphs
@graphs ||= [AnalysisGraph::StudentsAndTeachers.new, AnalysisGraph::StudentsByGroup.new]
end
def background
@background ||= BackgroundPresenter.new(num_of_columns: graph.columns.count)
end
end

@ -1,48 +1,20 @@
# frozen_string_literal: true
module AnalyzeHelper
def zone_label_width
15
end
def zone_label_x
2
end
def analyze_graph_height
85
end
def svg_height
400
end
def graph_width
85
end
def benchmark_y
(analyze_zone_height * 2) - (benchmark_height / 2.0)
end
def benchmark_height
1
end
def grouped_chart_column_width
graph_width / data_sources
end
def column_end_x(position)
zone_label_width + (grouped_chart_column_width * position)
def zone_label_width
15
end
def column_start_x(position)
column_end_x(position - 1)
def graph_width
85
end
def bar_label_height
(100 - ((100 - analyze_graph_height) / 2))
def analyze_graph_height
85
end
def analyze_zone_height
@ -53,14 +25,6 @@ module AnalyzeHelper
analyze_zone_height / 100.0
end
def zone_label_y(position)
8.5 * (position + position - 1)
end
def data_sources
3
end
def analyze_category_link(district:, school:, academic_year:, category:)
year = academic_year.range
"/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{year}&academic_years=#{year}&category=#{category.category_id}"

@ -1,3 +1,5 @@
# frozen_string_literal: true
module AnalysisGraph
class StudentsAndTeachers
def to_s
@ -7,5 +9,9 @@ module AnalysisGraph
def value
'students-and-teachers'
end
def columns
[StudentGroupedBarColumnPresenter, TeacherGroupedBarColumnPresenter, GroupedBarColumnPresenter]
end
end
end

@ -7,5 +7,9 @@ module AnalysisGraph
def value
'students-by-group'
end
def columns
[StudentGroupedBarColumnPresenter]
end
end
end

@ -0,0 +1,44 @@
class BackgroundPresenter
include AnalyzeHelper
attr_reader :num_of_columns
def initialize(num_of_columns:)
@num_of_columns = num_of_columns
end
def zone_label_x
2
end
def benchmark_y
(analyze_zone_height * 2) - (benchmark_height / 2.0)
end
def benchmark_height
1
end
def grouped_chart_column_width
graph_width / data_sources
end
def column_end_x(position)
zone_label_width + (grouped_chart_column_width * position)
end
def column_start_x(position)
column_end_x(position - 1)
end
def bar_label_height
(100 - ((100 - analyze_graph_height) / 2))
end
def zone_label_y(position)
8.5 * (position + position - 1)
end
def data_sources
num_of_columns
end
end

@ -81,6 +81,18 @@ class GroupedBarColumnPresenter
zone_label_width + (grouped_chart_column_width * position)
end
def grouped_chart_column_width
graph_width / data_sources
end
def bar_label_height
(100 - ((100 - analyze_graph_height) / 2))
end
def data_sources
3
end
private
YearlyScore = Struct.new(:year, :score)

@ -5,7 +5,7 @@
<input type="radio" id="<%= graph.value %>" name="graph"
value="<%= base_url %>"
data-action="click->analyze#refresh"
<%= graph.value == @graph ? "checked" : "" %>>
<%= graph.value == @graph.value ? "checked" : "" %>>
<label for="<%= graph.value %>"><%= graph.to_s %></label>
</div>
<% end %>

@ -1,10 +1,10 @@
<g id="graph-background">
<rect x="0" y="0" width="100%" height="<%= analyze_zone_height * 2 %>%" fill="#edecf0" />
<rect x="0" y="<%= analyze_zone_height * 2 %>%" width="100%" height="<%= analyze_zone_height * 3 %>%" fill="#fffaee" />
<rect x="0" y="0" width="100%" height="<%= analyze_graph_height %>%" fill="none" stroke="grey" />
<line x1="<%= column_end_x(1) %>%" y1="0" x2="<%= column_end_x(1) %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
<line x1="<%= column_end_x(2) %>%" y1="0" x2="<%= column_end_x(2) %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
<rect x="0" y="<%= benchmark_y %>%" width="100%" height="<%= benchmark_height %>%" fill="black" />
<rect x="0" y="0" width="100%" height="<%= background.analyze_zone_height * 2 %>%" fill="#edecf0" />
<rect x="0" y="<%= background.analyze_zone_height * 2 %>%" width="100%" height="<%= background.analyze_zone_height * 3 %>%" fill="#fffaee" />
<rect x="0" y="0" width="100%" height="<%= background.analyze_graph_height %>%" fill="none" stroke="grey" />
<line x1="<%= background.column_end_x(1) %>%" y1="0" x2="<%= background.column_end_x(1) %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
<line x1="<%= background.column_end_x(2) %>%" y1="0" x2="<%= background.column_end_x(2) %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
<rect x="0" y="<%= background.benchmark_y %>%" width="100%" height="<%= background.benchmark_height %>%" fill="black" />
<g id="zone-dividers" stroke-width="1">
<line x1="0" y1="17%" x2="100%" y2="17%" stroke="white" />
@ -13,19 +13,19 @@
</g>
<g id="zone-labels">
<text class="zone-header" x="<%= zone_label_x %>%" y="<%= zone_label_y(1) %>%" text-anchor="start" dominant-baseline="middle">
<text class="zone-header" x="<%= background.zone_label_x %>%" y="<%= background.zone_label_y(1) %>%" text-anchor="start" dominant-baseline="middle">
Ideal
</text>
<text class="zone-header" x="<%= zone_label_x %>%" y="<%= zone_label_y(2) %>%" text-anchor="start" dominant-baseline="middle">
<text class="zone-header" x="<%= background.zone_label_x %>%" y="<%= background.zone_label_y(2) %>%" text-anchor="start" dominant-baseline="middle">
Approval
</text>
<text class="zone-header" x="<%= zone_label_x %>%" y="<%= zone_label_y(3) %>%" text-anchor="start" dominant-baseline="middle">
<text class="zone-header" x="<%= background.zone_label_x %>%" y="<%= background.zone_label_y(3) %>%" text-anchor="start" dominant-baseline="middle">
Growth
</text>
<text class="zone-header" x="<%= zone_label_x %>%" y="<%= zone_label_y(4) %>%" text-anchor="start" dominant-baseline="middle">
<text class="zone-header" x="<%= background.zone_label_x %>%" y="<%= background.zone_label_y(4) %>%" text-anchor="start" dominant-baseline="middle">
Watch
</text>
<text class="zone-header" x="<%= zone_label_x %>%" y="<%= zone_label_y(5) %>%" text-anchor="start" dominant-baseline="middle">
<text class="zone-header" x="<%= background.zone_label_x %>%" y="<%= background.zone_label_y(5) %>%" text-anchor="start" dominant-baseline="middle">
Warning
</text>
</g>

@ -1,10 +1,10 @@
<svg width="100%" height="<%= svg_height %>">
<%= render "graph_background" %>
<%= render partial: "graph_background", locals: {background: @background} %>
<% presenters = [StudentGroupedBarColumnPresenter, TeacherGroupedBarColumnPresenter, GroupedBarColumnPresenter] %>
<% presenters.each_with_index do |presenter, index| %>
<% p = presenter.new(measure: measure, school: @school, academic_years: @selected_academic_years, position: index ) %>
<%= render partial: "grouped_bar_column", locals: {presenter: p} %>
<%# <% columns = [StudentGroupedBarColumnPresenter, TeacherGroupedBarColumnPresenter, GroupedBarColumnPresenter] %1> %>
<% @graph.columns.each_with_index do |column, index| %>
<% p = column.new(measure: measure, school: @school, academic_years: @selected_academic_years, position: index ) %>
<%= render partial: "grouped_bar_column", locals: {column: p} %>
<% end %>
</svg>

Before

Width:  |  Height:  |  Size: 472 B

After

Width:  |  Height:  |  Size: 516 B

@ -1,7 +1,7 @@
<g class="grouped-bar-column" data-for-measure-id="<%= presenter.measure.measure_id %>">
<g class="grouped-bar-column" data-for-measure-id="<%= column.measure.measure_id %>">
<% score_label_y = [5, 10, 15, 5, 10, 15 ] %>
<% presenter.bars.each_with_index do |bar, index| %>
<rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= presenter.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" />
<% column.bars.each_with_index do |bar, index| %>
<rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= column.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" />
<% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %>
<text x="<%= bar.x_position + 3 %>%" y="<%= score_label_y[index] %>%" text-anchor="middle" dominant-baseline="middle">
@ -10,24 +10,24 @@
<% end %>
<% end %>
<text class="graph-footer" x="<%= presenter.column_midpoint %>%" y="<%= bar_label_height %>%" text-anchor="middle" dominant-baseline="middle" data-grouped-bar-label="<%= presenter.label %>">
<%= presenter.label %>
<text class="graph-footer" x="<%= column.column_midpoint %>%" y="<%= column.bar_label_height %>%" text-anchor="middle" dominant-baseline="middle" data-grouped-bar-label="<%= column.label %>">
<%= column.label %>
</text>
<% if presenter.show_irrelevancy_message? %>
<rect x="<%= presenter.message_x %>%" y="<%= presenter.message_y %>%" rx="15" ry="15" width="<%= presenter.message_width %>%" height="<%= presenter.message_height %>%" fill="white" stroke="gray" />
<% if column.show_irrelevancy_message? %>
<rect x="<%= column.message_x %>%" y="<%= column.message_y %>%" rx="15" ry="15" width="<%= column.message_width %>%" height="<%= column.message_height %>%" fill="white" stroke="gray" />
<text x="<%= presenter.column_midpoint %>%" y="<%= 20 %>%" text-anchor="middle">
<tspan x="<%= presenter.column_midpoint %>%" y="29%">measure not</tspan>
<tspan x="<%= presenter.column_midpoint %>%" y="34%">based on</tspan>
<tspan x="<%= presenter.column_midpoint %>%" y="39%"><%= presenter.basis %> surveys </tspan>
<text x="<%= column.column_midpoint %>%" y="<%= 20 %>%" text-anchor="middle">
<tspan x="<%= column.column_midpoint %>%" y="29%">measure not</tspan>
<tspan x="<%= column.column_midpoint %>%" y="34%">based on</tspan>
<tspan x="<%= column.column_midpoint %>%" y="39%"><%= column.basis %> surveys </tspan>
</text>
<% elsif presenter.show_insufficient_data_message? %>
<rect x="<%= presenter.message_x %>%" y="<%= presenter.message_y %>%" rx="15" ry="15" width="<%= presenter.message_width %>%" height="<%= presenter.message_height %>%" fill="white" stroke="gray" />
<% elsif column.show_insufficient_data_message? %>
<rect x="<%= column.message_x %>%" y="<%= column.message_y %>%" rx="15" ry="15" width="<%= column.message_width %>%" height="<%= column.message_height %>%" fill="white" stroke="gray" />
<text x="<%= presenter.column_midpoint %>%" y="<%= 20 %>%" text-anchor="middle">
<tspan x="<%= presenter.column_midpoint %>%" y="29%">survey response</tspan>
<tspan x="<%= presenter.column_midpoint %>%" y="34%">rate below 25%</tspan>
<text x="<%= column.column_midpoint %>%" y="<%= 20 %>%" text-anchor="middle">
<tspan x="<%= column.column_midpoint %>%" y="29%">survey response</tspan>
<tspan x="<%= column.column_midpoint %>%" y="34%">rate below 25%</tspan>
</text>
<% end %>
</g>

Loading…
Cancel
Save