apexcharts 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -11
- data/lib/apexcharts/charts.rb +2 -0
- data/lib/apexcharts/charts/bubble.rb +20 -0
- data/lib/apexcharts/charts/cartesian.rb +6 -2
- data/lib/apexcharts/charts/heatmap.rb +10 -0
- data/lib/apexcharts/charts/mixed.rb +1 -1
- data/lib/apexcharts/charts/polar.rb +1 -1
- data/lib/apexcharts/charts/syncing.rb +4 -4
- data/lib/apexcharts/helper.rb +16 -6
- data/lib/apexcharts/series.rb +1 -0
- data/lib/apexcharts/series/bubble.rb +37 -0
- data/lib/apexcharts/series/cartesian.rb +60 -15
- data/lib/apexcharts/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a866b4e6545c50cf331fe31f383f8493ee2caf991e7e034654a011cd41d824ac
|
4
|
+
data.tar.gz: fd243a66fa09eb5ccbb7c9255dd536e6948f7b0f22d496986cd2788d966aec31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c1bf094d88f7bc524fefab6be0dc424454f552a490e83cd58df176dd236cdf799681a0e46af74548f176761681a6e69ab82fd67b7c1f9d2f5286f88b5aa3b1
|
7
|
+
data.tar.gz: 0cf54ed3c2d01f5991bdc1578c8a5b2af829fe2f936eb86d76a8d96f19629219119b70eefd56cd7fd25b5c8df0bc04083883825168f3e8f8c01c304f024c8d27
|
data/README.md
CHANGED
@@ -37,7 +37,8 @@ and I'll get the data in this format:
|
|
37
37
|
..
|
38
38
|
}
|
39
39
|
```
|
40
|
-
PS: `Property` can be any model you have and `inactive` and `active`
|
40
|
+
PS: `Property` can be any model you have and `inactive` and `active`
|
41
|
+
are just some normal ActiveRecord scopes.
|
41
42
|
|
42
43
|
Example options used for cartesian charts:
|
43
44
|
|
@@ -100,9 +101,9 @@ Example options used for cartesian charts:
|
|
100
101
|
![Example Scatter Chart](images/scatter_chart.png)
|
101
102
|
|
102
103
|
|
103
|
-
#### Mixed
|
104
|
+
#### Mixed Charts
|
104
105
|
|
105
|
-
You can mix charts by using `
|
106
|
+
You can mix charts by using `mixed_charts` or `combo_charts` methods. For example:
|
106
107
|
Given that:
|
107
108
|
```ruby
|
108
109
|
@total_properties = Property.group_by_week(:created_at).count
|
@@ -115,21 +116,21 @@ and
|
|
115
116
|
```
|
116
117
|
you can do this:
|
117
118
|
```erb
|
118
|
-
<%=
|
119
|
+
<%= combo_charts({**options, theme: 'palette4', stacked: false, data_labels: false}) do %>
|
119
120
|
<% line_chart(total_series) %>
|
120
121
|
<% area_chart(series.last) %>
|
121
122
|
<% column_chart(series.first) %>
|
122
123
|
<% end %>
|
123
124
|
```
|
124
|
-
![Example Mixed
|
125
|
+
![Example Mixed Charts](images/mixed_charts.gif)
|
125
126
|
|
126
127
|
|
127
|
-
#### Syncing
|
128
|
+
#### Syncing Charts
|
128
129
|
|
129
|
-
You can synchronize charts by using `
|
130
|
+
You can synchronize charts by using `syncing_charts` or `synchronized_charts` methods. For example:
|
130
131
|
```erb
|
131
|
-
<%=
|
132
|
-
<%
|
132
|
+
<%= syncing_charts(chart: {toolbar: false}, height: 250, style: 'display: inline-block; width: 32%;') do %>
|
133
|
+
<% mixed_charts(theme: 'palette4', data_labels: false) do %>
|
133
134
|
<% line_chart({name: "Total", data: @total_properties}) %>
|
134
135
|
<% area_chart({name: "Active", data: @active_properties}) %>
|
135
136
|
<% end %>
|
@@ -137,7 +138,7 @@ You can synchronize charts by using `syncing_chart` or `synchronized_chart` meth
|
|
137
138
|
<% line_chart({name: "Inactive", data: @active_properties}, theme: 'palette8') %>
|
138
139
|
<% end %>
|
139
140
|
```
|
140
|
-
![Example Syncing
|
141
|
+
![Example Syncing Charts](images/syncing_charts.gif)
|
141
142
|
|
142
143
|
|
143
144
|
#### Brush Chart
|
@@ -146,7 +147,7 @@ You can synchronize charts by using `syncing_chart` or `synchronized_chart` meth
|
|
146
147
|
<%= area_chart(total_series, {
|
147
148
|
**options, chart_id: 'the-chart', xtitle: nil, theme: 'palette2'
|
148
149
|
}) %>
|
149
|
-
<%=
|
150
|
+
<%= mixed_charts(brush_target: 'the-chart', theme: 'palette7') do %>
|
150
151
|
<% column_chart(series.first) %>
|
151
152
|
<% line_chart(series.last) %>
|
152
153
|
<% end %>
|
@@ -154,6 +155,36 @@ You can synchronize charts by using `syncing_chart` or `synchronized_chart` meth
|
|
154
155
|
![Example Brush Chart](images/brush_chart.gif)
|
155
156
|
|
156
157
|
|
158
|
+
#### Heatmap Chart
|
159
|
+
|
160
|
+
```erb
|
161
|
+
<% heatmap_series = 17.downto(10).map do |n|
|
162
|
+
{
|
163
|
+
name: "#{n}:00",
|
164
|
+
data: 15.times.map do |i|
|
165
|
+
["W#{i+1}", rand(90)]
|
166
|
+
end.to_h
|
167
|
+
}
|
168
|
+
end %>
|
169
|
+
<%= heatmap_chart(heatmap_series) %>
|
170
|
+
```
|
171
|
+
![Example Heatmap Chart](images/heatmap_chart.png)
|
172
|
+
|
173
|
+
|
174
|
+
#### Bubble Chart
|
175
|
+
|
176
|
+
```erb
|
177
|
+
<% bubble_series = (1..4).map do |n|
|
178
|
+
{
|
179
|
+
name: "Bubble#{n}",
|
180
|
+
data: 20.times.map{[rand(750),rand(10..60),rand(70)]}
|
181
|
+
}
|
182
|
+
end %>
|
183
|
+
<%= bubble_chart(bubble_series, data_labels: false, theme: 'palette6') %>
|
184
|
+
```
|
185
|
+
![Example Bubble Chart](images/bubble_chart.png)
|
186
|
+
|
187
|
+
|
157
188
|
#### Annotations
|
158
189
|
|
159
190
|
All cartesian charts can have annotations, for example:
|
data/lib/apexcharts/charts.rb
CHANGED
@@ -4,6 +4,8 @@ require_relative 'charts/area'
|
|
4
4
|
require_relative 'charts/bar'
|
5
5
|
require_relative 'charts/column'
|
6
6
|
require_relative 'charts/scatter'
|
7
|
+
require_relative 'charts/heatmap'
|
8
|
+
require_relative 'charts/bubble'
|
7
9
|
require_relative 'charts/mixed'
|
8
10
|
require_relative 'charts/syncing'
|
9
11
|
require_relative 'charts/polar'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Apexcharts
|
2
|
+
class BubbleChart < CartesianChart
|
3
|
+
def chart_type
|
4
|
+
'bubble'
|
5
|
+
end
|
6
|
+
|
7
|
+
def mixed_series
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def sanitize_data(data)
|
13
|
+
Apexcharts::BubbleSeries.new(data).sanitized
|
14
|
+
end
|
15
|
+
|
16
|
+
def x_sample
|
17
|
+
@series[:series][0][:data][0][0]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -15,7 +15,7 @@ module Apexcharts
|
|
15
15
|
@series = sanitize_data(data)
|
16
16
|
@options = Utils::Hash.camelize_keys(
|
17
17
|
Utils::Hash.deep_merge(
|
18
|
-
build_options(
|
18
|
+
build_options(x_sample, options),
|
19
19
|
{**@series, chart: {type: chart_type}}.compact
|
20
20
|
)
|
21
21
|
)
|
@@ -59,7 +59,7 @@ module Apexcharts
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
protected
|
63
63
|
|
64
64
|
def build_instance_variables
|
65
65
|
(@bindings.instance_variables - instance_variables).each do |i|
|
@@ -96,6 +96,10 @@ module Apexcharts
|
|
96
96
|
def handle_time(input)
|
97
97
|
Utils::DateTime.convert(input)
|
98
98
|
end
|
99
|
+
|
100
|
+
def x_sample
|
101
|
+
@series[:series][0][:data][0][:x]
|
102
|
+
end
|
99
103
|
end
|
100
104
|
end
|
101
105
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Apexcharts
|
2
|
-
class
|
2
|
+
class SyncingCharts
|
3
3
|
def initialize bindings, options={}, &block
|
4
4
|
@bindings = bindings
|
5
5
|
@html = ""
|
@@ -42,12 +42,12 @@ module Apexcharts
|
|
42
42
|
@html += ScatterChart.new(bindings, data, @options.merge(options), &block).render
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def mixed_charts options={}, &block
|
46
46
|
options[:id] = apexcharts_id
|
47
47
|
bindings = eval "self", block.binding
|
48
|
-
@html +=
|
48
|
+
@html += MixedCharts.new(bindings, @options.merge(options), &block).render
|
49
49
|
end
|
50
|
-
alias_method :
|
50
|
+
alias_method :combo_charts, :mixed_charts
|
51
51
|
|
52
52
|
def render
|
53
53
|
@html
|
data/lib/apexcharts/helper.rb
CHANGED
@@ -30,17 +30,27 @@ module Apexcharts
|
|
30
30
|
draw_chart(ScatterChart.new(bindings, *prepare_series_and_options(series, options), &block))
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def heatmap_chart series, options={}, &block
|
34
|
+
bindings = eval("self", block.binding) if block_given?
|
35
|
+
draw_chart(HeatmapChart.new(bindings, *prepare_series_and_options(series, options), &block))
|
36
|
+
end
|
37
|
+
|
38
|
+
def bubble_chart series, options={}, &block
|
39
|
+
bindings = eval("self", block.binding) if block_given?
|
40
|
+
draw_chart(BubbleChart.new(bindings, *prepare_series_and_options(series, options), &block))
|
41
|
+
end
|
42
|
+
|
43
|
+
def mixed_charts options={}, &block
|
34
44
|
bindings = eval("self", block.binding)
|
35
|
-
draw_chart(
|
45
|
+
draw_chart(MixedCharts.new(bindings, deep_copy(options), &block))
|
36
46
|
end
|
37
|
-
alias_method :
|
47
|
+
alias_method :combo_charts, :mixed_charts
|
38
48
|
|
39
|
-
def
|
49
|
+
def syncing_charts options={}, &block
|
40
50
|
bindings = eval("self", block.binding)
|
41
|
-
draw_chart(
|
51
|
+
draw_chart(SyncingCharts.new(bindings, deep_copy(options), &block))
|
42
52
|
end
|
43
|
-
alias_method :
|
53
|
+
alias_method :synchronized_charts, :syncing_charts
|
44
54
|
|
45
55
|
def pie_chart series, options={}
|
46
56
|
draw_chart(PieChart.new(*prepare_series_and_options(series, options)))
|
data/lib/apexcharts/series.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
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
|
+
|
@@ -4,26 +4,71 @@ module Apexcharts
|
|
4
4
|
|
5
5
|
def initialize(data)
|
6
6
|
data = deep_copy(data)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
@sanitized = case data
|
8
|
+
when Array
|
9
|
+
if array_of_pairs?(data)
|
10
|
+
case first_data = data[0]
|
11
|
+
when Array
|
12
|
+
[
|
13
|
+
{
|
14
|
+
data: array_of_array_to_array_of_xy(data)
|
15
|
+
}
|
16
|
+
]
|
17
|
+
|
18
|
+
when Hash
|
19
|
+
if first_data[:data]
|
20
|
+
data.each{|h| h[:data] = array_of_array_to_array_of_xy(h[:data]) }
|
21
|
+
data
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
else
|
27
|
+
data.map(&:to_h)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
when Hash
|
32
|
+
if data_value = data[:data]
|
33
|
+
if array_of_pairs?(data_value)
|
34
|
+
data[:data] = array_of_array_to_array_of_xy(data_value)
|
35
|
+
[data]
|
36
|
+
end
|
37
|
+
|
38
|
+
else
|
39
|
+
if data[:x] && data[:y]
|
40
|
+
[{data: [data]}]
|
41
|
+
|
42
|
+
else
|
43
|
+
[
|
44
|
+
{
|
45
|
+
data: data.map do |k,v|
|
46
|
+
{x: k, y: v}
|
47
|
+
end
|
48
|
+
}
|
49
|
+
]
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
@sanitized = {series: @sanitized}
|
22
58
|
end
|
23
59
|
|
24
60
|
def deep_copy(data)
|
25
61
|
Marshal.load(Marshal.dump(data))
|
26
62
|
end
|
63
|
+
|
64
|
+
def array_of_pairs?(data)
|
65
|
+
return false if data.empty?
|
66
|
+
data.all?{|d| d.length == 2 }
|
67
|
+
end
|
68
|
+
|
69
|
+
def array_of_array_to_array_of_xy(data)
|
70
|
+
data.map{|d| {x: d.first, y: d.last} }
|
71
|
+
end
|
27
72
|
end
|
28
73
|
end
|
29
74
|
|
data/lib/apexcharts/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.4
|
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
|
11
|
+
date: 2019-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_kv
|
@@ -93,10 +93,12 @@ files:
|
|
93
93
|
- lib/apexcharts/charts.rb
|
94
94
|
- lib/apexcharts/charts/area.rb
|
95
95
|
- lib/apexcharts/charts/bar.rb
|
96
|
+
- lib/apexcharts/charts/bubble.rb
|
96
97
|
- lib/apexcharts/charts/cartesian.rb
|
97
98
|
- lib/apexcharts/charts/column.rb
|
98
99
|
- lib/apexcharts/charts/donut.rb
|
99
100
|
- lib/apexcharts/charts/features/annotations.rb
|
101
|
+
- lib/apexcharts/charts/heatmap.rb
|
100
102
|
- lib/apexcharts/charts/line.rb
|
101
103
|
- lib/apexcharts/charts/mixed.rb
|
102
104
|
- lib/apexcharts/charts/pie.rb
|
@@ -127,6 +129,7 @@ files:
|
|
127
129
|
- lib/apexcharts/options/y_axis.rb
|
128
130
|
- lib/apexcharts/options_builder.rb
|
129
131
|
- lib/apexcharts/series.rb
|
132
|
+
- lib/apexcharts/series/bubble.rb
|
130
133
|
- lib/apexcharts/series/cartesian.rb
|
131
134
|
- lib/apexcharts/series/polar.rb
|
132
135
|
- lib/apexcharts/support/rails.rb
|