bum 0.0.4 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (576) hide show
  1. data/README +0 -12
  2. data/bin/bum +16 -49
  3. data/bin/bum_master +20 -0
  4. data/lib/actor.rb +0 -0
  5. data/lib/app_role.rb +83 -0
  6. data/lib/client.rb +104 -0
  7. data/lib/db_crap.rb +85 -0
  8. data/lib/db_role.rb +107 -0
  9. data/lib/demo_socket.rb +51 -0
  10. data/lib/master.rb +109 -0
  11. data/lib/master_web.rb +81 -0
  12. data/lib/nice_socket.rb +77 -0
  13. data/lib/node.rb +96 -0
  14. data/lib/proxy_role.rb +132 -0
  15. data/lib/role.rb +99 -0
  16. data/lib/scenario.rb +186 -0
  17. data/lib/server.rb +30 -0
  18. data/lib/stats_role.rb +89 -0
  19. data/public/app.css +91 -0
  20. data/public/css/light.css +105 -0
  21. data/public/d3/LICENSE +26 -0
  22. data/public/d3/Makefile +247 -0
  23. data/public/d3/README.md +51 -0
  24. data/public/d3/d3.chart.js +984 -0
  25. data/public/d3/d3.chart.min.js +1 -0
  26. data/public/d3/d3.csv.js +92 -0
  27. data/public/d3/d3.csv.min.js +1 -0
  28. data/public/d3/d3.geo.js +692 -0
  29. data/public/d3/d3.geo.min.js +1 -0
  30. data/public/d3/d3.geom.js +825 -0
  31. data/public/d3/d3.geom.min.js +1 -0
  32. data/public/d3/d3.js +4013 -0
  33. data/public/d3/d3.layout.js +1865 -0
  34. data/public/d3/d3.layout.min.js +1 -0
  35. data/public/d3/d3.min.js +2 -0
  36. data/public/d3/d3.time.js +663 -0
  37. data/public/d3/d3.time.min.js +1 -0
  38. data/public/d3/examples/albers/albers.html +168 -0
  39. data/public/d3/examples/area/area-radial.html +48 -0
  40. data/public/d3/examples/area/area.html +113 -0
  41. data/public/d3/examples/axis/axis-alternating.html +50 -0
  42. data/public/d3/examples/axis/axis-ggplot2.html +68 -0
  43. data/public/d3/examples/axis/axis-multiples.html +117 -0
  44. data/public/d3/examples/axis/axis-orientations.html +63 -0
  45. data/public/d3/examples/axis/axis-transition.html +153 -0
  46. data/public/d3/examples/azimuthal/azimuthal.css +21 -0
  47. data/public/d3/examples/azimuthal/azimuthal.html +84 -0
  48. data/public/d3/examples/azimuthal/azimuthal.js +27 -0
  49. data/public/d3/examples/bar/bar.html +93 -0
  50. data/public/d3/examples/box/box.css +4 -0
  51. data/public/d3/examples/box/box.html +19 -0
  52. data/public/d3/examples/box/box.js +68 -0
  53. data/public/d3/examples/bubble/bubble.css +8 -0
  54. data/public/d3/examples/bubble/bubble.html +14 -0
  55. data/public/d3/examples/bubble/bubble.js +46 -0
  56. data/public/d3/examples/bullet/bullet.css +10 -0
  57. data/public/d3/examples/bullet/bullet.html +18 -0
  58. data/public/d3/examples/bullet/bullet.js +53 -0
  59. data/public/d3/examples/bullet/bullets.json +7 -0
  60. data/public/d3/examples/bundle/bundle-radial.css +9 -0
  61. data/public/d3/examples/bundle/bundle-radial.html +15 -0
  62. data/public/d3/examples/bundle/bundle-radial.js +50 -0
  63. data/public/d3/examples/bundle/bundle-treemap.css +14 -0
  64. data/public/d3/examples/bundle/bundle-treemap.html +16 -0
  65. data/public/d3/examples/bundle/bundle-treemap.js +53 -0
  66. data/public/d3/examples/bundle/packages.js +49 -0
  67. data/public/d3/examples/button.css +35 -0
  68. data/public/d3/examples/calendar/calendar.css +16 -0
  69. data/public/d3/examples/calendar/calendar.js +50 -0
  70. data/public/d3/examples/calendar/dji.csv +5233 -0
  71. data/public/d3/examples/calendar/dji.html +16 -0
  72. data/public/d3/examples/calendar/dji.js +61 -0
  73. data/public/d3/examples/calendar/vix.csv +5231 -0
  74. data/public/d3/examples/calendar/vix.html +16 -0
  75. data/public/d3/examples/calendar/vix.js +60 -0
  76. data/public/d3/examples/cartogram/cartogram.css +20 -0
  77. data/public/d3/examples/cartogram/cartogram.html +15 -0
  78. data/public/d3/examples/cartogram/cartogram.js +51 -0
  79. data/public/d3/examples/cartogram/demers.css +9 -0
  80. data/public/d3/examples/cartogram/demers.html +16 -0
  81. data/public/d3/examples/cartogram/demers.js +79 -0
  82. data/public/d3/examples/cartogram/dorling.css +9 -0
  83. data/public/d3/examples/cartogram/dorling.html +16 -0
  84. data/public/d3/examples/cartogram/dorling.js +80 -0
  85. data/public/d3/examples/chord/chord-flare.html +109 -0
  86. data/public/d3/examples/chord/chord.css +9 -0
  87. data/public/d3/examples/chord/chord.html +14 -0
  88. data/public/d3/examples/chord/chord.js +98 -0
  89. data/public/d3/examples/choropleth/choropleth-area.html +51 -0
  90. data/public/d3/examples/choropleth/choropleth-bounds.html +46 -0
  91. data/public/d3/examples/choropleth/choropleth.css +16 -0
  92. data/public/d3/examples/choropleth/choropleth.html +15 -0
  93. data/public/d3/examples/choropleth/choropleth.js +38 -0
  94. data/public/d3/examples/choropleth/unemployment.json +1 -0
  95. data/public/d3/examples/clock/clock.css +23 -0
  96. data/public/d3/examples/clock/clock.html +17 -0
  97. data/public/d3/examples/clock/clock.js +87 -0
  98. data/public/d3/examples/cluster/cluster-radial.html +14 -0
  99. data/public/d3/examples/cluster/cluster-radial.js +39 -0
  100. data/public/d3/examples/cluster/cluster.css +15 -0
  101. data/public/d3/examples/cluster/cluster.html +14 -0
  102. data/public/d3/examples/cluster/cluster.js +39 -0
  103. data/public/d3/examples/contour/contour.html +108 -0
  104. data/public/d3/examples/crimea/crimea-stacked-area.html +109 -0
  105. data/public/d3/examples/crimea/crimea-stacked-bar.html +98 -0
  106. data/public/d3/examples/crimea/crimea.csv +24 -0
  107. data/public/d3/examples/data/README +5 -0
  108. data/public/d3/examples/data/faithful.json +8 -0
  109. data/public/d3/examples/data/flare-imports.json +222 -0
  110. data/public/d3/examples/data/flare.json +380 -0
  111. data/public/d3/examples/data/morley.csv +101 -0
  112. data/public/d3/examples/data/sample.csv +2 -0
  113. data/public/d3/examples/data/sample.html +5 -0
  114. data/public/d3/examples/data/sample.json +1 -0
  115. data/public/d3/examples/data/sample.txt +1 -0
  116. data/public/d3/examples/data/sample.xml +4 -0
  117. data/public/d3/examples/data/stocks.csv +807 -0
  118. data/public/d3/examples/data/unemployment.csv +1709 -0
  119. data/public/d3/examples/data/us-borders.json +1 -0
  120. data/public/d3/examples/data/us-counties.json +3216 -0
  121. data/public/d3/examples/data/us-state-centroids.json +1 -0
  122. data/public/d3/examples/data/us-states.json +54 -0
  123. data/public/d3/examples/data/world-countries.json +246 -0
  124. data/public/d3/examples/delaunay/delaunay.html +44 -0
  125. data/public/d3/examples/donut/donut.html +124 -0
  126. data/public/d3/examples/dot/dot.html +103 -0
  127. data/public/d3/examples/force/README +10 -0
  128. data/public/d3/examples/force/force-bounds.html +70 -0
  129. data/public/d3/examples/force/force-cluster.html +251 -0
  130. data/public/d3/examples/force/force-dynamic.html +118 -0
  131. data/public/d3/examples/force/force-interactive.html +136 -0
  132. data/public/d3/examples/force/force-map.html +104 -0
  133. data/public/d3/examples/force/force-multi-foci.html +68 -0
  134. data/public/d3/examples/force/force.css +9 -0
  135. data/public/d3/examples/force/force.html +14 -0
  136. data/public/d3/examples/force/force.js +56 -0
  137. data/public/d3/examples/force/miserables.json +1 -0
  138. data/public/d3/examples/hello-world/hello-data-key.html +60 -0
  139. data/public/d3/examples/hello-world/hello-data-nested-key.html +75 -0
  140. data/public/d3/examples/hello-world/hello-data-nested.html +77 -0
  141. data/public/d3/examples/hello-world/hello-data.html +46 -0
  142. data/public/d3/examples/hello-world/hello-event.html +53 -0
  143. data/public/d3/examples/hello-world/hello-node-key.html +25 -0
  144. data/public/d3/examples/hello-world/hello-sort.html +75 -0
  145. data/public/d3/examples/hello-world/hello-transform.html +41 -0
  146. data/public/d3/examples/hello-world/hello-transition-undefined.html +43 -0
  147. data/public/d3/examples/hello-world/hello-transition.html +47 -0
  148. data/public/d3/examples/hello-world/hello-webkit-transition.html +64 -0
  149. data/public/d3/examples/hello-world/select-enter-add.html +29 -0
  150. data/public/d3/examples/hello-world/selectAll-enter-add.html +20 -0
  151. data/public/d3/examples/histogram/histogram.html +80 -0
  152. data/public/d3/examples/horizon/horizon.css +9 -0
  153. data/public/d3/examples/horizon/horizon.html +25 -0
  154. data/public/d3/examples/horizon/horizon.js +43 -0
  155. data/public/d3/examples/horizon/unemployment.json +1 -0
  156. data/public/d3/examples/hull/hull.html +75 -0
  157. data/public/d3/examples/kde/kde.css +9 -0
  158. data/public/d3/examples/kde/kde.html +14 -0
  159. data/public/d3/examples/kde/kde.js +40 -0
  160. data/public/d3/examples/line/line.css +22 -0
  161. data/public/d3/examples/line/line.html +11 -0
  162. data/public/d3/examples/line/line.js +63 -0
  163. data/public/d3/examples/marimekko/marimekko.html +116 -0
  164. data/public/d3/examples/marimekko/marimekko.json +18 -0
  165. data/public/d3/examples/marker/marker.html +169 -0
  166. data/public/d3/examples/mercator/mercator.html +133 -0
  167. data/public/d3/examples/moire/moire.html +53 -0
  168. data/public/d3/examples/pack/pack.css +15 -0
  169. data/public/d3/examples/pack/pack.html +14 -0
  170. data/public/d3/examples/pack/pack.js +33 -0
  171. data/public/d3/examples/partition/partition-icicle-zoom.html +59 -0
  172. data/public/d3/examples/partition/partition-icicle.html +45 -0
  173. data/public/d3/examples/partition/partition-sunburst-zoom.html +72 -0
  174. data/public/d3/examples/partition/partition-sunburst.html +21 -0
  175. data/public/d3/examples/partition/partition-sunburst.js +72 -0
  176. data/public/d3/examples/pie/pie-transition.html +70 -0
  177. data/public/d3/examples/pie/pie.html +51 -0
  178. data/public/d3/examples/population/population.css +28 -0
  179. data/public/d3/examples/population/population.csv +571 -0
  180. data/public/d3/examples/population/population.html +13 -0
  181. data/public/d3/examples/population/population.js +126 -0
  182. data/public/d3/examples/qq/qq.css +18 -0
  183. data/public/d3/examples/qq/qq.html +21 -0
  184. data/public/d3/examples/qq/qq.js +66 -0
  185. data/public/d3/examples/qq/stats.js +28 -0
  186. data/public/d3/examples/qq/turkers.json +1 -0
  187. data/public/d3/examples/quadtree/quadtree.html +114 -0
  188. data/public/d3/examples/sizzle/sizzle.html +27 -0
  189. data/public/d3/examples/sort/sort.css +4 -0
  190. data/public/d3/examples/sort/sort.html +12 -0
  191. data/public/d3/examples/sort/sort.js +112 -0
  192. data/public/d3/examples/spline/spline.css +30 -0
  193. data/public/d3/examples/spline/spline.html +14 -0
  194. data/public/d3/examples/spline/spline.js +113 -0
  195. data/public/d3/examples/splom/cross.js +7 -0
  196. data/public/d3/examples/splom/flowers.json +1 -0
  197. data/public/d3/examples/splom/splom.css +8 -0
  198. data/public/d3/examples/splom/splom.html +14 -0
  199. data/public/d3/examples/splom/splom.js +149 -0
  200. data/public/d3/examples/stream/stack.css +7 -0
  201. data/public/d3/examples/stream/stack.html +22 -0
  202. data/public/d3/examples/stream/stack.js +119 -0
  203. data/public/d3/examples/stream/stream.css +3 -0
  204. data/public/d3/examples/stream/stream.html +19 -0
  205. data/public/d3/examples/stream/stream.js +42 -0
  206. data/public/d3/examples/stream/stream_layers.js +33 -0
  207. data/public/d3/examples/superformula/dot.html +104 -0
  208. data/public/d3/examples/superformula/explorer.html +120 -0
  209. data/public/d3/examples/superformula/superformula.html +70 -0
  210. data/public/d3/examples/superformula/superformula.js +98 -0
  211. data/public/d3/examples/symbol-map/symbol-map.html +67 -0
  212. data/public/d3/examples/touch/touch.html +65 -0
  213. data/public/d3/examples/tree/tree-dynamic.html +111 -0
  214. data/public/d3/examples/tree/tree-interactive.html +139 -0
  215. data/public/d3/examples/tree/tree-radial.html +14 -0
  216. data/public/d3/examples/tree/tree-radial.js +40 -0
  217. data/public/d3/examples/tree/tree.css +15 -0
  218. data/public/d3/examples/tree/tree.html +14 -0
  219. data/public/d3/examples/tree/tree.js +39 -0
  220. data/public/d3/examples/treemap/treemap-svg.html +22 -0
  221. data/public/d3/examples/treemap/treemap-svg.js +34 -0
  222. data/public/d3/examples/treemap/treemap.css +8 -0
  223. data/public/d3/examples/treemap/treemap.html +22 -0
  224. data/public/d3/examples/treemap/treemap.js +53 -0
  225. data/public/d3/examples/voroboids/boid.js +235 -0
  226. data/public/d3/examples/voroboids/voroboids.css +15 -0
  227. data/public/d3/examples/voroboids/voroboids.html +14 -0
  228. data/public/d3/examples/voroboids/voroboids.js +65 -0
  229. data/public/d3/examples/voronoi/voronoi.css +16 -0
  230. data/public/d3/examples/voronoi/voronoi.html +15 -0
  231. data/public/d3/examples/voronoi/voronoi.js +34 -0
  232. data/public/d3/examples/zoom-pan/zoom-pan-transform.html +95 -0
  233. data/public/d3/examples/zoom-pan/zoom-pan.html +119 -0
  234. data/public/d3/examples/zoom/dji.csv +5233 -0
  235. data/public/d3/examples/zoom/zoom.html +162 -0
  236. data/public/d3/lib/colorbrewer/LICENSE +38 -0
  237. data/public/d3/lib/colorbrewer/colorbrewer.css +1327 -0
  238. data/public/d3/lib/colorbrewer/colorbrewer.js +32 -0
  239. data/public/d3/lib/jit/LICENSE +27 -0
  240. data/public/d3/lib/jquery-ui/LICENSE +25 -0
  241. data/public/d3/lib/jquery-ui/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  242. data/public/d3/lib/jquery-ui/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  243. data/public/d3/lib/jquery-ui/images/ui-bg_flat_10_000000_40x100.png +0 -0
  244. data/public/d3/lib/jquery-ui/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  245. data/public/d3/lib/jquery-ui/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  246. data/public/d3/lib/jquery-ui/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  247. data/public/d3/lib/jquery-ui/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  248. data/public/d3/lib/jquery-ui/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  249. data/public/d3/lib/jquery-ui/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  250. data/public/d3/lib/jquery-ui/images/ui-icons_222222_256x240.png +0 -0
  251. data/public/d3/lib/jquery-ui/images/ui-icons_228ef1_256x240.png +0 -0
  252. data/public/d3/lib/jquery-ui/images/ui-icons_ef8c08_256x240.png +0 -0
  253. data/public/d3/lib/jquery-ui/images/ui-icons_ffd27a_256x240.png +0 -0
  254. data/public/d3/lib/jquery-ui/images/ui-icons_ffffff_256x240.png +0 -0
  255. data/public/d3/lib/jquery-ui/jquery-ui.css +318 -0
  256. data/public/d3/lib/jquery-ui/jquery-ui.min.js +83 -0
  257. data/public/d3/lib/jquery/LICENSE +20 -0
  258. data/public/d3/lib/jquery/jquery.js +6883 -0
  259. data/public/d3/lib/jquery/jquery.min.js +166 -0
  260. data/public/d3/lib/polymaps/LICENSE +28 -0
  261. data/public/d3/lib/protovis/LICENSE +27 -0
  262. data/public/d3/lib/science/LICENSE +26 -0
  263. data/public/d3/lib/science/science.js +5 -0
  264. data/public/d3/lib/science/science.min.js +1 -0
  265. data/public/d3/lib/science/science.stats.js +166 -0
  266. data/public/d3/lib/science/science.stats.min.js +1 -0
  267. data/public/d3/lib/sizzle/LICENSE +24 -0
  268. data/public/d3/lib/sizzle/sizzle.js +1376 -0
  269. data/public/d3/lib/sizzle/sizzle.min.js +28 -0
  270. data/public/d3/package.json +14 -0
  271. data/public/d3/src/behavior/behavior.js +1 -0
  272. data/public/d3/src/behavior/drag.js +106 -0
  273. data/public/d3/src/behavior/zoom.js +212 -0
  274. data/public/d3/src/chart/box.js +297 -0
  275. data/public/d3/src/chart/bullet.js +237 -0
  276. data/public/d3/src/chart/chart.js +1 -0
  277. data/public/d3/src/chart/horizon.js +203 -0
  278. data/public/d3/src/chart/qq.js +245 -0
  279. data/public/d3/src/compat/date.js +3 -0
  280. data/public/d3/src/compat/style.js +9 -0
  281. data/public/d3/src/core/array.js +11 -0
  282. data/public/d3/src/core/ascending.js +3 -0
  283. data/public/d3/src/core/bisect.js +38 -0
  284. data/public/d3/src/core/collapse.js +3 -0
  285. data/public/d3/src/core/core.js +1 -0
  286. data/public/d3/src/core/descending.js +3 -0
  287. data/public/d3/src/core/dispatch.js +45 -0
  288. data/public/d3/src/core/ease.js +128 -0
  289. data/public/d3/src/core/entries.js +5 -0
  290. data/public/d3/src/core/event.js +1 -0
  291. data/public/d3/src/core/first.js +13 -0
  292. data/public/d3/src/core/format.js +85 -0
  293. data/public/d3/src/core/functor.js +3 -0
  294. data/public/d3/src/core/hsl.js +62 -0
  295. data/public/d3/src/core/html.js +10 -0
  296. data/public/d3/src/core/interpolate.js +180 -0
  297. data/public/d3/src/core/json.js +5 -0
  298. data/public/d3/src/core/keys.js +5 -0
  299. data/public/d3/src/core/last.js +13 -0
  300. data/public/d3/src/core/max.js +14 -0
  301. data/public/d3/src/core/merge.js +3 -0
  302. data/public/d3/src/core/min.js +14 -0
  303. data/public/d3/src/core/nest.js +87 -0
  304. data/public/d3/src/core/noop.js +1 -0
  305. data/public/d3/src/core/ns.js +19 -0
  306. data/public/d3/src/core/permute.js +7 -0
  307. data/public/d3/src/core/quantile.js +8 -0
  308. data/public/d3/src/core/range.js +21 -0
  309. data/public/d3/src/core/rebind.js +7 -0
  310. data/public/d3/src/core/requote.js +5 -0
  311. data/public/d3/src/core/rgb.js +284 -0
  312. data/public/d3/src/core/round.js +5 -0
  313. data/public/d3/src/core/selection-append.js +15 -0
  314. data/public/d3/src/core/selection-attr.js +44 -0
  315. data/public/d3/src/core/selection-call.js +13 -0
  316. data/public/d3/src/core/selection-classed.js +46 -0
  317. data/public/d3/src/core/selection-data.js +110 -0
  318. data/public/d3/src/core/selection-each.js +9 -0
  319. data/public/d3/src/core/selection-empty.js +3 -0
  320. data/public/d3/src/core/selection-enter-select.js +24 -0
  321. data/public/d3/src/core/selection-enter.js +10 -0
  322. data/public/d3/src/core/selection-filter.js +19 -0
  323. data/public/d3/src/core/selection-html.js +6 -0
  324. data/public/d3/src/core/selection-insert.js +20 -0
  325. data/public/d3/src/core/selection-map.js +5 -0
  326. data/public/d3/src/core/selection-node.js +9 -0
  327. data/public/d3/src/core/selection-on.js +34 -0
  328. data/public/d3/src/core/selection-property.js +23 -0
  329. data/public/d3/src/core/selection-remove.js +9 -0
  330. data/public/d3/src/core/selection-root.js +16 -0
  331. data/public/d3/src/core/selection-select.js +30 -0
  332. data/public/d3/src/core/selection-selectAll.js +24 -0
  333. data/public/d3/src/core/selection-sort.js +20 -0
  334. data/public/d3/src/core/selection-style.js +26 -0
  335. data/public/d3/src/core/selection-text.js +6 -0
  336. data/public/d3/src/core/selection-transition.js +14 -0
  337. data/public/d3/src/core/selection.js +21 -0
  338. data/public/d3/src/core/split.js +21 -0
  339. data/public/d3/src/core/sum.js +14 -0
  340. data/public/d3/src/core/text.js +10 -0
  341. data/public/d3/src/core/this.js +3 -0
  342. data/public/d3/src/core/timer.js +104 -0
  343. data/public/d3/src/core/transition-attr.js +23 -0
  344. data/public/d3/src/core/transition-delay.js +6 -0
  345. data/public/d3/src/core/transition-duration.js +6 -0
  346. data/public/d3/src/core/transition-each.js +9 -0
  347. data/public/d3/src/core/transition-remove.js +6 -0
  348. data/public/d3/src/core/transition-select.js +22 -0
  349. data/public/d3/src/core/transition-selectAll.js +20 -0
  350. data/public/d3/src/core/transition-style.js +14 -0
  351. data/public/d3/src/core/transition-text.js +7 -0
  352. data/public/d3/src/core/transition-transition.js +3 -0
  353. data/public/d3/src/core/transition.js +105 -0
  354. data/public/d3/src/core/uninterpolate.js +9 -0
  355. data/public/d3/src/core/values.js +5 -0
  356. data/public/d3/src/core/xhr.js +10 -0
  357. data/public/d3/src/core/xml.js +10 -0
  358. data/public/d3/src/core/zip.js +13 -0
  359. data/public/d3/src/csv/csv.js +5 -0
  360. data/public/d3/src/csv/format.js +13 -0
  361. data/public/d3/src/csv/parse.js +73 -0
  362. data/public/d3/src/end.js +1 -0
  363. data/public/d3/src/externs.js +6 -0
  364. data/public/d3/src/geo/albers.js +128 -0
  365. data/public/d3/src/geo/azimuthal.js +70 -0
  366. data/public/d3/src/geo/bounds.js +76 -0
  367. data/public/d3/src/geo/geo.js +1 -0
  368. data/public/d3/src/geo/greatCircle.js +91 -0
  369. data/public/d3/src/geo/mercator.js +36 -0
  370. data/public/d3/src/geo/path.js +289 -0
  371. data/public/d3/src/geom/contour.js +78 -0
  372. data/public/d3/src/geom/delaunay.js +31 -0
  373. data/public/d3/src/geom/geom.js +1 -0
  374. data/public/d3/src/geom/hull.js +98 -0
  375. data/public/d3/src/geom/polygon.js +88 -0
  376. data/public/d3/src/geom/quadtree.js +129 -0
  377. data/public/d3/src/geom/voronoi.js +399 -0
  378. data/public/d3/src/layout/bundle.js +57 -0
  379. data/public/d3/src/layout/chord.js +148 -0
  380. data/public/d3/src/layout/cluster.js +77 -0
  381. data/public/d3/src/layout/force.js +332 -0
  382. data/public/d3/src/layout/hierarchy.js +120 -0
  383. data/public/d3/src/layout/histogram.js +102 -0
  384. data/public/d3/src/layout/layout.js +1 -0
  385. data/public/d3/src/layout/pack.js +200 -0
  386. data/public/d3/src/layout/partition.js +48 -0
  387. data/public/d3/src/layout/pie.js +95 -0
  388. data/public/d3/src/layout/stack.js +237 -0
  389. data/public/d3/src/layout/tree.js +234 -0
  390. data/public/d3/src/layout/treemap.js +213 -0
  391. data/public/d3/src/scale/bilinear.js +7 -0
  392. data/public/d3/src/scale/category.js +54 -0
  393. data/public/d3/src/scale/linear.js +115 -0
  394. data/public/d3/src/scale/log.js +80 -0
  395. data/public/d3/src/scale/nice.js +21 -0
  396. data/public/d3/src/scale/ordinal.js +74 -0
  397. data/public/d3/src/scale/polylinear.js +16 -0
  398. data/public/d3/src/scale/pow.js +54 -0
  399. data/public/d3/src/scale/quantile.js +43 -0
  400. data/public/d3/src/scale/quantize.js +36 -0
  401. data/public/d3/src/scale/scale.js +6 -0
  402. data/public/d3/src/scale/sqrt.js +3 -0
  403. data/public/d3/src/start.js +1 -0
  404. data/public/d3/src/svg/arc.js +95 -0
  405. data/public/d3/src/svg/area-radial.js +10 -0
  406. data/public/d3/src/svg/area.js +84 -0
  407. data/public/d3/src/svg/axis.js +182 -0
  408. data/public/d3/src/svg/chord.js +99 -0
  409. data/public/d3/src/svg/diagonal-radial.js +22 -0
  410. data/public/d3/src/svg/diagonal.js +38 -0
  411. data/public/d3/src/svg/line-radial.js +22 -0
  412. data/public/d3/src/svg/line.js +419 -0
  413. data/public/d3/src/svg/mouse.js +29 -0
  414. data/public/d3/src/svg/svg.js +1 -0
  415. data/public/d3/src/svg/symbol.js +98 -0
  416. data/public/d3/src/svg/touches.js +8 -0
  417. data/public/d3/src/time/day.js +7 -0
  418. data/public/d3/src/time/days.js +11 -0
  419. data/public/d3/src/time/format-iso.js +1 -0
  420. data/public/d3/src/time/format-utc.js +48 -0
  421. data/public/d3/src/time/format.js +315 -0
  422. data/public/d3/src/time/hour.js +8 -0
  423. data/public/d3/src/time/hours.js +11 -0
  424. data/public/d3/src/time/minute.js +5 -0
  425. data/public/d3/src/time/minutes.js +11 -0
  426. data/public/d3/src/time/month.js +7 -0
  427. data/public/d3/src/time/months.js +11 -0
  428. data/public/d3/src/time/range.js +16 -0
  429. data/public/d3/src/time/scale-utc.js +36 -0
  430. data/public/d3/src/time/scale.js +123 -0
  431. data/public/d3/src/time/second.js +5 -0
  432. data/public/d3/src/time/seconds.js +7 -0
  433. data/public/d3/src/time/time.js +3 -0
  434. data/public/d3/src/time/week.js +9 -0
  435. data/public/d3/src/time/weeks.js +11 -0
  436. data/public/d3/src/time/year.js +7 -0
  437. data/public/d3/src/time/years.js +11 -0
  438. data/public/d3/test/core/ascending-test.js +47 -0
  439. data/public/d3/test/core/bisect-test.js +103 -0
  440. data/public/d3/test/core/descending-test.js +47 -0
  441. data/public/d3/test/core/dispatch-test.js +116 -0
  442. data/public/d3/test/core/ease-test.js +129 -0
  443. data/public/d3/test/core/entries-test.js +43 -0
  444. data/public/d3/test/core/first-test.js +42 -0
  445. data/public/d3/test/core/format-test.js +204 -0
  446. data/public/d3/test/core/functor-test.js +29 -0
  447. data/public/d3/test/core/hsl-test.js +87 -0
  448. data/public/d3/test/core/html-test.js +37 -0
  449. data/public/d3/test/core/interpolate-test.js +203 -0
  450. data/public/d3/test/core/json-test.js +37 -0
  451. data/public/d3/test/core/keys-test.js +31 -0
  452. data/public/d3/test/core/last-test.js +42 -0
  453. data/public/d3/test/core/max-test.js +50 -0
  454. data/public/d3/test/core/merge-test.js +27 -0
  455. data/public/d3/test/core/min-test.js +50 -0
  456. data/public/d3/test/core/nest-test.js +236 -0
  457. data/public/d3/test/core/ns-test.js +53 -0
  458. data/public/d3/test/core/permute-test.js +53 -0
  459. data/public/d3/test/core/quantile-test.js +50 -0
  460. data/public/d3/test/core/range-test.js +93 -0
  461. data/public/d3/test/core/rebind-test.js +38 -0
  462. data/public/d3/test/core/requote-test.js +53 -0
  463. data/public/d3/test/core/rgb-test.js +89 -0
  464. data/public/d3/test/core/round-test.js +70 -0
  465. data/public/d3/test/core/select-test.js +42 -0
  466. data/public/d3/test/core/selectAll-test.js +42 -0
  467. data/public/d3/test/core/selection-append-test.js +119 -0
  468. data/public/d3/test/core/selection-attr-test.js +153 -0
  469. data/public/d3/test/core/selection-call-test.js +71 -0
  470. data/public/d3/test/core/selection-classed-test.js +200 -0
  471. data/public/d3/test/core/selection-data-test.js +165 -0
  472. data/public/d3/test/core/selection-each-test.js +83 -0
  473. data/public/d3/test/core/selection-empty-test.js +51 -0
  474. data/public/d3/test/core/selection-filter-test.js +63 -0
  475. data/public/d3/test/core/selection-html-test.js +121 -0
  476. data/public/d3/test/core/selection-insert-test.js +132 -0
  477. data/public/d3/test/core/selection-map-test.js +47 -0
  478. data/public/d3/test/core/selection-node-test.js +50 -0
  479. data/public/d3/test/core/selection-on-test.js +95 -0
  480. data/public/d3/test/core/selection-property-test.js +91 -0
  481. data/public/d3/test/core/selection-remove-test.js +39 -0
  482. data/public/d3/test/core/selection-select-test.js +125 -0
  483. data/public/d3/test/core/selection-selectAll-test.js +127 -0
  484. data/public/d3/test/core/selection-sort-test.js +59 -0
  485. data/public/d3/test/core/selection-style-test.js +100 -0
  486. data/public/d3/test/core/selection-test.js +35 -0
  487. data/public/d3/test/core/selection-text-test.js +109 -0
  488. data/public/d3/test/core/split-test.js +34 -0
  489. data/public/d3/test/core/sum-test.js +47 -0
  490. data/public/d3/test/core/text-test.js +48 -0
  491. data/public/d3/test/core/timer-test.js +62 -0
  492. data/public/d3/test/core/transition-test-attr.js +33 -0
  493. data/public/d3/test/core/transition-test-attrTween.js +67 -0
  494. data/public/d3/test/core/transition-test-call.js +33 -0
  495. data/public/d3/test/core/transition-test-delay.js +41 -0
  496. data/public/d3/test/core/transition-test-duration.js +41 -0
  497. data/public/d3/test/core/transition-test-each.js +166 -0
  498. data/public/d3/test/core/transition-test-id.js +20 -0
  499. data/public/d3/test/core/transition-test-remove.js +46 -0
  500. data/public/d3/test/core/transition-test-select.js +63 -0
  501. data/public/d3/test/core/transition-test-selectAll.js +55 -0
  502. data/public/d3/test/core/transition-test-style.js +38 -0
  503. data/public/d3/test/core/transition-test-styleTween.js +73 -0
  504. data/public/d3/test/core/transition-test-text.js +30 -0
  505. data/public/d3/test/core/transition-test-transition.js +60 -0
  506. data/public/d3/test/core/transition-test-tween.js +71 -0
  507. data/public/d3/test/core/transition-test.js +65 -0
  508. data/public/d3/test/core/values-test.js +35 -0
  509. data/public/d3/test/core/version-test.js +18 -0
  510. data/public/d3/test/core/xhr-test.js +56 -0
  511. data/public/d3/test/core/xml-test.js +48 -0
  512. data/public/d3/test/core/zip-test.js +32 -0
  513. data/public/d3/test/csv/csv-test.js +38 -0
  514. data/public/d3/test/csv/format-test.js +39 -0
  515. data/public/d3/test/csv/parse-test.js +101 -0
  516. data/public/d3/test/env-assert.js +96 -0
  517. data/public/d3/test/env-fragment.js +8 -0
  518. data/public/d3/test/env-xhr.js +56 -0
  519. data/public/d3/test/env.js +13 -0
  520. data/public/d3/test/geo/albers-test.js +57 -0
  521. data/public/d3/test/geo/azimuthal-test.js +89 -0
  522. data/public/d3/test/geo/greatCircle-test.js +42 -0
  523. data/public/d3/test/geo/mercator-test.js +57 -0
  524. data/public/d3/test/layout/histogram-test.js +91 -0
  525. data/public/d3/test/layout/partition-test.js +39 -0
  526. data/public/d3/test/layout/tree-test.js +21 -0
  527. data/public/d3/test/layout/treemap-test.js +180 -0
  528. data/public/d3/test/scale/category-test.js +74 -0
  529. data/public/d3/test/scale/linear-test.js +239 -0
  530. data/public/d3/test/scale/log-test.js +220 -0
  531. data/public/d3/test/scale/ordinal-test.js +193 -0
  532. data/public/d3/test/scale/pow-test.js +259 -0
  533. data/public/d3/test/scale/quantile-test.js +64 -0
  534. data/public/d3/test/scale/quantize-test.js +69 -0
  535. data/public/d3/test/scale/sqrt-test.js +256 -0
  536. data/public/d3/test/svg/arc-test.js +147 -0
  537. data/public/d3/test/svg/area-radial-test.js +200 -0
  538. data/public/d3/test/svg/area-test.js +191 -0
  539. data/public/d3/test/svg/axis-test.js +347 -0
  540. data/public/d3/test/svg/line-radial-test.js +125 -0
  541. data/public/d3/test/svg/line-test.js +189 -0
  542. data/public/d3/test/svg/symbol-test.js +96 -0
  543. data/public/d3/test/time/day-test.js +65 -0
  544. data/public/d3/test/time/days-test.js +105 -0
  545. data/public/d3/test/time/format-test.js +430 -0
  546. data/public/d3/test/time/hour-test.js +103 -0
  547. data/public/d3/test/time/hours-test.js +135 -0
  548. data/public/d3/test/time/minute-test.js +43 -0
  549. data/public/d3/test/time/minutes-test.js +101 -0
  550. data/public/d3/test/time/month-test.js +53 -0
  551. data/public/d3/test/time/months-test.js +105 -0
  552. data/public/d3/test/time/scale-test.js +525 -0
  553. data/public/d3/test/time/second-test.js +41 -0
  554. data/public/d3/test/time/seconds-test.js +101 -0
  555. data/public/d3/test/time/week-test.js +59 -0
  556. data/public/d3/test/time/weeks-test.js +105 -0
  557. data/public/d3/test/time/year-test.js +41 -0
  558. data/public/d3/test/time/years-test.js +73 -0
  559. data/public/graph.js +42 -0
  560. data/public/jquery.min.js +4 -0
  561. data/public/test.html +36 -0
  562. data/public/testdata/bigfucker.js +212 -0
  563. data/public/testdata/names_and_enabled.js +232 -0
  564. data/public/testdata/one.js +79 -0
  565. data/public/testdata/withnames.js +198 -0
  566. data/public/viz.js +289 -0
  567. data/views/graph.erb +15 -0
  568. data/views/one.erb +34 -0
  569. data/views/two.erb +44 -0
  570. data/views/vis.erb +47 -0
  571. metadata +594 -18
  572. data/lib/bum.rb +0 -385
  573. data/lib/client.rb.erb +0 -7
  574. data/lib/dhcpd.rb +0 -84
  575. data/lib/hosts.rb +0 -61
  576. data/lib/vmx.rb +0 -24
