You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

735 lines
20 KiB

4 years ago
  1. /**
  2. * Springy v2.7.1
  3. *
  4. * Copyright (c) 2010-2013 Dennis Hotson
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use,
  10. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. (function (root, factory) {
  28. if (typeof define === 'function' && define.amd) {
  29. // AMD. Register as an anonymous module.
  30. define(function () {
  31. return (root.returnExportsGlobal = factory());
  32. });
  33. } else if (typeof exports === 'object') {
  34. // Node. Does not work with strict CommonJS, but
  35. // only CommonJS-like enviroments that support module.exports,
  36. // like Node.
  37. module.exports = factory();
  38. } else {
  39. // Browser globals
  40. root.Springy = factory();
  41. }
  42. }(this, function() {
  43. var Springy = {};
  44. var Graph = Springy.Graph = function() {
  45. this.nodeSet = {};
  46. this.nodes = [];
  47. this.edges = [];
  48. this.adjacency = {};
  49. this.nextNodeId = 0;
  50. this.nextEdgeId = 0;
  51. this.eventListeners = [];
  52. };
  53. var Node = Springy.Node = function(id, data) {
  54. this.id = id;
  55. this.data = (data !== undefined) ? data : {};
  56. // Data fields used by layout algorithm in this file:
  57. // this.data.mass
  58. // Data used by default renderer in springyui.js
  59. // this.data.label
  60. };
  61. var Edge = Springy.Edge = function(id, source, target, data) {
  62. this.id = id;
  63. this.source = source;
  64. this.target = target;
  65. this.data = (data !== undefined) ? data : {};
  66. // Edge data field used by layout alorithm
  67. // this.data.length
  68. // this.data.type
  69. };
  70. Graph.prototype.addNode = function(node) {
  71. if (!(node.id in this.nodeSet)) {
  72. this.nodes.push(node);
  73. }
  74. this.nodeSet[node.id] = node;
  75. this.notify();
  76. return node;
  77. };
  78. Graph.prototype.addNodes = function() {
  79. // accepts variable number of arguments, where each argument
  80. // is a string that becomes both node identifier and label
  81. for (var i = 0; i < arguments.length; i++) {
  82. var name = arguments[i];
  83. var node = new Node(name, {label:name});
  84. this.addNode(node);
  85. }
  86. };
  87. Graph.prototype.addEdge = function(edge) {
  88. var exists = false;
  89. this.edges.forEach(function(e) {
  90. if (edge.id === e.id) { exists = true; }
  91. });
  92. if (!exists) {
  93. this.edges.push(edge);
  94. }
  95. if (!(edge.source.id in this.adjacency)) {
  96. this.adjacency[edge.source.id] = {};
  97. }
  98. if (!(edge.target.id in this.adjacency[edge.source.id])) {
  99. this.adjacency[edge.source.id][edge.target.id] = [];
  100. }
  101. exists = false;
  102. this.adjacency[edge.source.id][edge.target.id].forEach(function(e) {
  103. if (edge.id === e.id) { exists = true; }
  104. });
  105. if (!exists) {
  106. this.adjacency[edge.source.id][edge.target.id].push(edge);
  107. }
  108. this.notify();
  109. return edge;
  110. };
  111. Graph.prototype.addEdges = function() {
  112. // accepts variable number of arguments, where each argument
  113. // is a triple [nodeid1, nodeid2, attributes]
  114. for (var i = 0; i < arguments.length; i++) {
  115. var e = arguments[i];
  116. var node1 = this.nodeSet[e[0]];
  117. if (node1 == undefined) {
  118. throw new TypeError("invalid node name: " + e[0]);
  119. }
  120. var node2 = this.nodeSet[e[1]];
  121. if (node2 == undefined) {
  122. throw new TypeError("invalid node name: " + e[1]);
  123. }
  124. var attr = e[2];
  125. this.newEdge(node1, node2, attr);
  126. }
  127. };
  128. Graph.prototype.newNode = function(data) {
  129. var node = new Node(this.nextNodeId++, data);
  130. this.addNode(node);
  131. return node;
  132. };
  133. Graph.prototype.newEdge = function(source, target, data) {
  134. var edge = new Edge(this.nextEdgeId++, source, target, data);
  135. this.addEdge(edge);
  136. return edge;
  137. };
  138. // add nodes and edges from JSON object
  139. Graph.prototype.loadJSON = function(json) {
  140. /**
  141. Springy's simple JSON format for graphs.
  142. historically, Springy uses separate lists
  143. of nodes and edges:
  144. {
  145. "nodes": [
  146. "center",
  147. "left",
  148. "right",
  149. "up",
  150. "satellite"
  151. ],
  152. "edges": [
  153. ["center", "left"],
  154. ["center", "right"],
  155. ["center", "up"]
  156. ]
  157. }
  158. **/
  159. // parse if a string is passed (EC5+ browsers)
  160. if (typeof json == 'string' || json instanceof String) {
  161. json = JSON.parse( json );
  162. }
  163. if ('nodes' in json || 'edges' in json) {
  164. this.addNodes.apply(this, json['nodes']);
  165. this.addEdges.apply(this, json['edges']);
  166. }
  167. }
  168. // find the edges from node1 to node2
  169. Graph.prototype.getEdges = function(node1, node2) {
  170. if (node1.id in this.adjacency
  171. && node2.id in this.adjacency[node1.id]) {
  172. return this.adjacency[node1.id][node2.id];
  173. }
  174. return [];
  175. };
  176. // remove a node and it's associated edges from the graph
  177. Graph.prototype.removeNode = function(node) {
  178. if (node.id in this.nodeSet) {
  179. delete this.nodeSet[node.id];
  180. }
  181. for (var i = this.nodes.length - 1; i >= 0; i--) {
  182. if (this.nodes[i].id === node.id) {
  183. this.nodes.splice(i, 1);
  184. }
  185. }
  186. this.detachNode(node);
  187. };
  188. // removes edges associated with a given node
  189. Graph.prototype.detachNode = function(node) {
  190. var tmpEdges = this.edges.slice();
  191. tmpEdges.forEach(function(e) {
  192. if (e.source.id === node.id || e.target.id === node.id) {
  193. this.removeEdge(e);
  194. }
  195. }, this);
  196. this.notify();
  197. };
  198. // remove a node and it's associated edges from the graph
  199. Graph.prototype.removeEdge = function(edge) {
  200. for (var i = this.edges.length - 1; i >= 0; i--) {
  201. if (this.edges[i].id === edge.id) {
  202. this.edges.splice(i, 1);
  203. }
  204. }
  205. for (var x in this.adjacency) {
  206. for (var y in this.adjacency[x]) {
  207. var edges = this.adjacency[x][y];
  208. for (var j=edges.length - 1; j>=0; j--) {
  209. if (this.adjacency[x][y][j].id === edge.id) {
  210. this.adjacency[x][y].splice(j, 1);
  211. }
  212. }
  213. // Clean up empty edge arrays
  214. if (this.adjacency[x][y].length == 0) {
  215. delete this.adjacency[x][y];
  216. }
  217. }
  218. // Clean up empty objects
  219. if (isEmpty(this.adjacency[x])) {
  220. delete this.adjacency[x];
  221. }
  222. }
  223. this.notify();
  224. };
  225. /* Merge a list of nodes and edges into the current graph. eg.
  226. var o = {
  227. nodes: [
  228. {id: 123, data: {type: 'user', userid: 123, displayname: 'aaa'}},
  229. {id: 234, data: {type: 'user', userid: 234, displayname: 'bbb'}}
  230. ],
  231. edges: [
  232. {from: 0, to: 1, type: 'submitted_design', directed: true, data: {weight: }}
  233. ]
  234. }
  235. */
  236. Graph.prototype.merge = function(data) {
  237. var nodes = [];
  238. data.nodes.forEach(function(n) {
  239. nodes.push(this.addNode(new Node(n.id, n.data)));
  240. }, this);
  241. data.edges.forEach(function(e) {
  242. var from = nodes[e.from];
  243. var to = nodes[e.to];
  244. var id = (e.directed)
  245. ? (id = e.type + "-" + from.id + "-" + to.id)
  246. : (from.id < to.id) // normalise id for non-directed edges
  247. ? e.type + "-" + from.id + "-" + to.id
  248. : e.type + "-" + to.id + "-" + from.id;
  249. var edge = this.addEdge(new Edge(id, from, to, e.data));
  250. edge.data.type = e.type;
  251. }, this);
  252. };
  253. Graph.prototype.filterNodes = function(fn) {
  254. var tmpNodes = this.nodes.slice();
  255. tmpNodes.forEach(function(n) {
  256. if (!fn(n)) {
  257. this.removeNode(n);
  258. }
  259. }, this);
  260. };
  261. Graph.prototype.filterEdges = function(fn) {
  262. var tmpEdges = this.edges.slice();
  263. tmpEdges.forEach(function(e) {
  264. if (!fn(e)) {
  265. this.removeEdge(e);
  266. }
  267. }, this);
  268. };
  269. Graph.prototype.addGraphListener = function(obj) {
  270. this.eventListeners.push(obj);
  271. };
  272. Graph.prototype.notify = function() {
  273. this.eventListeners.forEach(function(obj){
  274. obj.graphChanged();
  275. });
  276. };
  277. // -----------
  278. var Layout = Springy.Layout = {};
  279. Layout.ForceDirected = function(graph, stiffness, repulsion, damping, minEnergyThreshold, maxSpeed) {
  280. this.graph = graph;
  281. this.stiffness = stiffness; // spring stiffness constant
  282. this.repulsion = repulsion; // repulsion constant
  283. this.damping = damping; // velocity damping factor
  284. this.minEnergyThreshold = minEnergyThreshold || 0.01; //threshold used to determine render stop
  285. this.maxSpeed = maxSpeed || Infinity; // nodes aren't allowed to exceed this speed
  286. this.nodePoints = {}; // keep track of points associated with nodes
  287. this.edgeSprings = {}; // keep track of springs associated with edges
  288. };
  289. Layout.ForceDirected.prototype.point = function(node) {
  290. if (!(node.id in this.nodePoints)) {
  291. var mass = (node.data.mass !== undefined) ? node.data.mass : 1.0;
  292. this.nodePoints[node.id] = new Layout.ForceDirected.Point(Vector.random(), mass);
  293. }
  294. return this.nodePoints[node.id];
  295. };
  296. Layout.ForceDirected.prototype.spring = function(edge) {
  297. if (!(edge.id in this.edgeSprings)) {
  298. var length = (edge.data.length !== undefined) ? edge.data.length : 1.0;
  299. var existingSpring = false;
  300. var from = this.graph.getEdges(edge.source, edge.target);
  301. from.forEach(function(e) {
  302. if (existingSpring === false && e.id in this.edgeSprings) {
  303. existingSpring = this.edgeSprings[e.id];
  304. }
  305. }, this);
  306. if (existingSpring !== false) {
  307. return new Layout.ForceDirected.Spring(existingSpring.point1, existingSpring.point2, 0.0, 0.0);
  308. }
  309. var to = this.graph.getEdges(edge.target, edge.source);
  310. from.forEach(function(e){
  311. if (existingSpring === false && e.id in this.edgeSprings) {
  312. existingSpring = this.edgeSprings[e.id];
  313. }
  314. }, this);
  315. if (existingSpring !== false) {
  316. return new Layout.ForceDirected.Spring(existingSpring.point2, existingSpring.point1, 0.0, 0.0);
  317. }
  318. this.edgeSprings[edge.id] = new Layout.ForceDirected.Spring(
  319. this.point(edge.source), this.point(edge.target), length, this.stiffness
  320. );
  321. }
  322. return this.edgeSprings[edge.id];
  323. };
  324. // callback should accept two arguments: Node, Point
  325. Layout.ForceDirected.prototype.eachNode = function(callback) {
  326. var t = this;
  327. this.graph.nodes.forEach(function(n){
  328. callback.call(t, n, t.point(n));
  329. });
  330. };
  331. // callback should accept two arguments: Edge, Spring
  332. Layout.ForceDirected.prototype.eachEdge = function(callback) {
  333. var t = this;
  334. this.graph.edges.forEach(function(e){
  335. callback.call(t, e, t.spring(e));
  336. });
  337. };
  338. // callback should accept one argument: Spring
  339. Layout.ForceDirected.prototype.eachSpring = function(callback) {
  340. var t = this;
  341. this.graph.edges.forEach(function(e){
  342. callback.call(t, t.spring(e));
  343. });
  344. };
  345. // Physics stuff
  346. Layout.ForceDirected.prototype.applyCoulombsLaw = function() {
  347. this.eachNode(function(n1, point1) {
  348. this.eachNode(function(n2, point2) {
  349. if (point1 !== point2)
  350. {
  351. var d = point1.p.subtract(point2.p);
  352. var distance = d.magnitude() + 0.1; // avoid massive forces at small distances (and divide by zero)
  353. var direction = d.normalise();
  354. // apply force to each end point
  355. point1.applyForce(direction.multiply(this.repulsion).divide(distance * distance * 0.5));
  356. point2.applyForce(direction.multiply(this.repulsion).divide(distance * distance * -0.5));
  357. }
  358. });
  359. });
  360. };
  361. Layout.ForceDirected.prototype.applyHookesLaw = function() {
  362. this.eachSpring(function(spring){
  363. var d = spring.point2.p.subtract(spring.point1.p); // the direction of the spring
  364. var displacement = spring.length - d.magnitude();
  365. var direction = d.normalise();
  366. // apply force to each end point
  367. spring.point1.applyForce(direction.multiply(spring.k * displacement * -0.5));
  368. spring.point2.applyForce(direction.multiply(spring.k * displacement * 0.5));
  369. });
  370. };
  371. Layout.ForceDirected.prototype.attractToCentre = function() {
  372. this.eachNode(function(node, point) {
  373. var direction = point.p.multiply(-1.0);
  374. point.applyForce(direction.multiply(this.repulsion / 50.0));
  375. });
  376. };
  377. Layout.ForceDirected.prototype.updateVelocity = function(timestep) {
  378. this.eachNode(function(node, point) {
  379. // Is this, along with updatePosition below, the only places that your
  380. // integration code exist?
  381. point.v = point.v.add(point.a.multiply(timestep)).multiply(this.damping);
  382. if (point.v.magnitude() > this.maxSpeed) {
  383. point.v = point.v.normalise().multiply(this.maxSpeed);
  384. }
  385. point.a = new Vector(0,0);
  386. });
  387. };
  388. Layout.ForceDirected.prototype.updatePosition = function(timestep) {
  389. this.eachNode(function(node, point) {
  390. // Same question as above; along with updateVelocity, is this all of
  391. // your integration code?
  392. point.p = point.p.add(point.v.multiply(timestep));
  393. });
  394. };
  395. // Calculate the total kinetic energy of the system
  396. Layout.ForceDirected.prototype.totalEnergy = function(timestep) {
  397. var energy = 0.0;
  398. this.eachNode(function(node, point) {
  399. var speed = point.v.magnitude();
  400. energy += 0.5 * point.m * speed * speed;
  401. });
  402. return energy;
  403. };
  404. var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; // stolen from coffeescript, thanks jashkenas! ;-)
  405. Springy.requestAnimationFrame = __bind(this.requestAnimationFrame ||
  406. this.webkitRequestAnimationFrame ||
  407. this.mozRequestAnimationFrame ||
  408. this.oRequestAnimationFrame ||
  409. this.msRequestAnimationFrame ||
  410. (function(callback, element) {
  411. this.setTimeout(callback, 10);
  412. }), this);
  413. /**
  414. * Start simulation if it's not running already.
  415. * In case it's running then the call is ignored, and none of the callbacks passed is ever executed.
  416. */
  417. Layout.ForceDirected.prototype.start = function(render, onRenderStop, onRenderStart) {
  418. var t = this;
  419. if (this._started) return;
  420. this._started = true;
  421. this._stop = false;
  422. if (onRenderStart !== undefined) { onRenderStart(); }
  423. Springy.requestAnimationFrame(function step() {
  424. t.tick(0.03);
  425. if (render !== undefined) {
  426. render();
  427. }
  428. // stop simulation when energy of the system goes below a threshold
  429. if (t._stop || t.totalEnergy() < t.minEnergyThreshold) {
  430. t._started = false;
  431. if (onRenderStop !== undefined) { onRenderStop(); }
  432. } else {
  433. Springy.requestAnimationFrame(step);
  434. }
  435. });
  436. };
  437. Layout.ForceDirected.prototype.stop = function() {
  438. this._stop = true;
  439. }
  440. Layout.ForceDirected.prototype.tick = function(timestep) {
  441. this.applyCoulombsLaw();
  442. this.applyHookesLaw();
  443. this.attractToCentre();
  444. this.updateVelocity(timestep);
  445. this.updatePosition(timestep);
  446. };
  447. // Find the nearest point to a particular position
  448. Layout.ForceDirected.prototype.nearest = function(pos) {
  449. var min = {node: null, point: null, distance: null};
  450. var t = this;
  451. this.graph.nodes.forEach(function(n){
  452. var point = t.point(n);
  453. var distance = point.p.subtract(pos).magnitude();
  454. if (min.distance === null || distance < min.distance) {
  455. min = {node: n, point: point, distance: distance};
  456. }
  457. });
  458. return min;
  459. };
  460. // returns [bottomleft, topright]
  461. Layout.ForceDirected.prototype.getBoundingBox = function() {
  462. var bottomleft = new Vector(-2,-2);
  463. var topright = new Vector(2,2);
  464. this.eachNode(function(n, point) {
  465. if (point.p.x < bottomleft.x) {
  466. bottomleft.x = point.p.x;
  467. }
  468. if (point.p.y < bottomleft.y) {
  469. bottomleft.y = point.p.y;
  470. }
  471. if (point.p.x > topright.x) {
  472. topright.x = point.p.x;
  473. }
  474. if (point.p.y > topright.y) {
  475. topright.y = point.p.y;
  476. }
  477. });
  478. var padding = topright.subtract(bottomleft).multiply(0.07); // ~5% padding
  479. return {bottomleft: bottomleft.subtract(padding), topright: topright.add(padding)};
  480. };
  481. // Vector
  482. var Vector = Springy.Vector = function(x, y) {
  483. this.x = x;
  484. this.y = y;
  485. };
  486. Vector.random = function() {
  487. return new Vector(10.0 * (Math.random() - 0.5), 10.0 * (Math.random() - 0.5));
  488. };
  489. Vector.prototype.add = function(v2) {
  490. return new Vector(this.x + v2.x, this.y + v2.y);
  491. };
  492. Vector.prototype.subtract = function(v2) {
  493. return new Vector(this.x - v2.x, this.y - v2.y);
  494. };
  495. Vector.prototype.multiply = function(n) {
  496. return new Vector(this.x * n, this.y * n);
  497. };
  498. Vector.prototype.divide = function(n) {
  499. return new Vector((this.x / n) || 0, (this.y / n) || 0); // Avoid divide by zero errors..
  500. };
  501. Vector.prototype.magnitude = function() {
  502. return Math.sqrt(this.x*this.x + this.y*this.y);
  503. };
  504. Vector.prototype.normal = function() {
  505. return new Vector(-this.y, this.x);
  506. };
  507. Vector.prototype.normalise = function() {
  508. return this.divide(this.magnitude());
  509. };
  510. // Point
  511. Layout.ForceDirected.Point = function(position, mass) {
  512. this.p = position; // position
  513. this.m = mass; // mass
  514. this.v = new Vector(0, 0); // velocity
  515. this.a = new Vector(0, 0); // acceleration
  516. };
  517. Layout.ForceDirected.Point.prototype.applyForce = function(force) {
  518. this.a = this.a.add(force.divide(this.m));
  519. };
  520. // Spring
  521. Layout.ForceDirected.Spring = function(point1, point2, length, k) {
  522. this.point1 = point1;
  523. this.point2 = point2;
  524. this.length = length; // spring length at rest
  525. this.k = k; // spring constant (See Hooke's law) .. how stiff the spring is
  526. };
  527. // Layout.ForceDirected.Spring.prototype.distanceToPoint = function(point)
  528. // {
  529. // // hardcore vector arithmetic.. ohh yeah!
  530. // // .. see http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment/865080#865080
  531. // var n = this.point2.p.subtract(this.point1.p).normalise().normal();
  532. // var ac = point.p.subtract(this.point1.p);
  533. // return Math.abs(ac.x * n.x + ac.y * n.y);
  534. // };
  535. /**
  536. * Renderer handles the layout rendering loop
  537. * @param onRenderStop optional callback function that gets executed whenever rendering stops.
  538. * @param onRenderStart optional callback function that gets executed whenever rendering starts.
  539. * @param onRenderFrame optional callback function that gets executed after each frame is rendered.
  540. */
  541. var Renderer = Springy.Renderer = function(layout, clear, drawEdge, drawNode, onRenderStop, onRenderStart, onRenderFrame) {
  542. this.layout = layout;
  543. this.clear = clear;
  544. this.drawEdge = drawEdge;
  545. this.drawNode = drawNode;
  546. this.onRenderStop = onRenderStop;
  547. this.onRenderStart = onRenderStart;
  548. this.onRenderFrame = onRenderFrame;
  549. this.layout.graph.addGraphListener(this);
  550. }
  551. Renderer.prototype.graphChanged = function(e) {
  552. this.start();
  553. };
  554. /**
  555. * Starts the simulation of the layout in use.
  556. *
  557. * Note that in case the algorithm is still or already running then the layout that's in use
  558. * might silently ignore the call, and your optional <code>done</code> callback is never executed.
  559. * At least the built-in ForceDirected layout behaves in this way.
  560. *
  561. * @param done An optional callback function that gets executed when the springy algorithm stops,
  562. * either because it ended or because stop() was called.
  563. */
  564. Renderer.prototype.start = function(done) {
  565. var t = this;
  566. this.layout.start(function render() {
  567. t.clear();
  568. t.layout.eachEdge(function(edge, spring) {
  569. t.drawEdge(edge, spring.point1.p, spring.point2.p);
  570. });
  571. t.layout.eachNode(function(node, point) {
  572. t.drawNode(node, point.p);
  573. });
  574. if (t.onRenderFrame !== undefined) { t.onRenderFrame(); }
  575. }, this.onRenderStop, this.onRenderStart);
  576. };
  577. Renderer.prototype.stop = function() {
  578. this.layout.stop();
  579. };
  580. // Array.forEach implementation for IE support..
  581. //https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
  582. if ( !Array.prototype.forEach ) {
  583. Array.prototype.forEach = function( callback, thisArg ) {
  584. var T, k;
  585. if ( this == null ) {
  586. throw new TypeError( " this is null or not defined" );
  587. }
  588. var O = Object(this);
  589. var len = O.length >>> 0; // Hack to convert O.length to a UInt32
  590. if ( {}.toString.call(callback) != "[object Function]" ) {
  591. throw new TypeError( callback + " is not a function" );
  592. }
  593. if ( thisArg ) {
  594. T = thisArg;
  595. }
  596. k = 0;
  597. while( k < len ) {
  598. var kValue;
  599. if ( k in O ) {
  600. kValue = O[ k ];
  601. callback.call( T, kValue, k, O );
  602. }
  603. k++;
  604. }
  605. };
  606. }
  607. var isEmpty = function(obj) {
  608. for (var k in obj) {
  609. if (obj.hasOwnProperty(k)) {
  610. return false;
  611. }
  612. }
  613. return true;
  614. };
  615. return Springy;
  616. }));