Skip to content

Commit

Permalink
Don't set default height
Browse files Browse the repository at this point in the history
This will fix chart height not overridable by global/default options
  • Loading branch information
styd committed Oct 23, 2024
1 parent ec60196 commit 85fcce8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/apex_charts/options_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def build_chart
built[:chart].merge!({
id: @options[:chartId] || @options[:id],
group: @options.delete(:group),
height: @options.delete(:height) { target ? 180 : 400 },
height: @options.delete(:height) { target ? 180 : nil },
width: @options.delete(:width),
stacked: @options.delete(:stacked),
animations: enabled(@options.delete(:animations)),
Expand Down
7 changes: 5 additions & 2 deletions lib/apex_charts/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ def css_class
end

def height
"#{options[:chart][:height].to_i}px"
chart_height = options.dig(:chart, :height)
if chart_height
"#{chart_height.to_i}px"
end
end

def style
"height: #{height}; #{attributes.delete(:style)}"
"#{height && "height: #{height}; "}#{attributes.delete(:style)}"
end

def window_apex
Expand Down
4 changes: 1 addition & 3 deletions spec/charts/mixed_charts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
expect(chart.more_options).to eq({})
expect(chart.instance_variable_get(:@series)).to eq(expected_series)
expect(chart.instance_variable_get(:@options)).to eq(
chart: {
height: 400, id: 'chart-1', type: 'area'
},
chart: {id: 'chart-1', type: 'area'},
defer: false,
div: {id: 'chart-1'},
module: false,
Expand Down

0 comments on commit 85fcce8

Please sign in to comment.