g.raphael-radar-rails 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fingerprintjs-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Valentin Vasilyev
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 @@
1
+ Ruby-on-Rails gem for https://github.com/Valve/g.raphael-radar JavaScript library
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,241 @@
1
+ /*
2
+ * g.raphael-radar 0.3 - Radar chart, based on Raphaël.js
3
+ * https://github.com/Valve/g.raphael-radar
4
+ * Copyright (c) 2012 Valentin Vasilyev (iamvalentin@gmail.com)
5
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
+ */
7
+ (function () {
8
+ function Radar(paper, cx, cy, r, values, opts) {
9
+ var $r = Raphael; //for minification;
10
+ if (!values || values.length == 0) throw 'Values array is required';
11
+ opts = opts || {};
12
+ var startAngle = 270,
13
+ angle = 360 / values.length;
14
+ var defaultOpts = {
15
+ meshSize: 30,
16
+ labels: [],
17
+ labelFontSize: 14,
18
+ valueFontSize: 14,
19
+ drawLabels: true,
20
+ drawValues: true,
21
+ armFill: 'none',
22
+ armStroke: 'rgba(255, 106, 0, .5)',
23
+ armStrokeWidth: 1,
24
+ drawArms: true,
25
+ meshFill: 'none',
26
+ meshStroke: 'rgba(120, 120, 120, .5)',
27
+ meshStrokeWidth: 1,
28
+ drawMesh: true,
29
+ max: Math.max.apply(Math, values),
30
+ pathFill: 'none',
31
+ pathStroke: '#0026ff',
32
+ pathStrokeWidth: 3,
33
+ pathCircleOuterRadius: 4,
34
+ pathCircleInnerRadius: 2,
35
+ drawPathCircles: true,
36
+ closePath: true
37
+ };
38
+ //replacing default opts with explicitly provided
39
+ for (var prop in opts) {
40
+ defaultOpts[prop] = opts[prop];
41
+ }
42
+ opts = defaultOpts;
43
+ delete defaultOpts;
44
+
45
+ var arm = function (cx, cy, r, angle) {
46
+ var rad = $r.rad(angle);
47
+ var x = cx + (r * Math.cos(rad));
48
+ var y = cy + (r * Math.sin(rad));
49
+ return ["M", cx, cy, "L", x, y, "Z"].join(",");
50
+ }
51
+
52
+ var meshLine = function (cx, cy, r, startAngle, angle) {
53
+ var mesh = ["M"];
54
+ var circle = startAngle + 360;
55
+ while (startAngle < circle) {
56
+ var x = cx + r * Math.cos($r.rad(startAngle));
57
+ var y = cy + r * Math.sin($r.rad(startAngle));
58
+ mesh.push(x);
59
+ mesh.push(y);
60
+ mesh.push("L");
61
+ startAngle += angle;
62
+ }
63
+ mesh.push("Z");
64
+ return mesh.join(",");
65
+ }
66
+
67
+ var label = function (cx, cy, r, angle) {
68
+ var rad = $r.rad(angle);
69
+ var x = cx + r * Math.cos(rad);
70
+ var y = cy + r * Math.sin(rad);
71
+ return {
72
+ x: (Math.round(x) === cx) ? x : (x < cx ? x - 10 : x + 10),
73
+ y: (Math.round(y) === cy) ? y : (y < cy ? y - 10 : y + 10),
74
+ attr: {
75
+ "text-anchor": (Math.round(x) === cx) ? "middle" : (x < cx ? "end" : "start"),
76
+ "font-size": opts.labelFontSize
77
+ }
78
+ };
79
+ }
80
+
81
+ var labelvalue = function (cx, cy, r, angle, value, max) {
82
+ var rad = $r.rad(angle);
83
+ var x = cx + r / max * value * Math.cos(rad);
84
+ var y = cy + r / max * value * Math.sin(rad);
85
+ if (Math.round(x) === cx) {
86
+ y += 10 * Math.sin(rad);
87
+ }
88
+
89
+ return {
90
+ x: (Math.round(x) === cx) ? x+2 : (x < cx ? x - 10 : x + 10),
91
+ y: (Math.round(y) === cy) ? y-2 : (y < cy ? y - 10 : y + 10),
92
+ attr: {
93
+ "text-anchor": (Math.round(x) === cx) ? "middle" : (x < cx ? "end" : "start"),
94
+ "font-size": opts.valueFontSize
95
+ }
96
+ };
97
+ }
98
+
99
+ var path = function (cx, cy, r, startAngle, values, max) {
100
+ var pathData = [];
101
+ var i = 0, l = values.length;
102
+ while (i < l) {
103
+ var rad = $r.rad(startAngle + 360 / values.length * i);
104
+ pathData.push(i == 0 ? "M" : "L");
105
+ pathData.push(cx + r / max * values[i] * Math.cos(rad));
106
+ pathData.push(cy + r / max * values[i] * Math.sin(rad));
107
+ ++i;
108
+ }
109
+
110
+ if (opts.closePath) {
111
+ pathData.push("Z");
112
+ }
113
+
114
+ paper.path(pathData.join(",")).attr({
115
+ "stroke": opts.pathStroke,
116
+ "fill": opts.pathFill,
117
+ "stroke-width": opts.pathStrokeWidth,
118
+ "stroke-linejoin": 'round'
119
+ });
120
+ }
121
+
122
+ var circle = function (cx, cy, r, angle, value, max, title) {
123
+ var rad = $r.rad(angle);
124
+ var p = {
125
+ x: cx + r / max * value * Math.cos(rad),
126
+ y: cy + r / max * value * Math.sin(rad)
127
+ };
128
+
129
+ paper.circle(p.x, p.y, opts.pathCircleOuterRadius * 2).attr({ fill: opts.pathStroke, stroke: 'none', title: title + ": " + value });
130
+ paper.circle(p.x, p.y, opts.pathCircleInnerRadius * 2).attr({ fill: "#fff", stroke: "none", title: title + ": " + value });
131
+ }
132
+
133
+ //arms
134
+ if (opts.drawArms) {
135
+ var i = 0, l = values.length;
136
+ while (i < l) {
137
+ paper.path(arm(cx, cy, r, startAngle + angle * i)).attr({
138
+ fill: opts.armFill,
139
+ stroke: opts.armStroke,
140
+ "stroke-width": opts.armStrokeWidth
141
+ });
142
+ ++i;
143
+ }
144
+ }
145
+ //mesh
146
+ if (opts.drawMesh) {
147
+ var meshCount = Math.floor(r / opts.meshSize);
148
+ var meshHeight = r / meshCount;
149
+ var meshRadius = meshHeight;
150
+ var meshes = [];
151
+ while (meshCount--) {
152
+ meshes.push(meshLine(cx, cy, meshRadius, startAngle, angle));
153
+ meshRadius += meshHeight;
154
+ }
155
+ var i = 0, l = meshes.length;
156
+ while (i < l) {
157
+ paper.path(meshes[i]).attr({
158
+ fill: opts.meshFill,
159
+ stroke: opts.meshStroke,
160
+ "stroke-width": opts.meshStrokeWidth
161
+ });
162
+ ++i;
163
+ }
164
+ }
165
+ // values
166
+ if (opts.drawValues) {
167
+ var i = values.length;
168
+ while (i--) {
169
+ var textObject = labelvalue(cx, cy, r, startAngle + angle * i, values[i], opts.max);
170
+ var fulltext = values[i];
171
+ var text = paper.text(textObject.x, textObject.y, fulltext).attr(textObject.attr);
172
+
173
+ }
174
+ }
175
+ //labels
176
+ if (opts.drawLabels) {
177
+ var i = opts.labels.length;
178
+ while (i--) {
179
+ var textObject = label(cx, cy, r, startAngle + angle * i);
180
+
181
+ var fulltext = opts.labels[i];
182
+ var text = paper.text(textObject.x, textObject.y, fulltext).attr(textObject.attr);
183
+ fulltext = fulltext.replace("-", "- ").replace("/", "/ ");
184
+
185
+ var words = fulltext.split(" ");
186
+ var wordsCount = words.length;
187
+
188
+ var maxwidth = Math.min(textObject.x, paper.width - textObject.x);
189
+ var maxheight = Math.min(textObject.y, paper.height - textObject.y);
190
+
191
+
192
+ var fontSizeMin = 8;
193
+ for (var fontSize = opts.labelFontSize; fontSize >= fontSizeMin; --fontSize) {
194
+ text.attr("font-size", fontSize);
195
+ var tempText = "";
196
+ for (var i1 = 0; i1 < wordsCount; ++i1) {
197
+ text.attr("text", tempText + " " + words[i1]);
198
+ if (text.getBBox().width > maxwidth) {
199
+ tempText += "\n" + words[i1];
200
+ } else {
201
+ tempText += " " + words[i1];
202
+ }
203
+ }
204
+ text.attr("text", tempText);
205
+ if (text.getBBox().width > maxwidth) {
206
+ tempText = tempText.replace("-", "-\n");
207
+ text.attr("text", tempText);
208
+ }
209
+ if (fontSize == fontSizeMin ||
210
+ (text.getBBox().height <= maxheight &&
211
+ (text.getBBox().width <= maxwidth || wordsCount > 1))) {
212
+ var titleCountLines = tempText.split("\n").length;
213
+ text.attr("text", tempText.substring(1));
214
+ break;
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+
221
+ path(cx, cy, r, startAngle, values, opts.max);
222
+
223
+ //circles on path
224
+ if (opts.drawPathCircles) {
225
+ var i = values.length;
226
+ while (i--) {
227
+ circle(cx, cy, r, startAngle + angle * i, values[i], opts.max, opts.labels[i]);
228
+
229
+ }
230
+ }
231
+ };
232
+ //inheritance
233
+ var F = function () { };
234
+ F.prototype = Raphael.g;
235
+ Radar.prototype = new F();
236
+
237
+ //public
238
+ Raphael.fn.radar = function (cx, cy, r, values, opts) {
239
+ return new Radar(this, cx, cy, r, values, opts);
240
+ };
241
+ })();
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "g.raphael-radar-rails"
7
+ gem.version = "0.3.0"
8
+ gem.authors = ["Valentin Vasilyev"]
9
+ gem.email = ["iamvalentin@gmail.com"]
10
+ gem.description = "Radar chart for Rails asset pipeline, implemented with RaphaelJS"
11
+ gem.summary = ""
12
+ gem.homepage = "https://github.com/Valve/g.raphael-radar"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.require_paths = ["lib"]
16
+ end
@@ -0,0 +1,5 @@
1
+
2
+ module GraphaelRadar
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: g.raphael-radar-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Valentin Vasilyev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Radar chart for Rails asset pipeline, implemented with RaphaelJS
15
+ email:
16
+ - iamvalentin@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - app/assets/javascripts/g.radar.js
27
+ - g.raphael-radar-rails.gemspec
28
+ - lib/g.raphael-radar-rails.rb
29
+ homepage: https://github.com/Valve/g.raphael-radar
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: ''
53
+ test_files: []
54
+ has_rdoc: