d3js-plugins-rails 0.0.12 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0faed227b2539d6a29a28f6c3efe3408f3e5fa1
4
- data.tar.gz: ca01ea7ef6130f37e3a6eac75f2b8c7322d90b69
3
+ metadata.gz: 7a17d75d2c86f99892135e42508aa38e0190560c
4
+ data.tar.gz: 0cdec6d6caaddd7db2329a5d929a1afe37cc248d
5
5
  SHA512:
6
- metadata.gz: 874df8304003858f14b48fc6a60acd4345e609fd7985527c08493fd875d27e3ea4982eae34386187d6f466a290b0a4433a594c21002287e539885771a0eaa7b0
7
- data.tar.gz: e2f852ad0364475a3e80aaf0b0c5752c933c62b9f9391b094297fffc7867c8453e8bc7c2d17ac8adcaa695276864cb31477bfd45602f85fc75c6234a86d602f4
6
+ metadata.gz: c979c51c71ee2f2eafe5cd7687877728a53a6df942257cd9f681d2392656edb59867117b3d3032cb0642f45721ebedc4f4b258f5e6460973098ea71e0e46a50c
7
+ data.tar.gz: 4da25bb701ae74cc54623585cf90cc627cc89f88e8f5800106353e55c9dc33b9bab4b0bee4b8912ee2b223b580643ab5279138425808a852ffbff834f49709c2
data/README.md CHANGED
@@ -19,17 +19,6 @@ Add the *needed* directives to your JavaScript manifest file (application.js):
19
19
 
20
20
  It's unlikely you will need to include all plugins globally.
21
21
 
