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,34 +1,35 @@
|
|
1
1
|
module ApexCharts
|
2
2
|
class BaseChart
|
3
|
-
|
3
|
+
include Utils::Hash
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
{**@series, chart: {type: chart_type}}.compact
|
11
|
-
)
|
12
|
-
)
|
5
|
+
attr_reader :options, :series, :sample
|
6
|
+
|
7
|
+
def initialize(data, options={})
|
8
|
+
@series = build_series(data)
|
9
|
+
@options = build_options(options)
|
13
10
|
end
|
14
11
|
|
15
12
|
def render
|
16
|
-
|
13
|
+
Renderer.render_default(options)
|
17
14
|
end
|
18
15
|
|
19
|
-
def chart_type
|
20
|
-
end
|
16
|
+
def chart_type; end
|
21
17
|
|
22
18
|
protected
|
23
19
|
|
24
|
-
def
|
25
|
-
|
20
|
+
def build_series(data)
|
21
|
+
series_object = series_type.new(data)
|
22
|
+
@sample = series_object.sample
|
23
|
+
series_object.sanitized
|
26
24
|
end
|
27
25
|
|
28
|
-
def
|
29
|
-
|
26
|
+
def build_options(options)
|
27
|
+
deep_merge(
|
28
|
+
OptionsBuilder.new(sample, options).build_options,
|
29
|
+
camelize_keys(
|
30
|
+
{**@series, chart: {type: chart_type}}.compact
|
31
|
+
)
|
32
|
+
)
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
33
|
-
|
34
|
-
|
@@ -2,67 +2,69 @@
|
|
2
2
|
|
3
3
|
require_relative 'features/annotations'
|
4
4
|
require_relative 'features/mixable'
|
5
|
+
require_relative '../utils/hash'
|
5
6
|
|
6
7
|
module ApexCharts
|
7
8
|
class CartesianChart < BaseChart
|
8
9
|
include Annotations
|
9
10
|
include Mixable
|
11
|
+
include Utils::Hash
|
10
12
|
|
11
|
-
def initialize
|
12
|
-
@
|
13
|
-
options =
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def initialize(outer_self, data, options={}, &block)
|
14
|
+
@outer_self = outer_self
|
15
|
+
options = deep_merge(
|
16
|
+
camelize_keys(options),
|
17
|
+
camelize_keys(more_options)
|
18
|
+
)
|
17
19
|
|
18
|
-
build_instance_variables if @
|
20
|
+
build_instance_variables if @outer_self
|
19
21
|
|
20
22
|
instance_eval &block if block_given?
|
21
23
|
|
22
24
|
options[:annotations] = @annotations if @annotations
|
23
|
-
@series =
|
24
|
-
@options =
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
get_selection_range if brush?
|
25
|
+
@series = build_series(data)
|
26
|
+
@options = build_options(options)
|
27
|
+
|
28
|
+
build_selection_range if brush?
|
29
|
+
end
|
30
|
+
|
31
|
+
def series_type
|
32
|
+
CartesianSeries
|
32
33
|
end
|
33
34
|
|
34
35
|
def more_options
|
35
36
|
{}
|
36
37
|
end
|
37
38
|
|
38
|
-
def method_missing
|
39
|
-
if @
|
40
|
-
@
|
39
|
+
def method_missing(method, *args, &block)
|
40
|
+
if @outer_self.respond_to?(method)
|
41
|
+
@outer_self.send method, *args, &block
|
41
42
|
else
|
42
43
|
super
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
def respond_to_missing?(method, *args)
|
48
|
+
@outer_self.respond_to?(method) || super
|
49
|
+
end
|
50
|
+
|
46
51
|
protected
|
47
52
|
|
48
53
|
def build_instance_variables
|
49
|
-
(@
|
50
|
-
instance_variable_set(i, @
|
54
|
+
(@outer_self.instance_variables - instance_variables).each do |i|
|
55
|
+
instance_variable_set(i, @outer_self.instance_variable_get(i))
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
54
|
-
def sanitize_data(data)
|
55
|
-
ApexCharts::CartesianSeries.new(data).sanitized
|
56
|
-
end
|
57
|
-
|
58
59
|
def brush?
|
59
60
|
@options[:chart][:brush]&.[](:enabled) && \
|
60
61
|
!@options[:chart][:selection]&.[](:xaxis)
|
61
62
|
end
|
62
63
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
64
|
+
def build_selection_range
|
65
|
+
last_data = @series[:series].last[:data]
|
66
|
+
first_x = last_data.first[:x]
|
67
|
+
last_x = last_data.last[:x]
|
66
68
|
@options[:chart][:selection][:xaxis] = {
|
67
69
|
min: handle_time(twenty_percent_before_last_x(first_x, last_x)),
|
68
70
|
max: handle_time(last_x)
|
@@ -78,4 +80,3 @@ module ApexCharts
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
81
|
-
|
@@ -3,36 +3,35 @@ module ApexCharts
|
|
3
3
|
def annotation(axis, value:, text:, color: nil, **options)
|
4
4
|
@annotations ||= {}
|
5
5
|
|
6
|
-
unless [
|
7
|
-
|
8
|
-
end
|
6
|
+
raise "unrecognized axis: #{axis}" unless %i[xaxis yaxis points].include? axis
|
7
|
+
|
9
8
|
@annotations[axis] ||= []
|
10
9
|
@annotations[axis] << annotation_value(axis, value).merge(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
if axis == :points
|
11
|
+
{marker: {size: 8, fillColor: 'white', strokeColor: color, radius: 2}, **options}
|
12
|
+
else
|
13
|
+
{borderColor: color, fillColor: color, opacity: 0.2}
|
14
|
+
end
|
15
|
+
).merge(
|
16
|
+
annotation_label(text, color, **options)
|
17
|
+
)
|
19
18
|
end
|
20
19
|
|
21
|
-
def x_annotation
|
20
|
+
def x_annotation(**args)
|
22
21
|
annotation :xaxis, **args
|
23
22
|
end
|
24
23
|
|
25
|
-
def y_annotation
|
24
|
+
def y_annotation(**args)
|
26
25
|
annotation :yaxis, **args
|
27
26
|
end
|
28
27
|
|
29
|
-
def point_annotation
|
28
|
+
def point_annotation(**args)
|
30
29
|
annotation :points, **args
|
31
30
|
end
|
32
31
|
|
33
32
|
private
|
34
33
|
|
35
|
-
def annotation_value
|
34
|
+
def annotation_value(axis, value)
|
36
35
|
axis = axis.to_s.delete_suffix('axis').to_sym
|
37
36
|
case value
|
38
37
|
when Range
|
@@ -48,7 +47,7 @@ module ApexCharts
|
|
48
47
|
end
|
49
48
|
else
|
50
49
|
if axis == :points
|
51
|
-
value.map!{
|
50
|
+
value.map! {|x| Utils::DateTime.convert(x) }
|
52
51
|
{x: value.first, y: value.last}
|
53
52
|
else
|
54
53
|
value = Utils::DateTime.convert(value)
|
@@ -57,7 +56,7 @@ module ApexCharts
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
def annotation_label
|
59
|
+
def annotation_label(text, color, **options)
|
61
60
|
{
|
62
61
|
label: {
|
63
62
|
borderColor: color,
|
@@ -3,9 +3,10 @@
|
|
3
3
|
module ApexCharts
|
4
4
|
class MixedCharts < BaseChart
|
5
5
|
include Annotations
|
6
|
+
include Utils::Hash
|
6
7
|
|
7
|
-
def initialize
|
8
|
-
@
|
8
|
+
def initialize(outer_self, options={}, &block)
|
9
|
+
@outer_self = outer_self
|
9
10
|
@series = {series: []}
|
10
11
|
options[:id] ||= apexcharts_id
|
11
12
|
build_instance_variables
|
@@ -13,50 +14,58 @@ module ApexCharts
|
|
13
14
|
instance_eval &block
|
14
15
|
|
15
16
|
options[:annotations] = @annotations if @annotations
|
16
|
-
@options =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
@options = build_options(options)
|
18
|
+
|
19
|
+
build_selection_range if brush?
|
20
|
+
end
|
21
|
+
|
22
|
+
def line_chart(data, options={}, &block)
|
23
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
24
|
+
@series[:series] +=
|
25
|
+
LineChart.new(outer_self, data, options, &block).mixed_series
|
24
26
|
end
|
25
27
|
|
26
|
-
def
|
27
|
-
|
28
|
-
@series[:series] +=
|
28
|
+
def area_chart(data, options={}, &block)
|
29
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
30
|
+
@series[:series] +=
|
31
|
+
AreaChart.new(outer_self, data, options, &block).mixed_series
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
32
|
-
|
33
|
-
@series[:series] +=
|
34
|
+
def bar_chart(data, options={}, &block)
|
35
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
36
|
+
@series[:series] +=
|
37
|
+
BarChart.new(outer_self, data, options, &block).mixed_series
|
34
38
|
end
|
35
39
|
|
36
|
-
def
|
37
|
-
|
38
|
-
@series[:series] +=
|
40
|
+
def column_chart(data, options={}, &block)
|
41
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
42
|
+
@series[:series] +=
|
43
|
+
ColumnChart.new(outer_self, data, options, &block).mixed_series
|
39
44
|
end
|
40
45
|
|
41
|
-
def
|
42
|
-
|
43
|
-
@series[:series] +=
|
46
|
+
def scatter_chart(data, options={}, &block)
|
47
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
48
|
+
@series[:series] +=
|
49
|
+
ScatterChart.new(outer_self, data, options, &block).mixed_series
|
44
50
|
end
|
45
51
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
52
|
+
def method_missing(method, *args, &block)
|
53
|
+
if @outer_self.respond_to?(method)
|
54
|
+
@outer_self.send method, *args, &block
|
55
|
+
else
|
56
|
+
super
|
57
|
+
end
|
49
58
|
end
|
50
59
|
|
51
|
-
def
|
52
|
-
@
|
60
|
+
def respond_to_missing?(method, *args)
|
61
|
+
@outer_self.respond_to?(method) || super
|
53
62
|
end
|
54
63
|
|
55
64
|
private
|
56
65
|
|
57
66
|
def build_instance_variables
|
58
|
-
(@
|
59
|
-
instance_variable_set(i, @
|
67
|
+
(@outer_self.instance_variables - instance_variables).each do |i|
|
68
|
+
instance_variable_set(i, @outer_self.instance_variable_get(i))
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
@@ -65,9 +74,10 @@ module ApexCharts
|
|
65
74
|
!@options[:chart][:selection]&.[](:xaxis)
|
66
75
|
end
|
67
76
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
77
|
+
def build_selection_range
|
78
|
+
last_data = @series[:series].last[:data]
|
79
|
+
first_x = last_data.first[:x]
|
80
|
+
last_x = last_data.last[:x]
|
71
81
|
@options[:chart][:selection][:xaxis] = {
|
72
82
|
min: handle_time(twenty_percent_before_last_x(first_x, last_x)),
|
73
83
|
max: handle_time(last_x)
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
module ApexCharts
|
4
4
|
class SyncingCharts
|
5
|
-
def initialize
|
6
|
-
@
|
7
|
-
@html =
|
5
|
+
def initialize(outer_self, options={}, &block)
|
6
|
+
@outer_self = outer_self
|
7
|
+
@html = ''
|
8
8
|
build_instance_variables
|
9
9
|
@options = options
|
10
10
|
@options[:group] ||= apexcharts_group
|
@@ -14,40 +14,46 @@ module ApexCharts
|
|
14
14
|
@options[:annotations] = @annotations if @annotations
|
15
15
|
end
|
16
16
|
|
17
|
-
def line_chart
|
17
|
+
def line_chart(data, options={}, &block)
|
18
18
|
options[:id] = apexcharts_id
|
19
|
-
|
20
|
-
@html +=
|
19
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
20
|
+
@html +=
|
21
|
+
LineChart.new(outer_self, data, @options.merge(options), &block).render
|
21
22
|
end
|
22
23
|
|
23
|
-
def area_chart
|
24
|
+
def area_chart(data, options={}, &block)
|
24
25
|
options[:id] = apexcharts_id
|
25
|
-
|
26
|
-
@html +=
|
26
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
27
|
+
@html +=
|
28
|
+
AreaChart.new(outer_self, data, @options.merge(options), &block).render
|
27
29
|
end
|
28
30
|
|
29
|
-
def bar_chart
|
31
|
+
def bar_chart(data, options={}, &block)
|
30
32
|
options[:id] = apexcharts_id
|
31
|
-
|
32
|
-
@html +=
|
33
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
34
|
+
@html +=
|
35
|
+
BarChart.new(outer_self, data, @options.merge(options), &block).render
|
33
36
|
end
|
34
37
|
|
35
|
-
def column_chart
|
38
|
+
def column_chart(data, options={}, &block)
|
36
39
|
options[:id] = apexcharts_id
|
37
|
-
|
38
|
-
@html +=
|
40
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
41
|
+
@html +=
|
42
|
+
ColumnChart.new(outer_self, data, @options.merge(options), &block).render
|
39
43
|
end
|
40
44
|
|
41
|
-
def scatter_chart
|
45
|
+
def scatter_chart(data, options={}, &block)
|
42
46
|
options[:id] = apexcharts_id
|
43
|
-
|
44
|
-
@html +=
|
47
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
48
|
+
@html +=
|
49
|
+
ScatterChart.new(outer_self, data, @options.merge(options), &block).render
|
45
50
|
end
|
46
51
|
|
47
|
-
def mixed_charts
|
52
|
+
def mixed_charts(options={}, &block)
|
48
53
|
options[:id] = apexcharts_id
|
49
|
-
|
50
|
-
@html +=
|
54
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__)
|
55
|
+
@html +=
|
56
|
+
MixedCharts.new(outer_self, @options.merge(options), &block).render
|
51
57
|
end
|
52
58
|
alias_method :combo_charts, :mixed_charts
|
53
59
|
|
@@ -55,15 +61,23 @@ module ApexCharts
|
|
55
61
|
@html
|
56
62
|
end
|
57
63
|
|
58
|
-
def method_missing
|
59
|
-
@
|
64
|
+
def method_missing(method, *args, &block)
|
65
|
+
if @outer_self.respond_to? method, *args
|
66
|
+
@outer_self.send method, *args, &block
|
67
|
+
else
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def respond_to_missing?(method, *args)
|
73
|
+
@outer_self.respond_to? method, *args || super
|
60
74
|
end
|
61
75
|
|
62
76
|
private
|
63
77
|
|
64
78
|
def build_instance_variables
|
65
|
-
(@
|
66
|
-
instance_variable_set(i, @
|
79
|
+
(@outer_self.instance_variables - instance_variables).each do |i|
|
80
|
+
instance_variable_set(i, @outer_self.instance_variable_get(i))
|
67
81
|
end
|
68
82
|
end
|
69
83
|
end
|