rainbowvis_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 745bdb7c4b729cf90e7169da3058fe78b9ab8415
4
+ data.tar.gz: 33421f5f88d2aee1382853ae29a0678fdc096760
5
+ SHA512:
6
+ metadata.gz: 18df809203aef4ee8c486b944a5a0a8cb5db6d6f1120d0feba0395172141469ede97b4a51d833f435b53f97383c38fe8e59bd1a2f87831fc868b5c01c1c71c3c
7
+ data.tar.gz: 5100ebfe3c0b4b7f6838099571ed94b9ba7cc0e4e623de14fb15f6f4ccbaf58f80327e29cc11cf46cf3dd1909f68eee7492efabacc833a39e4c7a228121eb444
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ .DS_Store
19
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rainbowvis_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Intrepidd
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.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Rainbowvis for Rails
2
+
3
+ Bringing rainbowvis to the rails asset pipeline
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rainbowvis_rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rainbowvis_rails
18
+
19
+ ## Usage
20
+
21
+
22
+ - Step1
23
+
24
+ In any javascript file :
25
+
26
+ // = require rainbowvis
27
+
28
+ - Step2
29
+
30
+ There is no step2.
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ require "rainbowvis_rails/version"
2
+
3
+ module RainbowvisRails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module RainbowvisRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rainbowvis_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rainbowvis_rails"
8
+ spec.version = RainbowvisRails::VERSION
9
+ spec.authors = ["Intrepidd"]
10
+ spec.email = ["adrien@siami.fr"]
11
+ spec.description = 'Bringing rainbowvis to the rails asset pipeline'
12
+ spec.summary = 'Bringing rainbowvis to the rails asset pipeline'
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "railties", ">= 3.1.0", "< 5.0"
25
+ end
@@ -0,0 +1,175 @@
1
+ /*
2
+ RainbowVis-JS
3
+ Released under MIT License
4
+ */
5
+
6
+ function Rainbow()
7
+ {
8
+ var gradients = null;
9
+ var minNum = 0;
10
+ var maxNum = 100;
11
+ var colours = ['ff0000', 'ffff00', '00ff00', '0000ff'];
12
+ setColours(colours);
13
+
14
+ function setColours (spectrum)
15
+ {
16
+ if (spectrum.length < 2) {
17
+ throw new Error('Rainbow must have two or more colours.');
18
+ } else {
19
+ var increment = (maxNum - minNum)/(spectrum.length - 1);
20
+ var firstGradient = new ColourGradient();
21
+ firstGradient.setGradient(spectrum[0], spectrum[1]);
22
+ firstGradient.setNumberRange(minNum, minNum + increment);
23
+ gradients = [ firstGradient ];
24
+
25
+ for (var i = 1; i < spectrum.length - 1; i++) {
26
+ var colourGradient = new ColourGradient();
27
+ colourGradient.setGradient(spectrum[i], spectrum[i + 1]);
28
+ colourGradient.setNumberRange(minNum + increment * i, minNum + increment * (i + 1));
29
+ gradients[i] = colourGradient;
30
+ }
31
+
32
+ colours = spectrum;
33
+ return this;
34
+ }
35
+ }
36
+
37
+ this.setColors = this.setColours;
38
+
39
+ this.setSpectrum = function ()
40
+ {
41
+ setColours(arguments);
42
+ return this;
43
+ }
44
+
45
+ this.setSpectrumByArray = function (array)
46
+ {
47
+ setColours(array);
48
+ return this;
49
+ }
50
+
51
+ this.colourAt = function (number)
52
+ {
53
+ if (isNaN(number)) {
54
+ throw new TypeError(number + ' is not a number');
55
+ } else if (gradients.length === 1) {
56
+ return gradients[0].colourAt(number);
57
+ } else {
58
+ var segment = (maxNum - minNum)/(gradients.length);
59
+ var index = Math.min(Math.floor((Math.max(number, minNum) - minNum)/segment), gradients.length - 1);
60
+ return gradients[index].colourAt(number);
61
+ }
62
+ }
63
+
64
+ this.colorAt = this.colourAt;
65
+
66
+ this.setNumberRange = function (minNumber, maxNumber)
67
+ {
68
+ if (maxNumber > minNumber) {
69
+ minNum = minNumber;
70
+ maxNum = maxNumber;
71
+ setColours(colours);
72
+ } else {
73
+ throw new RangeError('maxNumber (' + maxNumber + ') is not greater than minNumber (' + minNumber + ')');
74
+ }
75
+ return this;
76
+ }
77
+ }
78
+
79
+ function ColourGradient()
80
+ {
81
+ var startColour = 'ff0000';
82
+ var endColour = '0000ff';
83
+ var minNum = 0;
84
+ var maxNum = 100;
85
+
86
+ this.setGradient = function (colourStart, colourEnd)
87
+ {
88
+ startColour = getHexColour(colourStart);
89
+ endColour = getHexColour(colourEnd);
90
+ }
91
+
92
+ this.setNumberRange = function (minNumber, maxNumber)
93
+ {
94
+ if (maxNumber > minNumber) {
95
+ minNum = minNumber;
96
+ maxNum = maxNumber;
97
+ } else {
98
+ throw new RangeError('maxNumber (' + maxNumber + ') is not greater than minNumber (' + minNumber + ')');
99
+ }
100
+ }
101
+
102
+ this.colourAt = function (number)
103
+ {
104
+ return calcHex(number, startColour.substring(0,2), endColour.substring(0,2))
105
+ + calcHex(number, startColour.substring(2,4), endColour.substring(2,4))
106
+ + calcHex(number, startColour.substring(4,6), endColour.substring(4,6));
107
+ }
108
+
109
+ function calcHex(number, channelStart_Base16, channelEnd_Base16)
110
+ {
111
+ var num = number;
112
+ if (num < minNum) {
113
+ num = minNum;
114
+ }
115
+ if (num > maxNum) {
116
+ num = maxNum;
117
+ }
118
+ var numRange = maxNum - minNum;
119
+ var cStart_Base10 = parseInt(channelStart_Base16, 16);
120
+ var cEnd_Base10 = parseInt(channelEnd_Base16, 16);
121
+ var cPerUnit = (cEnd_Base10 - cStart_Base10)/numRange;
122
+ var c_Base10 = Math.round(cPerUnit * (num - minNum) + cStart_Base10);
123
+ return formatHex(c_Base10.toString(16));
124
+ }
125
+
126
+ formatHex = function (hex)
127
+ {
128
+ if (hex.length === 1) {
129
+ return '0' + hex;
130
+ } else {
131
+ return hex;
132
+ }
133
+ }
134
+
135
+ function isHexColour(string)
136
+ {
137
+ var regex = /^#?[0-9a-fA-F]{6}$/i;
138
+ return regex.test(string);
139
+ }
140
+
141
+ function getHexColour(string)
142
+ {
143
+ if (isHexColour(string)) {
144
+ return string.substring(string.length - 6, string.length);
145
+ } else {
146
+ var colourNames =
147
+ [
148
+ ['red', 'ff0000'],
149
+ ['lime', '00ff00'],
150
+ ['blue', '0000ff'],
151
+ ['yellow', 'ffff00'],
152
+ ['orange', 'ff8000'],
153
+ ['aqua', '00ffff'],
154
+ ['fuchsia', 'ff00ff'],
155
+ ['white', 'ffffff'],
156
+ ['black', '000000'],
157
+ ['gray', '808080'],
158
+ ['grey', '808080'],
159
+ ['silver', 'c0c0c0'],
160
+ ['maroon', '800000'],
161
+ ['olive', '808000'],
162
+ ['green', '008000'],
163
+ ['teal', '008080'],
164
+ ['navy', '000080'],
165
+ ['purple', '800080']
166
+ ];
167
+ for (var i = 0; i < colourNames.length; i++) {
168
+ if (string.toLowerCase() === colourNames[i][0]) {
169
+ return colourNames[i][1];
170
+ }
171
+ }
172
+ throw new Error(string + ' is not a valid colour.');
173
+ }
174
+ }
175
+ }
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rainbowvis_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Intrepidd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ - - <
49
+ - !ruby/object:Gem::Version
50
+ version: '5.0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 3.1.0
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ description: Bringing rainbowvis to the rails asset pipeline
62
+ email:
63
+ - adrien@siami.fr
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/rainbowvis_rails.rb
74
+ - lib/rainbowvis_rails/version.rb
75
+ - rainbowvis_rails.gemspec
76
+ - vendor/assets/javascripts/rainbowvis.js
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Bringing rainbowvis to the rails asset pipeline
101
+ test_files: []