rubyvis 0.6.0 → 0.6.1

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.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +13 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +37 -0
  6. data/History.txt +6 -0
  7. data/LICENSE.txt +23 -0
  8. data/{README.txt → README.md} +15 -12
  9. data/Rakefile +4 -11
  10. data/lib/rubyvis.rb +1 -1
  11. data/lib/rubyvis/scale/quantitative.rb +14 -18
  12. data/lib/rubyvis/scene/svg_label.rb +1 -1
  13. data/rubyvis.gemspec +21 -0
  14. data/spec/anchor_spec.rb +2 -1
  15. data/spec/line_spec.rb +2 -2
  16. data/spec/scale_linear_datetime_spec.rb +23 -8
  17. data/spec/spec_helper.rb +2 -1
  18. metadata +31 -214
  19. data/.gemtest +0 -0
  20. data/vendor/protovis/protovis-r3.3.js +0 -287
  21. data/vendor/protovis/src/behavior/Behavior.js +0 -32
  22. data/vendor/protovis/src/behavior/Drag.js +0 -112
  23. data/vendor/protovis/src/behavior/Pan.js +0 -110
  24. data/vendor/protovis/src/behavior/Point.js +0 -157
  25. data/vendor/protovis/src/behavior/Resize.js +0 -104
  26. data/vendor/protovis/src/behavior/Select.js +0 -100
  27. data/vendor/protovis/src/behavior/Zoom.js +0 -85
  28. data/vendor/protovis/src/color/Color.js +0 -598
  29. data/vendor/protovis/src/color/Colors.js +0 -135
  30. data/vendor/protovis/src/color/Ramp.js +0 -17
  31. data/vendor/protovis/src/data/Arrays.js +0 -277
  32. data/vendor/protovis/src/data/Dom.js +0 -380
  33. data/vendor/protovis/src/data/Flatten.js +0 -146
  34. data/vendor/protovis/src/data/Histogram.js +0 -120
  35. data/vendor/protovis/src/data/LinearScale.js +0 -54
  36. data/vendor/protovis/src/data/LogScale.js +0 -142
  37. data/vendor/protovis/src/data/Nest.js +0 -257
  38. data/vendor/protovis/src/data/Numbers.js +0 -313
  39. data/vendor/protovis/src/data/Objects.js +0 -78
  40. data/vendor/protovis/src/data/OrdinalScale.js +0 -267
  41. data/vendor/protovis/src/data/QuantileScale.js +0 -180
  42. data/vendor/protovis/src/data/QuantitativeScale.js +0 -440
  43. data/vendor/protovis/src/data/RootScale.js +0 -55
  44. data/vendor/protovis/src/data/Scale.js +0 -86
  45. data/vendor/protovis/src/data/Transform.js +0 -109
  46. data/vendor/protovis/src/data/Tree.js +0 -124
  47. data/vendor/protovis/src/data/Vector.js +0 -118
  48. data/vendor/protovis/src/geo/Geo.js +0 -5
  49. data/vendor/protovis/src/geo/GeoScale.js +0 -307
  50. data/vendor/protovis/src/geo/LatLng.js +0 -23
  51. data/vendor/protovis/src/geo/Projection.js +0 -43
  52. data/vendor/protovis/src/geo/Projections.js +0 -117
  53. data/vendor/protovis/src/lang/Array.js +0 -112
  54. data/vendor/protovis/src/lang/init.js +0 -26
  55. data/vendor/protovis/src/layout/Arc.js +0 -178
  56. data/vendor/protovis/src/layout/Bullet.js +0 -164
  57. data/vendor/protovis/src/layout/Cluster.js +0 -205
  58. data/vendor/protovis/src/layout/Force.js +0 -309
  59. data/vendor/protovis/src/layout/Grid.js +0 -119
  60. data/vendor/protovis/src/layout/Hierarchy.js +0 -249
  61. data/vendor/protovis/src/layout/Horizon.js +0 -159
  62. data/vendor/protovis/src/layout/Indent.js +0 -83
  63. data/vendor/protovis/src/layout/Layout.js +0 -56
  64. data/vendor/protovis/src/layout/Matrix.js +0 -177
  65. data/vendor/protovis/src/layout/Network.js +0 -302
  66. data/vendor/protovis/src/layout/Pack.js +0 -323
  67. data/vendor/protovis/src/layout/Partition.js +0 -203
  68. data/vendor/protovis/src/layout/Rollup.js +0 -203
  69. data/vendor/protovis/src/layout/Stack.js +0 -391
  70. data/vendor/protovis/src/layout/Tree.js +0 -282
  71. data/vendor/protovis/src/layout/Treemap.js +0 -347
  72. data/vendor/protovis/src/mark/Anchor.js +0 -81
  73. data/vendor/protovis/src/mark/Area.js +0 -268
  74. data/vendor/protovis/src/mark/Bar.js +0 -93
  75. data/vendor/protovis/src/mark/Dot.js +0 -212
  76. data/vendor/protovis/src/mark/Ease.js +0 -150
  77. data/vendor/protovis/src/mark/Image.js +0 -154
  78. data/vendor/protovis/src/mark/Label.js +0 -155
  79. data/vendor/protovis/src/mark/Line.js +0 -195
  80. data/vendor/protovis/src/mark/Mark.js +0 -1237
  81. data/vendor/protovis/src/mark/Panel.js +0 -273
  82. data/vendor/protovis/src/mark/Rule.js +0 -143
  83. data/vendor/protovis/src/mark/Transient.js +0 -7
  84. data/vendor/protovis/src/mark/Transition.js +0 -195
  85. data/vendor/protovis/src/mark/Wedge.js +0 -244
  86. data/vendor/protovis/src/physics/BoundConstraint.js +0 -75
  87. data/vendor/protovis/src/physics/ChargeForce.js +0 -184
  88. data/vendor/protovis/src/physics/CollisionConstraint.js +0 -113
  89. data/vendor/protovis/src/physics/Constraint.js +0 -26
  90. data/vendor/protovis/src/physics/DragForce.js +0 -49
  91. data/vendor/protovis/src/physics/Force.js +0 -25
  92. data/vendor/protovis/src/physics/Particle.js +0 -81
  93. data/vendor/protovis/src/physics/PositionConstraint.js +0 -72
  94. data/vendor/protovis/src/physics/Quadtree.js +0 -195
  95. data/vendor/protovis/src/physics/Simulation.js +0 -159
  96. data/vendor/protovis/src/physics/SpringForce.js +0 -141
  97. data/vendor/protovis/src/pv-internals.js +0 -154
  98. data/vendor/protovis/src/pv.js +0 -95
  99. data/vendor/protovis/src/scene/SvgArea.js +0 -172
  100. data/vendor/protovis/src/scene/SvgBar.js +0 -28
  101. data/vendor/protovis/src/scene/SvgCurve.js +0 -354
  102. data/vendor/protovis/src/scene/SvgDot.js +0 -81
  103. data/vendor/protovis/src/scene/SvgImage.js +0 -45
  104. data/vendor/protovis/src/scene/SvgLabel.js +0 -46
  105. data/vendor/protovis/src/scene/SvgLine.js +0 -159
  106. data/vendor/protovis/src/scene/SvgPanel.js +0 -126
  107. data/vendor/protovis/src/scene/SvgRule.js +0 -26
  108. data/vendor/protovis/src/scene/SvgScene.js +0 -185
  109. data/vendor/protovis/src/scene/SvgWedge.js +0 -66
  110. data/vendor/protovis/src/text/DateFormat.js +0 -262
  111. data/vendor/protovis/src/text/Format.js +0 -78
  112. data/vendor/protovis/src/text/NumberFormat.js +0 -227
  113. data/vendor/protovis/src/text/TimeFormat.js +0 -115
