apexcharts 0.1.5 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +456 -38
  3. data/lib/apex_charts/charts.rb +16 -0
  4. data/lib/{apexcharts/charts/area.rb → apex_charts/charts/area_chart.rb} +1 -1
  5. data/lib/{apexcharts/charts/bar.rb → apex_charts/charts/bar_chart.rb} +1 -1
  6. data/lib/apex_charts/charts/base_chart.rb +37 -0
  7. data/lib/apex_charts/charts/bubble_chart.rb +13 -0
  8. data/lib/{apexcharts/charts/candlestick.rb → apex_charts/charts/candlestick_chart.rb} +1 -1
  9. data/lib/apex_charts/charts/cartesian_chart.rb +82 -0
  10. data/lib/{apexcharts/charts/column.rb → apex_charts/charts/column_chart.rb} +3 -1
  11. data/lib/{apexcharts/charts/donut.rb → apex_charts/charts/donut_chart.rb} +1 -2
  12. data/lib/{apexcharts → apex_charts}/charts/features/annotations.rb +22 -21
  13. data/lib/{apexcharts → apex_charts}/charts/features/mixable.rb +2 -3
  14. data/lib/{apexcharts/charts/heatmap.rb → apex_charts/charts/heatmap_chart.rb} +3 -5
  15. data/lib/{apexcharts/charts/line.rb → apex_charts/charts/line_chart.rb} +1 -1
  16. data/lib/apex_charts/charts/mixed_charts.rb +101 -0
  17. data/lib/{apexcharts/charts/pie.rb → apex_charts/charts/pie_chart.rb} +1 -2
  18. data/lib/apex_charts/charts/polar_chart.rb +9 -0
  19. data/lib/{apexcharts/charts/radar.rb → apex_charts/charts/radar_chart.rb} +3 -5
  20. data/lib/{apexcharts/charts/radial_bar.rb → apex_charts/charts/radial_bar_chart.rb} +1 -2
  21. data/lib/apex_charts/charts/range_bar_chart.rb +9 -0
  22. data/lib/{apexcharts/charts/scatter.rb → apex_charts/charts/scatter_chart.rb} +1 -1
  23. data/lib/apex_charts/charts/syncing_charts.rb +84 -0
  24. data/lib/apex_charts/colors.rb +27 -0
  25. data/lib/apex_charts/config/default_options.rb +16 -0
  26. data/lib/apex_charts/configuration.rb +25 -0
  27. data/lib/apex_charts/helper.rb +190 -0
  28. data/lib/apex_charts/options/annotations_options.rb +15 -0
  29. data/lib/apex_charts/options/chart_options.rb +32 -0
  30. data/lib/apex_charts/options/data_labels_options.rb +18 -0
  31. data/lib/apex_charts/options/div_attributes.rb +11 -0
  32. data/lib/apex_charts/options/fill_options.rb +14 -0
  33. data/lib/apex_charts/options/grid_options.rb +17 -0
  34. data/lib/apex_charts/options/legend_options.rb +32 -0
  35. data/lib/apex_charts/options/markers_options.rb +24 -0
  36. data/lib/apex_charts/options/no_data_options.rb +14 -0
  37. data/lib/apex_charts/options/plot_options.rb +16 -0
  38. data/lib/apex_charts/options/root_options.rb +47 -0
  39. data/lib/apex_charts/options/states_options.rb +11 -0
  40. data/lib/apex_charts/options/stroke_options.rb +14 -0
  41. data/lib/apex_charts/options/theme_options.rb +11 -0
  42. data/lib/apex_charts/options/title_subtitle_options.rb +15 -0
  43. data/lib/apex_charts/options/tooltip_options.rb +25 -0
  44. data/lib/apex_charts/options/x_axis_options.rb +26 -0
  45. data/lib/apex_charts/options/y_axis_options.rb +28 -0
  46. data/lib/{apexcharts → apex_charts}/options_builder.rb +95 -90
  47. data/lib/apex_charts/prefix_with_apex.rb +7 -0
  48. data/lib/apex_charts/prefixer.rb +21 -0
  49. data/lib/apex_charts/renderer.rb +113 -0
  50. data/lib/apex_charts/series.rb +7 -0
  51. data/lib/apex_charts/series/bubble_series.rb +50 -0
  52. data/lib/apex_charts/series/cartesian_series.rb +81 -0
  53. data/lib/apex_charts/series/polar_series.rb +48 -0
  54. data/lib/{apexcharts → apex_charts}/support/rails.rb +1 -1
  55. data/lib/apex_charts/support/sinatra.rb +9 -0
  56. data/lib/apex_charts/theme.rb +60 -0
  57. data/lib/{apexcharts → apex_charts}/utils.rb +1 -0
  58. data/lib/apex_charts/utils/copy.rb +11 -0
  59. data/lib/apex_charts/utils/date_time.rb +70 -0
  60. data/lib/{apexcharts → apex_charts}/utils/hash.rb +4 -3
  61. data/lib/{apexcharts → apex_charts}/version.rb +2 -1
  62. data/lib/apexcharts.rb +3 -2
  63. data/vendor/assets/javascripts/apexcharts.js +11 -3
  64. metadata +85 -65
  65. data/lib/apexcharts/charts.rb +0 -19
  66. data/lib/apexcharts/charts/base.rb +0 -34
  67. data/lib/apexcharts/charts/bubble.rb +0 -19
  68. data/lib/apexcharts/charts/cartesian.rb +0 -81
  69. data/lib/apexcharts/charts/mixed.rb +0 -85
  70. data/lib/apexcharts/charts/polar.rb +0 -14
  71. data/lib/apexcharts/charts/syncing.rb +0 -70
  72. data/lib/apexcharts/helper.rb +0 -109
  73. data/lib/apexcharts/options/annotations.rb +0 -10
  74. data/lib/apexcharts/options/axis.rb +0 -17
  75. data/lib/apexcharts/options/chart.rb +0 -26
  76. data/lib/apexcharts/options/data_labels.rb +0 -12
  77. data/lib/apexcharts/options/div_attributes.rb +0 -10
  78. data/lib/apexcharts/options/fill.rb +0 -12
  79. data/lib/apexcharts/options/grid.rb +0 -15
  80. data/lib/apexcharts/options/legend.rb +0 -24
  81. data/lib/apexcharts/options/markers.rb +0 -18
  82. data/lib/apexcharts/options/no_data.rb +0 -12
  83. data/lib/apexcharts/options/plot_options.rb +0 -12
  84. data/lib/apexcharts/options/root.rb +0 -42
  85. data/lib/apexcharts/options/states.rb +0 -9
  86. data/lib/apexcharts/options/stroke.rb +0 -12
  87. data/lib/apexcharts/options/subtitle.rb +0 -7
  88. data/lib/apexcharts/options/theme.rb +0 -8
  89. data/lib/apexcharts/options/title.rb +0 -13
  90. data/lib/apexcharts/options/tooltip.rb +0 -22
  91. data/lib/apexcharts/options/x_axis.rb +0 -12
  92. data/lib/apexcharts/options/y_axis.rb +0 -15
  93. data/lib/apexcharts/renderer.rb +0 -21
  94. data/lib/apexcharts/series.rb +0 -5
  95. data/lib/apexcharts/series/bubble.rb +0 -37
  96. data/lib/apexcharts/series/cartesian.rb +0 -65
  97. data/lib/apexcharts/series/polar.rb +0 -32
  98. data/lib/apexcharts/utils/date_time.rb +0 -59
