apexcharts 0.1.11 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +64 -21
  3. data/lib/apex_charts/charts/box_plot_chart.rb +1 -0
  4. data/lib/apex_charts/configuration.rb +0 -2
  5. data/lib/apex_charts/options_builder.rb +128 -125
  6. data/lib/apex_charts/renderer.rb +10 -5
  7. data/lib/apex_charts/series/bubble_series.rb +2 -3
  8. data/lib/apex_charts/series/cartesian_series.rb +8 -2
  9. data/lib/apex_charts/version.rb +2 -2
  10. data/vendor/assets/javascripts/apexcharts.js +5 -5
  11. metadata +3 -79
  12. data/lib/apex_charts/config/schema.rb +0 -20
  13. data/lib/apex_charts/options/default/annotations_options.rb +0 -14
  14. data/lib/apex_charts/options/default/chart_options.rb +0 -33
  15. data/lib/apex_charts/options/default/data_labels_options.rb +0 -18
  16. data/lib/apex_charts/options/default/fill_options.rb +0 -14
  17. data/lib/apex_charts/options/default/grid_options.rb +0 -17
  18. data/lib/apex_charts/options/default/helper_options.rb +0 -22
  19. data/lib/apex_charts/options/default/legend_options.rb +0 -33
  20. data/lib/apex_charts/options/default/markers_options.rb +0 -26
  21. data/lib/apex_charts/options/default/no_data_options.rb +0 -14
  22. data/lib/apex_charts/options/default/plot_options.rb +0 -19
  23. data/lib/apex_charts/options/default/root_options.rb +0 -38
  24. data/lib/apex_charts/options/default/states_options.rb +0 -11
  25. data/lib/apex_charts/options/default/stroke_options.rb +0 -14
  26. data/lib/apex_charts/options/default/theme_options.rb +0 -11
  27. data/lib/apex_charts/options/default/title_subtitle_options.rb +0 -15
  28. data/lib/apex_charts/options/default/tooltip_options.rb +0 -25
  29. data/lib/apex_charts/options/default/x_axis_options.rb +0 -27
  30. data/lib/apex_charts/options/default/y_axis_options.rb +0 -28
  31. data/lib/apex_charts/options/dry_schema/annotations_options/annotation_label.rb +0 -24
  32. data/lib/apex_charts/options/dry_schema/annotations_options/image_annotations.rb +0 -15
  33. data/lib/apex_charts/options/dry_schema/annotations_options/point_annotations.rb +0 -33
  34. data/lib/apex_charts/options/dry_schema/annotations_options/text_annotations.rb +0 -26
  35. data/lib/apex_charts/options/dry_schema/annotations_options/x_axis_annotations.rb +0 -20
  36. data/lib/apex_charts/options/dry_schema/annotations_options/y_axis_annotations.rb +0 -21
  37. data/lib/apex_charts/options/dry_schema/annotations_options.rb +0 -22
  38. data/lib/apex_charts/options/dry_schema/chart_options.rb +0 -35
  39. data/lib/apex_charts/options/dry_schema/data_labels_options.rb +0 -37
  40. data/lib/apex_charts/options/dry_schema/fill_options.rb +0 -34
  41. data/lib/apex_charts/options/dry_schema/general_schema/drop_shadow.rb +0 -14
  42. data/lib/apex_charts/options/dry_schema/general_schema/function.rb +0 -12
  43. data/lib/apex_charts/options/dry_schema/grid_options.rb +0 -19
  44. data/lib/apex_charts/options/dry_schema/helper_options.rb +0 -22
  45. data/lib/apex_charts/options/dry_schema/legend_options.rb +0 -61
  46. data/lib/apex_charts/options/dry_schema/markers_options/discrete_point.rb +0 -13
  47. data/lib/apex_charts/options/dry_schema/markers_options.rb +0 -34
  48. data/lib/apex_charts/options/dry_schema/no_data_options.rb +0 -16
  49. data/lib/apex_charts/options/dry_schema/plot_options.rb +0 -231
  50. data/lib/apex_charts/options/dry_schema/root_options.rb +0 -42
  51. data/lib/apex_charts/options/dry_schema/schema.rb +0 -32
  52. data/lib/apex_charts/options/dry_schema/states_options/filter.rb +0 -10
  53. data/lib/apex_charts/options/dry_schema/states_options.rb +0 -22
  54. data/lib/apex_charts/options/dry_schema/stroke_options.rb +0 -21
  55. data/lib/apex_charts/options/dry_schema/theme_options.rb +0 -18
  56. data/lib/apex_charts/options/dry_schema/title_subtitle_options.rb +0 -22
  57. data/lib/apex_charts/options/dry_schema/tooltip_options.rb +0 -27
  58. data/lib/apex_charts/options/dry_schema/x_axis_options.rb +0 -30
  59. data/lib/apex_charts/options/dry_schema/y_axis_options.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 709e9e394138ca8ede2eec0fa33a175b3e08ccaa764907c53fc6c72db067e3d5
