apexcharts 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +248 -52
- data/lib/apexcharts.rb +2 -1
- data/lib/apexcharts/charts.rb +11 -18
- data/lib/apexcharts/charts/base.rb +19 -18
- data/lib/apexcharts/charts/bubble.rb +2 -8
- data/lib/apexcharts/charts/cartesian.rb +30 -29
- data/lib/apexcharts/charts/donut.rb +0 -1
- data/lib/apexcharts/charts/features/annotations.rb +16 -17
- data/lib/apexcharts/charts/features/mixable.rb +1 -2
- data/lib/apexcharts/charts/heatmap.rb +2 -4
- data/lib/apexcharts/charts/mixed.rb +42 -32
- data/lib/apexcharts/charts/pie.rb +0 -1
- data/lib/apexcharts/charts/polar.rb +2 -9
- data/lib/apexcharts/charts/radar.rb +2 -4
- data/lib/apexcharts/charts/radial_bar.rb +0 -1
- data/lib/apexcharts/charts/syncing.rb +39 -25
- data/lib/apexcharts/colors.rb +4 -6
- data/lib/apexcharts/config.rb +25 -0
- data/lib/apexcharts/config/default_options.rb +12 -0
- data/lib/apexcharts/helper.rb +151 -87
- data/lib/apexcharts/options/annotations.rb +5 -5
- data/lib/apexcharts/options/axis.rb +12 -12
- data/lib/apexcharts/options/chart.rb +21 -21
- data/lib/apexcharts/options/data_labels.rb +9 -7
- data/lib/apexcharts/options/div_attributes.rb +4 -5
- data/lib/apexcharts/options/fill.rb +7 -7
- data/lib/apexcharts/options/grid.rb +10 -10
- data/lib/apexcharts/options/legend.rb +22 -19
- data/lib/apexcharts/options/markers.rb +13 -13
- data/lib/apexcharts/options/no_data.rb +7 -7
- data/lib/apexcharts/options/plot_options.rb +7 -7
- data/lib/apexcharts/options/root.rb +30 -30
- data/lib/apexcharts/options/states.rb +4 -4
- data/lib/apexcharts/options/stroke.rb +7 -7
- data/lib/apexcharts/options/subtitle.rb +3 -1
- data/lib/apexcharts/options/theme.rb +3 -3
- data/lib/apexcharts/options/title.rb +8 -8
- data/lib/apexcharts/options/tooltip.rb +17 -17
- data/lib/apexcharts/options/x_axis.rb +5 -5
- data/lib/apexcharts/options/y_axis.rb +8 -8
- data/lib/apexcharts/options_builder.rb +49 -60
- data/lib/apexcharts/prefix_with_apex.rb +5 -0
- data/lib/apexcharts/prefixer.rb +19 -0
- data/lib/apexcharts/renderer.rb +64 -17
- data/lib/apexcharts/series.rb +5 -3
- data/lib/apexcharts/series/bubble.rb +33 -22
- data/lib/apexcharts/series/cartesian.rb +63 -49
- data/lib/apexcharts/series/polar.rb +31 -17
- data/lib/apexcharts/support/rails.rb +1 -1
- data/lib/apexcharts/support/sinatra.rb +9 -0
- data/lib/apexcharts/theme.rb +5 -6
- data/lib/apexcharts/utils.rb +1 -0
- data/lib/apexcharts/utils/copy.rb +9 -0
- data/lib/apexcharts/utils/date_time.rb +50 -44
- data/lib/apexcharts/utils/hash.rb +2 -3
- data/lib/apexcharts/version.rb +1 -1
- data/vendor/assets/javascripts/apexcharts.js +2 -2
- metadata +27 -7
@@ -1,15 +1,15 @@
|
|
1
1
|
module ApexCharts
|
2
2
|
class GridOptions < ::SmartKv
|
3
3
|
optional *%i[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
borderColor
|
5
|
+
column
|
6
|
+
padding
|
7
|
+
position
|
8
|
+
row
|
9
|
+
show
|
10
|
+
strokeDashArray
|
11
|
+
xaxis
|
12
|
+
yaxis
|
13
|
+
]
|
14
14
|
end
|
15
15
|
end
|
@@ -1,24 +1,27 @@
|
|
1
1
|
module ApexCharts
|
2
2
|
class LegendOptions < ::SmartKv
|
3
3
|
optional *%i[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
4
|
+
containerMargin
|
5
|
+
floating
|
6
|
+
fontFamily
|
7
|
+
fontSize
|
8
|
+
formatter
|
9
|
+
height
|
10
|
+
horizontalAlign
|
11
|
+
itemMargin
|
12
|
+
labels
|
13
|
+
markers
|
14
|
+
offsetX
|
15
|
+
offsetY
|
16
|
+
onItemClick
|
17
|
+
onItemHover
|
18
|
+
position
|
19
|
+
show
|
20
|
+
showForNullSeries
|
21
|
+
showForSingleSeries
|
22
|
+
showForZeroSeries
|
23
|
+
textAnchor
|
24
|
+
width
|
25
|
+
]
|
23
26
|
end
|
24
27
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module ApexCharts
|
2
2
|
class MarkersOptions < ::SmartKv
|
3
3
|
optional *%i[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
colors
|
5
|
+
discrete
|
6
|
+
fillOpacity
|
7
|
+
hover
|
8
|
+
offsetX
|
9
|
+
offsetY
|
10
|
+
radius
|
11
|
+
shape
|
12
|
+
size
|
13
|
+
strokeColor
|
14
|
+
strokeOpacity
|
15
|
+
strokeWidth
|
16
|
+
]
|
17
17
|
end
|
18
18
|
end
|
@@ -6,36 +6,36 @@ require_relative 'states'
|
|
6
6
|
module ApexCharts
|
7
7
|
class RootOptions < ::SmartKv
|
8
8
|
optional *%i[
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
9
|
+
annotations
|
10
|
+
brushTarget
|
11
|
+
chart
|
12
|
+
chartId
|
13
|
+
colors
|
14
|
+
dataLabels
|
15
|
+
fill
|
16
|
+
grid
|
17
|
+
group
|
18
|
+
labels
|
19
|
+
legend
|
20
|
+
markers
|
21
|
+
noData
|
22
|
+
plotOptions
|
23
|
+
responsive
|
24
|
+
series
|
25
|
+
states
|
26
|
+
stroke
|
27
|
+
subtitle
|
28
|
+
theme
|
29
|
+
title
|
30
|
+
tooltip
|
31
|
+
var
|
32
|
+
xaxis
|
33
|
+
xtitle
|
34
|
+
xtype
|
35
|
+
yaxis
|
36
|
+
ytitle
|
37
|
+
ytype
|
38
|
+
],
|
39
39
|
*DivAttributes.optional_keys,
|
40
40
|
*ChartOptions.optional_keys,
|
41
41
|
*StrokeOptions.optional_keys,
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module ApexCharts
|
2
2
|
class TooltipOptions < ::SmartKv
|
3
3
|
optional *%i[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
custom
|
5
|
+
enabled
|
6
|
+
fillSeriesColor
|
7
|
+
fixed
|
8
|
+
followCursor
|
9
|
+
intersect
|
10
|
+
inverseOrder
|
11
|
+
items
|
12
|
+
marker
|
13
|
+
onDatasetHover
|
14
|
+
shared
|
15
|
+
style
|
16
|
+
theme
|
17
|
+
x
|
18
|
+
y
|
19
|
+
z
|
20
|
+
]
|
21
21
|
end
|
22
22
|
end
|
@@ -3,13 +3,13 @@ require_relative 'axis'
|
|
3
3
|
module ApexCharts
|
4
4
|
class YAxisOptions < AxisOptions
|
5
5
|
optional *%i[
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
decimalsInFloat
|
7
|
+
forceNiceScale
|
8
|
+
logarithmic
|
9
|
+
opposite
|
10
|
+
seriesName
|
11
|
+
show
|
12
|
+
showAlways
|
13
|
+
]
|
14
14
|
end
|
15
15
|
end
|
@@ -19,14 +19,17 @@ require_relative 'options/y_axis'
|
|
19
19
|
|
20
20
|
module ApexCharts
|
21
21
|
class OptionsBuilder
|
22
|
+
include Utils::Hash
|
23
|
+
include Utils::DateTime
|
24
|
+
|
22
25
|
attr_reader :built
|
23
26
|
|
24
|
-
def initialize(
|
25
|
-
@options =
|
27
|
+
def initialize(sample, options)
|
28
|
+
@options = camelize_keys(options)
|
26
29
|
if options[:plotOptions]&.[](:bar)&.[](:horizontal)
|
27
|
-
@ytype =
|
30
|
+
@ytype = type(sample)
|
28
31
|
else
|
29
|
-
@xtype =
|
32
|
+
@xtype = type(sample)
|
30
33
|
end
|
31
34
|
@built = {}
|
32
35
|
end
|
@@ -36,6 +39,10 @@ module ApexCharts
|
|
36
39
|
|
37
40
|
build_chart
|
38
41
|
build_div
|
42
|
+
build_general_options
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_general_options
|
39
46
|
build_annotations
|
40
47
|
build_colors
|
41
48
|
build_data_labels
|
@@ -69,25 +76,18 @@ module ApexCharts
|
|
69
76
|
|
70
77
|
def build_annotations
|
71
78
|
annotations = @options.delete :annotations
|
72
|
-
@built[:annotations] =
|
73
|
-
|
74
|
-
|
79
|
+
@built[:annotations] = (
|
80
|
+
AnnotationsOptions.check annotations.compact if annotations.is_a? Hash
|
81
|
+
)
|
75
82
|
end
|
76
83
|
|
77
84
|
def build_chart
|
78
|
-
@built[:chart] =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
selection: {
|
85
|
-
enabled: true
|
86
|
-
}
|
87
|
-
}
|
88
|
-
else
|
89
|
-
{}
|
90
|
-
end
|
85
|
+
@built[:chart] =
|
86
|
+
if target = @options.delete(:brushTarget)
|
87
|
+
{brush: {enabled: true, target: target.to_s}, selection: {enabled: true}}
|
88
|
+
else
|
89
|
+
{}
|
90
|
+
end
|
91
91
|
|
92
92
|
@built[:chart].merge!({
|
93
93
|
id: @options[:chartId] || @options[:id],
|
@@ -102,9 +102,10 @@ module ApexCharts
|
|
102
102
|
}.compact)
|
103
103
|
|
104
104
|
chart = @options.delete :chart
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
|
106
|
+
return unless chart.is_a? Hash
|
107
|
+
|
108
|
+
@built[:chart].merge! ChartOptions.check(chart.compact)
|
108
109
|
end
|
109
110
|
|
110
111
|
def build_colors
|
@@ -116,11 +117,12 @@ module ApexCharts
|
|
116
117
|
def build_data_labels
|
117
118
|
data_labels = @options.delete :dataLabels
|
118
119
|
return if data_labels.nil?
|
120
|
+
|
119
121
|
@built[:dataLabels] = if [true, false].include? data_labels
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
122
|
+
{enabled: data_labels}
|
123
|
+
elsif data_labels.is_a? Hash
|
124
|
+
DataLabelsOptions.check data_labels.compact
|
125
|
+
end
|
124
126
|
end
|
125
127
|
|
126
128
|
def build_fill
|
@@ -170,17 +172,15 @@ module ApexCharts
|
|
170
172
|
def build_no_data
|
171
173
|
no_data = @options.delete :noData
|
172
174
|
@built[:noData] = if no_data.is_a? String
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
175
|
+
{text: no_data}
|
176
|
+
elsif no_data.is_a? Hash
|
177
|
+
NoDataOptions.check no_data.compact
|
178
|
+
end
|
177
179
|
end
|
178
180
|
|
179
181
|
def build_plot_options
|
180
182
|
plot_options = @options.delete :plotOptions
|
181
|
-
@built[:plotOptions] = if plot_options.is_a? Hash
|
182
|
-
PlotOptions.check plot_options.compact
|
183
|
-
end
|
183
|
+
@built[:plotOptions] = (PlotOptions.check plot_options.compact if plot_options.is_a? Hash)
|
184
184
|
end
|
185
185
|
|
186
186
|
def build_responsive
|
@@ -191,15 +191,13 @@ module ApexCharts
|
|
191
191
|
|
192
192
|
def build_states
|
193
193
|
@built[:states] = {
|
194
|
-
normal: filter_type_hash(@options.delete
|
195
|
-
hover: filter_type_hash(@options.delete
|
196
|
-
active: filter_type_hash(@options.delete
|
194
|
+
normal: filter_type_hash(@options.delete(:normal)),
|
195
|
+
hover: filter_type_hash(@options.delete(:hover)),
|
196
|
+
active: filter_type_hash(@options.delete(:active))
|
197
197
|
}.compact
|
198
198
|
|
199
199
|
states = @options.delete :states
|
200
|
-
if states.is_a? Hash
|
201
|
-
@built[:states].merge! StatesOptions.check(states.compact)
|
202
|
-
end
|
200
|
+
@built[:states].merge! StatesOptions.check(states.compact) if states.is_a? Hash
|
203
201
|
|
204
202
|
@built[:states] = nil if @built[:states].empty?
|
205
203
|
end
|
@@ -210,7 +208,7 @@ module ApexCharts
|
|
210
208
|
|
211
209
|
stroke = @options.delete :stroke
|
212
210
|
if [true, false].include? stroke
|
213
|
-
@built[:stroke].merge!(
|
211
|
+
@built[:stroke].merge!(show: stroke)
|
214
212
|
elsif stroke.is_a? Hash
|
215
213
|
@built[:stroke].merge! StrokeOptions.check(stroke.compact)
|
216
214
|
end
|
@@ -264,14 +262,12 @@ module ApexCharts
|
|
264
262
|
def build_xaxis
|
265
263
|
xaxis = @options.delete :xaxis
|
266
264
|
@built[:xaxis] = {
|
267
|
-
type: @options.delete(:xtype){ @xtype },
|
265
|
+
type: @options.delete(:xtype) { @xtype },
|
268
266
|
title: {
|
269
267
|
text: @options.delete(:xtitle)
|
270
268
|
}.compact
|
271
269
|
}.compact
|
272
|
-
if @built[:xaxis][:title].empty?
|
273
|
-
@built[:xaxis].delete(:title)
|
274
|
-
end
|
270
|
+
@built[:xaxis].delete(:title) if @built[:xaxis][:title].empty?
|
275
271
|
|
276
272
|
if xaxis.is_a? String
|
277
273
|
@built[:xaxis][:title] = {text: xaxis}
|
@@ -279,19 +275,19 @@ module ApexCharts
|
|
279
275
|
XAxisOptions.check xaxis
|
280
276
|
@built[:xaxis].merge! xaxis
|
281
277
|
end
|
278
|
+
|
279
|
+
@built[:xaxis] = nil if @built[:xaxis].empty?
|
282
280
|
end
|
283
281
|
|
284
282
|
def build_yaxis
|
285
283
|
yaxis = @options.delete :yaxis
|
286
284
|
@built[:yaxis] = [{
|
287
|
-
type: @options.delete(:ytype){ @ytype },
|
285
|
+
type: @options.delete(:ytype) { @ytype },
|
288
286
|
title: {
|
289
287
|
text: @options.delete(:ytitle)
|
290
288
|
}.compact
|
291
289
|
}.compact]
|
292
|
-
if @built[:yaxis][0][:title].empty?
|
293
|
-
@built[:yaxis][0].delete(:title)
|
294
|
-
end
|
290
|
+
@built[:yaxis][0].delete(:title) if @built[:yaxis][0][:title].empty?
|
295
291
|
|
296
292
|
if yaxis.is_a? String
|
297
293
|
@built[:yaxis][0][:title] = {text: yaxis}
|
@@ -299,26 +295,19 @@ module ApexCharts
|
|
299
295
|
YAxisOptions.check yaxis
|
300
296
|
@built[:yaxis][0].merge! yaxis
|
301
297
|
end
|
302
|
-
end
|
303
298
|
|
304
|
-
|
305
|
-
if DateTime.iso8601(x).iso8601 == x
|
306
|
-
'datetime'
|
307
|
-
elsif Date.iso8601(x).iso8601 = x
|
308
|
-
'datetime'
|
309
|
-
end
|
310
|
-
rescue
|
311
|
-
'numeric'
|
299
|
+
@built[:yaxis] = nil if @built[:yaxis].all?(&:empty?)
|
312
300
|
end
|
313
301
|
|
314
302
|
def enabled(options)
|
315
|
-
boolean_to_hash(options) do |
|
316
|
-
{enabled:
|
303
|
+
boolean_to_hash(options) do |opts|
|
304
|
+
{enabled: opts}
|
317
305
|
end
|
318
306
|
end
|
319
307
|
|
320
308
|
def boolean_to_hash(options)
|
321
309
|
return if options.nil?
|
310
|
+
|
322
311
|
if [true, false].include? options
|
323
312
|
yield(options)
|
324
313
|
elsif options.is_a?(Hash)
|