amcharts.rb 3.4.7.2 → 3.4.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/assets/javascripts/amcharts/helpers.js +11 -5
- data/app/helpers/amcharts/amcharts_helper.rb +8 -1
- data/app/views/amcharts/_data_source.erb +1 -1
- data/app/views/amcharts/_export.erb +11 -0
- data/app/views/amcharts/_legend.erb +1 -0
- data/app/views/amcharts/_listener.erb +5 -1
- data/app/views/amcharts/chart_builder.erb +4 -2
- data/lib/amcharts.rb +12 -11
- data/lib/amcharts/chart.rb +11 -1
- data/lib/amcharts/chart_builder.rb +8 -3
- data/lib/amcharts/export_settings.rb +48 -0
- data/lib/amcharts/legend.rb +13 -1
- data/lib/amcharts/uses_settings.rb +2 -0
- data/lib/amcharts/version.rb +1 -1
- data/vendor/assets/images/amcharts/export.png +0 -0
- data/vendor/assets/images/amcharts/exportBlack.png +0 -0
- data/vendor/assets/javascripts/amcharts/all.js +7 -7
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGUwZDE5ZDNkOGZhYWFmZDQ3NDY4YWExODUzMGJmZDcxMzkzZGMzYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTMzZWE0ZDgxMWNkMTYyNjYxZGIzZjEzM2NhYzgzOWYyZGFkYzQzYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTMyYmM1N2U4YTE5OTg5ZmU1MjZhYTc1YzY2Y2U3YTVmNGY2NzNmZTJkM2U0
|
10
|
+
ODExMDMwMDEyOWJkZDQ1ZjBjMDg0NDcxMzA5ZDFmYmNlMTk0ZjZjN2Y3OWZh
|
11
|
+
N2Y1NTk0YTIwYjFhMDY1NjNkYzQ3ZTI0OTA4MDQzNmQxZjQ3NDk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTU2NTIyM2UwYjg3MzllNjMyOTJjZjcxZGIwMTg5MzExM2RhOWQwZTM5ODI2
|
14
|
+
MmFmZWU0NzM4NjZjZWZlNjhlM2VhYjcxNDExNTFjZDljN2FmOGExNTY1NTQ0
|
15
|
+
YjNhNTkwNDQ4OTczODViNjc5ZGUzZTVlYmU1NWI4NTc0NmFhMmQ=
|
@@ -1,4 +1,10 @@
|
|
1
1
|
AmCharts.RB.Helpers = {
|
2
|
+
create_unit: function(num, unit)
|
3
|
+
{
|
4
|
+
// If the number doesn't end with a unit already, add the given one
|
5
|
+
return num.toString().match(/\d$/) ? num + unit : num;
|
6
|
+
},
|
7
|
+
|
2
8
|
add_container_if_needed: function(id, width, height)
|
3
9
|
{
|
4
10
|
var container = document.getElementById(id);
|
@@ -7,8 +13,8 @@ AmCharts.RB.Helpers = {
|
|
7
13
|
container = document.createElement("DIV");
|
8
14
|
container.className = 'chart';
|
9
15
|
container.id = id;
|
10
|
-
container.style.width = width
|
11
|
-
container.style.height = height
|
16
|
+
if (width) container.style.width = this.create_unit(width, 'px');
|
17
|
+
container.style.height = this.create_unit(height, 'px');
|
12
18
|
|
13
19
|
// Add the container before the last script
|
14
20
|
var scripts = document.getElementsByTagName('script');
|
@@ -19,7 +25,7 @@ AmCharts.RB.Helpers = {
|
|
19
25
|
return container;
|
20
26
|
},
|
21
27
|
|
22
|
-
add_blanket: function(container
|
28
|
+
add_blanket: function(container)
|
23
29
|
{
|
24
30
|
var wrapper = document.createElement("DIV"),
|
25
31
|
blanket = document.createElement("DIV"),
|
@@ -29,8 +35,8 @@ AmCharts.RB.Helpers = {
|
|
29
35
|
|
30
36
|
wrapper.className = 'chart-wrapper';
|
31
37
|
wrapper.id = container.id + "_wrapper";
|
32
|
-
wrapper.style.width = width
|
33
|
-
wrapper.style.minHeight = height
|
38
|
+
wrapper.style.width = container.style.width;
|
39
|
+
wrapper.style.minHeight = container.style.height;
|
34
40
|
|
35
41
|
container.style.width = '100%';
|
36
42
|
blanket.className = 'chart-blanket';
|
@@ -4,7 +4,14 @@ module AmCharts
|
|
4
4
|
# Load necessary JS and CSSfiles, without loading one more than once
|
5
5
|
@loaded_amchart_files ||= { js: [], css: []}
|
6
6
|
|
7
|
-
js_files = ['amcharts', "amcharts/#{chart.type}"]
|
7
|
+
js_files = ['amcharts', "amcharts/#{chart.type}"]
|
8
|
+
|
9
|
+
if chart.export?
|
10
|
+
js_files.concat(%w(amcharts/exporting/amexport amcharts/exporting/rgbcolor amcharts/exporting/canvg amcharts/exporting/filesaver))
|
11
|
+
js_files.concat(%w(amcharts/exporting/jspdf amcharts/exporting/jspdf.plugin.addimage)) if chart.export.pdf?
|
12
|
+
end
|
13
|
+
|
14
|
+
js_files -= @loaded_amchart_files[:js]
|
8
15
|
css_files = ['amcharts'] - @loaded_amchart_files[:css]
|
9
16
|
|
10
17
|
@loaded_amchart_files[:js] += js_files
|
@@ -4,5 +4,5 @@ chart.remoteProvider = new AmCharts.RB.RemoteJSONProvider(chart, data_source, pa
|
|
4
4
|
chart.remoteProvider.load();
|
5
5
|
<% end %>
|
6
6
|
<% if builder.chart.loading_indicator? %>
|
7
|
-
<%= builder.render_js 'listener', locals: { type: :dataUpdated, method: 'AmCharts.RB.Helpers.hide_loading_indicator' } %>
|
7
|
+
<%= builder.render_js 'listener', locals: { type: :dataUpdated, method: 'AmCharts.RB.Helpers.hide_loading_indicator', var_name: 'chart' } %>
|
8
8
|
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
var exportConfig = {};
|
2
|
+
<% builder.render_settings(export, 'exportConfig') %>
|
3
|
+
<% export.menus.each.with_index do |m, i| %>
|
4
|
+
var menu = {};
|
5
|
+
<% if i == 0 %>
|
6
|
+
exportConfig.menuItems = [];
|
7
|
+
<% end %>
|
8
|
+
<% builder.render_settings(m, 'menu') %>
|
9
|
+
exportConfig.menuItems.push(menu);
|
10
|
+
<% end %>
|
11
|
+
chart.exportConfig = exportConfig;
|
@@ -1 +1,5 @@
|
|
1
|
-
|
1
|
+
<%= var_name %>.addListener(<%= builder.to_js(type.to_s) %>, function() {
|
2
|
+
args = Array.prototype.slice.call(arguments);
|
3
|
+
args.unshift(chart);
|
4
|
+
return <%= method %>.apply(null, args)
|
5
|
+
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// If the container element doesn't already exist, create it
|
2
|
-
var container = AmCharts.RB.Helpers.add_container_if_needed('<%= container %>', <%= chart.width %>, <%= chart.height %>);
|
3
|
-
AmCharts.RB.Helpers.add_blanket(container
|
2
|
+
var container = AmCharts.RB.Helpers.add_container_if_needed('<%= container %>', <%= builder.to_js chart.width %>, <%= builder.to_js chart.height %>);
|
3
|
+
AmCharts.RB.Helpers.add_blanket(container)
|
4
4
|
<% if chart.loading_indicator? %>
|
5
5
|
AmCharts.RB.Helpers.add_loading_indicator(container, <%= builder.to_js(:chart_data_loading) %>, '<%= escape_javascript asset_path('amcharts/loading.gif') %>');
|
6
6
|
<% end %>
|
@@ -33,6 +33,8 @@ AmCharts.ready(function() {
|
|
33
33
|
|
34
34
|
<% builder.render_listeners %>
|
35
35
|
|
36
|
+
<% builder.render_export %>
|
37
|
+
|
36
38
|
chart.write('<%= container %>');
|
37
39
|
|
38
40
|
<% builder.render_data_source %>
|
data/lib/amcharts.rb
CHANGED
@@ -3,17 +3,18 @@ require "amcharts/version"
|
|
3
3
|
require_relative '../app/helpers/amcharts/amcharts_helper'
|
4
4
|
|
5
5
|
module AmCharts
|
6
|
-
autoload :Axis,
|
7
|
-
autoload :Chart,
|
8
|
-
autoload :ChartBuilder,
|
9
|
-
autoload :Cursor,
|
10
|
-
autoload :DataSource,
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
6
|
+
autoload :Axis, 'amcharts/axis'
|
7
|
+
autoload :Chart, 'amcharts/chart'
|
8
|
+
autoload :ChartBuilder, 'amcharts/chart_builder'
|
9
|
+
autoload :Cursor, 'amcharts/cursor'
|
10
|
+
autoload :DataSource, 'amcharts/data_source'
|
11
|
+
autoload :ExportSettings, 'amcharts/export_settings'
|
12
|
+
autoload :Graph, 'amcharts/graph'
|
13
|
+
autoload :Legend, 'amcharts/legend'
|
14
|
+
autoload :Listener, 'amcharts/listener'
|
15
|
+
autoload :ScrollBar, 'amcharts/scroll_bar'
|
16
|
+
autoload :Settings, 'amcharts/settings'
|
17
|
+
autoload :UsesSettings, 'amcharts/uses_settings'
|
17
18
|
|
18
19
|
ActiveSupport::Inflector.inflections do |inflect|
|
19
20
|
inflect.acronym "AmCharts"
|
data/lib/amcharts/chart.rb
CHANGED
@@ -15,7 +15,7 @@ module AmCharts
|
|
15
15
|
|
16
16
|
attr_accessor :data_provider, :data_source, :container
|
17
17
|
attr_accessor :width, :height, :loading_indicator
|
18
|
-
attr_reader :titles, :graphs, :legends, :data, :settings, :listeners, :legend_div
|
18
|
+
attr_reader :titles, :graphs, :legends, :data, :settings, :listeners, :legend_div, :export
|
19
19
|
|
20
20
|
def initialize(*data, &block)
|
21
21
|
@data = data.flatten
|
@@ -24,6 +24,7 @@ module AmCharts
|
|
24
24
|
@legends = Collection[Legend]
|
25
25
|
@listeners = Collection[Listener]
|
26
26
|
@settings = Settings.new
|
27
|
+
@export = ExportSettings.new
|
27
28
|
@titles = []
|
28
29
|
update_settings(&block) if block_given?
|
29
30
|
end
|
@@ -58,6 +59,15 @@ module AmCharts
|
|
58
59
|
"AmCharts.Am#{type.to_s.titleize}Chart()"
|
59
60
|
end
|
60
61
|
|
62
|
+
def export?
|
63
|
+
!@export.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def export(&block)
|
67
|
+
yield @export if block_given?
|
68
|
+
@export
|
69
|
+
end
|
70
|
+
|
61
71
|
def add_title(text, options = {})
|
62
72
|
@titles << [text, options.reverse_merge(size: 13, bold: true, alpha: 1, color: '#000000')]
|
63
73
|
end
|
@@ -72,12 +72,17 @@ module AmCharts
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def render_listeners()
|
76
|
-
|
77
|
-
concat render_js('listener', locals: { type: listener.type, method: listener.method })
|
75
|
+
def render_listeners(object = chart, var_name = 'chart')
|
76
|
+
object.listeners.each do |listener|
|
77
|
+
concat render_js('listener', locals: { type: listener.type, method: listener.method, var_name: var_name })
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
def render_export
|
82
|
+
return if chart.export.empty?
|
83
|
+
concat render_js('export', object: chart.export)
|
84
|
+
end
|
85
|
+
|
81
86
|
private
|
82
87
|
|
83
88
|
def method_missing(*args, &block)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'amcharts/uses_settings'
|
2
|
+
|
3
|
+
module AmCharts
|
4
|
+
class ExportSettings
|
5
|
+
class Menu
|
6
|
+
include UsesSettings
|
7
|
+
|
8
|
+
def initialize(*)
|
9
|
+
super
|
10
|
+
|
11
|
+
if defined? Rails
|
12
|
+
@settings.icon ||= ActionController::Base.helpers.asset_path('amcharts/export.png')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def formats
|
17
|
+
formats = []
|
18
|
+
formats << @settings[:format].to_s.downcase.to_sym if @settings[:format]
|
19
|
+
|
20
|
+
if @settings[:items]
|
21
|
+
@settings[:items].each do |i|
|
22
|
+
formats << i[:format].to_s.downcase.to_sym if i[:format]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
formats
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :settings, :menus
|
31
|
+
|
32
|
+
def initialize(&block)
|
33
|
+
@settings = Settings.new
|
34
|
+
@menus = Collection[Menu]
|
35
|
+
instance_exec(self, &block) if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
def pdf?
|
39
|
+
return false if menus.empty?
|
40
|
+
menus.flat_map(&:formats).any?{ |f| f == :pdf }
|
41
|
+
end
|
42
|
+
private
|
43
|
+
|
44
|
+
def method_missing(name, *args, &block)
|
45
|
+
@settings.send(name, *args, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/amcharts/legend.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
module AmCharts
|
2
2
|
class Legend
|
3
|
-
|
3
|
+
attr_reader :settings, :listeners
|
4
|
+
|
5
|
+
def initialize(&block)
|
6
|
+
@settings = Settings.new
|
7
|
+
@listeners = Collection[Listener]
|
8
|
+
instance_exec(self, &block) if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def method_missing(name, *args, &block)
|
14
|
+
@settings.send(name, *args, &block)
|
15
|
+
end
|
4
16
|
end
|
5
17
|
end
|
data/lib/amcharts/version.rb
CHANGED
Binary file
|
Binary file
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/*
|
2
2
|
*= require amcharts
|
3
|
-
*= require amstock
|
4
|
-
*= require funnel
|
5
|
-
*= require gauge
|
6
|
-
*= require pie
|
7
|
-
*= require radar
|
8
|
-
*= require serial
|
9
|
-
*= require xy
|
3
|
+
*= require amcharts/amstock
|
4
|
+
*= require amcharts/funnel
|
5
|
+
*= require amcharts/gauge
|
6
|
+
*= require amcharts/pie
|
7
|
+
*= require amcharts/radar
|
8
|
+
*= require amcharts/serial
|
9
|
+
*= require amcharts/xy
|
10
10
|
*/
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amcharts.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.7.
|
4
|
+
version: 3.4.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vandersluis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
type: :runtime
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- app/views/amcharts/_collection.erb
|
153
153
|
- app/views/amcharts/_data.erb
|
154
154
|
- app/views/amcharts/_data_source.erb
|
155
|
+
- app/views/amcharts/_export.erb
|
155
156
|
- app/views/amcharts/_legend.erb
|
156
157
|
- app/views/amcharts/_listener.erb
|
157
158
|
- app/views/amcharts/_object.erb
|
@@ -175,6 +176,7 @@ files:
|
|
175
176
|
- lib/amcharts/chart_builder/literal.rb
|
176
177
|
- lib/amcharts/cursor.rb
|
177
178
|
- lib/amcharts/data_source.rb
|
179
|
+
- lib/amcharts/export_settings.rb
|
178
180
|
- lib/amcharts/graph.rb
|
179
181
|
- lib/amcharts/legend.rb
|
180
182
|
- lib/amcharts/listener.rb
|
@@ -194,6 +196,7 @@ files:
|
|
194
196
|
- vendor/assets/images/amcharts/eraserIcon.gif
|
195
197
|
- vendor/assets/images/amcharts/eraserIconH.gif
|
196
198
|
- vendor/assets/images/amcharts/export.png
|
199
|
+
- vendor/assets/images/amcharts/exportBlack.png
|
197
200
|
- vendor/assets/images/amcharts/exportWhite.png
|
198
201
|
- vendor/assets/images/amcharts/lens.png
|
199
202
|
- vendor/assets/images/amcharts/lensWhite.png
|