4
- data.tar.gz: ea1a5e008282d9edc581da80d06a61c743fbf130f91cdbfea659bb450489d5a9
3
+ metadata.gz: e97e5e996cb05991f345e7cf9c6591aab1405925b2b92643f518687017923170
4
+ data.tar.gz: 5a64c5b2a09074483ab53abcbcaed281efe8241ae83978d04e48e0486c1bf5b5
5
5
  SHA512:
6
- metadata.gz: 561565108337e05159effd5c8c353765b6f4ac1b4741d2b8f520d3a3c8698f697ec0abb359debcaca14ae1ff32fa2ae8c8efe7ab2171377356a3293a2e81a0f2
7
- data.tar.gz: 79413ca860115ccf2e9e729b40af747865bf93252ac7ae90c29260a33be0702f05c9780b32ac65fd34e43005c84aabf5c1265d9551ddfc6835212f7338cfc5ab
6
+ metadata.gz: 438e96dcecf8766666b1b1d48bfa7f0a134ee3ee70d14a6309850ef9e47ea28633bf68101b3c11a90f92cabdece41da05e3e599b3523a2de3295470133c980e1
7
+ data.tar.gz: 1677bef319ca1190860641f188e0914f29400709f96d9afc42a3f4cb833671865227c61ae9d22cfec7c2ae14af88cfa78f47a0328e91f4c60809d1bbdcf7db46
data/README.md CHANGED
@@ -25,6 +25,10 @@
25
25
  <a href='http://clayallsopp.github.io/readme-score/?url=styd/apexcharts.rb'>
26
26
  <img src='http://readme-score-api.herokuapp.com/score.svg?url=styd/apexcharts.rb' alt='README Score' />
27
27
  </a>
28
+ <br />
29
+ <a href='https://ko-fi.com/setyadi' target='_blank'>
30
+ <img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi4.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' />
31
+ </a>
28
32
  </p>
29
33
 
30
34
 
@@ -46,7 +50,7 @@ Organization/Company | Use Cas
46
50
  <img src="/images/users/ventrata.png" width="180" height="40" /> | Ticket sales for clients (visitor attractions and tour operators)
47
51
 
48
52
  > If your organization/company uses ApexCharts.RB in production, please comment on
