d3-tip-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ tmp
2
+ .rvmrc
3
+ .ruby-version
4
+ .bundle
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2013 Justin Palmer
3
+
4
+ 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:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ 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.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ For D3 Tip, see D3-TIP-LICENSE. For the rest of the code, the following
2
+ license applies:
3
+
4
+ The MIT License
5
+
6
+ Copyright (c) 2013 Loren Norman
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # d3-tip-rails
2
+
3
+ [D3 Tip](https://github.com/Caged/d3-tip) adds tooltips to D3 sketches.
4
+
5
+ d3-tip-rails provides D3 Tip for Rails 3.1+ via the asset pipeline.
6
+
7
+ ## Version
8
+
9
+ d3-tip-rails comes with version 0.5.2 of d3-tip.js.
10
+
11
+ ## Requirements
12
+
13
+ The D3 library should already be loaded before requiring d3-tip. You can go with [d3 directly](https://github.com/mbostock/d3), but I also recommend the [d3-rails gem](https://github.com/iblue/d3-rails).
14
+
15
+ ## Installation
16
+
17
+ Add this line to your `Gemfile`:
18
+
19
+ gem "d3-tip-rails"
20
+
21
+ Then require it where you need it with JavaScript:
22
+
23
+ //= require d3-tip
24
+
25
+ ...or Coffeescript:
26
+
27
+ #= require d3-tip
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,20 @@
1
+ require File.expand_path('../lib/d3-tip/rails/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "d3-tip-rails"
5
+ s.version = D3Tip::Rails::VERSION
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Loren Norman"]
8
+ s.email = ["loren@github.com"]
9
+ s.homepage = "https://github.com/lorennorman/d3-tip-rails"
10
+ s.summary = "D3 Tip for the Rails Asset Pipeline"
11
+ s.description = "This gem provides D3 Tip for Rails 3.1+ via the Asset Pipeline."
12
+
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+
15
+ s.add_dependency "railties", ">= 3.1"
16
+ s.add_development_dependency "rails", ">= 3.1"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.require_path = 'lib'
20
+ end
@@ -0,0 +1 @@
1
+ require 'd3-tip/rails'
@@ -0,0 +1,2 @@
1
+ require 'd3-tip/rails/engine'
2
+ require 'd3-tip/rails/version'
@@ -0,0 +1,6 @@
1
+ module D3Tip
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module D3Tip
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,271 @@
1
+ // d3.tip
2
+ // Copyright (c) 2013 Justin Palmer
3
+ //
4
+ // Tooltips for d3.js SVG visualizations
5
+
6
+ // Public - contructs a new tooltip
7
+ //
8
+ // Returns a tip
9
+ d3.tip = function() {
10
+ var direction = d3_tip_direction,
11
+ offset = d3_tip_offset,
12
+ html = d3_tip_html,
13
+ node = initNode(),
14
+ svg = null,
15
+ point = null;
16
+
17
+ function tip(vis) {
18
+ svg = getSVGNode(vis)
19
+ point = svg.createSVGPoint()
20
+ document.body.appendChild(node)
21
+ }
22
+
23
+ // Public - show the tooltip on the screen
24
+ //
25
+ // Returns a tip
26
+ tip.show = function() {
27
+ var content = html.apply(this, arguments),
28
+ poffset = offset.apply(this, arguments),
29
+ dir = direction.apply(this, arguments),
30
+ nodel = d3.select(node), i = 0,
31
+ coords
32
+
33
+ nodel.html(content).style('display', 'block')
34
+ while(i--) nodel.classed(directions[i], false)
35
+ coords = direction_callbacks.get(dir).apply(this)
36
+ nodel.classed(dir, true).style({
37
+ top: (coords.top + poffset[0]) + 'px',
38
+ left: (coords.left + poffset[1]) + 'px'
39
+ })
40
+
41
+ return tip
42
+ }
43
+
44
+ // Public - hide the tooltip
45
+ //
46
+ // Returns a tip
47
+ tip.hide = function() {
48
+ node.style.display = 'none'
49
+ node.innerHTML = ''
50
+
51
+ return tip
52
+ }
53
+
54
+ // Public: Proxy attr calls to the d3 tip container. Sets or gets attribute value.
55
+ //
56
+ // n - name of the attribute
57
+ // v - value of the attribute
58
+ //
59
+ // Returns tip or attribute value
60
+ tip.attr = function(n, v) {
61
+ if (arguments.length < 2) {
62
+ return d3.select(node).attr(n)
63
+ } else {
64
+ d3.select(node).attr(n, v)
65
+ }
66
+
67
+ return tip;
68
+ }
69
+
70
+ // Public: Proxy style calls to the d3 tip container. Sets or gets a style value.
71
+ //
72
+ // n - name of the property
73
+ // v - value of the property
74
+ //
75
+ // Returns tip or style property value
76
+ tip.style = function(n, v) {
77
+ if (arguments.length < 2) {
78
+ return d3.select(node).style(n)
79
+ } else {
80
+ d3.select(node).style(n, v)
81
+ }
82
+
83
+ return tip;
84
+ }
85
+
86
+ // Public: Set or get the direction of the tooltip
87
+ //
88
+ // v - One of n(north), s(south), e(east), or w(west), nw(northwest),
89
+ // sw(southwest), ne(northeast) or se(southeast)
90
+ //
91
+ // Returns tip or direction
92
+ tip.direction = function(v) {
93
+ if (!arguments.length) return direction;
94
+ direction = v == null ? v : d3.functor(v);
95
+ return tip;
96
+ };
97
+
98
+ // Public: Sets or gets the offset of the tip
99
+ //
100
+ // v - Array of [x, y] offset
101
+ //
102
+ // Returns offset or
103
+ tip.offset = function(v) {
104
+ if (!arguments.length) return offset;
105
+ offset = v == null ? v : d3.functor(v);
106
+ return tip;
107
+ };
108
+
109
+ // Public: sets or gets the html value of the tooltip
110
+ //
111
+ // v - String value of the tip
112
+ //
113
+ // Returns html value or tip
114
+ tip.html = function(v) {
115
+ if (!arguments.length) return html;
116
+ html = v == null ? v : d3.functor(v)
117
+
118
+ return tip
119
+ };
120
+
121
+ function d3_tip_direction() { return 'n' }
122
+ function d3_tip_offset() { return [0, 0] }
123
+ function d3_tip_html() { return ' ' }
124
+
125
+ var direction_callbacks = d3.map({
126
+ n: direction_n,
127
+ s: direction_s,
128
+ e: direction_e,
129
+ w: direction_w,
130
+ nw: direction_nw,
131
+ ne: direction_ne,
132
+ sw: direction_sw,
133
+ se: direction_se
134
+ }),
135
+
136
+ directions = direction_callbacks.keys()
137
+
138
+ function direction_n() {
139
+ var bbox = getScreenBBox()
140
+ return {
141
+ top: bbox.n.y - node.offsetHeight,
142
+ left: bbox.n.x - node.offsetWidth / 2
143
+ }
144
+ }
145
+
146
+ function direction_s() {
147
+ var bbox = getScreenBBox()
148
+ return {
149
+ top: bbox.s.y,
150
+ left: bbox.s.x - node.offsetWidth / 2
151
+ }
152
+ }
153
+
154
+ function direction_e() {
155
+ var bbox = getScreenBBox()
156
+ return {
157
+ top: bbox.e.y - node.offsetHeight / 2,
158
+ left: bbox.e.x
159
+ }
160
+ }
161
+
162
+ function direction_w() {
163
+ var bbox = getScreenBBox()
164
+ return {
165
+ top: bbox.w.y - node.offsetHeight / 2,
166
+ left: bbox.w.x - node.offsetWidth
167
+ }
168
+ }
169
+
170
+ function direction_nw() {
171
+ var bbox = getScreenBBox()
172
+ return {
173
+ top: bbox.nw.y - node.offsetHeight,
174
+ left: bbox.nw.x - node.offsetWidth
175
+ }
176
+ }
177
+
178
+ function direction_ne() {
179
+ var bbox = getScreenBBox()
180
+ return {
181
+ top: bbox.ne.y - node.offsetHeight,
182
+ left: bbox.ne.x
183
+ }
184
+ }
185
+
186
+ function direction_sw() {
187
+ var bbox = getScreenBBox()
188
+ return {
189
+ top: bbox.sw.y,
190
+ left: bbox.sw.x - node.offsetWidth
191
+ }
192
+ }
193
+
194
+ function direction_se() {
195
+ var bbox = getScreenBBox()
196
+ return {
197
+ top: bbox.se.y,
198
+ left: bbox.e.x
199
+ }
200
+ }
201
+
202
+ function initNode() {
203
+ var node = document.createElement('div')
204
+ node.style.position = 'absolute'
205
+ node.style.display = 'none'
206
+ node.style.boxSizing = 'border-box'
207
+ return node
208
+ }
209
+
210
+ function getSVGNode(el) {
211
+ el = el.node()
212
+ if(el.tagName.toLowerCase() == 'svg')
213
+ return el
214
+
215
+ return el.ownerSVGElement
216
+ }
217
+
218
+ // Private - gets the screen coordinates of a shape
219
+ //
220
+ // Given a shape on the screen, will return an SVGPoint for the directions
221
+ // n(north), s(south), e(east), w(west), ne(northeast), se(southeast), nw(northwest),
222
+ // sw(southwest).
223
+ //
224
+ // +-+-+
225
+ // | |
226
+ // + +
227
+ // | |
228
+ // +-+-+
229
+ //
230
+ // Returns an Object {n, s, e, w, nw, sw, ne, se}
231
+ function getScreenBBox() {
232
+ var target = d3.event.target,
233
+ bbox = {},
234
+ matrix = target.getScreenCTM(),
235
+ tbbox = target.getBBox(),
236
+ width = tbbox.width,
237
+ height = tbbox.height,
238
+ x = tbbox.x,
239
+ y = tbbox.y,
240
+ scrollTop = document.body.scrollTop,
241
+ scrollLeft = document.body.scrollLeft
242
+
243
+ if(document.documentElement && document.documentElement.scrollTop) {
244
+ scrollTop = document.documentElement.scrollTop
245
+ scrollLeft = document.documentElement.scrollLeft
246
+ }
247
+
248
+ point.x = x + scrollLeft
249
+ point.y = y + scrollTop
250
+ bbox.nw = point.matrixTransform(matrix)
251
+ point.x += width
252
+ bbox.ne = point.matrixTransform(matrix)
253
+ point.y += height
254
+ bbox.se = point.matrixTransform(matrix)
255
+ point.x -= width
256
+ bbox.sw = point.matrixTransform(matrix)
257
+ point.y -= height / 2
258
+ bbox.w = point.matrixTransform(matrix)
259
+ point.x += width
260
+ bbox.e = point.matrixTransform(matrix)
261
+ point.x -= width / 2
262
+ point.y -= height / 2
263
+ bbox.n = point.matrixTransform(matrix)
264
+ point.y += height
265
+ bbox.s = point.matrixTransform(matrix)
266
+
267
+ return bbox
268
+ }
269
+
270
+ return tip;
271
+ }
@@ -0,0 +1 @@
1
+ d3.tip=function(){function t(t){v=d(t),w=v.createSVGPoint(),document.body.appendChild(g)}function e(){return"n"}function n(){return[0,0]}function r(){return" "}function o(){var t=y();return{top:t.n.y-g.offsetHeight,left:t.n.x-g.offsetWidth/2}}function s(){var t=y();return{top:t.s.y,left:t.s.x-g.offsetWidth/2}}function l(){var t=y();return{top:t.e.y-g.offsetHeight/2,left:t.e.x}}function u(){var t=y();return{top:t.w.y-g.offsetHeight/2,left:t.w.x-g.offsetWidth}}function f(){var t=y();return{top:t.nw.y-g.offsetHeight,left:t.nw.x-g.offsetWidth}}function i(){var t=y();return{top:t.ne.y-g.offsetHeight,left:t.ne.x}}function a(){var t=y();return{top:t.sw.y,left:t.sw.x-g.offsetWidth}}function c(){var t=y();return{top:t.se.y,left:t.e.x}}function m(){var t=document.createElement("div");return t.style.position="absolute",t.style.display="none",t.style.boxSizing="border-box",t}function d(t){return t=t.node(),"svg"==t.tagName.toLowerCase()?t:t.ownerSVGElement}function y(){var t=d3.event.target,e={},n=t.getScreenCTM(),r=t.getBBox(),o=r.width,s=r.height,l=r.x,u=r.y,f=document.body.scrollTop;return scrollLeft=document.body.scrollLeft,document.documentElement&&document.documentElement.scrollTop&&(f=document.documentElement.scrollTop,scrollLeft=document.documentElement.scrollLeft),w.x=l+scrollLeft,w.y=u+f,e.nw=w.matrixTransform(n),w.x+=o,e.ne=w.matrixTransform(n),w.y+=s,e.se=w.matrixTransform(n),w.x-=o,e.sw=w.matrixTransform(n),w.y-=s/2,e.w=w.matrixTransform(n),w.x+=o,e.e=w.matrixTransform(n),w.x-=o/2,w.y-=s/2,e.n=w.matrixTransform(n),w.y+=s,e.s=w.matrixTransform(n),e}var p=e,h=n,x=r,g=m(),v=null,w=null;t.show=function(){var e,n=x.apply(this,arguments),r=h.apply(this,arguments),o=p.apply(this,arguments),s=d3.select(g),l=0;for(s.html(n).style("display","block");l--;)s.classed(b[l],!1);return e=T.get(o).apply(this),s.classed(o,!0).style({top:e.top+r[0]+"px",left:e.left+r[1]+"px"}),t},t.hide=function(){return g.style.display="none",g.innerHTML="",t},t.attr=function(e,n){return 2>arguments.length?d3.select(g).attr(e):(d3.select(g).attr(e,n),t)},t.style=function(e,n){return 2>arguments.length?d3.select(g).style(e):(d3.select(g).style(e,n),t)},t.direction=function(e){return arguments.length?(p=null==e?e:d3.functor(e),t):p},t.offset=function(e){return arguments.length?(h=null==e?e:d3.functor(e),t):h},t.html=function(e){return arguments.length?(x=null==e?e:d3.functor(e),t):x};var T=d3.map({n:o,s:s,e:l,w:u,nw:f,ne:i,sw:a,se:c}),b=T.keys();return t};
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: d3-tip-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Loren Norman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.1'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.1'
46
+ description: This gem provides D3 Tip for Rails 3.1+ via the Asset Pipeline.
47
+ email:
48
+ - loren@github.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - D3-TIP-LICENSE
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - d3-rails.gemspec
60
+ - lib/d3-tip-rails.rb
61
+ - lib/d3-tip/rails.rb
62
+ - lib/d3-tip/rails/engine.rb
63
+ - lib/d3-tip/rails/version.rb
64
+ - vendor/assets/javascripts/d3.tip.js
65
+ - vendor/assets/javascripts/d3.tip.min.js
66
+ homepage: https://github.com/lorennorman/d3-tip-rails
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 1.3.6
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: D3 Tip for the Rails Asset Pipeline
90
+ test_files: []