apexcharts 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6b3b98ec99c06971c628785c5cad67c383761d510143618f44eb35d66b14b64
4
- data.tar.gz: 5529e49eb4a68568e307d811405252b7edb9917e9d2f1f0d3747974cb4846490
3
+ metadata.gz: 440e28c754dc121a96eabbfdef5215fd5efa44939111a031dfcf008ebb1362db
4
+ data.tar.gz: 373e2f066849672f92d6be10ce978fdf1077cec3ca2aa3da4dbfa2c3c6e3350e
5
5
  SHA512:
6
- metadata.gz: 27524883c3b7bc5fd74d61dce05996807e891b6a8162ba3443618060a60ccdbf211b47d1f8bccd6d23f3f724247bbf9ccb3035b2366d62ac66dd504f4088c23e
7
- data.tar.gz: 8be3f7162a6df1afdd91178f12576594932755e11152ab7b4d1f2a8b7ffd15d17d7ca01ccb62e96de3c10b0217df29fb9f68ad82bda2004b97ae642bac195c9b
6
+ metadata.gz: 0ab7c90e2a7957d8c805b9561421a1368d2b3f3e0bc0b82e3ce41863790fe0450aa6ce93c5f53659e8ecc010d92f660ee6faa8a2fbf217fc5ea6dea4c1a41ff8
7
+ data.tar.gz: 98185d2d33c2895bd4cf1c289add3fcd51d0f6d83ccea1e334ce9f506289fab89c01ffe2556b91663c347c8f6b2c234a4bcda2236027929f648961797a3f0339
data/README.md CHANGED
@@ -1,106 +1,198 @@
1
1
  <p align="center">
2
- <img src="https://apexcharts.com/media/apexcharts-logo.png" height="90">
3
- <span style="font-size: 40px; vertical-align: top; margin-right: 10px;">+</span>
4
- <img src="https://www.ruby-lang.org/images/header-ruby-logo.png">
2
+ <img src="images/apexcharts.rb.png" height="170">
5
3
  </p>
6
4
 
7
5
  <p align="center">
8
6
  <a href="https://github.com/styd/apexcharts.rb/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg" alt="License"></a>
9
- <a href="https://travis-ci.com/styd/apexcharts.rb"><img src="https://api.travis-ci.com/styd/apexcharts.rb.svg?branch=master" alt="build" /></a>
7
+ <a href="https://travis-ci.org/styd/apexcharts.rb"><img src="https://travis-ci.org/styd/apexcharts.rb.svg?branch=master" alt="Build Status" /></a>
8
+ <a href="https://rubygems.org/gems/apexcharts"><img src="https://badge.fury.io/rb/apexcharts.svg" alt="Gem Version" /></a>
10
9
  </p>
11
10
 
12
11
 
13
- <p align="center">
14
- <a href="https://twitter.com/intent/tweet?text=Create%20visualizations%20with%20this%20free%20and%20open-source%20JavaScript%20Chart%20library&url=https://www.apexcharts.com&hashtags=javascript,charts,visualizations,developers,apexcharts"><img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social"> </a>
15
- </p>
16
-
17
12
  <p align="center">Beautiful and interactive web charts for rubyist.</p>
18
13
 
19
14
 
20
15
  <p align="center"><img src="https://apexcharts.com/media/apexcharts-banner.png"></p>
21
16
 
22
- ## Installation
23
- Add this line to your application's Gemfile:
24
-
25
- ```ruby
26
- gem 'apexcharts'
27
- ```
28
-
29
- And then execute:
30
- ```bash
31
- $ bundle
32
- ```
33
-
34
17
  ## Usage
35
18
 
36
19
  ### Cartesian Charts
37
20
 
38
- Example series used for mixable charts:
21
+ Example series used for cartesian charts:
39
22
 