@@ -1,159 +0,0 @@
1
- /**
2
- * Constructs a new empty simulation.
3
- *
4
- * @param {array} particles
5
- * @returns {pv.Simulation} a new simulation for the specified particles.
6
- * @see pv.Simulation
7
- */
8
- pv.simulation = function(particles) {
9
- return new pv.Simulation(particles);
10
- };
11
-
12
- /**
13
- * Constructs a new simulation for the specified particles.
14
- *
15
- * @class Represents a particle simulation. Particles are massive points in
16
- * two-dimensional space. Forces can be applied to these particles, causing them
17
- * to move. Constraints can also be applied to restrict particle movement, for
18
- * example, constraining particles to a fixed position, or simulating collision
19
- * between circular particles with area.
20
- *
21
- * <p>The simulation uses <a
22
- * href="http://en.wikipedia.org/wiki/Verlet_integration">Position Verlet</a>
23
- * integration, due to the ease with which <a
24
- * href="http://www.teknikus.dk/tj/gdc2001.htm">geometric constraints</a> can be
25
- * implemented. For each time step, Verlet integration is performed, new forces
26
- * are accumulated, and then constraints are applied.
27
- *
28
- * <p>The simulation makes two simplifying assumptions: all particles are
29
- * equal-mass, and the time step of the simulation is fixed. It would be easy to
30
- * incorporate variable-mass particles as a future enhancement. Variable time
31
- * steps are also possible, but are likely to introduce instability in the
32
- * simulation.
33
- *
34
- * <p>This class can be used directly to simulate particle interaction.
35
- * Alternatively, for network diagrams, see {@link pv.Layout.Force}.
36
- *
37
- * @param {array} particles an array of {@link pv.Particle}s to simulate.
38
- * @see pv.Layout.Force
39
- * @see pv.Force
40
- * @see pv.Constraint
41
- */
42
- pv.Simulation = function(particles) {
43
- for (var i = 0; i < particles.length; i++) this.particle(particles[i]);
44
- };
45
-
46
- /**
47
- * The particles in the simulation. Particles are stored as a linked list; this
48
- * field represents the first particle in the simulation.
49
- *
50
- * @field
51
- * @type pv.Particle
52
- * @name pv.Simulation.prototype.particles
53
- */
54
-
55
- /**
56
- * The forces in the simulation. Forces are stored as a linked list; this field
57
- * represents the first force in the simulation.
58
- *
59
- * @field
60
- * @type pv.Force
61
- * @name pv.Simulation.prototype.forces
62
- */
63
-
64
- /**
65
- * The constraints in the simulation. Constraints are stored as a linked list;
66
- * this field represents the first constraint in the simulation.
67
- *
68
- * @field
69
- * @type pv.Constraint
70
- * @name pv.Simulation.prototype.constraints
71
- */
72
-
73
- /**
74
- * Adds the specified particle to the simulation.
75
- *
76
- * @param {pv.Particle} p the new particle.
77
- * @returns {pv.Simulation} this.
78
- */
79
- pv.Simulation.prototype.particle = function(p) {
80
- p.next = this.particles;
81
- /* Default velocities and forces to zero if unset. */
82
- if (isNaN(p.px)) p.px = p.x;
83
- if (isNaN(p.py)) p.py = p.y;
84
- if (isNaN(p.fx)) p.fx = 0;
85
- if (isNaN(p.fy)) p.fy = 0;
86
- this.particles = p;
87
- return this;
88
- };
89
-
90
- /**
91
- * Adds the specified force to the simulation.
92
- *
93
- * @param {pv.Force} f the new force.
94
- * @returns {pv.Simulation} this.
95
- */
96
- pv.Simulation.prototype.force = function(f) {
97
- f.next = this.forces;
98
- this.forces = f;
99
- return this;
100
- };
101
-
102
- /**
103
- * Adds the specified constraint to the simulation.
104
- *
105
- * @param {pv.Constraint} c the new constraint.
106
- * @returns {pv.Simulation} this.
107
- */
108
- pv.Simulation.prototype.constraint = function(c) {
109
- c.next = this.constraints;
110
- this.constraints = c;
111
- return this;
112
- };
113
-
114
- /**
115
- * Apply constraints, and then set the velocities to zero.
116
- *
117
- * @returns {pv.Simulation} this.
118
- */
119
- pv.Simulation.prototype.stabilize = function(n) {
120
- var c;
121
- if (!arguments.length) n = 3; // TODO use cooling schedule
122
- for (var i = 0; i < n; i++) {
123
- var q = new pv.Quadtree(this.particles);
124
- for (c = this.constraints; c; c = c.next) c.apply(this.particles, q);
125
- }
126
- for (var p = this.particles; p; p = p.next) {
127
- p.px = p.x;
128
- p.py = p.y;
129
- }
130
- return this;
131
- };
132
-
133
- /**
134
- * Advances the simulation one time-step.
135
- */
136
- pv.Simulation.prototype.step = function() {
137
- var p, f, c;
138
-
139
- /*
140
- * Assumptions:
141
- * - The mass (m) of every particles is 1.
142
- * - The time step (dt) is 1.
143
- */
144
-
145
- /* Position Verlet integration. */
146
- for (p = this.particles; p; p = p.next) {
147
- var px = p.px, py = p.py;
148
- p.px = p.x;
149
- p.py = p.y;
150
- p.x += p.vx = ((p.x - px) + p.fx);
151
- p.y += p.vy = ((p.y - py) + p.fy);
152
- }
153
-
154
- /* Apply constraints, then accumulate new forces. */
155
- var q = new pv.Quadtree(this.particles);
156
- for (c = this.constraints; c; c = c.next) c.apply(this.particles, q);
157
- for (p = this.particles; p; p = p.next) p.fx = p.fy = 0;
158
- for (f = this.forces; f; f = f.next) f.apply(this.particles, q);
159
- };
@@ -1,141 +0,0 @@
1
- /**
2
- * Constructs a new spring force with the specified constant. The links
3
- * associated with this spring force must be specified before the spring force
4
- * can be applied.
5
- *
6
- * @class Implements a spring force, per Hooke's law. The spring force can be
7
- * configured with a tension constant, rest length, and damping factor. The
8
- * tension and damping will automatically be normalized using the inverse square
9
- * root of the maximum link degree of attached nodes; this makes springs weaker
10
- * between nodes of high link degree.
11
- *
12
- * <p>Unlike other forces (such as charge and drag forces) which may be applied
13
- * globally, spring forces are only applied between linked particles. Therefore,
14
- * an array of links must be specified before this force can be applied; the
15
- * links should be an array of {@link pv.Layout.Network.Link}s. See also
16
- * {@link pv.Layout.Force} for an example of using spring and charge forces for
17
- * network layout.
18
- *
19
- * @extends pv.Force
20
- * @param {number} k the spring constant.
21
- * @see #constant
22
- * @see #links
23
- */
24
- pv.Force.spring = function(k) {
25
- var d = .1, // default damping factor
26
- l = 20, // default rest length
27
- links, // links on which to apply spring forces
28
- kl, // per-spring normalization
29
- force = {};
30
-
31
- if (!arguments.length) k = .1; // default spring constant (tension)
32
-
33
- /**
34
- * Sets or gets the links associated with this spring force. Unlike other
35
- * forces (such as charge and drag forces) which may be applied globally,
36
- * spring forces are only applied between linked particles. Therefore, an
37
- * array of links must be specified before this force can be applied; the
38
- * links should be an array of {@link pv.Layout.Network.Link}s.
39
- *
40
- * @function
41
- * @name pv.Force.spring.prototype.links
42
- * @param {array} x the new array of links.
43
- * @returns {pv.Force.spring} this, or the current array of links.
44
- */
45
- force.links = function(x) {
46
- if (arguments.length) {
47
- links = x;
48
- kl = x.map(function(l) {
49
- return 1 / Math.sqrt(Math.max(
50
- l.sourceNode.linkDegree,
51
- l.targetNode.linkDegree));
52
- });
53
- return force;
54
- }
55
- return links;
56
- };
57
-
58
- /**
59
- * Sets or gets the spring constant. The default value is 0.1; greater values
60
- * will result in stronger tension. The spring tension is automatically
61
- * normalized using the inverse square root of the maximum link degree of
62
- * attached nodes.
63
- *
64
- * @function
65
- * @name pv.Force.spring.prototype.constant
66
- * @param {number} x the new spring constant.
67
- * @returns {pv.Force.spring} this, or the current spring constant.
68
- */
69
- force.constant = function(x) {
70
- if (arguments.length) {
71
- k = Number(x);
72
- return force;
73
- }
74
- return k;
75
- };
76
-
77
- /**
78
- * The spring damping factor, in the range [0,1]. Damping functions
79
- * identically to drag forces, damping spring bounciness by applying a force
80
- * in the opposite direction of attached nodes' velocities. The default value
81
- * is 0.1. The spring damping is automatically normalized using the inverse
82
- * square root of the maximum link degree of attached nodes.
83
- *
84
- * @function
85
- * @name pv.Force.spring.prototype.damping
86
- * @param {number} x the new spring damping factor.
87
- * @returns {pv.Force.spring} this, or the current spring damping factor.
88
- */
89
- force.damping = function(x) {
90
- if (arguments.length) {
91
- d = Number(x);
92
- return force;
93
- }
94
- return d;
95
- };
96
-
97
- /**
98
- * The spring rest length. The default value is 20 pixels.
99
- *
100
- * @function
101
- * @name pv.Force.spring.prototype.length
102
- * @param {number} x the new spring rest length.
103
- * @returns {pv.Force.spring} this, or the current spring rest length.
104
- */
105
- force.length = function(x) {
106
- if (arguments.length) {
107
- l = Number(x);
108
- return force;
109
- }
110
- return l;
111
- };
112
-
113
- /**
114
- * Applies this force to the specified particles.
115
- *
116
- * @function
117
- * @name pv.Force.spring.prototype.apply
118
- * @param {pv.Particle} particles particles to which to apply this force.
119
- */
120
- force.apply = function(particles) {
121
- for (var i = 0; i < links.length; i++) {
122
- var a = links[i].sourceNode,
123
- b = links[i].targetNode,
124
- dx = a.x - b.x,
125
- dy = a.y - b.y,
126
- dn = Math.sqrt(dx * dx + dy * dy),
127
- dd = dn ? (1 / dn) : 1,
128
- ks = k * kl[i], // normalized tension
129
- kd = d * kl[i], // normalized damping
130
- kk = (ks * (dn - l) + kd * (dx * (a.vx - b.vx) + dy * (a.vy - b.vy)) * dd) * dd,
131
- fx = -kk * (dn ? dx : (.01 * (.5 - Math.random()))),
132
- fy = -kk * (dn ? dy : (.01 * (.5 - Math.random())));
133
- a.fx += fx;
134
- a.fy += fy;
135
- b.fx -= fx;
136
- b.fy -= fy;
137
- }
138
- };
139
-
140
- return force;
141
- };
@@ -1,154 +0,0 @@
1
- /**
2
- * @private Returns a prototype object suitable for extending the given class
3
- * <tt>f</tt>. Rather than constructing a new instance of <tt>f</tt> to serve as
4
- * the prototype (which unnecessarily runs the constructor on the created
5
- * prototype object, potentially polluting it), an anonymous function is
6
- * generated internally that shares the same prototype:
7
- *
8
- * <pre>function g() {}
9
- * g.prototype = f.prototype;
10
- * return new g();</pre>
11
- *
12
- * For more details, see Douglas Crockford's essay on prototypal inheritance.
13
- *
14
- * @param {function} f a constructor.
15
- * @returns a suitable prototype object.
16
- * @see Douglas Crockford's essay on <a
17
- * href="http://javascript.crockford.com/prototypal.html">prototypal
18
- * inheritance</a>.
19
- */
20
- pv.extend = function(f) {
21
- function g() {}
22
- g.prototype = f.prototype || f;
23
- return new g();
24
- };
25
-
26
- try {
27
- eval("pv.parse = function(x) x;"); // native support
28
- } catch (e) {
29
-
30
- /**
31
- * @private Parses a Protovis specification, which may use JavaScript 1.8
32
- * function expresses, replacing those function expressions with proper
33
- * functions such that the code can be run by a JavaScript 1.6 interpreter. This
34
- * hack only supports function expressions (using clumsy regular expressions, no
35
- * less), and not other JavaScript 1.8 features such as let expressions.
36
- *
37
- * @param {string} s a Protovis specification (i.e., a string of JavaScript 1.8
38
- * source code).
39
- * @returns {string} a conformant JavaScript 1.6 source code.
40
- */
41
- pv.parse = function(js) { // hacky regex support
42
- var re = new RegExp("function\\s*(\\b\\w+)?\\s*\\([^)]*\\)\\s*", "mg"), m, d, i = 0, s = "";
43
- while (m = re.exec(js)) {
44
- var j = m.index + m[0].length;
45
- if (js.charAt(j) != '{') {
46
- s += js.substring(i, j) + "{return ";
47
- i = j;
48
- for (var p = 0; p >= 0 && j < js.length; j++) {
49
- var c = js.charAt(j);
50
- switch (c) {
51
- case '"': case '\'': {
52
- while (++j < js.length && (d = js.charAt(j)) != c) {
53
- if (d == '\\') j++;
54
- }
55
- break;
56
- }
57
- case '[': case '(': p++; break;
58
- case ']': case ')': p--; break;
59
- case ';':
60
- case ',': if (p == 0) p--; break;
61
- }
62
- }
63
- s += pv.parse(js.substring(i, --j)) + ";}";
64
- i = j;
65
- }
66
- re.lastIndex = j;
67
- }
68
- s += js.substring(i);
69
- return s;
70
- };
71
- }
72
-
73
- /**
74
- * @private Computes the value of the specified CSS property <tt>p</tt> on the
75
- * specified element <tt>e</tt>.
76
- *
77
- * @param {string} p the name of the CSS property.
78
- * @param e the element on which to compute the CSS property.
79
- */
80
- pv.css = function(e, p) {
81
- return window.getComputedStyle
82
- ? window.getComputedStyle(e, null).getPropertyValue(p)
83
- : e.currentStyle[p];
84
- };
85
-
86
- /**
87
- * @private Reports the specified error to the JavaScript console. Mozilla only
88
- * allows logging to the console for privileged code; if the console is
89
- * unavailable, the alert dialog box is used instead.
90
- *
91
- * @param e the exception that triggered the error.
92
- */
93
- pv.error = function(e) {
94
- (typeof console == "undefined") ? alert(e) : console.error(e);
95
- };
96
-
97
- /**
98
- * @private Registers the specified listener for events of the specified type on
99
- * the specified target. For standards-compliant browsers, this method uses
100
- * <tt>addEventListener</tt>; for Internet Explorer, <tt>attachEvent</tt>.
101
- *
102
- * @param target a DOM element.
103
- * @param {string} type the type of event, such as "click".
104
- * @param {function} the event handler callback.
105
- */
106
- pv.listen = function(target, type, listener) {
107
- listener = pv.listener(listener);
108
- return target.addEventListener
109
- ? target.addEventListener(type, listener, false)
110
- : target.attachEvent("on" + type, listener);
111
- };
112
-
113
- /**
114
- * @private Returns a wrapper for the specified listener function such that the
115
- * {@link pv.event} is set for the duration of the listener's invocation. The
116
- * wrapper is cached on the returned function, such that duplicate registrations
117
- * of the wrapped event handler are ignored.
118
- *
119
- * @param {function} f an event handler.
120
- * @returns {function} the wrapped event handler.
121
- */
122
- pv.listener = function(f) {
123
- return f.$listener || (f.$listener = function(e) {
124
- try {
125
- pv.event = e;
126
- return f.call(this, e);
127
- } finally {
128
- delete pv.event;
129
- }
130
- });
131
- };
132
-
133
- /**
134
- * @private Returns true iff <i>a</i> is an ancestor of <i>e</i>. This is useful
135
- * for ignoring mouseout and mouseover events that are contained within the
136
- * target element.
137
- */
138
- pv.ancestor = function(a, e) {
139
- while (e) {
140
- if (e == a) return true;
141
- e = e.parentNode;
142
- }
143
- return false;
144
- };
145
-
146
- /** @private Returns a locally-unique positive id. */
147
- pv.id = function() {
148
- var id = 1; return function() { return id++; };
149
- }();
150
-
151
- /** @private Returns a function wrapping the specified constant. */
152
- pv.functor = function(v) {
153
- return typeof v == "function" ? v : function() { return v; };
154
- };