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 +4 -4
- data/README.md +1 -3
- data/examples/line_chart.rb +1 -0
- data/lib/chart_js/chart/chart.rb +4 -4
- data/lib/chart_js/chart/line_chart/line_chart.rb +11 -8
- data/lib/chart_js/version.rb +1 -1
- metadata +4 -5
- data/lib/chart_js/chart/line_chart.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5433dfcad2fb978dc2b9474edda31381e9e483
|
4
|
+
data.tar.gz: 95d91c7d2be4974d1f578d4bd0bff15c4b621bd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe11f5028539cb7913216f635f1bb31ac0692795bb12059ade9240269cff23306043d758dcfa4385bb01eb373b18216435fe78b2f6d966387908f08749a0fd1c
|
7
|
+
data.tar.gz: 64ed9b7621094280315ec0f74b3d70bf6f795a0dae93602f0cc4dd64175213410b384403fed4fa22ecc4ef4af09fcad346a44e35d940c03956e6d46362da4a85
|
data/README.md
CHANGED
data/examples/line_chart.rb
CHANGED
data/lib/chart_js/chart/chart.rb
CHANGED
@@ -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
|
-
|
67
|
-
|
68
|
-
|
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
|
|
data/lib/chart_js/version.rb
CHANGED
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.
|
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-
|
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:
|
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
|