22
- ## HighSecurity
23
-
24
- To ensure that you're including a gem with original code, you can install this gem using a HighSecurity policy.
25
-
26
- gem cert --add <(curl -Ls https://gist.github.com/bai/5150087/raw/public_cert.pem)
27
- bundle install --trust-policy HighSecurity
28
-
29
- Or, if you don't use bundler:
30
-
31
- gem install d3js-plugins-rails -P HighSecurity
32
-
33
22
  ## Contributing
34
23
 
35
24
  1. Fork it
@@ -18,8 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.signing_key = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
22
- gem.cert_chain = ["certs/bai.pem"]
23
-
24
21
  gem.add_dependency "railties", ">= 3.0", "< 5.0"
25
22
  end
@@ -1,8 +1,8 @@
1
1
  module D3js
2
2
  module Plugins
3
3
  module Rails
4
- VERSION = "0.0.12"
5
- D3_PLUGINS_VERSION = "88ae0e7d8f285d2f8f3a8e71e52ad2e5b75d403c"
4
+ VERSION = "0.0.15"
5
+ D3_PLUGINS_VERSION = "bfc4a8a42b3b0c8613c7ac582180547f2c21ac35"
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,3 @@
1
1
  # D3 Plugins
2
2
 
3
- This is a repository for sharing D3 plugins.
4
-
5
- Each plugin should live in a directory that matches its name.
3
+ Please note: the plugins in this repository will soon be broken up into separate repositories for easier distributed ownership. If you have a new plugin you’d like to share, please add a link to it from the [D3 plugins wiki](https://github.com/mbostock/d3/wiki/Plugins).
@@ -0,0 +1,48 @@
1
+ An interpolator that implements Dave Green’s [cubehelix color scheme](http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/).
2
+
3
+ See [bl.ocks.org/11413789](http://bl.ocks.org/mbostock/11413789) and [bl.ocks.org/11415064](http://bl.ocks.org/mbostock/11415064) for examples.
4
+
5
+ <a href="#interpolateCubehelix" name="interpolateCubehelix">#</a> d3.<b>interpolateCubehelix</b>(<i>a</i>, <i>b</i>)
6
+
7
+ Returns a cubehelix <a href="https://github.com/mbostock/d3/wiki/Transitions#_interpolate">interpolator</a> between the two colors <i>a</i> and <i>b</i>, using a gamma correction value of 1. The two colors are typically specified in HSL color space. For example, the default cubehelix color scheme is:
8
+
9
+ ```js
10
+ var cubehelix = d3.interpolateCubehelix("hsl(300,50%,0%)", "hsl(-240,50%,100%)");
11
+ ```
12
+
13
+ The hue of color <i>a</i> determines the starting hue angle in degrees, while the hue of color <i>b</i> determines the ending hue angle in degrees; the hue angle is interpolated linearly for intermediate values. Likewise for saturation and lightness, which are specified in percentages. (The [d3.hsl](https://github.com/mbostock/d3/wiki/Colors#d3_hsl) constructor can also be used.)
14
+
15
+ If either color <i>a</i> or <i>b</i> is not an HSL color, the colors are converted to HSL color space first. However, it is recommended that you specify each color’s hue, saturation and lightness explicitly: cubehelix interpolation does not actually use the HSL color space, and thus the terms <i>hue</i>, <i>saturation</i> and <i>lightness</i> here are similar but slightly different to their meaning in HSL color space.
16
+
17
+ The return value of the interpolator is a hexadecimal RGB string.
18
+
19
+ To convert from the original color scheme’s <i>START</i>, <i>ROTS</i> and <i>HUE</i> parameters, use the following equalities:
20
+
21
+ * starting hue angle = (<i>START</i> - 1) * 120
22
+ * ending hue angle = (<i>START</i> - 1) * 120 + <i>ROTS</i> * 360
23
+ * saturation = <i>HUE</i> / 2
24
+
25
+ For example, the default color scheme’s settings are:
26
+
27
+ * <i>START</i> = 0.5
28
+ * <i>ROTS</i> = -1.5
29
+ * <i>HUE</i> = 1.0
30
+
31
+ These correspond to the following start and end colors:
32
+
33
+ * hsl(300, 50%, 0%)
34
+ * hsl(-240, 50%, 100%)
35
+
36
+ While the original cubehelix color scheme always uses the full range of lightness from 0% to 100%, note that it is possible in this interpolator to use a subset of this range by specifying start and end colors with different lightnesses.
37
+
38
+ <a href="#interpolateCubehelix_gamma" name="interpolateCubehelix_gamma">#</a> d3.interpolateCubehelix.<b>gamma</b>(<i>gamma</i>)
39
+
40
+ Returns a cubehelix interpolator factory with the specified <i>gamma</i> correction value. For example, to create the default cubehelix color scheme with a gamma correction value of 1.2:
41
+
42
+ ```js
43
+ var cubehelix = d3.interpolateCubehelix.gamma(1.2)("hsl(300,50%,0%)", "hsl(-240,50%,100%)");
44
+ ```
45
+
46
+ <a href="#cubehelix" name="cubehelix">#</a> d3.scale.<b>cubehelix</b>
47
+
48
+ Constructs a new [linear scale](https://github.com/mbostock/d3/wiki/Quantitative-Scales) with the interpolator [d3.interpolateCubehelix](#interpolateCubehelix), the domain [0, 1] and the range [hsl(300°, 50%, 0%), hsl(-240°, 50%, 100%)]. This is merely a convenience function.
@@ -0,0 +1,46 @@
1
+ (function() {
2
+ var radians = Math.PI / 180;
3
+
4
+ d3.scale.cubehelix = function() {
5
+ return d3.scale.linear()
6
+ .range([d3.hsl(300, .5, 0), d3.hsl(-240, .5, 1)])
7
+ .interpolate(d3.interpolateCubehelix);
8
+ };
9
+
10
+ d3.interpolateCubehelix = d3_interpolateCubehelix(1);
11
+ d3.interpolateCubehelix.gamma = d3_interpolateCubehelix;
12
+
13
+ function d3_interpolateCubehelix(γ) {
14
+ return function(a, b) {
15
+ a = d3.hsl(a);
16
+ b = d3.hsl(b);
17
+
18
+ var ah = (a.h + 120) * radians,
19
+ bh = (b.h + 120) * radians - ah,
20
+ as = a.s,
21
+ bs = b.s - as,
22
+ al = a.l,
23
+ bl = b.l - al;
24
+
25
+ if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
26
+ if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah;
27
+
28
+ return function(t) {
29
+ var h = ah + bh * t,
30
+ l = Math.pow(al + bl * t, γ),
31
+ a = (as + bs * t) * l * (1 - l),
32
+ cosh = Math.cos(h),
33
+ sinh = Math.sin(h);
34
+ return "#"
35
+ + hex(l + a * (-0.14861 * cosh + 1.78277 * sinh))
36
+ + hex(l + a * (-0.29227 * cosh - 0.90649 * sinh))
37
+ + hex(l + a * (+1.97294 * cosh));
38
+ };
39
+ };
40
+ }
41
+
42
+ function hex(v) {
43
+ var s = (v = v <= 0 ? 0 : v >= 1 ? 255 : v * 255 | 0).toString(16);
44
+ return v < 0x10 ? "0" + s : s;
45
+ }
46
+ })();
@@ -14,7 +14,7 @@
14
14
  var dx = d.x - focus[0],
15
15
  dy = d.y - focus[1],
16
16
  dd = Math.sqrt(dx * dx + dy * dy);
17
- if (!dd || dd >= radius) return {x: d.x, y: d.y, z: 1};
17
+ if (!dd || dd >= radius) return {x: d.x, y: d.y, z: dd >= radius ? 1 : 10};
18
18
  var k = k0 * (1 - Math.exp(-dd * k1)) / dd * .75 + .25;
19
19
  return {x: focus[0] + dx * k, y: focus[1] + dy * k, z: Math.min(k, 10)};
20
20
  }
@@ -3,5 +3,6 @@
3
3
  * Panning & Zooming: <http://bl.ocks.org/mbostock/4132797>
4
4
  * Clipping: <http://bl.ocks.org/mbostock/4150951>
5
5
  * Vector Tiles: <http://bl.ocks.org/mbostock/5593150>
6
+ * Raster Tiles & Vector Overlay: <http://bl.ocks.org/mbostock/5342063>
6
7
 
7
8
  A layout for determining which 256x256 quadtree tiles to display in a rectangular viewport, based on a scale and translate. This layout can be used to create a simple slippy map, or render standard map tiles (e.g., MapBox, CloudMade) as a base layer behind a geographic projection.
@@ -27,7 +27,6 @@
27
27
  face = face.map(project);
28
28
  face.push(face[0]);
29
29
  face = [face];
30
- if (d3.geo.area({type: "Polygon", coordinates: face}) > Math.PI) face[0].reverse();
31
30
  return face;
32
31
  })
33
32
  };
@@ -72,8 +71,8 @@
72
71
  for (var j = 0; j < i; ++j) {
73
72
  faces.push([
74
73
  i1(j / i),
75
- i1((j + 1) / i),
76
- i2((j + 1) / (i + 1))
74
+ i2((j + 1) / (i + 1)),
75
+ i1((j + 1) / i)
77
76
  ]);
78
77
  }
79
78
  }
@@ -48,11 +48,15 @@ Alternatively, use a transform attribute:
48
48
 
49
49
  ```js
50
50
  path.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
51
- .attr("d", hexbin.hexagon);
51
+ .attr("d", hexbin.hexagon());
52
52
  ```
53
53
 
54
54
  If *radius* is not specified, the hexbin’s current radius is used. If *radius* is specified, a hexagon with the specified radius is returned, which is useful for area-encoded bivariate hexbins.
55
55
 
56
+ <a href="centers" href="#centers">#</a> hexbin.<b>centers</b>()
57
+
58
+ Returns an array of [*x*, *y*] points representing the centers of each hexagon. Each point also has properties *i* and *j* representing the grid column and row, respectively, of the hexagon.
59
+
56
60
  <a href="mesh" href="#mesh">#</a> hexbin.<b>mesh</b>()
57
61
 
58
62
  Returns the SVG path string for a hexagonal mesh that covers the area of the layout (as determined by the layout size). The returned mesh is designed to be stroked. The mesh may extend slightly beyond the layout’s defined area, and thus may need to be clipped.
@@ -2,12 +2,12 @@
2
2
  d3.horizon = function() {
3
3
  var bands = 1, // between 1 and 5, typically
4
4
  mode = "offset", // or mirror
5
- interpolate = "linear", // or basis, monotone, step-before, etc.
5
+ area = d3.svg.area(),
6
+ defined,
6
7
  x = d3_horizonX,
7
8
  y = d3_horizonY,
8
- w = 960,
9
- h = 40,
10
- duration = 0;
9
+ width = 960,
10
+ height = 40;
11
11
 
12
12
  var color = d3.scale.linear()
13
13
  .domain([-1, 0, 1])
@@ -37,9 +37,9 @@
37
37
  });