49
- > [this issue](https://github.com/styd/apexcharts.rb/issues/34).
53
+ > [this discussion](https://github.com/styd/apexcharts.rb/discussions/34).
50
54
 
51
55
 
52
56
  ## README Versions
@@ -54,8 +58,8 @@ Organization/Company | Use Cas
54
58
  This README might not be for the version you use.
55
59
  Choose the right README:
56
60
 
57
- > [v0.1.11] | [v0.1.10] | [v0.1.9] | [v0.1.8] | [v0.1.7] | [v0.1.6] |
58
- > [v0.1.5] | [v0.1.4] | [v0.1.3] | [v0.1.2] | [v0.1.1]
61
+ > [v0.2.0] | [v0.1.11] | [v0.1.10] | [v0.1.9] | [v0.1.8] | [v0.1.7] |
62
+ > [v0.1.6] | [v0.1.5] | [v0.1.4] | [v0.1.3] | [v0.1.2] | [v0.1.1]
59
63
 
60
64
  ## Table of Contents
61
65
 
@@ -78,6 +82,7 @@ Choose the right README:
78
82
  - [Syncing Charts](#syncing-charts)
79
83
  - [Brush Chart](#brush-chart)
80
84
  - [Annotations](#annotations)
85
+ - [Multiple Y-Axes](#multiple-y-axes)
81
86
  - [Heatmap Chart](#heatmap-chart)
82
87
  - [Radar Chart](#radar-chart)
83
88
  - [Bubble Chart](#bubble-chart)
@@ -97,7 +102,7 @@ Choose the right README:
97
102
  - [Global Options](#global-options)
98
103
  - [Formatter Function](#formatter-function)
99
104
  - [Defer Chart Rendering](#defer-chart-rendering)
100
- - [Schema](#schema)
105
+ - [Render with a script whose type is module](#render-with-a-script-whose-type-is-module)
101
106
  - [Reusable Custom Palette](#reusable-custom-palette)
102
107
  - [Use Alongside Other Charting Libraries](#use-alongside-other-charting-libraries)
103
108
  - [Alongside Chartkick](#alongside-chartkick)
@@ -111,7 +116,7 @@ Choose the right README:
111
116
  - [Plain HTML+ERB (Without Framework)](#plain-htmlerb-without-framework)
112
117
  - [Contributing](#contributing)
113
118
  - [License](#license)
114
- - [Like the charts?](#like-the-charts)
119
+ - [Articles](#articles)
115
120
 
116
121
 
117
122
  ## Usage
@@ -387,6 +392,52 @@ All cartesian charts can have annotations, for example:
387
392
  ![Example Area Chart with Annotations](images/chart_with_annotations.gif)
388
393
 
389
394
 
395
+ #### Multiple Y-Axes
396
+
397
+ There's no fancy shortcut for multiple Y axes yet, but it is allowed. Here is an example
398
+ for that.
399
+
400
+ ```erb
401
+ <% series = [
402
+ {
403
+ name: 'Income',
404
+ type: 'column',
405
+ data: [1.4, 2, 2.5, 1.5, 2.5, 2.8, 3.8, 4.6]
406
+ },
407
+ {
408
+ name: 'Cashflow',
409
+ type: 'column',
410
+ data: [1.1, 3, 3.1, 4, 4.1, 4.9, 6.5, 8.5]
411
+ },
412
+ {
413
+ name: 'Revenue',
414
+ data: [20, 29, 37, 36, 44, 45, 50, 58]
415
+ }
416
+ ]
417
+
418
+ xaxis = {
419
+ title: {text: 'Year'},
420
+ categories: [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016]
421
+ }
422
+
423
+ yaxis = [
424
+ {title: {text: "Income"}},
425
+ {
426
+ title: {text: "Operating Cashflow"},
427
+ opposite: true,
428
+ seriesName: 'Cashflow'
429
+ },
430
+ {
431
+ title: {text: "Revenue"},
432
+ opposite: true,
433
+ seriesName: 'Revenue'
434
+ }
435
+ ]
436
+ %>
437
+ <%= line_chart(series, xaxis: xaxis, yaxis: yaxis) %>
438
+ ```
439
+ ![Example Chart with multiple Y-Axes](images/chart_with_multiple_y-axes.gif)
440
+
390
441
  ### Heatmap Chart
391
442
 
392
443
  ```erb
@@ -697,29 +748,22 @@ Or, without the _functionable-json_ gem, use function as object as follows:
697
748
 
698
749
  ### Defer Chart Rendering
699
750
 
700
- It's possible to defer chart rendering by passing the argument `defer: true` as options.
751
+ It's possible to defer chart rendering by passing the argument `defer: true` as option.
701
752
 
702
753
  ```erb
703
754
  <%= line_chart series, defer: true %>
704
755
  ```
705
756
 
757
+ ### Render with a script whose type is module
706
758
 
707
- ## Schema
759
+ The charts are rendered by inserting a <script> block in the HTML.
760
+ In order to generate this <script> with `type="module"` use the
761
+ option `module: true`.
708
762
 
709
- To use [dry-schema] as an alternative options schema, you can specify the following config
710
- before calling your charts:
711
-
712
- ```ruby
713
- ApexCharts.config.schema = :dry_schema
763
+ ```erb
764
+ <%= line_chart series, module: true %>
714
765
  ```
715
766
 
716
- or
717
-
718
- ```ruby
719
- ApexCharts.configure do |config|
720
- config.schema = :dry_schema
721
- end
722
- ```
723
767
 
724
768
  ## Reusable Custom Palette
725
769
 
@@ -942,10 +986,9 @@ The gem is available as open source under the terms of the
942
986
 
943
987
 
944
988
  [ApexCharts.JS]: https://github.com/apexcharts/apexcharts.js
945
- [dry-schema]: https://github.com/dry-rb/dry-schema
946
989
 
947
990
 
948
- [Unreleased]: https://github.com/styd/apexcharts.rb/compare/v0.1.11...HEAD
991
+ [v0.2.0]: https://github.com/styd/apexcharts.rb/blob/v0.2.0/README.md
949
992
  [v0.1.11]: https://github.com/styd/apexcharts.rb/blob/v0.1.11/README.md
950
993
  [v0.1.10]: https://github.com/styd/apexcharts.rb/blob/v0.1.10/README.md
951
994
  [v0.1.9]: https://github.com/styd/apexcharts.rb/blob/v0.1.9/README.md
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module ApexCharts::Charts
3
4
  class BoxPlotChart < CartesianChart
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'config/default_options'
4
- require_relative 'config/schema'
5
4
 
6
5
  module ApexCharts
7
6
  class << self
@@ -22,6 +21,5 @@ module ApexCharts
22
21
 
23
22
  class Configuration
24
23
  include ApexCharts::Config::DefaultOptions
25
- include ApexCharts::Config::Schema
26
24
  end
27
25
  end
@@ -1,29 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- %w(default dry_schema).each do |schema_dir|
4
- require_relative "options/#{schema_dir}/root_options"
5
- require_relative "options/#{schema_dir}/annotations_options"
6
- require_relative "options/#{schema_dir}/data_labels_options"
7
- require_relative "options/#{schema_dir}/fill_options"
8
- require_relative "options/#{schema_dir}/grid_options"
9
- require_relative "options/#{schema_dir}/legend_options"
10
- require_relative "options/#{schema_dir}/markers_options"
11
- require_relative "options/#{schema_dir}/no_data_options"
12
- require_relative "options/#{schema_dir}/plot_options"
13
- require_relative "options/#{schema_dir}/states_options"
14
- require_relative "options/#{schema_dir}/title_subtitle_options"
15
- require_relative "options/#{schema_dir}/theme_options"
16
- require_relative "options/#{schema_dir}/tooltip_options"
17
- require_relative "options/#{schema_dir}/x_axis_options"
18
- require_relative "options/#{schema_dir}/y_axis_options"
19
- end
20
-
21
3
  module ApexCharts
22
4
  class OptionsBuilder
23
5
  include ApexCharts::Utils::Hash
24
6
  include ApexCharts::Utils::DateTime
25
7
 
26
- attr_reader :built
8
+ attr_accessor :built
27
9
 
28
10
  def initialize(sample, options)
29
11
  @options = camelize_keys(options)
@@ -36,8 +18,6 @@ module ApexCharts
36
18
  end
37
19
 
38
20
  def build_options
39
- options_class(:Root).check @options
40
-
41
21
  build_chart
42
22
  build_div
43
23
  build_general_options
@@ -53,6 +33,7 @@ module ApexCharts
53
33
  build_labels
54
34
  build_legend
55
35
  build_markers
36
+ build_module
56
37
  build_no_data
57
38
  build_plot_options
58
39
  build_responsive
@@ -68,7 +49,7 @@ module ApexCharts
68
49
  end
69
50
 
70
51
  def build_div
71
- @built[:div] = {
52
+ built[:div] = {
72
53
  id: @options.delete(:id),
73
54
  var: @options.delete(:var),
74
55
  class: @options.delete(:class),
@@ -78,15 +59,13 @@ module ApexCharts
78
59
 
79
60
  def build_annotations
80
61
  annotations = @options.delete :annotations
81
- @built[:annotations] = (
82
- if annotations.is_a? Hash
83
- options_class(:Annotations).check annotations.compact
84
- end
62
+ built[:annotations] = (
63
+ annotations.compact if annotations.is_a? Hash
85
64
  )
86
65
  end
87
66
 
88
67
  def build_chart
89
- @built[:chart] =
68
+ built[:chart] =
90
69
  if target = @options.delete(:brushTarget)
91
70
  {
92
71
  brush: {enabled: true, target: target.to_s},
@@ -96,7 +75,7 @@ module ApexCharts
96
75
  {}
97
76
  end
98
77
 
99
- @built[:chart].merge!({
78
+ built[:chart].merge!({
100
79
  id: @options[:chartId] || @options[:id],
101
80
  group: @options.delete(:group),
102
81
  height: @options.delete(:height) { target ? 180 : 400 },
@@ -112,207 +91,230 @@ module ApexCharts
112
91
 
113
92
  return unless chart.is_a? Hash
114
93
 
115
- @built[:chart].merge! options_class(:Chart).check(chart.compact)
94
+ built[:chart].merge! chart.compact
116
95
  end
117
96
 
118
97
  def build_colors
119
98
  colors = @options.delete :colors
120
99
  colors &&= Array(colors)
121
- @built[:colors] = colors
100
+ built[:colors] = colors
122
101
  end
123
102
 
124
103
  def build_data_labels
125
104
  data_labels = @options.delete :dataLabels
126
105
  return if data_labels.nil?
127
106
 
128
- @built[:dataLabels] = if [true, false].include? data_labels
129
- {enabled: data_labels}
130
- elsif data_labels.is_a? Hash
131
- options_class(:DataLabels).check data_labels.compact
132
- end
107
+ built[:dataLabels] = if [true, false].include? data_labels
108
+ {enabled: data_labels}
109
+ elsif data_labels.is_a? Hash
110
+ data_labels.compact
111
+ end
133
112
  end
134
113
 
135
114
  def build_defer
136
115
  defer = @options.delete :defer
137
- @built[:defer] = defer == true
116
+ built[:defer] = defer == true
138
117
  end
139
118
 
119
+ def build_module
120
+ omodule = @options.delete :module
121
+ built[:module] = omodule == true
122
+ end
140
123
 
141
124
  def build_fill
142
125
  fill = @options.delete :fill
143
- @built[:fill] = if fill.is_a? String
144
- {type: fill}
145
- elsif fill.is_a? Hash
146
- options_class(:Fill).check fill.compact
147
- end
126
+ built[:fill] = case fill
127
+ when String
128
+ {type: fill}
129
+ when Hash
130
+ fill.compact
131
+ end
148
132
  end
149
133
 
150
134
  def build_grid
151
135
  grid = @options.delete :grid
152
- @built[:grid] = if [true, false].include? grid
153
- {show: grid}
154
- elsif grid.is_a? Hash
155
- options_class(:Grid).check grid.compact
156
- end
136
+ built[:grid] = if [true, false].include? grid
137
+ {show: grid}
138
+ elsif grid.is_a? Hash
139
+ grid.compact
140
+ end
157
141
  end
158
142
 
159
143
  def build_labels
160
144
  labels = @options.delete :labels
161
145
  labels &&= Array(labels)
162
- @built[:labels] = labels
146
+ built[:labels] = labels
163
147
  end
164
148
 
165
149
  def build_legend
166
150
  legend = @options.delete :legend
167
- @built[:legend] = if [true, false].include? legend
168
- {show: legend}
169
- elsif legend.is_a? String
170
- {show: true, position: legend}
171
- elsif legend.is_a? Hash
172
- options_class(:Legend).check legend.compact
173
- end
151
+ built[:legend] = if [true, false].include? legend
152
+ {show: legend}
153
+ elsif legend.is_a? String
154
+ {show: true, position: legend}
155
+ elsif legend.is_a? Hash
156
+ legend.compact
157
+ end
174
158
  end
175
159
 
176
160
  def build_markers
177
161
  markers = @options.delete :markers
178
- @built[:markers] = if markers.is_a? String
179
- {shape: markers}
180
- elsif markers.is_a? Hash
181
- options_class(:Markers).check markers.compact
182
- end
162
+ built[:markers] = case markers
163
+ when String
164
+ {shape: markers}
165
+ when Hash
166
+ markers.compact
167
+ end
183
168
  end
184
169
 
185
170
  def build_no_data
186
171
  no_data = @options.delete :noData
187
- @built[:noData] = if no_data.is_a? String
188
- {text: no_data}
189
- elsif no_data.is_a? Hash
190
- options_class(:NoData).check no_data.compact
191
- end
172
+ built[:noData] = case no_data
173
+ when String
174
+ {text: no_data}
175
+ when Hash
176
+ no_data.compact
177
+ end
192
178
  end
193
179
 
194
180
  def build_plot_options
195
181
  plot_options = @options.delete :plotOptions
196
182
  return unless plot_options.is_a? Hash
197
183
 
198
- @built[:plotOptions] =
199
- options_class(:Plot).check plot_options.compact
184
+ built[:plotOptions] =
185
+ plot_options.compact
200
186
  end
201
187
 
202
188
  def build_responsive
203
189
  responsive = @options.delete :responsive
204
190
  responsive &&= responsive.is_a?(Hash) ? [responsive] : Array(responsive)
205
- @built[:responsive] = responsive
191
+ built[:responsive] = responsive
206
192
  end
207
193
 
208
194
  def build_states
209
- @built[:states] = {
195
+ built[:states] = {
210
196
  normal: filter_type_hash(@options.delete(:normal)),
211
197
  hover: filter_type_hash(@options.delete(:hover)),
212
198
  active: filter_type_hash(@options.delete(:active))
213
199
  }.compact
214
200
 
215
201
  states = @options.delete :states
216
- @built[:states].merge! options_class(:States).check(states.compact) if states.is_a? Hash
202
+ built[:states].merge! states.compact if states.is_a? Hash
217
203
 
218
- @built[:states] = nil if @built[:states].empty?
204
+ built[:states] = nil if built[:states].empty?
219
205
  end
220
206
 
221
207
  def build_stroke
222
208
  curve = @options.delete :curve
223
- @built[:stroke] = {curve: curve}.compact
209
+ built[:stroke] = {curve: curve}.compact
224
210
 
225
211
  stroke = @options.delete :stroke
226
212
  if [true, false].include? stroke
227
- @built[:stroke].merge!(show: stroke)
213
+ built[:stroke].merge!(show: stroke)
228
214
  elsif stroke.is_a? Hash
229
- @built[:stroke].merge! options_class(:Stroke).check(stroke.compact)
215
+ built[:stroke].merge! stroke.compact
230
216
  end
231
217
 
232
- @built[:stroke] = nil if @built[:stroke].empty?
218
+ built[:stroke] = nil if built[:stroke].empty?
233
219
  end
234
220
 
235
221
  def build_subtitle
236
222
  subtitle = @options.delete(:subtitle)
237
- @built[:subtitle] = if subtitle.is_a? String
238
- {text: subtitle}
239
- elsif subtitle.is_a? Hash
240
- options_class(:TitleSubtitle).check subtitle.compact
241
- end
223
+ built[:subtitle] = case subtitle
224
+ when String
225
+ {text: subtitle}
226
+ when Hash
227
+ subtitle.compact
228
+ end
242
229
  end
243
230
 
244
231
  def build_theme
245
232
  theme = @options.delete(:theme)
246
- @built[:theme] = if theme.is_a? String
247
- case theme
248
- when 'random'
249
- resolve_theme(Theme.all_palettes.sample)
250
- when 'monochrome'
251
- {monochrome: {enabled: true}}
252
- else
253
- resolve_theme(theme)
254
- end
255
- elsif theme.is_a? Hash
256
- options_class(:Theme).check theme.compact
257
- end
233
+ built[:theme] = case theme
234
+ when String
235
+ case theme
236
+ when 'random'
237
+ resolve_theme(Theme.all_palettes.sample)
238
+ when 'monochrome'
239
+ {monochrome: {enabled: true}}
240
+ else
241
+ resolve_theme(theme)
242
+ end
243
+ when Hash
244
+ theme.compact
245
+ end
258
246
  end
259
247
 
260
248
  def build_title
261
249
  title = @options.delete(:title)
262
- @built[:title] = if title.is_a? String
263
- {text: title}
264
- elsif title.is_a? Hash
265
- options_class(:TitleSubtitle).check title.compact
266
- end
250
+ built[:title] = case title
251
+ when String
252
+ {text: title}
253
+ when Hash
254
+ title.compact
255
+ end
267
256
  end
268
257
 
269
258
  def build_tooltip
270
259
  tooltip = @options.delete :tooltip
271
- @built[:tooltip] = if [true, false].include? tooltip
272
- {enabled: tooltip}
273
- elsif tooltip.is_a? Hash
274
- options_class(:Tooltip).check tooltip.compact
275
- end
260
+ built[:tooltip] = if [true, false].include? tooltip
261
+ {enabled: tooltip}
262
+ elsif tooltip.is_a? Hash
263
+ tooltip.compact
264
+ end
276
265
  end
277
266
 
278
267
  def build_xaxis
279
268
  xaxis = @options.delete :xaxis
280
- @built[:xaxis] = {
269
+ built[:xaxis] = {
281
270
  type: @options.delete(:xtype) { @xtype },
282
271
  title: {
283
272
  text: @options.delete(:xtitle)
284
273
  }.compact
285
274
  }.compact
286
- @built[:xaxis].delete(:title) if @built[:xaxis][:title].empty?
275
+ built[:xaxis].delete(:title) if built[:xaxis][:title].empty?
287
276
 
288
- if xaxis.is_a? String
289
- @built[:xaxis][:title] = {text: xaxis}
290
- elsif xaxis.is_a? Hash
291
- options_class(:XAxis).check xaxis
292
- @built[:xaxis].merge! xaxis
277
+ case xaxis
278
+ when String
279
+ built[:xaxis][:title] = {text: xaxis}
280
+ when Hash
281
+ built[:xaxis].merge! xaxis
293
282
  end
294
283
 
295
- @built[:xaxis] = nil if @built[:xaxis].empty?
284
+ built[:xaxis] = nil if built[:xaxis].empty?
296
285
  end
297
286
 
298
287
  def build_yaxis
299
288
  yaxis = @options.delete :yaxis
300
- @built[:yaxis] = [{
301
- type: @options.delete(:ytype) { @ytype },
302
- title: {
303
- text: @options.delete(:ytitle)
289
+
290
+ case yaxis
291
+ when Array
292
+ built[:yaxis] = yaxis
293
+ when Hash
294
+ built[:yaxis] = {
295
+ type: @options.delete(:ytype) { @ytype },
296
+ title: {
297
+ text: @options.delete(:ytitle)
298
+ }.compact
304
299
  }.compact
305
- }.compact]
306
- @built[:yaxis][0].delete(:title) if @built[:yaxis][0][:title].empty?
307
-
308
- if yaxis.is_a? String
309
- @built[:yaxis][0][:title] = {text: yaxis}
310
- elsif yaxis.is_a? Hash
311
- options_class(:YAxis).check yaxis
312
- @built[:yaxis][0].merge! yaxis
300
+ built[:yaxis].delete(:title) if built[:yaxis][:title].empty?
301
+ built[:yaxis].merge! yaxis
302
+ when String
303
+ built[:yaxis] = {
304
+ type: @options.delete(:ytype) { @ytype },
305
+ title: {
306
+ text: yaxis
307
+ }
308
+ }.compact
309
+ when NilClass
310
+ built[:yaxis] = if ytitle = @options.delete(:ytitle)
311
+ {title: {text: ytitle}}
312
+ else
313
+ {}
314
+ end
313
315
  end
314
316
 
315
- @built[:yaxis] = nil if @built[:yaxis].all?(&:empty?)
317
+ built[:yaxis] = nil if built[:yaxis].all?(&:empty?)
316
318
  end
317
319
 
318
320
  private
@@ -334,9 +336,10 @@ module ApexCharts
334
336
  end
335
337
 
336
338
  def filter_type_hash(state)
337
- if state.is_a? String
339
+ case state
340
+ when String
338
341
  {filter: {type: state}}
339
- elsif state.is_a? Hash
342
+ when Hash
340
343
  state.compact
341
344
  end
342
345
  end
@@ -345,7 +348,7 @@ module ApexCharts
345
348
  if Theme::PALETTES.include? theme
346
349
  {palette: theme}
347
350
  elsif Theme.palette_names.include? theme
348
- @built[:colors] = Theme.get_colors(theme)
351
+ built[:colors] = Theme.get_colors(theme)
349
352
  nil
350
353
  end
351
354
  end
@@ -54,9 +54,9 @@ module ApexCharts
54
54
  end
55
55
 
56
56
  def substitute_function_object(json)
57
- json.gsub(%r[{"function":{"args":"(?<args>.*?)","body":"(?<body>.*?)"}}]) do
58
- body = "\"#{$~&.[](:body)}\"".undump
59
- "function(#{$~&.[](:args)}){#{body}}"
57
+ json.gsub(/{"function":{"args":"(?<args>.*?)","body":"(?<body>.*?)"}}/) do
58
+ body = "\"#{$LAST_MATCH_INFO&.[](:body)}\"".undump
59
+ "function(#{$LAST_MATCH_INFO&.[](:args)}){#{body}}"
60
60
  end
61
61
  end
62
62
 
@@ -64,6 +64,10 @@ module ApexCharts
64
64
  @defer ||= options.delete(:defer)
65
65
  end
66
66
 
67
+ def module?
68
+ @module ||= options.delete(:module)
69
+ end
70
+
67
71
  def attributes
68
72
  @attributes ||= options.delete(:div) { {} }
69
73
  end
@@ -97,8 +101,9 @@ module ApexCharts
97
101
  end
98
102
 
99
103
  def script(js)
104
+ type = module? ? 'module' : 'text/javascript'
100
105
  <<~SCRIPT
101
- <script type="text/javascript" apexcharts-rb="#{RELEASE}">
106
+ <script type="#{type}" apexcharts-rb="#{RELEASE}" >
102
107
  #{js}
103
108
  </script>
104
109
  SCRIPT
@@ -106,7 +111,7 @@ module ApexCharts
106
111
 
107
112
  def indent(content, times=2)
108
113
  content.lines.map.with_index do |line, index|
109
- (index == 0 ? '' : ' ' * times) + line
114
+ (index.zero? ? '' : ' ' * times) + line
110
115
  end.join
111
116
  end
112
117
  end
@@ -20,9 +20,8 @@ module ApexCharts::Series
20
20
  end
21
21
 
22
22
  when Hash
23
- if data_value = data[:data]
24
- [data] if array_of_threes?(data_value)
25
- end
23
+ data_value = data[:data]
24
+ [data] if data_value && array_of_threes?(data_value)
26
25
 
27
26
  end
28
27