apexcharts 0.1.5 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +456 -38
- data/lib/apex_charts/charts.rb +16 -0
- data/lib/{apexcharts/charts/area.rb → apex_charts/charts/area_chart.rb} +1 -1
- data/lib/{apexcharts/charts/bar.rb → apex_charts/charts/bar_chart.rb} +1 -1
- data/lib/apex_charts/charts/base_chart.rb +37 -0
- data/lib/apex_charts/charts/bubble_chart.rb +13 -0
- data/lib/{apexcharts/charts/candlestick.rb → apex_charts/charts/candlestick_chart.rb} +1 -1
- data/lib/apex_charts/charts/cartesian_chart.rb +82 -0
- data/lib/{apexcharts/charts/column.rb → apex_charts/charts/column_chart.rb} +3 -1
- data/lib/{apexcharts/charts/donut.rb → apex_charts/charts/donut_chart.rb} +1 -2
- data/lib/{apexcharts → apex_charts}/charts/features/annotations.rb +22 -21
- data/lib/{apexcharts → apex_charts}/charts/features/mixable.rb +2 -3
- data/lib/{apexcharts/charts/heatmap.rb → apex_charts/charts/heatmap_chart.rb} +3 -5
- data/lib/{apexcharts/charts/line.rb → apex_charts/charts/line_chart.rb} +1 -1
- data/lib/apex_charts/charts/mixed_charts.rb +101 -0
- data/lib/{apexcharts/charts/pie.rb → apex_charts/charts/pie_chart.rb} +1 -2
- data/lib/apex_charts/charts/polar_chart.rb +9 -0
- data/lib/{apexcharts/charts/radar.rb → apex_charts/charts/radar_chart.rb} +3 -5
- data/lib/{apexcharts/charts/radial_bar.rb → apex_charts/charts/radial_bar_chart.rb} +1 -2
- data/lib/apex_charts/charts/range_bar_chart.rb +9 -0
- data/lib/{apexcharts/charts/scatter.rb → apex_charts/charts/scatter_chart.rb} +1 -1
- data/lib/apex_charts/charts/syncing_charts.rb +84 -0
- data/lib/apex_charts/colors.rb +27 -0
- data/lib/apex_charts/config/default_options.rb +16 -0
- data/lib/apex_charts/configuration.rb +25 -0
- data/lib/apex_charts/helper.rb +190 -0
- data/lib/apex_charts/options/annotations_options.rb +15 -0
- data/lib/apex_charts/options/chart_options.rb +32 -0
- data/lib/apex_charts/options/data_labels_options.rb +18 -0
- data/lib/apex_charts/options/div_attributes.rb +11 -0
- data/lib/apex_charts/options/fill_options.rb +14 -0
- data/lib/apex_charts/options/grid_options.rb +17 -0
- data/lib/apex_charts/options/legend_options.rb +32 -0
- data/lib/apex_charts/options/markers_options.rb +24 -0
- data/lib/apex_charts/options/no_data_options.rb +14 -0
- data/lib/apex_charts/options/plot_options.rb +16 -0
- data/lib/apex_charts/options/root_options.rb +47 -0
- data/lib/apex_charts/options/states_options.rb +11 -0
- data/lib/apex_charts/options/stroke_options.rb +14 -0
- data/lib/apex_charts/options/theme_options.rb +11 -0
- data/lib/apex_charts/options/title_subtitle_options.rb +15 -0
- data/lib/apex_charts/options/tooltip_options.rb +25 -0
- data/lib/apex_charts/options/x_axis_options.rb +26 -0
- data/lib/apex_charts/options/y_axis_options.rb +28 -0
- data/lib/{apexcharts → apex_charts}/options_builder.rb +95 -90
- data/lib/apex_charts/prefix_with_apex.rb +7 -0
- data/lib/apex_charts/prefixer.rb +21 -0
- data/lib/apex_charts/renderer.rb +113 -0
- data/lib/apex_charts/series.rb +7 -0
- data/lib/apex_charts/series/bubble_series.rb +50 -0
- data/lib/apex_charts/series/cartesian_series.rb +81 -0
- data/lib/apex_charts/series/polar_series.rb +48 -0
- data/lib/{apexcharts → apex_charts}/support/rails.rb +1 -1
- data/lib/apex_charts/support/sinatra.rb +9 -0
- data/lib/apex_charts/theme.rb +60 -0
- data/lib/{apexcharts → apex_charts}/utils.rb +1 -0
- data/lib/apex_charts/utils/copy.rb +11 -0
- data/lib/apex_charts/utils/date_time.rb +70 -0
- data/lib/{apexcharts → apex_charts}/utils/hash.rb +4 -3
- data/lib/{apexcharts → apex_charts}/version.rb +2 -1
- data/lib/apexcharts.rb +3 -2
- data/vendor/assets/javascripts/apexcharts.js +11 -3
- metadata +85 -65
- data/lib/apexcharts/charts.rb +0 -19
- data/lib/apexcharts/charts/base.rb +0 -34
- data/lib/apexcharts/charts/bubble.rb +0 -19
- data/lib/apexcharts/charts/cartesian.rb +0 -81
- data/lib/apexcharts/charts/mixed.rb +0 -85
- data/lib/apexcharts/charts/polar.rb +0 -14
- data/lib/apexcharts/charts/syncing.rb +0 -70
- data/lib/apexcharts/helper.rb +0 -109
- data/lib/apexcharts/options/annotations.rb +0 -10
- data/lib/apexcharts/options/axis.rb +0 -17
- data/lib/apexcharts/options/chart.rb +0 -26
- data/lib/apexcharts/options/data_labels.rb +0 -12
- data/lib/apexcharts/options/div_attributes.rb +0 -10
- data/lib/apexcharts/options/fill.rb +0 -12
- data/lib/apexcharts/options/grid.rb +0 -15
- data/lib/apexcharts/options/legend.rb +0 -24
- data/lib/apexcharts/options/markers.rb +0 -18
- data/lib/apexcharts/options/no_data.rb +0 -12
- data/lib/apexcharts/options/plot_options.rb +0 -12
- data/lib/apexcharts/options/root.rb +0 -42
- data/lib/apexcharts/options/states.rb +0 -9
- data/lib/apexcharts/options/stroke.rb +0 -12
- data/lib/apexcharts/options/subtitle.rb +0 -7
- data/lib/apexcharts/options/theme.rb +0 -8
- data/lib/apexcharts/options/title.rb +0 -13
- data/lib/apexcharts/options/tooltip.rb +0 -22
- data/lib/apexcharts/options/x_axis.rb +0 -12
- data/lib/apexcharts/options/y_axis.rb +0 -15
- data/lib/apexcharts/renderer.rb +0 -21
- data/lib/apexcharts/series.rb +0 -5
- data/lib/apexcharts/series/bubble.rb +0 -37
- data/lib/apexcharts/series/cartesian.rb +0 -65
- data/lib/apexcharts/series/polar.rb +0 -32
- data/lib/apexcharts/utils/date_time.rb +0 -59
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApexCharts::Charts
|
4
|
+
%w[
|
5
|
+
base cartesian line area bar column scatter
|
6
|
+
candlestick heatmap bubble radar polar pie donut
|
7
|
+
].each do |type|
|
8
|
+
autoload :"#{type.capitalize}Chart", "apex_charts/charts/#{type}_chart.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
autoload :RangeBarChart, 'apex_charts/charts/range_bar_chart.rb'
|
12
|
+
autoload :RadialBarChart, 'apex_charts/charts/radial_bar_chart.rb'
|
13
|
+
|
14
|
+
autoload :MixedCharts, 'apex_charts/charts/mixed_charts.rb'
|
15
|
+
autoload :SyncingCharts, 'apex_charts/charts/syncing_charts.rb'
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApexCharts::Charts
|
4
|
+
class BaseChart
|
5
|
+
include ApexCharts::Utils::Hash
|
6
|
+
|
7
|
+
attr_reader :options, :series, :sample
|
8
|
+
|
9
|
+
def initialize(data, options={})
|
10
|
+
@series = build_series(data)
|
11
|
+
@options = build_options(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
ApexCharts::Renderer.render(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def chart_type; end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def build_series(data)
|
23
|
+
series_object = series_type.new(data)
|
24
|
+
@sample = series_object.sample
|
25
|
+
series_object.sanitized
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_options(options)
|
29
|
+
deep_merge(
|
30
|
+
ApexCharts::OptionsBuilder.new(sample, options).build_options,
|
31
|
+
camelize_keys(
|
32
|
+
{**@series, chart: {type: chart_type}}.compact
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'features/annotations'
|
4
|
+
require_relative 'features/mixable'
|
5
|
+
require_relative '../utils/hash'
|
6
|
+
|
7
|
+
module ApexCharts::Charts
|
8
|
+
class CartesianChart < BaseChart
|
9
|
+
include Features::Annotations
|
10
|
+
include Features::Mixable
|
11
|
+
include ApexCharts::Utils::Hash
|
12
|
+
|
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
|
+
)
|
19
|
+
|
20
|
+
build_instance_variables if @outer_self
|
21
|
+
|
22
|
+
instance_eval &block if block_given?
|
23
|
+
|
24
|
+
options[:annotations] = @annotations if @annotations
|
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
|
+
ApexCharts::Series::CartesianSeries
|
33
|
+
end
|
34
|
+
|
35
|
+
def more_options
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(method, *args, &block)
|
40
|
+
if @outer_self.respond_to?(method, true)
|
41
|
+
@outer_self.send method, *args, &block
|
42
|
+
else
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def respond_to_missing?(method, *args)
|
48
|
+
@outer_self.respond_to?(method, true) || super
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def build_instance_variables
|
54
|
+
(@outer_self.instance_variables - instance_variables).each do |i|
|
55
|
+
instance_variable_set(i, @outer_self.instance_variable_get(i))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def brush?
|
60
|
+
@options[:chart][:brush]&.[](:enabled) &&
|
61
|
+
!@options[:chart][:selection]&.[](:xaxis)
|
62
|
+
end
|
63
|
+
|
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]
|
68
|
+
@options[:chart][:selection][:xaxis] = {
|
69
|
+
min: handle_time(twenty_percent_before_last_x(first_x, last_x)),
|
70
|
+
max: handle_time(last_x)
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def twenty_percent_before_last_x(first, last)
|
75
|
+
last - (0.2 * (last - first))
|
76
|
+
end
|
77
|
+
|
78
|
+
def handle_time(input)
|
79
|
+
ApexCharts::Utils::DateTime.convert(input)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,42 +1,43 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApexCharts::Charts::Features
|
2
4
|
module Annotations
|
3
5
|
def annotation(axis, value:, text:, color: nil, **options)
|
4
6
|
@annotations ||= {}
|
5
7
|
|
6
|
-
unless [
|
7
|
-
|
8
|
-
end
|
8
|
+
raise "unrecognized axis: #{axis}" unless %i[xaxis yaxis points].include? axis
|
9
|
+
|
9
10
|
@annotations[axis] ||= []
|
10
11
|
@annotations[axis] << annotation_value(axis, value).merge(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
if axis == :points
|
13
|
+
{marker: {size: 8, fillColor: 'white', strokeColor: color, radius: 2}, **options}
|
14
|
+
else
|
15
|
+
{borderColor: color, fillColor: color, opacity: 0.2}
|
16
|
+
end
|
17
|
+
).merge(
|
18
|
+
annotation_label(text, color, **options)
|
19
|
+
)
|
19
20
|
end
|
20
21
|
|
21
|
-
def x_annotation
|
22
|
+
def x_annotation(**args)
|
22
23
|
annotation :xaxis, **args
|
23
24
|
end
|
24
25
|
|
25
|
-
def y_annotation
|
26
|
+
def y_annotation(**args)
|
26
27
|
annotation :yaxis, **args
|
27
28
|
end
|
28
29
|
|
29
|
-
def point_annotation
|
30
|
+
def point_annotation(**args)
|
30
31
|
annotation :points, **args
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
34
35
|
|
35
|
-
def annotation_value
|
36
|
+
def annotation_value(axis, value)
|
36
37
|
axis = axis.to_s.delete_suffix('axis').to_sym
|
37
38
|
case value
|
38
39
|
when Range
|
39
|
-
value = Utils::DateTime.convert_range(value)
|
40
|
+
value = ApexCharts::Utils::DateTime.convert_range(value)
|
40
41
|
|
41
42
|
case axis
|
42
43
|
when :x
|
@@ -48,16 +49,16 @@ module ApexCharts
|
|
48
49
|
end
|
49
50
|
else
|
50
51
|
if axis == :points
|
51
|
-
value.map!{
|
52
|
+
value.map! {|x| ApexCharts::Utils::DateTime.convert(x) }
|
52
53
|
{x: value.first, y: value.last}
|
53
54
|
else
|
54
|
-
value = Utils::DateTime.convert(value)
|
55
|
+
value = ApexCharts::Utils::DateTime.convert(value)
|
55
56
|
{axis => value}
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
60
|
-
def annotation_label
|
61
|
+
def annotation_label(text, color, **options)
|
61
62
|
{
|
62
63
|
label: {
|
63
64
|
borderColor: color,
|
@@ -70,6 +71,6 @@ module ApexCharts
|
|
70
71
|
}
|
71
72
|
end
|
72
73
|
|
73
|
-
include Utils::Hash
|
74
|
+
include ApexCharts::Utils::Hash
|
74
75
|
end
|
75
76
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module ApexCharts
|
3
|
+
module ApexCharts::Charts::Features
|
4
4
|
module Mixable
|
5
5
|
def mixed_series
|
6
|
-
series[:series].each{|d| d.merge!(type: chart_type) }
|
6
|
+
series[:series].each {|d| d.merge!(type: chart_type) }
|
7
7
|
series[:series]
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module ApexCharts
|
3
|
+
module ApexCharts::Charts
|
4
4
|
class HeatmapChart < BaseChart
|
5
5
|
def chart_type
|
6
6
|
'heatmap'
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
def sanitize_data(data)
|
12
|
-
ApexCharts::CartesianSeries.new(data).sanitized
|
9
|
+
def series_type
|
10
|
+
ApexCharts::Series::CartesianSeries
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'features/annotations'
|
4
|
+
|
5
|
+
module ApexCharts::Charts
|
6
|
+
class MixedCharts < BaseChart
|
7
|
+
include Features::Annotations
|
8
|
+
include ApexCharts::Utils::Hash
|
9
|
+
|
10
|
+
def initialize(outer_self, options={}, &block)
|
11
|
+
@outer_self = outer_self
|
12
|
+
@series = {series: []}
|
13
|
+
options[:id] ||= apexcharts_id
|
14
|
+
build_instance_variables
|
15
|
+
|
16
|
+
instance_eval &block
|
17
|
+
|
18
|
+
options[:annotations] = @annotations if @annotations
|
19
|
+
@options = build_options(options)
|
20
|
+
|
21
|
+
build_selection_range if brush?
|
22
|
+
end
|
23
|
+
|
24
|
+
def chart_type
|
25
|
+
'area' # chosen default
|
26
|
+
end
|
27
|
+
|
28
|
+
def line_chart(data, options={}, &block)
|
29
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
30
|
+
@series[:series] +=
|
31
|
+
LineChart.new(outer_self, data, options, &block).mixed_series
|
32
|
+
end
|
33
|
+
|
34
|
+
def area_chart(data, options={}, &block)
|
35
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
36
|
+
@series[:series] +=
|
37
|
+
AreaChart.new(outer_self, data, options, &block).mixed_series
|
38
|
+
end
|
39
|
+
|
40
|
+
def bar_chart(data, options={}, &block)
|
41
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
42
|
+
@series[:series] +=
|
43
|
+
BarChart.new(outer_self, data, options, &block).mixed_series
|
44
|
+
end
|
45
|
+
|
46
|
+
def column_chart(data, options={}, &block)
|
47
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
48
|
+
@series[:series] +=
|
49
|
+
ColumnChart.new(outer_self, data, options, &block).mixed_series
|
50
|
+
end
|
51
|
+
|
52
|
+
def scatter_chart(data, options={}, &block)
|
53
|
+
outer_self = eval('self', block.binding, __FILE__, __LINE__) if block_given?
|
54
|
+
@series[:series] +=
|
55
|
+
ScatterChart.new(outer_self, data, options, &block).mixed_series
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(method, *args, &block)
|
59
|
+
if @outer_self.respond_to?(method, true)
|
60
|
+
@outer_self.send method, *args, &block
|
61
|
+
else
|
62
|
+
super
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def respond_to_missing?(method, *args)
|
67
|
+
@outer_self.respond_to?(method, true) || super
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def build_instance_variables
|
73
|
+
(@outer_self.instance_variables - instance_variables).each do |i|
|
74
|
+
instance_variable_set(i, @outer_self.instance_variable_get(i))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def brush?
|
79
|
+
@options[:chart][:brush]&.[](:enabled) &&
|
80
|
+
!@options[:chart][:selection]&.[](:xaxis)
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_selection_range
|
84
|
+
last_data = @series[:series].last[:data]
|
85
|
+
first_x = last_data.first[:x]
|
86
|
+
last_x = last_data.last[:x]
|
87
|
+
@options[:chart][:selection][:xaxis] = {
|
88
|
+
min: handle_time(twenty_percent_before_last_x(first_x, last_x)),
|
89
|
+
max: handle_time(last_x)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def twenty_percent_before_last_x(first, last)
|
94
|
+
last - (0.2 * (last - first))
|
95
|
+
end
|
96
|
+
|
97
|
+
def handle_time(input)
|
98
|
+
ApexCharts::Utils::DateTime.convert(input)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|