38
38
 
39
39
  // Compute the new x- and y-scales, and transform.
40
- var x1 = d3.scale.linear().domain([xMin, xMax]).range([0, w]),
41
- y1 = d3.scale.linear().domain([0, yMax]).range([0, h * bands]),
42
- t1 = d3_horizonTransform(bands, h, mode);
40
+ var x1 = d3.scale.linear().domain([xMin, xMax]).range([0, width]),
41
+ y1 = d3.scale.linear().domain([0, yMax]).range([0, height * bands]),
42
+ t1 = d3_horizonTransform(bands, height, mode);
43
43
 
44
44
  // Retrieve the old scales, if this is an update.
45
45
  if (this.__chart__) {
@@ -62,13 +62,12 @@
62
62
  defs.enter().append("defs").append("clipPath")
63
63
  .attr("id", "d3_horizon_clip" + id)
64
64
  .append("rect")
65
- .attr("width", w)
66
- .attr("height", h);
65
+ .attr("width", width)
66
+ .attr("height", height);
67
67
 
68
- defs.select("rect").transition()
69
- .duration(duration)
70
- .attr("width", w)
71
- .attr("height", h);
68
+ d3.transition(defs.select("rect"))
69
+ .attr("width", width)
70
+ .attr("height", height);
72
71
 
73
72
  // We'll use a container to clip all horizon layers at once.
74
73
  g.selectAll("g")
@@ -80,16 +79,17 @@
80
79
  var path = g.select("g").selectAll("path")
81
80
  .data(d3.range(-1, -bands - 1, -1).concat(d3.range(1, bands + 1)), Number);
82
81
 
83
- var d0 = d3_horizonArea
84
- .interpolate(interpolate)
82
+ if (defined) area.defined(function(_, i) { return defined.call(this, d[i], i); });
83
+
84
+ var d0 = area
85
85
  .x(function(d) { return x0(d[0]); })
86
- .y0(h * bands)
87
- .y1(function(d) { return h * bands - y0(d[1]); })
86
+ .y0(height * bands)
87
+ .y1(function(d) { return height * bands - y0(d[1]); })
88
88
  (data);
89
89
 
90
- var d1 = d3_horizonArea
90
+ var d1 = area
91
91
  .x(function(d) { return x1(d[0]); })
92
- .y1(function(d) { return h * bands - y1(d[1]); })
92
+ .y1(function(d) { return height * bands - y1(d[1]); })
93
93
  (data);
94
94
 
95
95
  path.enter().append("path")
@@ -97,14 +97,12 @@
97
97
  .attr("transform", t0)
98
98
  .attr("d", d0);
99
99
 
100
- path.transition()
101
- .duration(duration)
100
+ d3.transition(path)
102
101
  .style("fill", color)
103
102
  .attr("transform", t1)
104
103
  .attr("d", d1);
105
104
 
106
- path.exit().transition()
107
- .duration(duration)
105
+ d3.transition(path.exit())
108
106
  .attr("transform", t1)
109
107
  .attr("d", d1)
110
108
  .remove();
@@ -112,77 +110,64 @@
112
110
  // Stash the new scales.
113
111
  this.__chart__ = {x: x1, y: y1, t: t1, id: id};
114
112
  });
115
- d3.timer.flush();
116
113
  }
117
114
 
