jquery-peity-rails 3.2.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba61e5ae1c02a44a86da4c4cf6020ac7c7dc4b0c
4
+ data.tar.gz: 3b40a59e35058e90df412f22267eeb3b1517877f
5
+ SHA512:
6
+ metadata.gz: d64050c7c8538f7f7b9f7927aaf1c1e532c56bd1b6879f21133f989bdea38180a32c5dafaf302fa45fbf9be219b0a492cb6f86a5a74629981a1401e4b8b184e1
7
+ data.tar.gz: e87f4e76045424e6a7841e675f3d5f22a9a8c11f581ac148aac57c401390e06728c4033b33360fc6926095d85cba030568d8814b17382dcae0890ecab2df62c6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-peity-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Hiroyuki Inoue
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.
22
+
@@ -0,0 +1,41 @@
1
+ # Jquery::Peity::Rails
2
+
3
+ An asset-pipeline gem to provide [jquery-peity](http://benpickles.github.io/peity/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'jquery-peity-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jquery-peity-rails
20
+
21
+ ## Usage
22
+
23
+ Write require in your application.js:
24
+
25
+ ```js
26
+ //= require jquery-peity
27
+ ```
28
+
29
+ or in application.js.coffee:
30
+
31
+ ```coffee
32
+ #= require jquery-peity
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/inohiro/jquery-peity-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery/peity/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery-peity-rails"
8
+ spec.version = Jquery::Peity::Rails::VERSION
9
+ spec.authors = ["Hiroyuki Inoue"]
10
+ spec.email = ["mammymax@gmail.com"]
11
+
12
+ spec.summary = %q{jquery-peity for Rails Asset Pipeline.}
13
+ spec.description = %q{jquery-peity for Rails Asset Pipeline.}
14
+ spec.homepage = "https://github.com/inohiro/jquery-peity-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,13 @@
1
+ require "jquery/peity/rails/version"
2
+
3
+ module Jquery
4
+ module Peity
5
+ module Rails
6
+ if defined?(::Rails) and Gem::Requirement.new('>= 3.1').satisfied_by?(Gem::Version.new ::Rails.version)
7
+ class Rails::Engine < ::Rails::Engine
8
+ # To enable Rails Asset Pipeline
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Peity
3
+ module Rails
4
+ VERSION = '3.2.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,383 @@
1
+ // Peity jQuery plugin version 3.2.0
2
+ // (c) 2015 Ben Pickles
3
+ //
4
+ // http://benpickles.github.io/peity
5
+ //
6
+ // Released under MIT license.
7
+ (function($, document, Math, undefined) {
8
+ var peity = $.fn.peity = function(type, options) {
9
+ if (svgSupported) {
10
+ this.each(function() {
11
+ var $this = $(this)
12
+ var chart = $this.data('_peity')
13
+
14
+ if (chart) {
15
+ if (type) chart.type = type
16
+ $.extend(chart.opts, options)
17
+ } else {
18
+ chart = new Peity(
19
+ $this,
20
+ type,
21
+ $.extend({},
22
+ peity.defaults[type],
23
+ $this.data('peity'),
24
+ options)
25
+ )
26
+
27
+ $this
28
+ .change(function() { chart.draw() })
29
+ .data('_peity', chart)
30
+ }
31
+
32
+ chart.draw()
33
+ });
34
+ }
35
+
36
+ return this;
37
+ };
38
+
39
+ var Peity = function($el, type, opts) {
40
+ this.$el = $el
41
+ this.type = type
42
+ this.opts = opts
43
+ }
44
+
45
+ var PeityPrototype = Peity.prototype
46
+
47
+ var svgElement = PeityPrototype.svgElement = function(tag, attrs) {
48
+ return $(
49
+ document.createElementNS('http://www.w3.org/2000/svg', tag)
50
+ ).attr(attrs)
51
+ }
52
+
53
+ // https://gist.github.com/madrobby/3201472
54
+ var svgSupported = 'createElementNS' in document && svgElement('svg', {})[0].createSVGRect
55
+
56
+ PeityPrototype.draw = function() {
57
+ var opts = this.opts
58
+ peity.graphers[this.type].call(this, opts)
59
+ if (opts.after) opts.after.call(this, opts)
60
+ }
61
+
62
+ PeityPrototype.fill = function() {
63
+ var fill = this.opts.fill
64
+
65
+ return $.isFunction(fill)
66
+ ? fill
67
+ : function(_, i) { return fill[i % fill.length] }
68
+ }
69
+
70
+ PeityPrototype.prepare = function(width, height) {
71
+ if (!this.$svg) {
72
+ this.$el.hide().after(
73
+ this.$svg = svgElement('svg', {
74
+ "class": "peity"
75
+ })
76
+ )
77
+ }
78
+
79
+ return this.$svg
80
+ .empty()
81
+ .data('peity', this)
82
+ .attr({
83
+ height: height,
84
+ width: width
85
+ })
86
+ }
87
+
88
+ PeityPrototype.values = function() {
89
+ return $.map(this.$el.text().split(this.opts.delimiter), function(value) {
90
+ return parseFloat(value)
91
+ })
92
+ }
93
+
94
+ peity.defaults = {}
95
+ peity.graphers = {}
96
+
97
+ peity.register = function(type, defaults, grapher) {
98
+ this.defaults[type] = defaults
99
+ this.graphers[type] = grapher
100
+ }
101
+
102
+ peity.register(
103
+ 'pie',
104
+ {
105
+ fill: ['#ff9900', '#fff4dd', '#ffc66e'],
106
+ radius: 8
107
+ },
108
+ function(opts) {
109
+ if (!opts.delimiter) {
110
+ var delimiter = this.$el.text().match(/[^0-9\.]/)
111
+ opts.delimiter = delimiter ? delimiter[0] : ","
112
+ }
113
+
114
+ var values = $.map(this.values(), function(n) {
115
+ return n > 0 ? n : 0
116
+ })
117
+
118
+ if (opts.delimiter == "/") {
119
+ var v1 = values[0]
120
+ var v2 = values[1]
121
+ values = [v1, Math.max(0, v2 - v1)]
122
+ }
123
+
124
+ var i = 0
125
+ var length = values.length
126
+ var sum = 0
127
+
128
+ for (; i < length; i++) {
129
+ sum += values[i]
130
+ }
131
+
132
+ if (!sum) {
133
+ length = 2
134
+ sum = 1
135
+ values = [0, 1]
136
+ }
137
+
138
+ var diameter = opts.radius * 2
139
+
140
+ var $svg = this.prepare(
141
+ opts.width || diameter,
142
+ opts.height || diameter
143
+ )
144
+
145
+ var width = $svg.width()
146
+ , height = $svg.height()
147
+ , cx = width / 2
148
+ , cy = height / 2
149
+
150
+ var radius = Math.min(cx, cy)
151
+ , innerRadius = opts.innerRadius
152
+
153
+ if (this.type == 'donut' && !innerRadius) {
154
+ innerRadius = radius * 0.5
155
+ }
156
+
157
+ var pi = Math.PI
158
+ var fill = this.fill()
159
+
160
+ var scale = this.scale = function(value, radius) {
161
+ var radians = value / sum * pi * 2 - pi / 2
162
+
163
+ return [
164
+ radius * Math.cos(radians) + cx,
165
+ radius * Math.sin(radians) + cy
166
+ ]
167
+ }
168
+
169
+ var cumulative = 0
170
+
171
+ for (i = 0; i < length; i++) {
172
+ var value = values[i]
173
+ , portion = value / sum
174
+ , $node
175
+
176
+ if (portion == 0) continue
177
+
178
+ if (portion == 1) {
179
+ if (innerRadius) {
180
+ var x2 = cx - 0.01
181
+ , y1 = cy - radius
182
+ , y2 = cy - innerRadius
183
+
184
+ $node = svgElement('path', {
185
+ d: [
186
+ 'M', cx, y1,
187
+ 'A', radius, radius, 0, 1, 1, x2, y1,
188
+ 'L', x2, y2,
189
+ 'A', innerRadius, innerRadius, 0, 1, 0, cx, y2
190
+ ].join(' ')
191
+ })
192
+ } else {
193
+ $node = svgElement('circle', {
194
+ cx: cx,
195
+ cy: cy,
196
+ r: radius
197
+ })
198
+ }
199
+ } else {
200
+ var cumulativePlusValue = cumulative + value
201
+
202
+ var d = ['M'].concat(
203
+ scale(cumulative, radius),
204
+ 'A', radius, radius, 0, portion > 0.5 ? 1 : 0, 1,
205
+ scale(cumulativePlusValue, radius),
206
+ 'L'
207
+ )
208
+
209
+ if (innerRadius) {
210
+ d = d.concat(
211
+ scale(cumulativePlusValue, innerRadius),
212
+ 'A', innerRadius, innerRadius, 0, portion > 0.5 ? 1 : 0, 0,
213
+ scale(cumulative, innerRadius)
214
+ )
215
+ } else {
216
+ d.push(cx, cy)
217
+ }
218
+
219
+ cumulative += value
220
+
221
+ $node = svgElement('path', {
222
+ d: d.join(" ")
223
+ })
224
+ }
225
+
226
+ $node.attr('fill', fill.call(this, value, i, values))
227
+
228
+ $svg.append($node)
229
+ }
230
+ }
231
+ )
232
+
233
+ peity.register(
234
+ 'donut',
235
+ $.extend(true, {}, peity.defaults.pie),
236
+ function(opts) {
237
+ peity.graphers.pie.call(this, opts)
238
+ }
239
+ )
240
+
241
+ peity.register(
242
+ "line",
243
+ {
244
+ delimiter: ",",
245
+ fill: "#c6d9fd",
246
+ height: 16,
247
+ min: 0,
248
+ stroke: "#4d89f9",
249
+ strokeWidth: 1,
250
+ width: 32
251
+ },
252
+ function(opts) {
253
+ var values = this.values()
254
+ if (values.length == 1) values.push(values[0])
255
+ var max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max))
256
+ , min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min))
257
+
258
+ var $svg = this.prepare(opts.width, opts.height)
259
+ , strokeWidth = opts.strokeWidth
260
+ , width = $svg.width()
261
+ , height = $svg.height() - strokeWidth
262
+ , diff = max - min
263
+
264
+ var xScale = this.x = function(input) {
265
+ return input * (width / (values.length - 1))
266
+ }
267
+
268
+ var yScale = this.y = function(input) {
269
+ var y = height
270
+
271
+ if (diff) {
272
+ y -= ((input - min) / diff) * height
273
+ }
274
+
275
+ return y + strokeWidth / 2
276
+ }
277
+
278
+ var zero = yScale(Math.max(min, 0))
279
+ , coords = [0, zero]
280
+
281
+ for (var i = 0; i < values.length; i++) {
282
+ coords.push(
283
+ xScale(i),
284
+ yScale(values[i])
285
+ )
286
+ }
287
+
288
+ coords.push(width, zero)
289
+
290
+ if (opts.fill) {
291
+ $svg.append(
292
+ svgElement('polygon', {
293
+ fill: opts.fill,
294
+ points: coords.join(' ')
295
+ })
296
+ )
297
+ }
298
+
299
+ if (strokeWidth) {
300
+ $svg.append(
301
+ svgElement('polyline', {
302
+ fill: 'none',
303
+ points: coords.slice(2, coords.length - 2).join(' '),
304
+ stroke: opts.stroke,
305
+ 'stroke-width': strokeWidth,
306
+ 'stroke-linecap': 'square'
307
+ })
308
+ )
309
+ }
310
+ }
311
+ );
312
+
313
+ peity.register(
314
+ 'bar',
315
+ {
316
+ delimiter: ",",
317
+ fill: ["#4D89F9"],
318
+ height: 16,
319
+ min: 0,
320
+ padding: 0.1,
321
+ width: 32
322
+ },
323
+ function(opts) {
324
+ var values = this.values()
325
+ , max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max))
326
+ , min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min))
327
+
328
+ var $svg = this.prepare(opts.width, opts.height)
329
+ , width = $svg.width()
330
+ , height = $svg.height()
331
+ , diff = max - min
332
+ , padding = opts.padding
333
+ , fill = this.fill()
334
+
335
+ var xScale = this.x = function(input) {
336
+ return input * width / values.length
337
+ }
338
+
339
+ var yScale = this.y = function(input) {
340
+ return height - (
341
+ diff
342
+ ? ((input - min) / diff) * height
343
+ : 1
344
+ )
345
+ }
346
+
347
+ for (var i = 0; i < values.length; i++) {
348
+ var x = xScale(i + padding)
349
+ , w = xScale(i + 1 - padding) - x
350
+ , value = values[i]
351
+ , valueY = yScale(value)
352
+ , y1 = valueY
353
+ , y2 = valueY
354
+ , h
355
+
356
+ if (!diff) {
357
+ h = 1
358
+ } else if (value < 0) {
359
+ y1 = yScale(Math.min(max, 0))
360
+ } else {
361
+ y2 = yScale(Math.max(min, 0))
362
+ }
363
+
364
+ h = y2 - y1
365
+
366
+ if (h == 0) {
367
+ h = 1
368
+ if (max > 0 && diff) y1--
369
+ }
370
+
371
+ $svg.append(
372
+ svgElement('rect', {
373
+ fill: fill.call(this, value, i, values),
374
+ x: x,
375
+ y: y1,
376
+ width: w,
377
+ height: h
378
+ })
379
+ )
380
+ }
381
+ }
382
+ );
383
+ })(jQuery, document, Math);
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-peity-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Inoue
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: jquery-peity for Rails Asset Pipeline.
14
+ email:
15
+ - mammymax@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - jquery-peity-rails.gemspec
26
+ - lib/jquery/peity/rails.rb
27
+ - lib/jquery/peity/rails/version.rb
28
+ - vendor/assets/javascripts/jquery.peity.js
29
+ homepage: https://github.com/inohiro/jquery-peity-rails
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.4.5
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: jquery-peity for Rails Asset Pipeline.
53
+ test_files: []
54
+ has_rdoc: