chart_js 1.0.0pre → 1.0.0

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
  SHA1:
3
- metadata.gz: 0a2713c9196c3d35025af1e7bb53c642f85290e4
4
- data.tar.gz: ee8e2c484bd08f69e6da46fdfaead46081b5a57b
3
+ metadata.gz: 6d5433dfcad2fb978dc2b9474edda31381e9e483
4
+ data.tar.gz: 95d91c7d2be4974d1f578d4bd0bff15c4b621bd7
5
5
  SHA512:
6
- metadata.gz: 969504c4340a4f2f041fd720fc43168dc7d6ddb44c0431177ded05546a5505a2bfa1ee9aeba1ea8d8fc075859ddda5ad5308882d953d0a8cdc9f3b7f6c20c895
7
- data.tar.gz: 3cdc111e2fa229eba1067490557846608e4d9b32e908bbf1537a1b97493002586a07bb643f9a3289ff7ebf92723ca71eb1b2be1ab085ad6bb0c166c1b9e956c4
6
+ metadata.gz: fe11f5028539cb7913216f635f1bb31ac0692795bb12059ade9240269cff23306043d758dcfa4385bb01eb373b18216435fe78b2f6d966387908f08749a0fd1c
7
+ data.tar.gz: 64ed9b7621094280315ec0f74b3d70bf6f795a0dae93602f0cc4dd64175213410b384403fed4fa22ecc4ef4af09fcad346a44e35d940c03956e6d46362da4a85
data/README.md CHANGED
@@ -4,9 +4,7 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- This gem is still in development. Install with `--pre`.
8
-
9
- $ gem install chart_js --pre
7
+ $ gem install chart_js
10
8
 
11
9
  ## Usage
12
10
 
@@ -16,3 +16,4 @@ ChartJS.line do
16
16
  end
17
17
  end
18
18
  end
19
+
@@ -65,17 +65,17 @@ module ChartJS
65
65
  SecureRandom.uuid
66
66
  end
67
67
 
68
- def script(config: to_json, id: random_id)
68
+ def script(config: to_json, id: random_id, chart_name: id)
69
69
  "<script>
70
70
  var config = #{config}