40
- ```ruby
41
- series = [
42
- {name: "Total", data: @total_users},
43
- {name: "Verified", data: @verified_users},
44
- {name: "Unverified", data: @unverified_users}
45
- ]
23
+ ```erb
24
+ <% series = [
25
+ {name: "Inactive", data: @inactive_properties},
26
+ {name: "Active", data: @active_properties}
27
+ ] %>
46
28
  ```
47
- To build the data, you can use gem [groupdate](https://github.com/ankane/groupdate).
29
+ To build the data, you can use gem [groupdate](https://github.com/ankane/groupdate).
30
+ In my case, it was:
48
31
 
49
- Example options used for mixable charts:
32
+ ```ruby
33
+ @inactive_properties = Property.inactive.group_by_week(:created_at).count
34
+ @active_properties = Property.active.group_by_week(:created_at).count
35
+ ```
50
36
 
37
+ and I'll get the data in this format:
51
38
  ```ruby
52
- options = {
53
- title: 'Users Growth',
54
- subtitle: 'Grouped Per Week',
55
- xtitle: 'Week', ytitle: 'Users'
39
+ {
40
+ Sun, 29 Jul 2018=>1,
41
+ Sun, 05 Aug 2018=>6,
42
+ ..
56
43
  }
57
44
  ```
58
45
 
46
+ Example options used for cartesian charts:
47
+
48
+ ```erb
49
+ <% options = {
50
+ title: 'Properties Growth',
51
+ subtitle: 'Grouped Per Week',
52
+ xtitle: 'Week',
53
+ ytitle: 'Properties',
54
+ stacked: true
55
+ } %>
56
+ ```
57
+
59
58
  #### Line Chart
60
59
 
61
- ```ruby
60
+ ```erb
62
61
  <%= line_chart(series, options) %>
63
62
  ```
63
+ ![Example Line Chart](images/line_chart.png)
64
+
64
65
 
65
66
  #### Area Chart
66
67
 
67
- ```ruby
68
- <%= area_chart(series, options) %>
68
+ ```erb
69
+ <%= area_chart(series, {**options, theme: 'palette5'}) %>
69
70
  ```
71
+ ![Example Area Chart](images/area_chart.png)
72
+
70
73
 
71
74
  #### Column Chart
72
75
 
73
- ```ruby
74
- <%= column_chart(series, options) %>
76
+ ```erb
77
+ <%= column_chart(series, {**options, theme: 'palette4'}) %>
75
78
  ```
79
+ ![Example Column Chart](images/column_chart.png)
80
+
76
81
 
77
82
  #### Bar Chart
78
83
 
79
- ```ruby
80
- <%= bar_chart(series, options) %>
84
+ ```erb
85
+ <%= bar_chart(series, {**options, xtitle: 'Properties', ytitle: 'Week', height: 800, theme: 'palette7'}) %>
81
86
  ```
87
+ ![Example Bar Chart](images/bar_chart.png)
88
+
82
89
 
83
90
  #### Scatter Chart
84
91
 
85
- ```ruby
86
- <%= scatter_chart(series, options) %>
92
+ ```erb
93
+ <%= scatter_chart(series, {**options, theme: 'palette3'}) %>
87
94
  ```
95
+ ![Example Scatter Chart](images/scatter_chart.png)
88
96
 
89
- All charts can have annotations, for example:
90
97
 
98
+ #### Mixed Chart
99
+
100
+ You can mix charts by using `mixed_chart` or `combo_chart` methods. For example:
101
+ Given that:
91
102
  ```ruby
103
+ @total_properties = Property.group_by_week(:created_at).count
104
+ ```
105
+ you can do this:
106
+ ```erb
107
+ <%= combo_chart({**options, theme: 'palette4', stacked: false, data_labels: false}) do %>
108
+ <% line_chart({name: "Total", data: @total_properties}) %>
109
+ <% area_chart({name: "Active", data: @active_properties}) %>
110
+ <% column_chart({name: "Inactive", data: @inactive_properties}) %>
111
+ <% end %>
112
+ ```
113
+ ![Example Mixed Chart](images/mixed_chart.gif)
114
+
115
+
116
+ #### Syncing Chart
117
+ You can synchronize charts by using `syncing_chart` or `synchronized_chart` methods. For example:
118
+ ```erb
119
+ <%= syncing_chart(chart: {toolbar: false}, height: 250, style: 'display: inline-block; width: 32%;') do %>
120
+ <% mixed_chart(theme: 'palette4', data_labels: false) do %>
121
+ <% line_chart({name: "Total", data: @total_properties}) %>
122
+ <% area_chart({name: "Active", data: @active_properties}) %>
123
+ <% end %>
124
+ <% area_chart({name: "Active", data: @active_properties}, theme: 'palette6') %>
125
+ <% line_chart({name: "Inactive", data: @active_properties}, theme: 'palette8') %>
126
+ <% end %>
127
+ ```
128
+ ![Example Syncing Chart](images/syncing_chart.gif)
129
+
130
+
131
+ #### Annotations
132
+
133
+ All cartesian charts can have annotations, for example:
134
+
135
+ ```erb
92
136
  <%= line_chart(series, options) do %>
93
- <% x_annotation(value: ('2018-11-18'..'2018-12-02'),
94
- text: "Busy Time", color: 'green') %>
95
- <% y_annotation(value: 59, text: "Max Users", color: 'blue') %>
96
- <% point_annotation(value: ['2018-07-22', 12],
97
- text: "First Peak", color: 'magenta') %>
137
+ <% x_annotation(value: ('2019-01-06'..'2019-02-24'), text: "Busy Time", color: 'green') %>
138
+ <% y_annotation(value: 29, text: "Max Properties", color: 'blue') %>
139
+ <% point_annotation(value: ['2018-10-07', 24], text: "First Peak", color: 'magenta') %>
98
140
  <% end %>
99
141
  ```
142
+ ![Example Line Chart with Annotations](images/chart_with_annotations.png)
143
+
144
+
145
+ ### Polar Charts
146
+
147
+ #### Pie Chart
148
+
149
+ ```erb
150
+ <%= pie_chart([
151
+ {name: "Series A", data: 25},
152
+ {name: "Series B", data: 100},
153
+ {name: "Series C", data: 200},
154
+ {name: "Series D", data: 125}
155
+ ], legend: "left") %>
156
+ ```
157
+ ![Example Pie Chart](images/pie_chart.gif)
158
+
159
+
160
+ #### Donut Chart
161
+
162
+ ```erb
163
+ <%= donut_chart([25, 100, 200, 125], theme: 'palette4' %>
164
+ ```
165
+ ![Example Pie Chart](images/donut_chart.gif)
166
+
167
+
168
+ #### Radial Bar Chart
169
+
170
+ Also called `circle_chart`.
171
+ ```erb
172
+ <%= radial_bar_chart([
173
+ {name: "Circle A", data: 25},
174
+ {name: "Circle B", data: 40},
175
+ {name: "Circle C", data: 80},
176
+ {name: "Circle D", data: 45}
177
+ ], legend: true) %>
178
+ ```
179
+ ![Example Circle Chart](images/radial_bar_chart.gif)
180
+
181
+
182
+ ## Installation
183
+ Add this line to your application's Gemfile:
184
+
185
+ ```ruby
186
+ gem 'apexcharts'
187
+ ```
188
+
189
+ And then execute:
190
+ ```bash
191
+ $ bundle
192
+ ```
100
193
 
101
- ![Example Line Chart with Annotations](images/example-annotations.png)
102
194
 
103
- ## Web Framework
195
+ ## Web Support
104
196
 
105
197
  ### Rails
106
198
 
@@ -122,11 +214,16 @@ require("apexcharts")
122
214
  - To bring out as much apexcharts.js capabilities as possible but in ruby ways.
123
215
 
124
216
  ## Roadmap
125
- - Other charts (pie, donut, radar, heatmap, etc.)
217
+ - Other charts (~~pie~~, ~~donut~~, radar, heatmap, etc.)
126
218
  - Support other ruby frameworks (sinatra, hanami, etc.)
219
+ - Render as Vue or React elements
127
220
 
128
221
  ## Contributing
129
- Contribution directions go here.
222
+ Everyone is encouraged to help improve this project by:
223
+ - Reporting bugs
224
+ - Fixing bugs and submiting pull requests
225
+ - Fixing documentation
226
+ - Suggesting new features
130
227
 
131
228
  ## License
132
229
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -9,11 +9,11 @@ module Apexcharts
9
9
  instance_eval &block if block_given?
10
10
 
11
11
  options[:annotations] = @annotations if @annotations
12
- @data = sanitize_data(data)
12
+ @series = sanitize_data(data)
13
13
  @options = Utils::Hash.camelize_keys(
14
14
  Utils::Hash.deep_merge(
15
- build_options(@data[0][:data][0][:x], options),
16
- {series: @data, chart: {type: chart_type}}.compact
15
+ build_options(@series[:series][0][:data][0][:x], options),
16
+ {**@series, chart: {type: chart_type}}.compact
17
17
  )
18
18
  )
19
19
  end
@@ -26,8 +26,8 @@ module Apexcharts
26
26
  end
27
27
 
28
28
  def mixed_series
29
- @data.each{|d| d.merge!(type: chart_type) }
30
- @data
29
+ @series[:series].each{|d| d.merge!(type: chart_type) }
30
+ @series[:series]
31
31
  end
32
32
 
33
33
  def render
@@ -0,0 +1,8 @@
1
+ module Apexcharts
2
+ class DonutChart < PolarChart
3
+ def chart_type
4
+ 'donut'
5
+ end
6
+ end
7
+ end
8
+
@@ -4,37 +4,37 @@ module Apexcharts
4
4
 
5
5
  def initialize options={}, bindings, &block
6
6
  @bindings = bindings
7
- @mixed_series = []
7
+ @mixed_series = {series: []}
8
8
  build_instance_variables
9
9
  instance_eval &block
10
10
 
11
11
  options[:annotations] = @annotations if @annotations
12
12
  @options = Utils::Hash.camelize_keys(
13
13
  Utils::Hash.deep_merge(
14
- build_options(@mixed_series[0][:data][0][:x], options),
15
- {chart: {type: 'area'}, series: @mixed_series}
14
+ build_options(@mixed_series[:series][0][:data][0][:x], options),
15
+ {chart: {type: 'area'}, **@mixed_series}
16
16
  )
17
17
  )
18
18
  end
19
19
 
20
20
  def line_chart data, options={}, &block
21
- @mixed_series += LineChart.new(data, options, &block).mixed_series
21
+ @mixed_series[:series] += LineChart.new(data, options, &block).mixed_series
22
22
  end
23
23
 
24
24
  def area_chart data, options={}, &block
25
- @mixed_series += AreaChart.new(data, options, &block).mixed_series
25
+ @mixed_series[:series] += AreaChart.new(data, options, &block).mixed_series
26
26
  end
27
27
 
28
28
  def bar_chart data, options={}, &block
29
- @mixed_series += BarChart.new(data, options, &block).mixed_series
29
+ @mixed_series[:series] += BarChart.new(data, options, &block).mixed_series
30
30
  end
31
31
 
32
32
  def column_chart data, options={}, &block
33
- @mixed_series += ColumnChart.new(data, options, &block).mixed_series
33
+ @mixed_series[:series] += ColumnChart.new(data, options, &block).mixed_series
34
34
  end
35
35
 
36
36
  def scatter_chart data, options={}, &block
37
- @mixed_series += ScatterChart.new(data, options, &block).mixed_series
37
+ @mixed_series[:series] += ScatterChart.new(data, options, &block).mixed_series
38
38
  end
39
39
 
40
40
  def render
@@ -0,0 +1,8 @@
1
+ module Apexcharts
2
+ class PieChart < PolarChart
3
+ def chart_type
4
+ 'pie'
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,43 @@
1
+ module Apexcharts
2
+ class PolarChart
3
+ def initialize data, options={}
4
+ @series = sanitize_data(data)
5
+ @options = Utils::Hash.camelize_keys(
6
+ Utils::Hash.deep_merge(
7
+ build_options(options),
8
+ {**@series, chart: {type: chart_type}}.compact
9
+ )
10
+ )
11
+ end
12
+
13
+ def chart_type
14
+ end
15
+
16
+ def render
17
+ attributes = @options.delete(:div)
18
+ variable = attributes.delete(:var) || "chart#{attributes[:id][/\d+/]}"
19
+ element_id = attributes.delete(:id)
20
+ css_class = attributes.delete(:class)
21
+ height = "#{@options[:chart][:height].to_i}px"
22
+ style = "height: #{height}; #{attributes.delete(:style)}"
23
+ html =<<~HTML
24
+ <div id="#{element_id}" class="#{css_class}" style="#{style}"></div>
25
+ <script type="text/javascript">
26
+ var #{variable} = new ApexCharts(document.querySelector("##{element_id}"), #{@options.to_json});
27
+ #{variable}.render();
28
+ </script>
29
+ HTML
30
+ end
31
+
32
+ private
33
+
34
+ def sanitize_data(data)
35
+ Apexcharts::PolarSeries.new(data).sanitized
36
+ end
37
+
38
+ def build_options(options)
39
+ Apexcharts::OptionsBuilder.new(nil, options).built
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,8 @@
1
+ module Apexcharts
2
+ class RadialBarChart < PolarChart
3
+ def chart_type
4
+ 'radialBar'
5
+ end
6
+ end
7
+ end
8
+
@@ -7,7 +7,7 @@ module Apexcharts
7
7
  @options = options
8
8
  instance_eval &block
9
9
 
10
- @options[:annotations] = @_annotations if @_annotations
10
+ @options[:annotations] = @annotations if @annotations
11
11
  end
12
12
 
13
13
  def line_chart data, options={}, &block
@@ -6,3 +6,7 @@ require_relative 'charts/column'
6
6
  require_relative 'charts/scatter'
7
7
  require_relative 'charts/mixed'
8
8
  require_relative 'charts/syncing'
9
+ require_relative 'charts/polar'
10
+ require_relative 'charts/pie'
11
+ require_relative 'charts/donut'
12
+ require_relative 'charts/radial_bar'
@@ -5,32 +5,33 @@ require_relative 'charts'
5
5
 
6
6
  module Apexcharts
7
7
  module Helper
8
- def line_chart data, options={}, &block
9
- options[:id] ||= apexcharts_id
10
- draw_chart(LineChart.new(data, options, &block))
8
+ def line_chart series, options={}, &block
9
+ series, options = prepare_series_and_options(series, options)
10
+ draw_chart(LineChart.new(series, options, &block))
11
11
  end
12
12
 
13
- def area_chart data, options={}, &block
14
- options[:id] ||= apexcharts_id
15
- draw_chart(AreaChart.new(data, options, &block))
13
+ def area_chart series, options={}, &block
14
+ series, options = prepare_series_and_options(series, options)
15
+ draw_chart(AreaChart.new(series, options, &block))
16
16
  end
17
17
 
18
- def column_chart data, options={}, &block
19
- options[:id] ||= apexcharts_id
20
- draw_chart(ColumnChart.new(data, options, &block))
18
+ def column_chart series, options={}, &block
19
+ series, options = prepare_series_and_options(series, options)
20
+ draw_chart(ColumnChart.new(series, options, &block))
21
21
  end
22
22
 
23
- def bar_chart data, options={}, &block
24
- options[:id] ||= apexcharts_id
25
- draw_chart(BarChart.new(data, options, &block))
23
+ def bar_chart series, options={}, &block
24
+ series, options = prepare_series_and_options(series, options)
25
+ draw_chart(BarChart.new(series, options, &block))
26
26
  end
27
27
 
28
- def scatter_chart data, options={}, &block
29
- options[:id] ||= apexcharts_id
30
- draw_chart(ScatterChart.new(data, options, &block))
28
+ def scatter_chart series, options={}, &block
29
+ series, options = prepare_series_and_options(series, options)
30
+ draw_chart(ScatterChart.new(series, options, &block))
31
31
  end
32
32
 
33
33
  def mixed_chart options={}, &block
34
+ options = deep_copy(options)
34
35
  options[:id] ||= apexcharts_id
35
36
  bindings = eval "self", block.binding
36
37
  draw_chart(MixedChart.new(options, bindings, &block))
@@ -38,12 +39,29 @@ module Apexcharts
38
39
  alias_method :combo_chart, :mixed_chart
39
40
 
40
41
  def syncing_chart options={}, &block
42
+ options = deep_copy(options)
41
43
  options[:group] ||= apexcharts_group
42
44
  bindings = eval "self", block.binding
43
45
  draw_chart(SyncingChart.new(options, bindings, &block))
44
46
  end
45
47
  alias_method :synchronized_chart, :syncing_chart
46
48
 
49
+ def pie_chart series, options={}
50
+ series, options = prepare_series_and_options(series, options)
51
+ draw_chart(PieChart.new(series, options))
52
+ end
53
+
54
+ def donut_chart series, options={}
55
+ series, options = prepare_series_and_options(series, options)
56
+ draw_chart(DonutChart.new(series, options))
57
+ end
58
+
59
+ def radial_bar_chart series, options={}
60
+ series, options = prepare_series_and_options(series, options)
61
+ draw_chart(RadialBarChart.new(series, options))
62
+ end
63
+ alias_method :circle_chart, :radial_bar_chart
64
+
47
65
  private
48
66
 
49
67
  def draw_chart chart
@@ -51,6 +69,13 @@ module Apexcharts
51
69
  chart.respond_to?(:html_safe) ? chart.html_safe : chart
52
70
  end
53
71
 
72
+ def prepare_series_and_options series, options
73
+ series = deep_copy(series)
74
+ options = deep_copy(options)
75
+ options[:id] ||= apexcharts_id
76
+ [series, options]
77
+ end
78
+
54
79
  def apexcharts_id
55
80
  @_apexcharts_id ||= 0
56
81
  @_apexcharts_id += 1
@@ -62,5 +87,9 @@ module Apexcharts
62
87
  @_apexcharts_group += 1
63
88
  "chart-group-#{@_apexcharts_group}"
64
89
  end
90
+
91
+ def deep_copy(options)
92
+ Marshal.load(Marshal.dump(options))
93
+ end
65
94
  end
66
95
  end
@@ -24,7 +24,11 @@ module Apexcharts
24
24
 
25
25
  def initialize(x_sample, options)
26
26
  @options = options
27
- @xtype = Utils::DateTime.xtype(x_sample)
27
+ if options[:plot_options]&.[](:bar)&.[](:horizontal)
28
+ @ytype = Utils::DateTime.type(x_sample)
29
+ else
30
+ @xtype = Utils::DateTime.type(x_sample)
31
+ end
28
32
  @built = {}
29
33
  build_options
30
34
  @built.compact!
@@ -133,11 +137,13 @@ module Apexcharts
133
137
  end
134
138
 
135
139
  def build_legend
136
- labels = @options.delete :labels
137
- @built[:legend] = if [true, false].include? labels
138
- {show: labels}
139
- elsif labels.is_a? Hash
140
- LegendOptions.check labels.compact
140
+ legend = @options.delete :legend
141
+ @built[:legend] = if [true, false].include? legend
142
+ {show: legend}
143
+ elsif legend.is_a? String
144
+ {show: true, position: legend}
145
+ elsif legend.is_a? Hash
146
+ LegendOptions.check legend.compact
141
147
  end
142
148
  end
143
149
 
@@ -278,7 +284,7 @@ module Apexcharts
278
284
  def build_yaxis
279
285
  yaxis = @options.delete :yaxis
280
286
  @built[:yaxis] = [{
281
- type: @options.delete(:ytype),
287
+ type: @options.delete(:ytype){ @ytype },
282
288
  title: {
283
289
  text: @options.delete(:ytitle)
284
290
  }.compact
@@ -292,7 +298,7 @@ module Apexcharts
292
298
  end
293
299
  end
294
300
 
295
- def xtype(x)
301
+ def type(x)
296
302
  if DateTime.iso8601(x).iso8601 == x
297
303
  'datetime'
298
304
  elsif Date.iso8601(x).iso8601 = x
@@ -1,6 +1,6 @@
1
1
  module Apexcharts
2
2
  class CartesianSeries
3
- attr_accessor :sanitized
3
+ attr_reader :sanitized
4
4
 
5
5
  def initialize(data)
6
6
  if data.is_a?(Array)
@@ -17,7 +17,7 @@ module Apexcharts
17
17
  @sanitized = sanitized.map{|a| {data: a} }
18
18
  end
19
19
 
20
- @sanitized = sanitized.each {|a| a[:data] = a[:data].map{|k,v| {x: k, y: v} } }
20
+ @sanitized = {series: sanitized.each {|a| a[:data] = a[:data].map{|k,v| {x: k, y: v} } } }
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,27 @@
1
+ module Apexcharts
2
+ class PolarSeries
3
+ attr_reader :sanitized
4
+
5
+ def initialize(data)
6
+ @labels = []
7
+ if data.is_a? Array
8
+ if data.first.is_a? Numeric
9
+ @series = data
10
+ elsif data.first.is_a? Hash
11
+ @labels = data.map{|m| m[:name] }.compact
12
+ @series = data.map{|m| m[:data] }
13
+ end
14
+ elsif data.is_a? Hash
15
+ if data[:data].is_a? Array
16
+ @series = data[:data]
17
+ end
18
+ end
19
+
20
+ @sanitized = {
21
+ labels: @labels.empty? ? nil : @labels,
22
+ series: @series
23
+ }.compact
24
+ end
25
+ end
26
+ end
27
+
@@ -1 +1,2 @@
1
1
  require_relative 'series/cartesian'
2
+ require_relative 'series/polar'
@@ -36,14 +36,10 @@ module Apexcharts::Utils
36
36
  input
37
37
  end
38
38
 
39
- def self.xtype input
39
+ def self.type input
40
40
  case input
41
- when Time
42
- 'datetime'
43
- when DateTime, Date
41
+ when Time, DateTime, Date
44
42
  'datetime'
45
- when Date
46
- 'date'
47
43
  else
48
44
  if DateTime.iso8601(input).iso8601 == input
49
45
  'datetime'
@@ -1,3 +1,3 @@
1
1
  module Apexcharts
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apexcharts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Setyadi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-13 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_kv
@@ -96,8 +96,12 @@ files:
96
96
  - lib/apexcharts/charts/capabilities/annotations.rb
97
97
  - lib/apexcharts/charts/cartesian.rb
98
98
  - lib/apexcharts/charts/column.rb
99
+ - lib/apexcharts/charts/donut.rb
99
100
  - lib/apexcharts/charts/line.rb
100
101
  - lib/apexcharts/charts/mixed.rb
102
+ - lib/apexcharts/charts/pie.rb
103
+ - lib/apexcharts/charts/polar.rb
104
+ - lib/apexcharts/charts/radial_bar.rb
101
105
  - lib/apexcharts/charts/scatter.rb
102
106
  - lib/apexcharts/charts/syncing.rb
103
107
  - lib/apexcharts/helper.rb
@@ -124,6 +128,7 @@ files:
124
128
  - lib/apexcharts/options_builder.rb
125
129
  - lib/apexcharts/series.rb
126
130
  - lib/apexcharts/series/cartesian.rb
131
+ - lib/apexcharts/series/polar.rb
127
132
  - lib/apexcharts/support/rails.rb
128
133
  - lib/apexcharts/utils.rb
129
134
  - lib/apexcharts/utils/date_time.rb