@@ -0,0 +1 @@
1
+ (function(){function o(a){return a.target}function n(a){return a.source}function m(a,b){for(var c=a.coordinates[0],d=0,e=c.length;d<e;d++)b.apply(null,c[d])}function l(a,b){b.apply(null,a.coordinates)}function k(a,b){for(var c=a.coordinates,d=0,e=c.length;d<e;d++)for(var f=c[d][0],g=0,h=f.length;g<h;g++)b.apply(null,f[g])}function j(a,b){for(var c=a.coordinates,d=0,e=c.length;d<e;d++)for(var f=c[d],g=0,h=f.length;g<h;g++)b.apply(null,f[g])}function i(a,b){for(var c=a.coordinates,d=0,e=c.length;d<e;d++)b.apply(null,c[d])}function h(a,b){for(var c=a.features,d=0,f=c.length;d<f;d++)e(c[d].geometry,b)}function g(a,b){e(a.geometry,b)}function e(a,b){a.type in f&&f[a.type](a,b)}function d(a,b){return b&&b.type in a?a[b.type](b):""}function c(){return 0}function b(a){return"m0,"+a+"a"+a+","+a+" 0 1,1 0,"+ -2*a+"a"+a+","+a+" 0 1,1 0,"+2*a+"z"}d3.geo={},d3.geo.azimuthal=function(){function j(c){var g=c[0]*a-f,j=c[1]*a,k=Math.cos(g),l=Math.sin(g),m=Math.cos(j),n=Math.sin(j),o=b==="stereographic"?1/(1+i*n+h*m*k):1,p=o*m*l,q=o*(i*m*k-h*n);return[d*p+e[0],d*q+e[1]]}var b="orthographic",c,d=200,e=[480,250],f,g,h,i;j.invert=function(c){var g=(c[0]-e[0])/d,j=(c[1]-e[1])/d,k=Math.sqrt(g*g+j*j),l=b==="stereographic"?2*Math.atan(k):Math.asin(k),m=Math.sin(l),n=Math.cos(l);return[(f+Math.atan2(g*m,k*h*n+j*i*m))/a,Math.asin(n*i-j*m*h/k)/a]},j.mode=function(a){if(!arguments.length)return b;b=a+"";return j},j.origin=function(b){if(!arguments.length)return c;c=b,f=c[0]*a,g=c[1]*a,h=Math.cos(g),i=Math.sin(g);return j},j.scale=function(a){if(!arguments.length)return d;d=+a;return j},j.translate=function(a){if(!arguments.length)return e;e=[+a[0],+a[1]];return j};return j.origin([0,0])},d3.geo.albers=function(){function k(){var d=a*c[0],e=a*c[1],k=a*b[1],l=Math.sin(d),m=Math.cos(d);f=a*b[0],g=.5*(l+Math.sin(e)),h=m*m+2*g*l,i=Math.sqrt(h-2*g*Math.sin(k))/g;return j}function j(b){var c=g*(a*b[0]-f),j=Math.sqrt(h-2*g*Math.sin(a*b[1]))/g;return[d*j*Math.sin(c)+e[0],d*(j*Math.cos(c)-i)+e[1]]}var b=[-98,38],c=[29.5,45.5],d=1e3,e=[480,250],f,g,h,i;j.invert=function(b){var c=(b[0]-e[0])/d,j=(b[1]-e[1])/d,k=i+j,l=Math.atan2(c,k),m=Math.sqrt(c*c+k*k);return[(f+l/g)/a,Math.asin((h-m*m*g*g)/(2*g))/a]},j.origin=function(a){if(!arguments.length)return b;b=[+a[0],+a[1]];return k()},j.parallels=function(a){if(!arguments.length)return c;c=[+a[0],+a[1]];return k()},j.scale=function(a){if(!arguments.length)return d;d=+a;return j},j.translate=function(a){if(!arguments.length)return e;e=[+a[0],+a[1]];return j};return k()},d3.geo.albersUsa=function(){function e(e){var f=e[0],g=e[1];return(g>50?b:f<-140?c:g<21?d:a)(e)}var a=d3.geo.albers(),b=d3.geo.albers().origin([-160,60]).parallels([55,65]),c=d3.geo.albers().origin([-160,20]).parallels([8,18]),d=d3.geo.albers().origin([-60,10]).parallels([8,18]);e.scale=function(f){if(!arguments.length)return a.scale();a.scale(f),b.scale(f*.6),c.scale(f),d.scale(f*1.5);return e.translate(a.translate())},e.translate=function(f){if(!arguments.length)return a.translate();var g=a.scale()/1e3,h=f[0],i=f[1];a.translate(f),b.translate([h-400*g,i+170*g]),c.translate([h-190*g,i+200*g]),d.translate([h+580*g,i+430*g]);return e};return e.scale(a.scale())};var a=Math.PI/180;d3.geo.mercator=function(){function d(d){var e=d[0]/360,f=-(Math.log(Math.tan(Math.PI/4+d[1]*a/2))/a)/360;return[b*e+c[0],b*Math.max(-0.5,Math.min(.5,f))+c[1]]}var b=500,c=[480,250];d.invert=function(d){var e=(d[0]-c[0])/b,f=(d[1]-c[1])/b;return[360*e,2*Math.atan(Math.exp(-360*f*a))/a-90]},d.scale=function(a){if(!arguments.length)return b;b=+a;return d},d.translate=function(a){if(!arguments.length)return c;c=[+a[0],+a[1]];return d};return d},d3.geo.path=function(){function n(a){return Math.abs(d3.geom.polygon(a.map(f)).area())}function l(a){var b=d3.geom.polygon(a[0].map(f)),c=b.centroid(1),d=c[0],e=c[1],g=Math.abs(b.area()),h=0,i=a.length;while(++h<i)b=d3.geom.polygon(a[h].map(f)),c=b.centroid(1),d-=c[0],e-=c[1],g-=Math.abs(b.area());return[d,e,6*g]}function k(a){var b=n(a[0]),c=0,d=a.length;while(++c<d)b-=n(a[c]);return b}function h(a){return f(a).join(",")}function g(c,f){typeof a=="function"&&(e=b(a.apply(this,arguments)));return d(i,c)}var a=4.5,e=b(a),f=d3.geo.albersUsa(),i={FeatureCollection:function(a){var b=[],c=a.features,e=-1,f=c.length;while(++e<f)b.push(d(i,c[e].geometry));return b.join("")},Feature:function(a){return d(i,a.geometry)},Point:function(a){return"M"+h(a.coordinates)+e},MultiPoint:function(a){var b=[],c=a.coordinates,d=-1,f=c.length;while(++d<f)b.push("M",h(c[d]),e);return b.join("")},LineString:function(a){var b=["M"],c=a.coordinates,d=-1,e=c.length;while(++d<e)b.push(h(c[d]),"L");b.pop();return b.join("")},MultiLineString:function(a){var b=[],c=a.coordinates,d=-1,e=c.length,f,g,i;while(++d<e){f=c[d],g=-1,i=f.length,b.push("M");while(++g<i)b.push(h(f[g]),"L");b.pop()}return b.join("")},Polygon:function(a){var b=[],c=a.coordinates,d=-1,e=c.length,f,g,i;while(++d<e){f=c[d],g=-1,i=f.length,b.push("M");while(++g<i)b.push(h(f[g]),"L");b[b.length-1]="Z"}return b.join("")},MultiPolygon:function(a){var b=[],c=a.coordinates,d=-1,e=c.length,f,g,i,j,k,l;while(++d<e){f=c[d],g=-1,i=f.length;while(++g<i){j=f[g],k=-1,l=j.length-1,b.push("M");while(++k<l)b.push(h(j[k]),"L");b[b.length-1]="Z"}}return b.join("")},GeometryCollection:function(a){var b=[],c=a.geometries,e=-1,f=c.length;while(++e<f)b.push(d(i,c[e]));return b.join("")}},j={FeatureCollection:function(a){var b=0,c=a.features,e=-1,f=c.length;while(++e<f)b+=d(j,c[e]);return b},Feature:function(a){return d(j,a.geometry)},Point:c,MultiPoint:c,LineString:c,MultiLineString:c,Polygon:function(a){return k(a.coordinates)},MultiPolygon:function(a){var b=0,c=a.coordinates,d=-1,e=c.length;while(++d<e)b+=k(c[d]);return b},GeometryCollection:function(a){var b=0,c=a.geometries,e=-1,f=c.length;while(++e<f)b+=d(j,c[e]);return b}},m={Feature:function(a){return d(m,a.geometry)},Polygon:function(a){var b=l(a.coordinates);return[b[0]/b[2],b[1]/b[2]]},MultiPolygon:function(a){var b=0,c=a.coordinates,d,e=0,f=0,g=0,h=-1,i=c.length;while(++h<i)d=l(c[h]),e+=d[0],f+=d[1],g+=d[2];return[e/g,f/g]}};g.projection=function(a){f=a;return g},g.area=function(a){return d(j,a)},g.centroid=function(a){return d(m,a)},g.pointRadius=function(c){typeof c=="function"?a=c:(a=+c,e=b(a));return g};return g},d3.geo.bounds=function(a){var b=Infinity,c=Infinity,d=-Infinity,f=-Infinity;e(a,function(a,e){a<b&&(b=a),a>d&&(d=a),e<c&&(c=e),e>f&&(f=e)});return[[b,c],[d,f]]};var f={Feature:g,FeatureCollection:h,LineString:i,MultiLineString:j,MultiPoint:i,MultiPolygon:k,Point:l,Polygon:m};d3.geo.greatCircle=function(){function f(e,f){var g=b.call(this,e,f),h=c.call(this,e,f),i=g[0]*a,j=g[1]*a,k=h[0]*a,l=h[1]*a,m=Math.cos(i),n=Math.sin(i),o=Math.cos(j),p=Math.sin(j),q=Math.cos(k),r=Math.sin(k),s=Math.cos(l),t=Math.sin(l),e=Math.acos(p*t+o*s*Math.cos(k-i)),u=Math.sin(e),v=e/(d-1),w=-v,x=[],f=-1;while(++f<d){w+=v;var y=Math.sin(e-w)/u,z=Math.sin(w)/u,A=y*o*m+z*s*q,B=y*o*n+z*s*r,C=y*p+z*t;x[f]=[Math.atan2(B,A)/a,Math.atan2(C,Math.sqrt(A*A+B*B))/a]}return x}var b=n,c=o,d=100,e=6371;f.source=function(a){if(!arguments.length)return b;b=a;return f},f.target=function(a){if(!arguments.length)return c;c=a;return f},f.n=function(a){if(!arguments.length)return d;d=+a;return f},f.radius=function(a){if(!arguments.length)return e;e=+a;return f},f.distance=function(d,f){var g=b.call(this,d,f),h=c.call(this,d,f),i=g[0]*a,j=g[1]*a,k=h[0]*a,l=h[1]*a,m=Math.sin((l-j)/2),n=Math.sin((k-i)/2),o=m*m+Math.cos(j)*Math.cos(l)*n*n;return e*2*Math.atan2(Math.sqrt(o),Math.sqrt(1-o))};return f}})()
@@ -0,0 +1,825 @@
1
+ (function(){d3.geom = {};
2
+ /**
3
+ * Computes a contour for a given input grid function using the <a
4
+ * href="http://en.wikipedia.org/wiki/Marching_squares">marching
5
+ * squares</a> algorithm. Returns the contour polygon as an array of points.
6
+ *
7
+ * @param grid a two-input function(x, y) that returns true for values
8
+ * inside the contour and false for values outside the contour.
9
+ * @param start an optional starting point [x, y] on the grid.
10
+ * @returns polygon [[x1, y1], [x2, y2], …]
11
+ */
12
+ d3.geom.contour = function(grid, start) {
13
+ var s = start || d3_geom_contourStart(grid), // starting point
14
+ c = [], // contour polygon
15
+ x = s[0], // current x position
16
+ y = s[1], // current y position
17
+ dx = 0, // next x direction
18
+ dy = 0, // next y direction
19
+ pdx = NaN, // previous x direction
20
+ pdy = NaN, // previous y direction
21
+ i = 0;
22
+
23
+ do {
24
+ // determine marching squares index
25
+ i = 0;
26
+ if (grid(x-1, y-1)) i += 1;
27
+ if (grid(x, y-1)) i += 2;
28
+ if (grid(x-1, y )) i += 4;
29
+ if (grid(x, y )) i += 8;
30
+
31
+ // determine next direction
32
+ if (i === 6) {
33
+ dx = pdy === -1 ? -1 : 1;
34
+ dy = 0;
35
+ } else if (i === 9) {
36
+ dx = 0;
37
+ dy = pdx === 1 ? -1 : 1;
38
+ } else {
39
+ dx = d3_geom_contourDx[i];
40
+ dy = d3_geom_contourDy[i];
41
+ }
42
+
43
+ // update contour polygon
44
+ if (dx != pdx && dy != pdy) {
45
+ c.push([x, y]);
46
+ pdx = dx;
47
+ pdy = dy;
48
+ }
49
+
50
+ x += dx;
51
+ y += dy;
52
+ } while (s[0] != x || s[1] != y);
53
+
54
+ return c;
55
+ };
56
+
57
+ // lookup tables for marching directions
58
+ var d3_geom_contourDx = [1, 0, 1, 1,-1, 0,-1, 1,0, 0,0,0,-1, 0,-1,NaN],
59
+ d3_geom_contourDy = [0,-1, 0, 0, 0,-1, 0, 0,1,-1,1,1, 0,-1, 0,NaN];
60
+
61
+ function d3_geom_contourStart(grid) {
62
+ var x = 0,
63
+ y = 0;
64
+
65
+ // search for a starting point; begin at origin
66
+ // and proceed along outward-expanding diagonals
67
+ while (true) {
68
+ if (grid(x,y)) {
69
+ return [x,y];
70
+ }
71
+ if (x === 0) {
72
+ x = y + 1;
73
+ y = 0;
74
+ } else {
75
+ x = x - 1;
76
+ y = y + 1;
77
+ }
78
+ }
79
+ }
80
+ /**
81
+ * Computes the 2D convex hull of a set of points using Graham's scanning
82
+ * algorithm. The algorithm has been implemented as described in Cormen,
83
+ * Leiserson, and Rivest's Introduction to Algorithms. The running time of
84
+ * this algorithm is O(n log n), where n is the number of input points.
85
+ *
86
+ * @param vertices [[x1, y1], [x2, y2], …]
87
+ * @returns polygon [[x1, y1], [x2, y2], …]
88
+ */
89
+ d3.geom.hull = function(vertices) {
90
+ if (vertices.length < 3) return [];
91
+
92
+ var len = vertices.length,
93
+ plen = len - 1,
94
+ points = [],
95
+ stack = [],
96
+ i, j, h = 0, x1, y1, x2, y2, u, v, a, sp;
97
+
98
+ // find the starting ref point: leftmost point with the minimum y coord
99
+ for (i=1; i<len; ++i) {
100
+ if (vertices[i][1] < vertices[h][1]) {
101
+ h = i;
102
+ } else if (vertices[i][1] == vertices[h][1]) {
103
+ h = (vertices[i][0] < vertices[h][0] ? i : h);
104
+ }
105
+ }
106
+
107
+ // calculate polar angles from ref point and sort
108
+ for (i=0; i<len; ++i) {
109
+ if (i === h) continue;
110
+ y1 = vertices[i][1] - vertices[h][1];
111
+ x1 = vertices[i][0] - vertices[h][0];
112
+ points.push({angle: Math.atan2(y1, x1), index: i});
113
+ }
114
+ points.sort(function(a, b) { return a.angle - b.angle; });
115
+
116
+ // toss out duplicate angles
117
+ a = points[0].angle;
118
+ v = points[0].index;
119
+ u = 0;
120
+ for (i=1; i<plen; ++i) {
121
+ j = points[i].index;
122
+ if (a == points[i].angle) {
123
+ // keep angle for point most distant from the reference
124
+ x1 = vertices[v][0] - vertices[h][0];
125
+ y1 = vertices[v][1] - vertices[h][1];
126
+ x2 = vertices[j][0] - vertices[h][0];
127
+ y2 = vertices[j][1] - vertices[h][1];
128
+ if ((x1*x1 + y1*y1) >= (x2*x2 + y2*y2)) {
129
+ points[i].index = -1;
130
+ } else {
131
+ points[u].index = -1;
132
+ a = points[i].angle;
133
+ u = i;
134
+ v = j;
135
+ }
136
+ } else {
137
+ a = points[i].angle;
138
+ u = i;
139
+ v = j;
140
+ }
141
+ }
142
+
143
+ // initialize the stack
144
+ stack.push(h);
145
+ for (i=0, j=0; i<2; ++j) {
146
+ if (points[j].index !== -1) {
147
+ stack.push(points[j].index);
148
+ i++;
149
+ }
150
+ }
151
+ sp = stack.length;
152
+
153
+ // do graham's scan
154
+ for (; j<plen; ++j) {
155
+ if (points[j].index === -1) continue; // skip tossed out points
156
+ while (!d3_geom_hullCCW(stack[sp-2], stack[sp-1], points[j].index, vertices)) {
157
+ --sp;
158
+ }
159
+ stack[sp++] = points[j].index;
160
+ }
161
+
162
+ // construct the hull
163
+ var poly = [];
164
+ for (i=0; i<sp; ++i) {
165
+ poly.push(vertices[stack[i]]);
166
+ }
167
+ return poly;
168
+ }
169
+
170
+ // are three points in counter-clockwise order?
171
+ function d3_geom_hullCCW(i1, i2, i3, v) {
172
+ var t, a, b, c, d, e, f;
173
+ t = v[i1]; a = t[0]; b = t[1];
174
+ t = v[i2]; c = t[0]; d = t[1];
175
+ t = v[i3]; e = t[0]; f = t[1];
176
+ return ((f-b)*(c-a) - (d-b)*(e-a)) > 0;
177
+ }
178
+ // Note: requires coordinates to be counterclockwise and convex!
179
+ d3.geom.polygon = function(coordinates) {
180
+
181
+ coordinates.area = function() {
182
+ var i = 0,
183
+ n = coordinates.length,
184
+ a = coordinates[n - 1][0] * coordinates[0][1],
185
+ b = coordinates[n - 1][1] * coordinates[0][0];
186
+ while (++i < n) {
187
+ a += coordinates[i - 1][0] * coordinates[i][1];
188
+ b += coordinates[i - 1][1] * coordinates[i][0];
189
+ }
190
+ return (b - a) * .5;
191
+ };
192
+
193
+ coordinates.centroid = function(k) {
194
+ var i = -1,
195
+ n = coordinates.length - 1,
196
+ x = 0,
197
+ y = 0,
198
+ a,
199
+ b,
200
+ c;
201
+ if (!arguments.length) k = 1 / (6 * coordinates.area());
202
+ while (++i < n) {
203
+ a = coordinates[i];
204
+ b = coordinates[i + 1];
205
+ c = a[0] * b[1] - b[0] * a[1];
206
+ x += (a[0] + b[0]) * c;
207
+ y += (a[1] + b[1]) * c;
208
+ }
209
+ return [x * k, y * k];
210
+ };
211
+
212
+ // The Sutherland-Hodgman clipping algorithm.
213
+ coordinates.clip = function(subject) {
214
+ var input,
215
+ i = -1,
216
+ n = coordinates.length,
217
+ j,
218
+ m,
219
+ a = coordinates[n - 1],
220
+ b,
221
+ c,
222
+ d;
223
+ while (++i < n) {
224
+ input = subject.slice();
225
+ subject.length = 0;
226
+ b = coordinates[i];
227
+ c = input[(m = input.length) - 1];
228
+ j = -1;
229
+ while (++j < m) {
230
+ d = input[j];
231
+ if (d3_geom_polygonInside(d, a, b)) {
232
+ if (!d3_geom_polygonInside(c, a, b)) {
233
+ subject.push(d3_geom_polygonIntersect(c, d, a, b));
234
+ }
235
+ subject.push(d);
236
+ } else if (d3_geom_polygonInside(c, a, b)) {
237
+ subject.push(d3_geom_polygonIntersect(c, d, a, b));
238
+ }
239
+ c = d;
240
+ }
241
+ a = b;
242
+ }
243
+ return subject;
244
+ };
245
+
246
+ return coordinates;
247
+ };
248
+
249
+ function d3_geom_polygonInside(p, a, b) {
250
+ return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
251
+ }
252
+
253
+ // Intersect two infinite lines cd and ab.
254
+ function d3_geom_polygonIntersect(c, d, a, b) {
255
+ var x1 = c[0], x2 = d[0], x3 = a[0], x4 = b[0],
256
+ y1 = c[1], y2 = d[1], y3 = a[1], y4 = b[1],
257
+ x13 = x1 - x3,
258
+ x21 = x2 - x1,
259
+ x43 = x4 - x3,
260
+ y13 = y1 - y3,
261
+ y21 = y2 - y1,
262
+ y43 = y4 - y3,
263
+ ua = (x43 * y13 - y43 * x13) / (y43 * x21 - x43 * y21);
264
+ return [x1 + ua * x21, y1 + ua * y21];
265
+ }
266
+ // Adapted from Nicolas Garcia Belmonte's JIT implementation:
267
+ // http://blog.thejit.org/2010/02/12/voronoi-tessellation/
268
+ // http://blog.thejit.org/assets/voronoijs/voronoi.js
269
+ // See lib/jit/LICENSE for details.
270
+
271
+ /**
272
+ * @param vertices [[x1, y1], [x2, y2], …]
273
+ * @returns polygons [[[x1, y1], [x2, y2], …], …]
274
+ */
275
+ d3.geom.voronoi = function(vertices) {
276
+ var polygons = vertices.map(function() { return []; });
277
+
278
+ // Note: we expect the caller to clip the polygons, if needed.
279
+ d3_voronoi_tessellate(vertices, function(e) {
280
+ var s1,
281
+ s2,
282
+ x1,
283
+ x2,
284
+ y1,
285
+ y2;
286
+ if (e.a === 1 && e.b >= 0) {
287
+ s1 = e.ep.r;
288
+ s2 = e.ep.l;
289
+ } else {
290
+ s1 = e.ep.l;
291
+ s2 = e.ep.r;
292
+ }
293
+ if (e.a === 1) {
294
+ y1 = s1 ? s1.y : -1e6;
295
+ x1 = e.c - e.b * y1;
296
+ y2 = s2 ? s2.y : 1e6;
297
+ x2 = e.c - e.b * y2;
298
+ } else {
299
+ x1 = s1 ? s1.x : -1e6;
300
+ y1 = e.c - e.a * x1;
301
+ x2 = s2 ? s2.x : 1e6;
302
+ y2 = e.c - e.a * x2;
303
+ }
304
+ var v1 = [x1, y1],
305
+ v2 = [x2, y2];
306
+ polygons[e.region.l.index].push(v1, v2);
307
+ polygons[e.region.r.index].push(v1, v2);
308
+ });
309
+
310
+ // Reconnect the polygon segments into counterclockwise loops.
311
+ return polygons.map(function(polygon, i) {
312
+ var cx = vertices[i][0],
313
+ cy = vertices[i][1];
314
+ polygon.forEach(function(v) {
315
+ v.angle = Math.atan2(v[0] - cx, v[1] - cy);
316
+ });
317
+ return polygon.sort(function(a, b) {
318
+ return a.angle - b.angle;
319
+ }).filter(function(d, i) {
320
+ return !i || (d.angle - polygon[i - 1].angle > 1e-10);
321
+ });
322
+ });
323
+ };
324
+
325
+ var d3_voronoi_opposite = {"l": "r", "r": "l"};
326
+
327
+ function d3_voronoi_tessellate(vertices, callback) {
328
+
329
+ var Sites = {
330
+ list: vertices
331
+ .map(function(v, i) {
332
+ return {
333
+ index: i,
334
+ x: v[0],
335
+ y: v[1]
336
+ };
337
+ })
338
+ .sort(function(a, b) {
339
+ return a.y < b.y ? -1
340
+ : a.y > b.y ? 1
341
+ : a.x < b.x ? -1
342
+ : a.x > b.x ? 1
343
+ : 0;
344
+ }),
345
+ bottomSite: null
346
+ };
347
+
348
+ var EdgeList = {
349
+ list: [],
350
+ leftEnd: null,
351
+ rightEnd: null,
352
+
353
+ init: function() {
354
+ EdgeList.leftEnd = EdgeList.createHalfEdge(null, "l");
355
+ EdgeList.rightEnd = EdgeList.createHalfEdge(null, "l");
356
+ EdgeList.leftEnd.r = EdgeList.rightEnd;
357
+ EdgeList.rightEnd.l = EdgeList.leftEnd;
358
+ EdgeList.list.unshift(EdgeList.leftEnd, EdgeList.rightEnd);
359
+ },
360
+
361
+ createHalfEdge: function(edge, side) {
362
+ return {
363
+ edge: edge,
364
+ side: side,
365
+ vertex: null,
366
+ "l": null,
367
+ "r": null
368
+ };
369
+ },
370
+
371
+ insert: function(lb, he) {
372
+ he.l = lb;
373
+ he.r = lb.r;
374
+ lb.r.l = he;
375
+ lb.r = he;
376
+ },
377
+
378
+ leftBound: function(p) {
379
+ var he = EdgeList.leftEnd;
380
+ do {
381
+ he = he.r;
382
+ } while (he != EdgeList.rightEnd && Geom.rightOf(he, p));
383
+ he = he.l;
384
+ return he;
385
+ },
386
+
387
+ del: function(he) {
388
+ he.l.r = he.r;
389
+ he.r.l = he.l;
390
+ he.edge = null;
391
+ },
392
+
393
+ right: function(he) {
394
+ return he.r;
395
+ },
396
+
397
+ left: function(he) {
398
+ return he.l;
399
+ },
400
+
401
+ leftRegion: function(he) {
402
+ return he.edge == null
403
+ ? Sites.bottomSite
404
+ : he.edge.region[he.side];
405
+ },
406
+
407
+ rightRegion: function(he) {
408
+ return he.edge == null
409
+ ? Sites.bottomSite
410
+ : he.edge.region[d3_voronoi_opposite[he.side]];
411
+ }
412
+ };
413
+
414
+ var Geom = {
415
+
416
+ bisect: function(s1, s2) {
417
+ var newEdge = {
418
+ region: {"l": s1, "r": s2},
419
+ ep: {"l": null, "r": null}
420
+ };
421
+
422
+ var dx = s2.x - s1.x,
423
+ dy = s2.y - s1.y,
424
+ adx = dx > 0 ? dx : -dx,
425
+ ady = dy > 0 ? dy : -dy;
426
+
427
+ newEdge.c = s1.x * dx + s1.y * dy
428
+ + (dx * dx + dy * dy) * .5;
429
+
430
+ if (adx > ady) {
431
+ newEdge.a = 1;
432
+ newEdge.b = dy / dx;
433
+ newEdge.c /= dx;
434
+ } else {
435
+ newEdge.b = 1;
436
+ newEdge.a = dx / dy;
437
+ newEdge.c /= dy;
438
+ }
439
+
440
+ return newEdge;
441
+ },
442
+
443
+ intersect: function(el1, el2) {
444
+ var e1 = el1.edge,
445
+ e2 = el2.edge;
446
+ if (!e1 || !e2 || (e1.region.r == e2.region.r)) {
447
+ return null;
448
+ }
449
+ var d = (e1.a * e2.b) - (e1.b * e2.a);
450
+ if (Math.abs(d) < 1e-10) {
451
+ return null;
452
+ }
453
+ var xint = (e1.c * e2.b - e2.c * e1.b) / d,
454
+ yint = (e2.c * e1.a - e1.c * e2.a) / d,
455
+ e1r = e1.region.r,
456
+ e2r = e2.region.r,
457
+ el,
458
+ e;
459
+ if ((e1r.y < e2r.y) ||
460
+ (e1r.y == e2r.y && e1r.x < e2r.x)) {
461
+ el = el1;
462
+ e = e1;
463
+ } else {
464
+ el = el2;
465
+ e = e2;
466
+ }
467
+ var rightOfSite = (xint >= e.region.r.x);
468
+ if ((rightOfSite && (el.side === "l")) ||
469
+ (!rightOfSite && (el.side === "r"))) {
470
+ return null;
471
+ }
472
+ return {
473
+ x: xint,
474
+ y: yint
475
+ };
476
+ },
477
+
478
+ rightOf: function(he, p) {
479
+ var e = he.edge,
480
+ topsite = e.region.r,
481
+ rightOfSite = (p.x > topsite.x);
482
+
483
+ if (rightOfSite && (he.side === "l")) {
484
+ return 1;
485
+ }
486
+ if (!rightOfSite && (he.side === "r")) {
487
+ return 0;
488
+ }
489
+ if (e.a === 1) {
490
+ var dyp = p.y - topsite.y,
491
+ dxp = p.x - topsite.x,
492
+ fast = 0,
493
+ above = 0;
494
+
495
+ if ((!rightOfSite && (e.b < 0)) ||
496
+ (rightOfSite && (e.b >= 0))) {
497
+ above = fast = (dyp >= e.b * dxp);
498
+ } else {
499
+ above = ((p.x + p.y * e.b) > e.c);
500
+ if (e.b < 0) {
501
+ above = !above;
502
+ }
503
+ if (!above) {
504
+ fast = 1;
505
+ }
506
+ }
507
+ if (!fast) {
508
+ var dxs = topsite.x - e.region.l.x;
509
+ above = (e.b * (dxp * dxp - dyp * dyp)) <
510
+ (dxs * dyp * (1 + 2 * dxp / dxs + e.b * e.b));
511
+
512
+ if (e.b < 0) {
513
+ above = !above;
514
+ }
515
+ }
516
+ } else /* e.b == 1 */ {
517
+ var yl = e.c - e.a * p.x,
518
+ t1 = p.y - yl,
519
+ t2 = p.x - topsite.x,
520
+ t3 = yl - topsite.y;
521
+
522
+ above = (t1 * t1) > (t2 * t2 + t3 * t3);
523
+ }
524
+ return he.side === "l" ? above : !above;
525
+ },
526
+
527
+ endPoint: function(edge, side, site) {
528
+ edge.ep[side] = site;
529
+ if (!edge.ep[d3_voronoi_opposite[side]]) return;
530
+ callback(edge);
531
+ },
532
+
533
+ distance: function(s, t) {
534
+ var dx = s.x - t.x,
535
+ dy = s.y - t.y;
536
+ return Math.sqrt(dx * dx + dy * dy);
537
+ }
538
+ };
539
+
540
+ var EventQueue = {
541
+ list: [],
542
+
543
+ insert: function(he, site, offset) {
544
+ he.vertex = site;
545
+ he.ystar = site.y + offset;
546
+ for (var i=0, list=EventQueue.list, l=list.length; i<l; i++) {
547
+ var next = list[i];
548
+ if (he.ystar > next.ystar ||
549
+ (he.ystar == next.ystar &&
550
+ site.x > next.vertex.x)) {
551
+ continue;
552
+ } else {
553
+ break;
554
+ }
555
+ }
556
+ list.splice(i, 0, he);
557
+ },
558
+
559
+ del: function(he) {
560
+ for (var i=0, ls=EventQueue.list, l=ls.length; i<l && (ls[i] != he); ++i) {}
561
+ ls.splice(i, 1);
562
+ },
563
+
564
+ empty: function() { return EventQueue.list.length === 0; },
565
+
566
+ nextEvent: function(he) {
567
+ for (var i=0, ls=EventQueue.list, l=ls.length; i<l; ++i) {
568
+ if (ls[i] == he) return ls[i+1];
569
+ }
570
+ return null;
571
+ },
572
+
573
+ min: function() {
574
+ var elem = EventQueue.list[0];
575
+ return {
576
+ x: elem.vertex.x,
577
+ y: elem.ystar
578
+ };
579
+ },
580
+
581
+ extractMin: function() {
582
+ return EventQueue.list.shift();
583
+ }
584
+ };
585
+
586
+ EdgeList.init();
587
+ Sites.bottomSite = Sites.list.shift();
588
+
589
+ var newSite = Sites.list.shift(), newIntStar;
590
+ var lbnd, rbnd, llbnd, rrbnd, bisector;
591
+ var bot, top, temp, p, v;
592
+ var e, pm;
593
+
594
+ while (true) {
595
+ if (!EventQueue.empty()) {
596
+ newIntStar = EventQueue.min();
597
+ }
598
+ if (newSite && (EventQueue.empty()
599
+ || newSite.y < newIntStar.y
600
+ || (newSite.y == newIntStar.y
601
+ && newSite.x < newIntStar.x))) { //new site is smallest
602
+ lbnd = EdgeList.leftBound(newSite);
603
+ rbnd = EdgeList.right(lbnd);
604
+ bot = EdgeList.rightRegion(lbnd);
605
+ e = Geom.bisect(bot, newSite);
606
+ bisector = EdgeList.createHalfEdge(e, "l");
607
+ EdgeList.insert(lbnd, bisector);
608
+ p = Geom.intersect(lbnd, bisector);
609
+ if (p) {
610
+ EventQueue.del(lbnd);
611
+ EventQueue.insert(lbnd, p, Geom.distance(p, newSite));
612
+ }
613
+ lbnd = bisector;
614
+ bisector = EdgeList.createHalfEdge(e, "r");
615
+ EdgeList.insert(lbnd, bisector);
616
+ p = Geom.intersect(bisector, rbnd);
617
+ if (p) {
618
+ EventQueue.insert(bisector, p, Geom.distance(p, newSite));
619
+ }
620
+ newSite = Sites.list.shift();
621
+ } else if (!EventQueue.empty()) { //intersection is smallest
622
+ lbnd = EventQueue.extractMin();
623
+ llbnd = EdgeList.left(lbnd);
624
+ rbnd = EdgeList.right(lbnd);
625
+ rrbnd = EdgeList.right(rbnd);
626
+ bot = EdgeList.leftRegion(lbnd);
627
+ top = EdgeList.rightRegion(rbnd);
628
+ v = lbnd.vertex;
629
+ Geom.endPoint(lbnd.edge, lbnd.side, v);
630
+ Geom.endPoint(rbnd.edge, rbnd.side, v);
631
+ EdgeList.del(lbnd);
632
+ EventQueue.del(rbnd);
633
+ EdgeList.del(rbnd);
634
+ pm = "l";
635
+ if (bot.y > top.y) {
636
+ temp = bot;
637
+ bot = top;
638
+ top = temp;
639
+ pm = "r";
640
+ }
641
+ e = Geom.bisect(bot, top);
642
+ bisector = EdgeList.createHalfEdge(e, pm);
643
+ EdgeList.insert(llbnd, bisector);
644
+ Geom.endPoint(e, d3_voronoi_opposite[pm], v);
645
+ p = Geom.intersect(llbnd, bisector);
646
+ if (p) {
647
+ EventQueue.del(llbnd);
648
+ EventQueue.insert(llbnd, p, Geom.distance(p, bot));
649
+ }
650
+ p = Geom.intersect(bisector, rrbnd);
651
+ if (p) {
652
+ EventQueue.insert(bisector, p, Geom.distance(p, bot));
653
+ }
654
+ } else {
655
+ break;
656
+ }
657
+ }//end while
658
+
659
+ for (lbnd = EdgeList.right(EdgeList.leftEnd);
660
+ lbnd != EdgeList.rightEnd;
661
+ lbnd = EdgeList.right(lbnd)) {
662
+ callback(lbnd.edge);
663
+ }
664
+ }
665
+ /**
666
+ * @param vertices [[x1, y1], [x2, y2], …]
667
+ * @returns triangles [[[x1, y1], [x2, y2], [x3, y3]], …]
668
+ */
669
+ d3.geom.delaunay = function(vertices) {
670
+ var edges = vertices.map(function() { return []; }),
671
+ triangles = [];
672
+
673
+ // Use the Voronoi tessellation to determine Delaunay edges.
674
+ d3_voronoi_tessellate(vertices, function(e) {
675
+ edges[e.region.l.index].push(vertices[e.region.r.index]);
676
+ });
677
+
678
+ // Reconnect the edges into counterclockwise triangles.
679
+ edges.forEach(function(edge, i) {
680
+ var v = vertices[i],
681
+ cx = v[0],
682
+ cy = v[1];
683
+ edge.forEach(function(v) {
684
+ v.angle = Math.atan2(v[0] - cx, v[1] - cy);
685
+ });
686
+ edge.sort(function(a, b) {
687
+ return a.angle - b.angle;
688
+ });
689
+ for (var j = 0, m = edge.length - 1; j < m; j++) {
690
+ triangles.push([v, edge[j], edge[j + 1]]);
691
+ }
692
+ });
693
+
694
+ return triangles;
695
+ };
696
+ // Constructs a new quadtree for the specified array of points. A quadtree is a
697
+ // two-dimensional recursive spatial subdivision. This implementation uses
698
+ // square partitions, dividing each square into four equally-sized squares. Each
699
+ // point exists in a unique node; if multiple points are in the same position,
700
+ // some points may be stored on internal nodes rather than leaf nodes. Quadtrees
701
+ // can be used to accelerate various spatial operations, such as the Barnes-Hut
702
+ // approximation for computing n-body forces, or collision detection.
703
+ d3.geom.quadtree = function(points, x1, y1, x2, y2) {
704
+ var p,
705
+ i = -1,
706
+ n = points.length;
707
+
708
+ // Type conversion for deprecated API.
709
+ if (n && isNaN(points[0].x)) points = points.map(d3_geom_quadtreePoint);
710
+
711
+ // Allow bounds to be specified explicitly.
712
+ if (arguments.length < 5) {
713
+ if (arguments.length === 3) {
714
+ y2 = x2 = y1;
715
+ y1 = x1;
716
+ } else {
717
+ x1 = y1 = Infinity;
718
+ x2 = y2 = -Infinity;
719
+
720
+ // Compute bounds.
721
+ while (++i < n) {
722
+ p = points[i];
723
+ if (p.x < x1) x1 = p.x;
724
+ if (p.y < y1) y1 = p.y;
725
+ if (p.x > x2) x2 = p.x;
726
+ if (p.y > y2) y2 = p.y;
727
+ }
728
+
729
+ // Squarify the bounds.
730
+ var dx = x2 - x1,
731
+ dy = y2 - y1;
732
+ if (dx > dy) y2 = y1 + dx;
733
+ else x2 = x1 + dy;
734
+ }
735
+ }
736
+
737
+ // Recursively inserts the specified point p at the node n or one of its
738
+ // descendants. The bounds are defined by [x1, x2] and [y1, y2].
739
+ function insert(n, p, x1, y1, x2, y2) {
740
+ if (isNaN(p.x) || isNaN(p.y)) return; // ignore invalid points
741
+ if (n.leaf) {
742
+ var v = n.point;
743
+ if (v) {
744
+ // If the point at this leaf node is at the same position as the new
745
+ // point we are adding, we leave the point associated with the
746
+ // internal node while adding the new point to a child node. This
747
+ // avoids infinite recursion.
748
+ if ((Math.abs(v.x - p.x) + Math.abs(v.y - p.y)) < .01) {
749
+ insertChild(n, p, x1, y1, x2, y2);
750
+ } else {
751
+ n.point = null;
752
+ insertChild(n, v, x1, y1, x2, y2);
753
+ insertChild(n, p, x1, y1, x2, y2);
754
+ }
755
+ } else {
756
+ n.point = p;
757
+ }
758
+ } else {
759
+ insertChild(n, p, x1, y1, x2, y2);
760
+ }
761
+ }
762
+
763
+ // Recursively inserts the specified point p into a descendant of node n. The
764
+ // bounds are defined by [x1, x2] and [y1, y2].
765
+ function insertChild(n, p, x1, y1, x2, y2) {
766
+ // Compute the split point, and the quadrant in which to insert p.
767
+ var sx = (x1 + x2) * .5,
768
+ sy = (y1 + y2) * .5,
769
+ right = p.x >= sx,
770
+ bottom = p.y >= sy,
771
+ i = (bottom << 1) + right;
772
+
773
+ // Recursively insert into the child node.
774
+ n.leaf = false;
775
+ n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
776
+
777
+ // Update the bounds as we recurse.
778
+ if (right) x1 = sx; else x2 = sx;
779
+ if (bottom) y1 = sy; else y2 = sy;
780
+ insert(n, p, x1, y1, x2, y2);
781
+ }
782
+
783
+ // Create the root node.
784
+ var root = d3_geom_quadtreeNode();
785
+
786
+ root.add = function(p) {
787
+ insert(root, p, x1, y1, x2, y2);
788
+ };
789
+
790
+ root.visit = function(f) {
791
+ d3_geom_quadtreeVisit(f, root, x1, y1, x2, y2);
792
+ };
793
+
794
+ // Insert all points.
795
+ points.forEach(root.add);
796
+ return root;
797
+ };
798
+
799
+ function d3_geom_quadtreeNode() {
800
+ return {
801
+ leaf: true,
802
+ nodes: [],
803
+ point: null
804
+ };
805
+ }
806
+
807
+ function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
808
+ if (!f(node, x1, y1, x2, y2)) {
809
+ var sx = (x1 + x2) * .5,
810
+ sy = (y1 + y2) * .5,
811
+ children = node.nodes;
812
+ if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
813
+ if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
814
+ if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
815
+ if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
816
+ }
817
+ }
818
+
819
+ function d3_geom_quadtreePoint(p) {
820
+ return {
821
+ x: p[0],
822
+ y: p[1]
823
+ };
824
+ }
825
+ })();