@@ -1,7 +0,0 @@
1
- require_relative 'title'
2
-
3
- module ApexCharts
4
- class SubtitleOptions < TitleOptions
5
- optional *%i[ ]
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- module ApexCharts
2
- class ThemeOptions < ::SmartKv
3
- optional *%i[
4
- monochrome
5
- palette
6
- ]
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- module ApexCharts
2
- class TitleOptions < ::SmartKv
3
- optional *%i[
4
- align
5
- floating
6
- margin
7
- offsetX
8
- offsetY
9
- style
10
- text
11
- ]
12
- end
13
- end
@@ -1,22 +0,0 @@
1
- module ApexCharts
2
- class TooltipOptions < ::SmartKv
3
- optional *%i[
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
- end
22
- end
@@ -1,12 +0,0 @@
1
- require_relative 'axis'
2
-
3
- module ApexCharts
4
- class XAxisOptions < AxisOptions
5
- optional *%i[
6
- categories
7
- position
8
- range
9
- tickPlacement
10
- ]
11
- end
12
- end
@@ -1,15 +0,0 @@
1
- require_relative 'axis'
2
-
3
- module ApexCharts
4
- class YAxisOptions < AxisOptions
5
- optional *%i[
6
- decimalsInFloat
7
- forceNiceScale
8
- logarithmic
9
- opposite
10
- seriesName
11
- show
12
- showAlways
13
- ]
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json' unless defined? JSON
4
-
5
- class ApexCharts::Renderer
6
- def self.render_default(options)
7
- attributes = options.delete(:div) { {} }
8
- variable = attributes.delete(:var) { "chart#{attributes[:id]&.[](/\d+/)}" }
9
- element_id = attributes.delete(:id)
10
- css_class = attributes.delete(:class)
11
- height = "#{options[:chart][:height].to_i}px"
12
- style = "height: #{height}; #{attributes.delete(:style)}"
13
- html =<<~HTML
14
- <div id="#{element_id}" class="#{css_class}" style="#{style}"></div>
15
- <script type="text/javascript">
16
- var #{variable} = new ApexCharts(document.querySelector("##{element_id}"), #{options.to_json});
17
- #{variable}.render();
18
- </script>
19
- HTML
20
- end
21
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'series/cartesian'
4
- require_relative 'series/bubble'
5
- require_relative 'series/polar'
@@ -1,37 +0,0 @@
1
- module ApexCharts
2
- class BubbleSeries
3
- attr_reader :sanitized
4
-
5
- def initialize(data)
6
- data = deep_copy(data)
7
- @sanitized = case data
8
- when Array
9
- if array_of_threes?(data)
10
- [{data: data}]
11
- else
12
- data
13
- end
14
-
15
- when Hash
16
- if data_value = data[:data]
17
- if array_of_threes?(data_value)
18
- [data]
19
- end
20
- end
21
-
22
- end
23
-
24
- @sanitized = {series: @sanitized}
25
- end
26
-
27
- def deep_copy(data)
28
- Marshal.load(Marshal.dump(data))
29
- end
30
-
31
- def array_of_threes?(data)
32
- return false if data.empty?
33
- data.all?{|d| d.length == 3 }
34
- end
35
- end
36
- end
37
-
@@ -1,65 +0,0 @@
1
- module ApexCharts
2
- class CartesianSeries
3
- attr_reader :sanitized
4
-
5
- def initialize(data)
6
- data = deep_copy(data)
7
- @sanitized = case data
8
- when Array
9
- case first_data = data[0]
10
- when Array
11
- [
12
- {
13
- data: array_of_array_to_array_of_xy(data)
14
- }
15
- ]
16
-
17
- when Hash
18
- if first_data[:data]
19
- data.each{|h| h[:data] = array_of_array_to_array_of_xy(h[:data]) }
20
- data
21
- end
22
-
23
- end
24
-
25
- when Hash
26
- if data_value = data[:data]
27
- if array_of_pairs?(data_value)
28
- data[:data] = array_of_array_to_array_of_xy(data_value)
29
- [data]
30
- end
31
-
32
- else
33
- if data[:x] && data[:y]
34
- [{data: [data]}]
35
-
36
- else
37
- [
38
- {
39
- data: data.map do |k,v|
40
- {x: k, y: v}
41
- end
42
- }
43
- ]
44
-
45
- end
46
- end
47
- end
48
-
49
- @sanitized = {series: @sanitized}
50
- end
51
-
52
- def deep_copy(data)
53
- Marshal.load(Marshal.dump(data))
54
- end
55
-
56
- def array_of_pairs?(data)
57
- !data.empty? && data.all?{|d| d.length == 2 }
58
- end
59
-
60
- def array_of_array_to_array_of_xy(data)
61
- data.map{|d| {x: d.first, y: d.last} }
62
- end
63
- end
64
- end
65
-
@@ -1,32 +0,0 @@
1
- module ApexCharts
2
- class PolarSeries
3
- attr_reader :sanitized
4
-
5
- def initialize(data)
6
- @labels = []
7
- data = deep_copy(data)
8
- if data.is_a? Array
9
- if data.first.is_a? Numeric
10
- @series = data
11
- elsif data.first.is_a? Hash
12
- @labels = data.map{|m| m[:name] }.compact
13
- @series = data.map{|m| m[:data] }
14
- end
15
- elsif data.is_a? Hash
16
- if data[:data].is_a? Array
17
- @series = data[:data]
18
- end
19
- end
20
-
21
- @sanitized = {
22
- labels: @labels.empty? ? nil : @labels,
23
- series: @series
24
- }.compact
25
- end
26
-
27
- def deep_copy(data)
28
- Marshal.load(Marshal.dump(data))
29
- end
30
- end
31
- end
32
-
@@ -1,59 +0,0 @@
1
- require 'date'
2
-
3
- module ApexCharts::Utils
4
- module DateTime
5
- def convert input
6
- case input
7
- when Time
8
- (input.to_f * 1000).round
9
- when ::DateTime, Date
10
- (input.to_time.to_f * 1000).round
11
- else
12
- if (dt = ::DateTime.iso8601(input)).iso8601 == input
13
- (dt.to_time.to_f * 1000).round
14
- else (d = Date.iso8601(input)).iso8601 == input
15
- (d.to_time.to_f * 1000).round
16
- end
17
- end
18
- rescue
19
- input
20
- end
21
- module_function :convert
22
-
23
- def convert_range input
24
- case input.first
25
- when Time
26
- ((input.first.to_f * 1000).round..(input.last.to_f * 1000).round)
27
- when ::DateTime, Date
28
- ((input.first.to_time.to_f * 1000).round..(input.last.to_time.to_f * 1000).round)
29
- else
30
- if (dt = ::DateTime.iso8601(input.first)).iso8601 == input.first
31
- ((dt.to_time.to_f * 1000).round..(::DateTime.iso8601(input.last).to_time.to_f * 1000).round)
32
- else (d = Date.iso8601(input.first)).iso8601 == input.first
33
- ((d.to_time.to_f * 1000).round..(Date.iso8601(input.last).to_time.to_f * 1000).round)
34
- end
35
- end
36
- rescue
37
- input
38
- end
39
- module_function :convert_range
40
-
41
- def type input
42
- case input
43
- when Time, ::DateTime, Date
44
- 'datetime'
45
- else
46
- if ::DateTime.iso8601(input).iso8601 == input
47
- 'datetime'
48
- elsif Date.iso8601(input).iso8601 == input
49
- 'datetime'
50
- else
51
- 'number'
52
- end
53
- end
54
- rescue
55
- 'number'
56
- end
57
- module_function :type
58
- end
59
- end