Skip to content

Commit

Permalink
Remove unnecessary chart code
Browse files Browse the repository at this point in the history
  • Loading branch information
PanSpagetka committed Mar 2, 2017
1 parent 92b5071 commit 8b98b94
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 61 deletions.
57 changes: 1 addition & 56 deletions app/models/miq_report/formatters/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,8 @@ module MiqReport::Formatters::Graph

module ClassMethods
# Set the graph options based on chart width and height
def graph_options(w = 350, h = 250, options = nil)
def graph_options(options = nil)
options ||= {}
w = w.to_i
h = h.to_i
options[:legendwidth] = w - 10
options[:legendheight] = h * 5 / 100
options[:legendx] = 5
options[:legendy] = 5

options[:chartx] = w * 20 / 100
options[:chartwidth] = w * 75 / 100

# Set sizes based on chart pixel width
if w < 500
options[:titlesize] = 16
options[:legendsize] = 10
options[:chartsize] = :small
elsif w < 700
options[:titlesize] = 32
options[:legendsize] = 12
options[:chartsize] = :medium
else
options[:titlesize] = 48
options[:legendsize] = 15
options[:chartsize] = :large
end

options[:totalwidth] = w
if options[:chart2] # Does this chart have a composite chart along with it
if options[:composite] # Rendering composite chart
options[:totalheight] = h * 30 / 100 # Composite area is 30% of total height
options[:charty] = (h * 30 / 100) * 28 / 100
options[:chartheight] = (h * 70 / 100) * 20 / 100
options[:titlesize] = options[:titlesize] * 3 / 4
options[:no_legend] = true
options[:no_xlabels] = nil
else # Rendering main chart w/composite present
options[:totalheight] = h * 70 / 100 # Main is 70% of total height
options[:charty] = h * 23 / 100
options[:chartheight] = (h * 70 / 100) * 65 / 100
options[:no_legend] = nil
options[:no_xlabels] = true
end
else # Rendering single chart
options[:totalheight] = h
options[:charty] = h * 23 / 100
options[:chartheight] = h * 70 / 100
end

options[:barchartheight] = h * 50 / 100 # Special bar chart options
options[:barcharty] = h * 40 / 100

options[:piechartx] = w * 12 / 100 # Special pie chart options
options[:piecharty] = h * 27 / 100

# Legend font size
# options[:legendsize] = w < 500 ? 10 : 20
options
end
end
Expand Down
1 change: 1 addition & 0 deletions providers/manageiq-providers-amazon
Submodule manageiq-providers-amazon added at 47340c
8 changes: 4 additions & 4 deletions spec/models/miq_report/charting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

@report_theme = 'miq'
@show_title = true
@options = MiqReport.graph_options(600, 400)
@options = MiqReport.graph_options({ :title => "CPU (Mhz)", :type => "Line", :columns => ["col"] })

allow(Charting).to receive(:backend).and_return(:c3)
allow(Charting).to receive(:format).and_return(:c3)
end

context 'graph_options' do
it 'returns a hash with options' do
expect(MiqReport.graph_options(400, 600)).to include(
:totalwidth => 400,
:totalheight => 600
expect(MiqReport.graph_options({ :title => "CPU (Mhz)", :type => "Line", :columns => ["col"] })).to include(
:type => "Line",
:title => "CPU (Mhz)"
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/miq_report_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

@report_theme = 'miq'
@show_title = true
@options = MiqReport.graph_options(600, 400)
@options = MiqReport.graph_options({ :title => "CPU (Mhz)", :type => "Line", :columns => ["col"] })

allow(Charting).to receive(:detect_available_plugin).and_return(C3Charting)
end
Expand Down

0 comments on commit 8b98b94

Please sign in to comment.