118
- horizon.duration = function(x) {
119
- if (!arguments.length) return duration;
120
- duration = +x;
121
- return horizon;
122
- };
123
-
124
- horizon.bands = function(x) {
115
+ horizon.bands = function(_) {
125
116
  if (!arguments.length) return bands;
126
- bands = +x;
117
+ bands = +_;
127
118
  color.domain([-bands, 0, bands]);
128
119
  return horizon;
129
120
  };
130
121
 
131
- horizon.mode = function(x) {
122
+ horizon.mode = function(_) {
132
123
  if (!arguments.length) return mode;
133
- mode = x + "";
124
+ mode = _ + "";
134
125
  return horizon;
135
126
  };
136
127
 
137
- horizon.colors = function(x) {
128
+ horizon.colors = function(_) {
138
129
  if (!arguments.length) return color.range();
139
- color.range(x);
130
+ color.range(_);
140
131
  return horizon;
141
132
  };
142
133
 
143
- horizon.interpolate = function(x) {
144
- if (!arguments.length) return interpolate;
145
- interpolate = x + "";
134
+ horizon.x = function(_) {
135
+ if (!arguments.length) return x;
136
+ x = _;
146
137
  return horizon;
147
138
  };
148
139
 
149
- horizon.x = function(z) {
150
- if (!arguments.length) return x;
151
- x = z;
140
+ horizon.y = function(_) {
141
+ if (!arguments.length) return y;
142
+ y = _;
152
143
  return horizon;
153
144
  };
154
145
 
155
- horizon.y = function(z) {
156
- if (!arguments.length) return y;
157
- y = z;
146
+ horizon.width = function(_) {
147
+ if (!arguments.length) return width;
148
+ width = +_;
158
149
  return horizon;
159
150
  };
160
151
 
161
- horizon.width = function(x) {
162
- if (!arguments.length) return w;
163
- w = +x;
152
+ horizon.height = function(_) {
153
+ if (!arguments.length) return height;
154
+ height = +_;
164
155
  return horizon;
165
156
  };
166
157
 
167
- horizon.height = function(x) {
168
- if (!arguments.length) return h;
169
- h = +x;
158
+ horizon.defined = function(_) {
159
+ if (!arguments.length) return defined;
160
+ defined = _;
170
161
  return horizon;
171
162
  };
172
163
 
173
- return horizon;
164
+ return d3.rebind(horizon, area, "interpolate", "tension");
174
165
  };
175
166
 
176
- var d3_horizonArea = d3.svg.area(),
177
- d3_horizonId = 0;
167
+ var d3_horizonId = 0;
178
168
 
179
- function d3_horizonX(d) {
180
- return d[0];
181
- }
182
-
183
- function d3_horizonY(d) {
184
- return d[1];
185
- }
169
+ function d3_horizonX(d) { return d[0]; }
170
+ function d3_horizonY(d) { return d[1]; }
186
171
 
187
172
  function d3_horizonTransform(bands, h, mode) {
188
173
  return mode == "offset"
@@ -0,0 +1,88 @@
1
+ lasso
2
+ =========
3
+
4
+ lasso.js is a D3 plugin that allows you to tag elements on a page by drawing a line over or around objects. Functions can be run based on the lasso action. This functionality can be useful for brushing or filtering.
5
+
6
+ An example of the lasso implemented in a scatterplot can be found here: [http://bl.ocks.org/skokenes/511c5b658c405ad68941](http://bl.ocks.org/skokenes/511c5b658c405ad68941)
7
+
8
+ This example is based off of Mike Bostock's scatterplot example here: [http://bl.ocks.org/mbostock/3887118](http://bl.ocks.org/mbostock/3887118)
9
+
10
+ Lassoing tags
11
+ --
12
+ When the lasso is used, it tags elements by adding properties to their data. The properties are:
13
+
14
+ - possible: while drawing a lasso, if an element is part of the final selection that would be made if the lasso was completed at that instance, this value is true. Otherwise, it is false.
15
+ - selected: when a lasso is completed, all elements that were tagged as possible are given a selected value of true. Otherwise, the value is false.
16
+
17
+ The tags can be used in combination with functions to perform actions like styling the possible or selected values while the lasso is in use.
18
+
19
+ Note that the lasso only works with elements whose data is defined as an object.
20
+
21
+
22
+ Function Overview
23
+ --
24
+ **d3.lasso**()
25
+
26
+ Creates a new lasso object. This object can then have parameters set before the lasso is drawn.
27
+ ```
28
+ var lasso = d3.lasso(); // creates a new lasso
29
+ ```
30
+
31
+ lasso.**items**(_[selection]_)
32
+
33
+ The items() parameter takes in a d3 selection. Each element in the selection will be tagged with lasso-specific properties when the lasso is used. If no input is specified, the function returns the lasso's current items.
34
+ ```
35
+ lasso.items(d3.selectAll("circle")); // sets all circles on the page to be lasso-able
36
+ ```
37
+
38
+ lasso.**hoverSelect**(_[bool]_)
39
+
40
+ The hoverSelect() parameter takes in a boolean that determines whether objects can be lassoed by hovering over an element during lassoing. The default value is set to true. If no input is specified, the function returns the lasso's current hover parameter.
41
+ ```
42
+ lasso.hoverSelect(true); // allows hovering of elements for selection during lassoing
43
+ ```
44
+
45
+ lasso.**closePathSelect**(_[bool]_)
46
+
47
+ The closePathSelect() parameter takes in a boolean that determines whether objects can be lassoed by drawing a loop around them. The default value is set to true. If no input is specified, the function returns the lasso's current parameter.
48
+ ```
49
+ lasso.closePathSelect(true); // allows looping of elements for selection during lassoing
50
+ ```
51
+
52
+ lasso.**closePathDistance**(_[num]_)
53
+
54
+ The closePathDistance() parameter takes in a number that specifies the maximum distance in pixels from the lasso origin that a lasso needs to be drawn in order to complete the loop and select elements. This parameter only works if closePathSelect is set to true; If no input is specified, the function returns the lasso's current parameter.
55
+ ```
56
+ lasso.closePathDistance(75); // the lasso loop will complete itself whenever the lasso end is within 75 pixels of the origin
57
+ ```
58
+
59
+ lasso.**area**(_[sel]_)
60
+
61
+ The area() parameter takes in a selection representing the element to be used as a target area for the lasso event. If no input is specified, the function returns the current area selection.
62
+ ```
63
+ lasso.area(d3.select("#myLassoRect")); // the lasso will be trigger whenever a user clicks and drags on #myLassoRect
64
+ ```
65
+
66
+ lasso.**on**(_type,[func]_)
67
+
68
+ The on() parameter takes in a type of event and a function for that event. There are 3 types of events that can be defined:
69
+ - start: this function will be executed whenever a lasso is started
70
+ - draw: this function will execute repeatedly as the lasso is drawn
71
+ - end: this function will be executed whenever a lasso is completed
72
+
73
+ If no function is specified, the function will return the current function defined for the type specified.
74
+ ```
75
+ lasso.on("start",function() { alert("lasso started!"); }); // every time a lasso is started, an alert will trigger
76
+ ```
77
+
78
+ Initiating a lasso
79
+ --
80
+ Once a lasso object is defined, it can be added to a page by calling it on an element like an svg.
81
+ ```
82
+ var lasso = d3.lasso()
83
+ .items(d3.selectAll("circle")) // Create a lasso and provide it some target elements
84
+ .area(de.select("#myLassoRect")); // Sets the drag area for the lasso on the rectangle #myLassoRect
85
+ d3.select("svg").call(lasso); // Initiate the lasso on an svg element
86
+ ```
87
+
88
+ If a lasso is going to be used on graphical elements that have been translated via a g element acting as a container, which is a common practice for incorporating chart margins, then the lasso should be called on that g element so that it is in the same coordinate system as the graphical elements.
@@ -0,0 +1,299 @@
1
+ d3.lasso = function() {
2
+
3
+ var items = null,
4
+ closePathDistance = 75,
5
+ closePathSelect = true,
6
+ isPathClosed = false,
7
+ hoverSelect = true,
8
+ area = null,
9
+ on = {start:function(){}, draw: function(){}, end: function(){}};
10
+
11
+ function lasso() {
12
+ var _this = d3.select(this[0][0]);
13
+ var g = _this.append("g")
14
+ .attr("class","lasso");
15
+ var dyn_path = g.append("path")
16
+ .attr("class","drawn");
17
+ var close_path = g.append("path")
18
+ .attr("class","loop_close");
19
+ var complete_path = g.append("path")
20
+ .attr("display","none");
21
+ var origin_node = g.append("circle")
22
+ .attr("class","origin");
23
+ var path;
24
+ var origin;
25
+ var last_known_point;
26
+ var path_length_start;
27
+ var drag = d3.behavior.drag()
28
+ .on("dragstart",dragstart)
29
+ .on("drag",dragmove)
30
+ .on("dragend",dragend);
31
+ area.call(drag);
32
+
33
+ function dragstart() {
34
+ // Reset blank lasso path
35
+ path="";
36
+ dyn_path.attr("d",null);
37
+ close_path.attr("d",null);
38
+ // Set path length start
39
+ path_length_start = 0;
40
+ // Set every item to have a false selection and reset their center point and counters
41
+ items[0].forEach(function(d) {
42
+ d.hoverSelected = false;
43
+ d.loopSelected = false;
44
+ var cur_box = d.getBBox();
45
+ d.lassoPoint = {
46
+ cx: Math.round(cur_box.x + cur_box.width/2),
47
+ cy: Math.round(cur_box.y + cur_box.height/2),
48
+ edges: {top:0,right:0,bottom:0,left:0},
49
+ close_edges: {left: 0, right: 0}
50
+ };
51
+ });
52
+
53
+ // if hover is on, add hover function
54
+ if(hoverSelect==true) {
55
+ items.on("mouseover.lasso",function() {
56
+ // if hovered, change lasso selection attribute to true
57
+ d3.select(this)[0][0].hoverSelected = true;
58
+ })
59
+ }
60
+
61
+ // Run user defined start function
62
+ on.start();
63
+ }
64
+
65
+ function dragmove() {
66
+ var x = d3.mouse(this)[0];
67
+ var y = d3.mouse(this)[1];
68
+ // Initialize the path or add the latest point to it
69
+ if (path=="") {
70
+ path = path + "M " + x + " " + y;
71
+ origin = [x,y];
72
+ // Draw origin node
73
+ origin_node
74
+ .attr("cx",x)
75
+ .attr("cy",y)
76
+ .attr("r",7)
77
+ .attr("display",null);
78
+ }
79
+ else {
80
+ path = path + " L " + x + " " + y;
81
+ }
82
+
83
+ // Reset closed edges counter
84
+ items[0].forEach(function(d) {
85
+ d.lassoPoint.close_edges = {left:0,right:0};
86
+ });
87
+
88
+ // Calculate the current distance from the lasso origin
89
+ var distance = Math.sqrt(Math.pow(x-origin[0],2)+Math.pow(y-origin[1],2));
90
+
91
+ // Set the closed path line
92
+ var close_draw_path = "M " + x + " " + y + " L " + origin[0] + " " + origin[1];
93
+
94
+ // Draw the lines
95
+ dyn_path.attr("d",path);
96
+
97
+
98
+ // If within the closed path distance parameter, show the closed path. otherwise, hide it
99
+ if(distance<=closePathDistance) {
100
+ close_path.attr("display",null);
101
+ }
102
+ else {
103
+ close_path.attr("display","none");
104
+ }
105
+
106
+ isPathClosed = distance<=closePathDistance;
107
+
108
+ // create complete path
109
+ var complete_path_d = d3.select("path")[0][0].attributes.d.value + "Z";
110
+ complete_path.attr("d",complete_path_d);
111
+
112
+ // get path length
113
+ var path_node = dyn_path.node();
114
+ var path_length_end = path_node.getTotalLength();
115
+ var last_pos = path_node.getPointAtLength(path_length_start-1);
116
+
117
+ for (var i = path_length_start; i<=path_length_end; i++) {
118
+ var cur_pos = path_node.getPointAtLength(i);
119
+ var cur_pos_obj = {
120
+ x:Math.round(cur_pos.x*100)/100,
121
+ y:Math.round(cur_pos.y*100)/100
122
+ };
123
+ var prior_pos = path_node.getPointAtLength(i-1);
124
+ var prior_pos_obj = {
125
+ x:Math.round(prior_pos.x*100)/100,
126
+ y:Math.round(prior_pos.y*100)/100
127
+ };
128
+
129
+ items[0].filter(function(d) {
130
+ var a;
131
+ if(d.lassoPoint.cy === cur_pos_obj.y && d.lassoPoint.cy != prior_pos_obj.y) {
132
+ last_known_point = {
133
+ x: prior_pos_obj.x,
134
+ y: prior_pos_obj.y
135
+ };
136
+ a=false;
137
+ }
138
+ else if (d.lassoPoint.cy === cur_pos_obj.y && d.lassoPoint.cy === prior_pos_obj.y) {
139
+ a = false;
140
+ }
141
+ else if (d.lassoPoint.cy === prior_pos_obj.y && d.lassoPoint.cy != cur_pos_obj.y) {
142
+ a = sign(d.lassoPoint.cy-cur_pos_obj.y)!=sign(d.lassoPoint.cy-last_known_point.y);
143
+ }
144
+ else {
145
+ last_known_point = {
146
+ x: prior_pos_obj.x,
147
+ y: prior_pos_obj.y
148
+ };
149
+ a = sign(d.lassoPoint.cy-cur_pos_obj.y)!=sign(d.lassoPoint.cy-prior_pos_obj.y);
150
+ }
151
+ return a;
152
+ }).forEach(function(d) {
153
+ if(cur_pos_obj.x>d.lassoPoint.cx) {
154
+ d.lassoPoint.edges.right = d.lassoPoint.edges.right+1;
155
+ }
156
+ if(cur_pos_obj.x<d.lassoPoint.cx) {
157
+ d.lassoPoint.edges.left = d.lassoPoint.edges.left+1;
158
+ }
159
+ });
160
+ }
161
+
162
+
163
+ if(isPathClosed == true && closePathSelect == true) {
164
+ close_path.attr("d",close_draw_path);
165
+ close_path_node =close_path.node();
166
+ var close_path_length = close_path_node.getTotalLength();
167
+ var close_path_edges = {left:0,right:0};
168
+ for (var i = 0; i<=close_path_length; i++) {
169
+ var cur_pos = close_path_node.getPointAtLength(i);
170
+ var prior_pos = close_path_node.getPointAtLength(i-1);
171
+
172
+ items[0].filter(function(d) {return d.lassoPoint.cy==Math.round(cur_pos.y)}).forEach(function(d) {
173
+ if(Math.round(cur_pos.y)!=Math.round(prior_pos.y) && Math.round(cur_pos.x)>d.lassoPoint.cx) {
174
+ d.lassoPoint.close_edges.right = 1;
175
+ }
176
+ if(Math.round(cur_pos.y)!=Math.round(prior_pos.y) && Math.round(cur_pos.x)<d.lassoPoint.cx) {
177
+ d.lassoPoint.close_edges.left = 1;
178
+ }
179
+ });
180
+
181
+ }
182
+
183
+ items[0].forEach(function(a) {
184
+ if((a.lassoPoint.edges.left+a.lassoPoint.close_edges.left)>0 && (a.lassoPoint.edges.right + a.lassoPoint.close_edges.right)%2 ==1) {
185
+ a.loopSelected = true;
186
+ }
187
+ else {
188
+ a.loopSelected = false;
189
+ }
190
+ });
191
+ }
192
+ else {
193
+ items[0].forEach(function(d) {
194
+ d.loopSelected = false;
195
+ })
196
+ }
197
+
198
+ // Tag possible items
199
+ d3.selectAll(items[0].filter(function(d) {return (d.loopSelected && isPathClosed) || d.hoverSelected}))
200
+ .attr("d",function(d) {return d.possible = true;});
201
+
202
+ d3.selectAll(items[0].filter(function(d) {return !((d.loopSelected && isPathClosed) || d.hoverSelected)}))
203
+ .attr("d",function(d) {return d.possible = false;});
204
+
205
+ on.draw();
206
+
207
+ // Continue drawing path from where it left off
208
+ path_length_start = path_length_end+1;
209
+ }
210
+
211
+ function dragend() {
212
+ // Remove mouseover tagging function
213
+ items.on("mouseover.lasso",null);
214
+
215
+ // Tag selected items
216
+ items.filter(function(d) {return d.possible === true})
217
+ .attr("d",function(d) {return d.selected = true;});
218
+
219
+ items.filter(function(d) {return d.possible === false})
220
+ .attr("d",function(d) {return d.selected = false;});
221
+
222
+ // Reset possible items
223
+ items.attr("d",function(d) {return d.possible = false});
224
+
225
+ // Clear lasso
226
+ dyn_path.attr("d",null);
227
+ close_path.attr("d",null);
228
+ origin_node.attr("display","none");
229
+
230
+ // Run user defined end function
231
+ on.end();
232
+
233
+ }
234
+ }
235
+
236
+ lasso.items = function(_) {
237
+
238
+ if (!arguments.length) return items;
239
+ items = _;
240
+ items[0].forEach(function(d) {
241
+ var item = d3.select(d);
242
+ if(typeof item.datum() === 'undefined') {
243
+ item.datum({possible:false,selected:false});
244
+ }
245
+ else {
246
+ item.attr("d",function(e) {e.possible = false; e.selected = false; return e;});
247
+ }
248
+ });
249
+ return lasso;
250
+ };
251
+
252
+ lasso.closePathDistance = function(_) {
253
+ if (!arguments.length) return closePathDistance;
254
+ closePathDistance = _;
255
+ return lasso;
256
+ };
257
+
258
+ lasso.closePathSelect = function(_) {
259
+ if (!arguments.length) return closePathSelect;
260
+ closePathSelect = _==true;
261
+ return lasso;
262
+ };
263
+
264
+ lasso.isPathClosed = function(_) {
265
+ if (!arguments.length) return isPathClosed;
266
+ isPathClosed = _==true;
267
+ return lasso;
268
+ };
269
+
270
+ lasso.hoverSelect = function(_) {
271
+ if (!arguments.length) return hoverSelect;
272
+ hoverSelect = _==true;
273
+ return lasso;
274
+ };
275
+
276
+ lasso.on = function(type,_) {
277
+ if(!arguments.length) return on;
278
+ if(arguments.length===1) return on[type];
279
+ var types = ["start","draw","end"];
280
+ if(types.indexOf(type)>-1) {
281
+ on[type] = _;
282
+ }
283
+ return lasso;
284
+ };
285
+
286
+ lasso.area = function(_) {
287
+ if(!arguments.length) return area;
288
+ area=_;
289
+ return lasso;
290
+ };
291
+
292
+ function sign(x) {
293
+ return x?x<0?-1:1:0;
294
+ }
295
+
296
+
297
+ return lasso;
298
+
299
+ };
@@ -47,27 +47,19 @@ d3.longscroll = function() {
47
47
  }
48
48
 
49
49
  longscroll.render = function(_) {
50
- if (!arguments.length) return render;
51
- render = _;
52
- return longscroll;
50
+ return arguments.length ? (render = _, longscroll) : render;
53
51
  };
54
52
 
55
53
  longscroll.rowHeight = function(_) {
56
- if (!arguments.length) return rowHeight;
57
- rowHeight = +_;
58
- return longscroll;
54
+ return arguments.length ? (rowHeight = +_, longscroll) : rowHeight;
59
55
  };
60
56
 
61
57
  longscroll.position = function(_) {
62
- if (!arguments.length) return position;
63
- position = +_;
64
- return longscroll;
58
+ return arguments.length ? (position = +_, longscroll) : position;
65
59
  };
66
60
 
67
61
  longscroll.size = function(_) {
68
- if (!arguments.length) return size;
69
- size = +_;
70
- return longscroll;
62
+ return arguments.length ? (size = +_, longscroll) : size;
71
63
  };
72
64
 
73
65
  return longscroll;
@@ -118,7 +118,9 @@ d3.sankey = function() {
118
118
  node.x = x;
119
119
  node.dx = nodeWidth;
120
120
  node.sourceLinks.forEach(function(link) {
121
- nextNodes.push(link.target);
121
+ if (nextNodes.indexOf(link.target) < 0) {
122
+ nextNodes.push(link.target);
123
+ }
122
124
  });
123
125
  });
124
126
  remainingNodes = nextNodes;
metadata CHANGED
@@ -1,35 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: d3js-plugins-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Gorodetsky
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDSDCCAjCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA1MQowCAYDVQQDDAF2MRMw
14
- EQYKCZImiZPyLGQBGRYDZ29yMRIwEAYKCZImiZPyLGQBGRYCaW8wHhcNMTMwNTIz
15
- MjA0MTI3WhcNMTQwNTIzMjA0MTI3WjA1MQowCAYDVQQDDAF2MRMwEQYKCZImiZPy
16
- LGQBGRYDZ29yMRIwEAYKCZImiZPyLGQBGRYCaW8wggEiMA0GCSqGSIb3DQEBAQUA
17
- A4IBDwAwggEKAoIBAQCtb8+GfjqcYl6M4IhIGomKsGgWEC4mwTXIq/Yl+jJAdP7s
18
- bdV3lWnZybUPKtdHSQIJcxbm8GZspTqSqDgsECI/laTyLj7Srqcbyivf/ov50Tg1
19
- CxMtt8STA6wNmY0ljO4SK72Pr8uQwFZIgNHBB9LcvrpmRn/TWDXlcqaq0db6QJKk
20
- jGOv74ukiQun+saqthpxwNN6wm0rj1GDulrDuMeeMj/XDgu0piNHhBtsgQ6KrN94
21
- cs0XGgwKihL0LdqWiOG9L8tZKeksKk72EcTpvaw1EYUfJ/rAcC8l6SluN2+BDMA0
22
- /4LU70O+wTwHcHv2HimtKdlcpS936qOez3lXUD+3AgMBAAGjYzBhMAkGA1UdEwQC
23
- MAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBSRvHatldjBIKT5agA2bnkfm4KUxTAT
24
- BgNVHREEDDAKgQh2QGdvci5pbzATBgNVHRIEDDAKgQh2QGdvci5pbzANBgkqhkiG
25
- 9w0BAQUFAAOCAQEAmyGZCL6ISHS6UCkPAie1LZgyc+yS4ckMPtzBJtjODr5kfRTC
26
- tLb9W4epJ9Aa2aGkKy/NL8MFS0BwTJmjSfufFDwFZlw0kI9aAvL4Nx9OHWNen9Dm
27
- GtEWXXKpB0du12DBjfavJYl0QLcz18M0mtvug634t40H06GussO83uu7wHEvIPBP
28
- Z5VMAbKvOmDgaP2I9XxZ2/lDmBKDZkVNqmqYiScw2CWsKxVPx3vhMGprTIz4O8y/
29
- JCf887eMZl/8mEIeCLb+gH5sh5yJJpti2HTLnR4Q1QKWR/0T9tASoQPF3kL62n9+
30
- m1B90+fEzJsBDQIAsnLPqxjivWbIIfZ7GeGZyA==
31
- -----END CERTIFICATE-----
32
- date: 2014-03-10 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2015-05-31 00:00:00.000000000 Z
33
12
  dependencies:
34
13
  - !ruby/object:Gem::Dependency
35
14
  name: railties
@@ -63,7 +42,6 @@ files:
63
42
  - LICENSE
64
43
  - README.md
65
44
  - Rakefile
66
- - certs/bai.pem
67
45
  - d3js-plugins-rails.gemspec
68
46
  - lib/d3js-plugins-rails.rb
69
47
  - lib/d3js-plugins-rails/version.rb
@@ -74,6 +52,8 @@ files:
74
52
  - vendor/assets/javascripts/d3/plugins/bullet/bullet.js
75
53
  - vendor/assets/javascripts/d3/plugins/chernoff/README.md
76
54
  - vendor/assets/javascripts/d3/plugins/chernoff/chernoff.js
55
+ - vendor/assets/javascripts/d3/plugins/cubehelix/README.md
56
+ - vendor/assets/javascripts/d3/plugins/cubehelix/cubehelix.js
77
57
  - vendor/assets/javascripts/d3/plugins/fisheye/README.md
78
58
  - vendor/assets/javascripts/d3/plugins/fisheye/fisheye.js
79
59
  - vendor/assets/javascripts/d3/plugins/force_labels/README.md
@@ -106,6 +86,8 @@ files:
106
86
  - vendor/assets/javascripts/d3/plugins/jsonp/jsonp.js
107
87
  - vendor/assets/javascripts/d3/plugins/keybinding/README.md
108
88
  - vendor/assets/javascripts/d3/plugins/keybinding/keybinding.js
89
+ - vendor/assets/javascripts/d3/plugins/lasso/README.md
90
+ - vendor/assets/javascripts/d3/plugins/lasso/lasso.js
109
91
  - vendor/assets/javascripts/d3/plugins/longscroll/README.md
110
92
  - vendor/assets/javascripts/d3/plugins/longscroll/longscroll.js
111
93
  - vendor/assets/javascripts/d3/plugins/qq/README.md
@@ -138,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
120
  version: '0'
139
121
  requirements: []
140
122
  rubyforge_project:
141
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.4.7
142
124
  signing_key:
143
125
  specification_version: 4
144
126
  summary: Gemified d3js-plugins asset for Rails
Binary file
data.tar.gz.sig DELETED
Binary file
@@ -1,20 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDSDCCAjCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA1MQowCAYDVQQDDAF2MRMw
3
- EQYKCZImiZPyLGQBGRYDZ29yMRIwEAYKCZImiZPyLGQBGRYCaW8wHhcNMTMwNTIz
4
- MjA0MTI3WhcNMTQwNTIzMjA0MTI3WjA1MQowCAYDVQQDDAF2MRMwEQYKCZImiZPy
5
- LGQBGRYDZ29yMRIwEAYKCZImiZPyLGQBGRYCaW8wggEiMA0GCSqGSIb3DQEBAQUA
6
- A4IBDwAwggEKAoIBAQCtb8+GfjqcYl6M4IhIGomKsGgWEC4mwTXIq/Yl+jJAdP7s
7
- bdV3lWnZybUPKtdHSQIJcxbm8GZspTqSqDgsECI/laTyLj7Srqcbyivf/ov50Tg1
8
- CxMtt8STA6wNmY0ljO4SK72Pr8uQwFZIgNHBB9LcvrpmRn/TWDXlcqaq0db6QJKk
9
- jGOv74ukiQun+saqthpxwNN6wm0rj1GDulrDuMeeMj/XDgu0piNHhBtsgQ6KrN94
10
- cs0XGgwKihL0LdqWiOG9L8tZKeksKk72EcTpvaw1EYUfJ/rAcC8l6SluN2+BDMA0
11
- /4LU70O+wTwHcHv2HimtKdlcpS936qOez3lXUD+3AgMBAAGjYzBhMAkGA1UdEwQC
12
- MAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBSRvHatldjBIKT5agA2bnkfm4KUxTAT
13
- BgNVHREEDDAKgQh2QGdvci5pbzATBgNVHRIEDDAKgQh2QGdvci5pbzANBgkqhkiG
14
- 9w0BAQUFAAOCAQEAmyGZCL6ISHS6UCkPAie1LZgyc+yS4ckMPtzBJtjODr5kfRTC
15
- tLb9W4epJ9Aa2aGkKy/NL8MFS0BwTJmjSfufFDwFZlw0kI9aAvL4Nx9OHWNen9Dm
16
- GtEWXXKpB0du12DBjfavJYl0QLcz18M0mtvug634t40H06GussO83uu7wHEvIPBP
17
- Z5VMAbKvOmDgaP2I9XxZ2/lDmBKDZkVNqmqYiScw2CWsKxVPx3vhMGprTIz4O8y/
18
- JCf887eMZl/8mEIeCLb+gH5sh5yJJpti2HTLnR4Q1QKWR/0T9tASoQPF3kL62n9+
19
- m1B90+fEzJsBDQIAsnLPqxjivWbIIfZ7GeGZyA==
20
- -----END CERTIFICATE-----
metadata.gz.sig DELETED
Binary file