piko-sharp-rb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/chartkick-5.2.1/CHANGELOG.md +418 -0
- data/chartkick-5.2.1/LICENSE.txt +22 -0
- data/chartkick-5.2.1/README.md +655 -0
- data/chartkick-5.2.1/lib/chartkick/core_ext.rb +26 -0
- data/chartkick-5.2.1/lib/chartkick/engine.rb +13 -0
- data/chartkick-5.2.1/lib/chartkick/helper.rb +138 -0
- data/chartkick-5.2.1/lib/chartkick/sinatra.rb +5 -0
- data/chartkick-5.2.1/lib/chartkick/utils.rb +24 -0
- data/chartkick-5.2.1/lib/chartkick/version.rb +3 -0
- data/chartkick-5.2.1/lib/chartkick.rb +27 -0
- data/chartkick-5.2.1/licenses/LICENSE-chart.js.txt +9 -0
- data/chartkick-5.2.1/licenses/LICENSE-chartjs-adapter-date-fns.txt +9 -0
- data/chartkick-5.2.1/licenses/LICENSE-chartkick.js.txt +22 -0
- data/chartkick-5.2.1/licenses/LICENSE-date-fns.txt +21 -0
- data/chartkick-5.2.1/licenses/LICENSE-kurkle-color.txt +9 -0
- data/chartkick-5.2.1/vendor/assets/javascripts/Chart.bundle.js +24219 -0
- data/chartkick-5.2.1/vendor/assets/javascripts/chartkick.js +2570 -0
- data/piko-sharp-rb.gemspec +12 -0
- metadata +59 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
module Chartkick
|
|
2
|
+
module Helper
|
|
3
|
+
def line_chart(data_source, **options)
|
|
4
|
+
chartkick_chart "LineChart", data_source, **options
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def pie_chart(data_source, **options)
|
|
8
|
+
chartkick_chart "PieChart", data_source, **options
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def column_chart(data_source, **options)
|
|
12
|
+
chartkick_chart "ColumnChart", data_source, **options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def bar_chart(data_source, **options)
|
|
16
|
+
chartkick_chart "BarChart", data_source, **options
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def area_chart(data_source, **options)
|
|
20
|
+
chartkick_chart "AreaChart", data_source, **options
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def scatter_chart(data_source, **options)
|
|
24
|
+
chartkick_chart "ScatterChart", data_source, **options
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def geo_chart(data_source, **options)
|
|
28
|
+
chartkick_chart "GeoChart", data_source, **options
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def timeline(data_source, **options)
|
|
32
|
+
chartkick_chart "Timeline", data_source, **options
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# don't break out options since need to merge with default options
|
|
38
|
+
def chartkick_chart(klass, data_source, **options)
|
|
39
|
+
options = Chartkick::Utils.deep_merge(Chartkick.options, options)
|
|
40
|
+
|
|
41
|
+
@chartkick_chart_id ||= 0
|
|
42
|
+
element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
|
|
43
|
+
|
|
44
|
+
height = (options.delete(:height) || "300px").to_s
|
|
45
|
+
width = (options.delete(:width) || "100%").to_s
|
|
46
|
+
defer = !!options.delete(:defer)
|
|
47
|
+
|
|
48
|
+
# content_for: nil must override default
|
|
49
|
+
content_for = options.key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
|
|
50
|
+
|
|
51
|
+
nonce = options.fetch(:nonce, true)
|
|
52
|
+
options.delete(:nonce)
|
|
53
|
+
if nonce == true
|
|
54
|
+
# Secure Headers also defines content_security_policy_nonce but it takes an argument
|
|
55
|
+
# Rails 5.2 overrides this method, but earlier versions do not
|
|
56
|
+
if respond_to?(:content_security_policy_nonce) && (content_security_policy_nonce rescue nil)
|
|
57
|
+
# Rails 5.2+
|
|
58
|
+
nonce = content_security_policy_nonce
|
|
59
|
+
elsif respond_to?(:content_security_policy_script_nonce)
|
|
60
|
+
# Secure Headers
|
|
61
|
+
nonce = content_security_policy_script_nonce
|
|
62
|
+
else
|
|
63
|
+
nonce = nil
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
nonce_html = nonce ? " nonce=\"#{ERB::Util.html_escape(nonce)}\"" : nil
|
|
67
|
+
|
|
68
|
+
# html vars
|
|
69
|
+
html_vars = {
|
|
70
|
+
id: element_id,
|
|
71
|
+
height: height,
|
|
72
|
+
width: width,
|
|
73
|
+
# don't delete loading option since it needs to be passed to JS
|
|
74
|
+
loading: options[:loading] || "Loading..."
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
[:height, :width].each do |k|
|
|
78
|
+
# limit to alphanumeric and % for simplicity
|
|
79
|
+
# this prevents things like calc() but safety is the priority
|
|
80
|
+
# dot does not need escaped in square brackets
|
|
81
|
+
raise ArgumentError, "Invalid #{k}" unless /\A[a-zA-Z0-9%.]*\z/.match?(html_vars[k])
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
html_vars.each_key do |k|
|
|
85
|
+
# escape all variables
|
|
86
|
+
# we already limit height and width above, but escape for safety as fail-safe
|
|
87
|
+
# to prevent XSS injection in worse-case scenario
|
|
88
|
+
html_vars[k] = ERB::Util.html_escape(html_vars[k])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
html = (options.delete(:html) || %(<div id="%{id}" style="height: %{height}; width: %{width}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">%{loading}</div>)) % html_vars
|
|
92
|
+
|
|
93
|
+
# js vars
|
|
94
|
+
js_vars = {
|
|
95
|
+
type: klass.to_json,
|
|
96
|
+
id: element_id.to_json,
|
|
97
|
+
data: data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json,
|
|
98
|
+
options: options.to_json
|
|
99
|
+
}
|
|
100
|
+
js_vars.each_key do |k|
|
|
101
|
+
js_vars[k] = Chartkick::Utils.json_escape(js_vars[k])
|
|
102
|
+
end
|
|
103
|
+
createjs = "new Chartkick[%{type}](%{id}, %{data}, %{options});" % js_vars
|
|
104
|
+
|
|
105
|
+
warn "[chartkick] The defer option is no longer needed and can be removed" if defer
|
|
106
|
+
|
|
107
|
+
# Turbolinks preview restores the DOM except for painted <canvas>
|
|
108
|
+
# since it uses cloneNode(true) - https://developer.mozilla.org/en-US/docs/Web/API/Node/
|
|
109
|
+
#
|
|
110
|
+
# don't rerun JS on preview to prevent
|
|
111
|
+
# 1. animation
|
|
112
|
+
# 2. loading data from URL
|
|
113
|
+
js = <<~JS
|
|
114
|
+
<script#{nonce_html}>
|
|
115
|
+
(function() {
|
|
116
|
+
if (document.documentElement.hasAttribute("data-turbolinks-preview")) return;
|
|
117
|
+
if (document.documentElement.hasAttribute("data-turbo-preview")) return;
|
|
118
|
+
|
|
119
|
+
var createChart = function() { #{createjs} };
|
|
120
|
+
if ("Chartkick" in window) {
|
|
121
|
+
createChart();
|
|
122
|
+
} else {
|
|
123
|
+
window.addEventListener("chartkick:load", createChart, true);
|
|
124
|
+
}
|
|
125
|
+
})();
|
|
126
|
+
</script>
|
|
127
|
+
JS
|
|
128
|
+
|
|
129
|
+
if content_for
|
|
130
|
+
content_for(content_for) { js.respond_to?(:html_safe) ? js.html_safe : js }
|
|
131
|
+
else
|
|
132
|
+
html += "\n#{js}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Chartkick
|
|
2
|
+
module Utils
|
|
3
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
|
4
|
+
def self.deep_merge(hash_a, hash_b)
|
|
5
|
+
hash_a = hash_a.dup
|
|
6
|
+
hash_b.each_pair do |k, v|
|
|
7
|
+
tv = hash_a[k]
|
|
8
|
+
hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge(tv, v) : v
|
|
9
|
+
end
|
|
10
|
+
hash_a
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb
|
|
14
|
+
JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
|
|
15
|
+
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
|
16
|
+
def self.json_escape(s)
|
|
17
|
+
if ERB::Util.respond_to?(:json_escape)
|
|
18
|
+
ERB::Util.json_escape(s)
|
|
19
|
+
else
|
|
20
|
+
s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# stdlib
|
|
2
|
+
require "erb"
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
# modules
|
|
6
|
+
require_relative "chartkick/core_ext"
|
|
7
|
+
require_relative "chartkick/helper"
|
|
8
|
+
require_relative "chartkick/utils"
|
|
9
|
+
require_relative "chartkick/version"
|
|
10
|
+
|
|
11
|
+
# integrations
|
|
12
|
+
require_relative "chartkick/engine" if defined?(Rails)
|
|
13
|
+
require_relative "chartkick/sinatra" if defined?(Sinatra)
|
|
14
|
+
|
|
15
|
+
if defined?(ActiveSupport.on_load)
|
|
16
|
+
ActiveSupport.on_load(:action_view) do
|
|
17
|
+
include Chartkick::Helper
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module Chartkick
|
|
22
|
+
class << self
|
|
23
|
+
attr_accessor :content_for
|
|
24
|
+
attr_accessor :options
|
|
25
|
+
end
|
|
26
|
+
self.options = {}
|
|
27
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2024 Chart.js Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Chart.js Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013-2021 Andrew Kane
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Sasha Koss and Lesha Koss https://kossnocorp.mit-license.org
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2021 Jukka Kurkela
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|