Skip to content

Commit

Permalink
Fix chart options not settable in default options
Browse files Browse the repository at this point in the history
  • Loading branch information
styd committed Oct 23, 2024
1 parent 5202f4e commit ec60196
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/apex_charts/config/default_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Config
module DefaultOptions
def default_options=(options)
@default_options =
ApexCharts::OptionsBuilder.new(nil, options).build_general_options
ApexCharts::OptionsBuilder.new(nil, options).build_global_options
end

def default_options
Expand Down
7 changes: 6 additions & 1 deletion lib/apex_charts/options_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def initialize(sample, options)
@built = {}
end

def build_global_options
build_chart
build_general_options
end

def build_options
build_chart
build_div
Expand Down Expand Up @@ -45,7 +50,7 @@ def build_general_options
build_tooltip
build_xaxis
build_yaxis
built.compact
built.compact!
end

def build_div
Expand Down
48 changes: 48 additions & 0 deletions spec/options_builder/global_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

RSpec.describe '#build_global_options' do
let(:sample) { nil }
let(:options) {
{
chart: {background: '#ddd', height: 350},
id: 'an-html-element-id',
var: 'aVariableName',
class: 'the-div-class',
style: 'css-style',
chart_id: 'a-chart-id',
group: 'group-name',
height: 300,
width: 400,
stacked: true,
animations: true,
sparkline: true,
background: '#ccc',
fore_color: '#fc9'
}
}
let(:ob) {
ApexCharts::OptionsBuilder.new(sample, options)
}
let(:expected_built) {
{
chart: {
id: 'a-chart-id',
animations: {enabled: true},
background: '#ddd',
foreColor: '#fc9',
group: 'group-name',
height: 350,
width: 400,
sparkline: {enabled: true},
stacked: true
},
defer: false,
module: false
}
}

it 'exclude div related key-values' do
ob.build_global_options
expect(ob.built).to match(expected_built)
end
end

0 comments on commit ec60196

Please sign in to comment.