Skip to content

Commit ec60196

Browse files
committed
Fix chart options not settable in default options
1 parent 5202f4e commit ec60196

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

lib/apex_charts/config/default_options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Config
55
module DefaultOptions
66
def default_options=(options)
77
@default_options =
8-
ApexCharts::OptionsBuilder.new(nil, options).build_general_options
8+
ApexCharts::OptionsBuilder.new(nil, options).build_global_options
99
end
1010

1111
def default_options

lib/apex_charts/options_builder.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def initialize(sample, options)
1717
@built = {}
1818
end
1919

20+
def build_global_options
21+
build_chart
22+
build_general_options
23+
end
24+
2025
def build_options
2126
build_chart
2227
build_div
@@ -45,7 +50,7 @@ def build_general_options
4550
build_tooltip
4651
build_xaxis
4752
build_yaxis
48-
built.compact
53+
built.compact!
4954
end
5055

5156
def build_div

spec/options_builder/global_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe '#build_global_options' do
4+
let(:sample) { nil }
5+
let(:options) {
6+
{
7+
chart: {background: '#ddd', height: 350},
8+
id: 'an-html-element-id',
9+
var: 'aVariableName',
10+
class: 'the-div-class',
11+
style: 'css-style',
12+
chart_id: 'a-chart-id',
13+
group: 'group-name',
14+
height: 300,
15+
width: 400,
16+
stacked: true,
17+
animations: true,
18+
sparkline: true,
19+
background: '#ccc',
20+
fore_color: '#fc9'
21+
}
22+
}
23+
let(:ob) {
24+
ApexCharts::OptionsBuilder.new(sample, options)
25+
}
26+
let(:expected_built) {
27+
{
28+
chart: {
29+
id: 'a-chart-id',
30+
animations: {enabled: true},
31+
background: '#ddd',
32+
foreColor: '#fc9',
33+
group: 'group-name',
34+
height: 350,
35+
width: 400,
36+
sparkline: {enabled: true},
37+
stacked: true
38+
},
39+
defer: false,
40+
module: false
41+
}
42+
}
43+
44+
it 'exclude div related key-values' do
45+
ob.build_global_options
46+
expect(ob.built).to match(expected_built)
47+
end
48+
end

0 commit comments

Comments
 (0)