From 85fcce89895a8013930b1e0ae90f143eae1ee2ff Mon Sep 17 00:00:00 2001 From: Adrian Setyadi Date: Wed, 23 Oct 2024 09:16:26 +0700 Subject: [PATCH] Don't set default height This will fix chart height not overridable by global/default options --- lib/apex_charts/options_builder.rb | 2 +- lib/apex_charts/renderer.rb | 7 +++++-- spec/charts/mixed_charts_spec.rb | 4 +--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/apex_charts/options_builder.rb b/lib/apex_charts/options_builder.rb index c27621a..961368c 100644 --- a/lib/apex_charts/options_builder.rb +++ b/lib/apex_charts/options_builder.rb @@ -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)), diff --git a/lib/apex_charts/renderer.rb b/lib/apex_charts/renderer.rb index dfcb1c3..9781a2c 100644 --- a/lib/apex_charts/renderer.rb +++ b/lib/apex_charts/renderer.rb @@ -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 diff --git a/spec/charts/mixed_charts_spec.rb b/spec/charts/mixed_charts_spec.rb index a7385ff..b2de59f 100644 --- a/spec/charts/mixed_charts_spec.rb +++ b/spec/charts/mixed_charts_spec.rb @@ -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,