71
71
  window.onload = function() {
72
72
  var ctx = document.getElementById(\"#{id}\").getContext(\"2d\");
73
- new Chart(ctx, config);
73
+ var #{chart_name} = new Chart(ctx, config);
74
74
  };
75
75
  </script>"
76
76
  end
77
77
 
78
- def to_html(width: "60%", heigth: width, head: true, cdn: head, version: "2.6.0", body: true, id: random_id, script: true)
78
+ def to_html(width: "60%", heigth: width, head: true, cdn: head, version: "2.6.0", body: true, id: random_id, script: true, chart_name: id)
79
79
  str = []
80
80
  if cdn
81
81
  str << "<head>#{cdn(version: version)}</head>"
@@ -85,7 +85,7 @@ module ChartJS
85
85
  str << "<canvas id=\"#{id}\"/>"
86
86
  str << "</div>"
87
87
  str << "</body>" if body
88
- str << script(id: id) if script
88
+ str << script(id: id, chart_name: chart_name) if script
89
89
  str.join("\n")
90
90
  end
91
91
 
@@ -60,17 +60,20 @@ module ChartJS
60
60
  SecureRandom.uuid
61
61
  end
62
62
 
63
- def script(config: to_json, id: random_id)
63
+ def script(config: to_json, id: random_id, chart_name: id)
64
64
  "<script>
65
- var config = #{config}
66
- window.onload = function() {
67
- var ctx = document.getElementById(\"#{id}\").getContext(\"2d\");
68
- new Chart(ctx, config);
69
- };
65
+ var config = #{config};
66
+ var ctx = document.getElementById(\"#{id}\").getContext(\"2d\");
67
+ var #{chart_name.gsub("-","_")} = new Chart(ctx, config);
68
+ // var #{chart_name.gsub("-","_")};
69
+ // window.onload = function() {
70
+ // var ctx = document.getElementById(\"#{id}\").getContext(\"2d\");
71
+ // var #{chart_name.gsub("-","_")} = new Chart(ctx, config);
72
+ //};
70
73
  </script>"
71
74
  end
72
75
 
73
- def to_html(width: "60%", heigth: width, head: true, cdn: head, version: "2.6.0", body: true, id: random_id, script: true)
76
+ def to_html(width: "60%", heigth: width, head: true, cdn: head, version: "2.6.0", body: true, id: random_id, script: true, chart_name: "line_chart")
74
77
  str = []
75
78
  if cdn
76
79
  str << "<head>#{cdn(version: version)}</head>"
@@ -80,7 +83,7 @@ module ChartJS
80
83
  str << "<canvas id=\"#{id}\"/>"
81
84
  str << "</div>"
82
85
  str << "</body>" if body
83
- str << script(id: id) if script
86
+ str << script(id: id, chart_name: chart_name) if script
84
87
  str.join("\n")
85
88
  end
86
89
 
@@ -1,3 +1,3 @@
1
1
  module ChartJS
2
- VERSION = "1.0.0pre"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chart_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0pre
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent 'picat' Gruber
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-30 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,7 +105,6 @@ files:
105
105
  - lib/chart_js/chart/dataset/point_border.rb
106
106
  - lib/chart_js/chart/dataset/point_hover.rb
107
107
  - lib/chart_js/chart/file.rb
108
- - lib/chart_js/chart/line_chart.rb
109
108
  - lib/chart_js/chart/line_chart/background.rb
110
109
  - lib/chart_js/chart/line_chart/border.rb
111
110
  - lib/chart_js/chart/line_chart/data.rb
@@ -157,9 +156,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
156
  version: '0'
158
157
  required_rubygems_version: !ruby/object:Gem::Requirement
159
158
  requirements:
160
- - - ">"
159
+ - - ">="
161
160
  - !ruby/object:Gem::Version
162
- version: 1.3.1
161
+ version: '0'
163
162
  requirements: []
164
163
  rubyforge_project:
165
164
  rubygems_version: 2.6.8
@@ -1,99 +0,0 @@
1
- require "json"
2
- require "securerandom"
3
- require_relative "data.rb"
4
- require_relative "opts.rb"
5
- require_relative "file.rb"
6
-
7
- module ChartJS
8
-
9
- class LineChart
10
-
11
- def initialize(&block)
12
- @type = nil
13
- @data = nil
14
- @opts = nil
15
- @file = false
16
- build(&block) if block_given?
17
- end
18
-
19
- def build(&block)
20
- instance_eval(&block)
21
- if @file
22
- f = SaveFile.new(@file, html: to_html)
23
- f.save!
24
- end
25
- self
26
- end
27
-
28
- def to_h
29
- { type: @type, data: @data.to_h, options: @opts.to_h }
30
- end
31
-
32
- def to_json(type = :pretty)
33
- return JSON.pretty_generate(to_h) if type == :pretty
34
- to_h.to_json
35
- end
36
-
37
- def type(value = nil)
38
- return @type if value.nil?
39
- @type = value
40
- end
41
-
42
- def data(&block)
43
- return @data unless block_given?
44
- @data = Data.new.build(&block)
45
- end
46
-
47
- def opts(&block)
48
- return @opts unless block_given?
49
- @opts = Opts.new.build(&block)
50
- end
51
-
52
- def cdn(version: "2.6.0", min: true)
53
- if min
54
- "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/#{version}/Chart.min.js\"></script>"
55
- else
56
- "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/#{version}/Chart.js\"></script>"
57
- end
58
- end
59
-
60
- def random_color
61
- "##{SecureRandom.hex(3)}"
62
- end
63
-
64
- def random_id
65
- SecureRandom.uuid
66
- end
67
-
68
- def script(config: to_json, id: random_id)
69
- "<script>
70
- var config = #{config}
71
- window.onload = function() {
72
- var ctx = document.getElementById(\"#{id}\").getContext(\"2d\");
73
- new Chart(ctx, config);
74
- };
75
- </script>"
76
- end
77
-
78
- def to_html(width: "60%", heigth: width, head: true, cdn: head, version: "2.6.0", body: true, id: random_id, script: true)
79
- str = []
80
- if cdn
81
- str << "<head>#{cdn(version: version)}</head>"
82
- end
83
- str << "<body>" if body
84
- str << "<div id=\"canvas-holder\" style=\"width:#{width} heigth:#{heigth}\">"
85
- str << "<canvas id=\"#{id}\"/>"
86
- str << "</div>"
87
- str << "</body>" if body
88
- str << script(id: id) if script
89
- str.join("\n")
90
- end
91
-
92
- def file(path, &block)
93
- @file = path
94
- @file_block = block
95
- end
96
-
97
- end
98
-
99
- end