Skip to content
Browse files

Consolidate everything into d3.v2.js.

Rather than producing separate files for each module, the default build now
produces a single file. This should encourage better page-load performance as
the files were relatively small. Also, it's easier to deal with only one file
rather than many, especially if you're not quite sure what the dependencies are.
You may still create minimized builds, if you don't want every feature.

This commit also demotes the chart components to the examples directory, rather
than keeping them as part of the core library. As always, D3 is not a charting
library, and these were ever only intended to serve as examples.
  • Loading branch information...
1 parent 230d8e9 commit 3081dd45efe27067e7b1f9677a6a2f1d894b651f @mbostock committed
Showing with 5,612 additions and 6,901 deletions.
  1. +16 −48 Makefile
  2. +0 −984 d3.chart.js
  3. +0 −1 d3.chart.min.js
  4. +0 −92 d3.csv.js
  5. +0 −1 d3.csv.min.js
  6. +0 −938 d3.geo.js
  7. +0 −1 d3.geo.min.js
  8. +0 −835 d3.geom.js
  9. +0 −1 d3.geom.min.js
  10. +0 −1,882 d3.layout.js
  11. +0 −1 d3.layout.min.js
  12. +0 −2 d3.min.js
  13. +0 −726 d3.time.js
  14. +0 −1 d3.time.min.js
  15. +4,468 −0 d3.js → d3.v2.js
  16. +4 −0 d3.v2.min.js
  17. +1 −2 examples/albers/albers.html
  18. +1 −1 examples/area/area-radial.html
  19. +1 −1 examples/area/area.html
  20. +1 −1 examples/axis/axis-alternating.html
  21. +1 −1 examples/axis/axis-ggplot2.html
  22. +1 −3 examples/axis/axis-multiples.html
  23. +1 −2 examples/axis/axis-orientations.html
  24. +1 −3 examples/axis/axis-transition.html
  25. +1 −2 examples/azimuthal/azimuthal.html
  26. +1 −2 examples/bar/bar-hierarchy.html
  27. +1 −2 examples/bar/bar.html
  28. +1 −2 examples/bonne/bonne.html
  29. +1 −3 examples/box/box.html
  30. +299 −1 examples/box/box.js
  31. +1 −1 examples/brush/brush-ordinal.html
  32. +1 −1 examples/brush/brush-x.html
  33. +1 −1 examples/brush/brush-y.html
  34. +1 −1 examples/brush/brush.html
  35. +1 −2 examples/bubble/bubble.html
  36. +1 −2 examples/bullet/bullet.html
  37. +239 −1 examples/bullet/bullet.js
  38. +1 −2 examples/bundle/bundle-radial.html
  39. +1 −2 examples/bundle/bundle-treemap.html
  40. +1 −3 examples/calendar/dji-area.html
  41. +1 −3 examples/calendar/dji.html
  42. +1 −3 examples/calendar/vix.html
  43. +1 −3 examples/cartogram/cartogram.html
  44. +1 −4 examples/cartogram/demers.html
  45. +1 −4 examples/cartogram/dorling.html
  46. +1 −2 examples/chord/chord-flare.html
  47. +1 −2 examples/chord/chord.html
  48. +1 −4 examples/choropleth/choropleth-area.html
  49. +1 −2 examples/choropleth/choropleth-bounds.html
  50. +1 −2 examples/choropleth/choropleth.html
  51. +1 −2 examples/clock/clock.html
  52. +1 −2 examples/cluster/cluster-radial.html
  53. +1 −2 examples/cluster/cluster.html
  54. +1 −2 examples/contour/contour.html
  55. +1 −4 examples/crimea/crimea-stacked-area.html
  56. +1 −4 examples/crimea/crimea-stacked-bar.html
  57. +1 −1 examples/custom/custom.html
  58. +1 −2 examples/delaunay/delaunay.html
  59. +1 −2 examples/donut/donut.html
  60. +1 −1 examples/dot/dot.html
  61. +1 −1 examples/drag/drag.html
  62. +1 −3 examples/force/force-bounds.html
  63. +1 −3 examples/force/force-cluster.html
  64. +1 −3 examples/force/force-collapsible.html
  65. +1 −3 examples/force/force-dynamic.html
  66. +1 −4 examples/force/force-map.html
  67. +1 −3 examples/force/force-multi-foci.html
  68. +1 −3 examples/force/force.html
  69. +1 −2 examples/great-arc/great-arc.html
  70. +1 −1 examples/hello-world/hello-data-key.html
  71. +1 −1 examples/hello-world/hello-data-nested-key.html
  72. +1 −1 examples/hello-world/hello-data-nested.html
  73. +1 −1 examples/hello-world/hello-data.html
  74. +1 −1 examples/hello-world/hello-event.html
  75. +1 −1 examples/hello-world/hello-node-key.html
  76. +1 −1 examples/hello-world/hello-order.html
  77. +1 −1 examples/hello-world/hello-sort.html
  78. +1 −1 examples/hello-world/hello-transform.html
  79. +1 −1 examples/hello-world/hello-transition-undefined.html
  80. +1 −1 examples/hello-world/hello-transition.html
  81. +1 −1 examples/hello-world/hello-webkit-transition.html
  82. +1 −1 examples/hello-world/select-enter-add.html
  83. +1 −1 examples/hello-world/selectAll-enter-add.html
  84. +1 −2 examples/histogram/histogram.html
  85. +1 −2 examples/horizon/horizon.html
  86. +204 −1 examples/horizon/horizon.js
  87. +1 −2 examples/hull/hull.html
  88. +1 −2 examples/kde/kde.html
  89. +1 −1 examples/line/line.html
  90. +1 −2 examples/marimekko/marimekko.html
  91. +1 −3 examples/marker/marker.html
  92. +1 −2 examples/mercator/mercator.html
  93. +1 −1 examples/moire/moire.html
  94. +0 −2 examples/node-canvas/us-counties.js
  95. +1 −2 examples/pack/pack.html
  96. +1 −2 examples/parallel/parallel.html
  97. +1 −2 examples/partition/partition-icicle-zoom.html
  98. +1 −2 examples/partition/partition-icicle.html
  99. +1 −2 examples/partition/partition-sunburst-zoom.html
  100. +1 −2 examples/partition/partition-sunburst.html
  101. +1 −2 examples/pie/pie-transition.html
  102. +1 −2 examples/pie/pie.html
  103. +1 −2 examples/population/population.html
  104. +1 −2 examples/qq/qq.html
  105. +248 −4 examples/qq/qq.js
  106. +1 −2 examples/quadtree/quadtree.html
  107. +19 −6 examples/rollup/rollup.html
  108. +1 −6 examples/showreel/showreel.html
  109. +1 −1 examples/sizzle/sizzle.html
  110. +1 −1 examples/sort/sort.html
  111. +1 −1 examples/spline/spline.html
  112. +1 −1 examples/splom/splom.html
  113. +1 −2 examples/stream/stack.html
  114. +1 −2 examples/stream/stream.html
  115. +1 −1 examples/superformula/dot.html
  116. +1 −1 examples/superformula/explorer.html
  117. +1 −1 examples/superformula/superformula.html
  118. +1 −2 examples/symbol-map/symbol-map.html
  119. +1 −1 examples/touch/touch.html
  120. +1 −1 examples/transform/test.html
  121. +1 −1 examples/transform/transform.html
  122. +1 −2 examples/tree/tree-dynamic.html
  123. +1 −2 examples/tree/tree-interactive.html
  124. +1 −2 examples/tree/tree-radial.html
  125. +1 −2 examples/tree/tree.html
  126. +1 −2 examples/treemap/treemap-svg.html
  127. +1 −2 examples/treemap/treemap.html
  128. +1 −2 examples/voroboids/voroboids.html
  129. +1 −2 examples/voronoi/voronoi.html
  130. +1 −1 examples/zoom-pan/zoom-pan-transform.html
  131. +1 −1 examples/zoom-pan/zoom-pan.html
  132. +2 −6 examples/zoom/zoom.html
  133. +1 −6 index.js
  134. +0 −297 src/chart/box.js
  135. +0 −237 src/chart/bullet.js
  136. +0 −1 src/chart/chart.js
  137. +0 −203 src/chart/horizon.js
  138. +0 −245 src/chart/qq.js
  139. +1 −2 src/package.js
  140. +0 −1 test/core/ascending-test.js
  141. +0 −1 test/core/bisect-test.js
  142. +0 −1 test/core/descending-test.js
  143. +0 −1 test/core/dispatch-test.js
  144. +0 −1 test/core/ease-test.js
  145. +0 −1 test/core/entries-test.js
  146. +0 −1 test/core/extent-test.js
  147. +0 −1 test/core/first-test.js
  148. +0 −1 test/core/format-test.js
  149. +0 −1 test/core/formatPrefix-test.js
  150. +0 −1 test/core/functor-test.js
  151. +0 −1 test/core/hsl-test.js
  152. +0 −1 test/core/html-test.js
  153. +0 −1 test/core/interpolate-test.js
  154. +0 −1 test/core/json-test.js
  155. +0 −1 test/core/keys-test.js
  156. +0 −1 test/core/last-test.js
  157. +0 −1 test/core/max-test.js
  158. +0 −1 test/core/mean-test.js
  159. +0 −1 test/core/median-test.js
  160. +0 −1 test/core/merge-test.js
  161. +0 −1 test/core/min-test.js
  162. +0 −1 test/core/nest-test.js
  163. +0 −1 test/core/ns-test.js
  164. +0 −1 test/core/permute-test.js
  165. +0 −1 test/core/quantile-test.js
  166. +0 −1 test/core/range-test.js
  167. +0 −1 test/core/rebind-test.js
  168. +0 −1 test/core/requote-test.js
  169. +0 −1 test/core/rgb-test.js
  170. +0 −1 test/core/round-test.js
  171. +0 −1 test/core/select-test.js
  172. +0 −1 test/core/selectAll-test.js
  173. +0 −1 test/core/selection-append-test.js
  174. +0 −1 test/core/selection-attr-test.js
  175. +0 −1 test/core/selection-call-test.js
  176. +0 −1 test/core/selection-classed-test.js
  177. +0 −1 test/core/selection-data-test.js
  178. +0 −1 test/core/selection-each-test.js
  179. +0 −1 test/core/selection-empty-test.js
  180. +0 −1 test/core/selection-filter-test.js
  181. +0 −1 test/core/selection-html-test.js
  182. +0 −1 test/core/selection-insert-test.js
  183. +0 −1 test/core/selection-map-test.js
  184. +0 −1 test/core/selection-node-test.js
  185. +0 −1 test/core/selection-on-test.js
  186. +0 −1 test/core/selection-order-test.js
  187. +0 −1 test/core/selection-property-test.js
  188. +0 −1 test/core/selection-remove-test.js
  189. +0 −1 test/core/selection-select-test.js
  190. +0 −1 test/core/selection-selectAll-test.js
  191. +0 −1 test/core/selection-sort-test.js
  192. +0 −1 test/core/selection-style-test.js
  193. +0 −1 test/core/selection-test.js
  194. +0 −1 test/core/selection-text-test.js
  195. +0 −1 test/core/split-test.js
  196. +0 −1 test/core/sum-test.js
  197. +0 −1 test/core/text-test.js
  198. +0 −1 test/core/timer-test.js
  199. +0 −1 test/core/transition-test-attr.js
  200. +0 −1 test/core/transition-test-attrTween.js
  201. +0 −1 test/core/transition-test-call.js
  202. +0 −1 test/core/transition-test-delay.js
  203. +0 −1 test/core/transition-test-duration.js
  204. +0 −1 test/core/transition-test-each.js
  205. +0 −1 test/core/transition-test-id.js
  206. +0 −1 test/core/transition-test-remove.js
  207. +0 −1 test/core/transition-test-select.js
  208. +0 −1 test/core/transition-test-selectAll.js
  209. +0 −1 test/core/transition-test-style.js
  210. +0 −1 test/core/transition-test-styleTween.js
  211. +0 −1 test/core/transition-test-text.js
  212. +0 −1 test/core/transition-test-time.js
  213. +0 −1 test/core/transition-test-transition.js
  214. +0 −1 test/core/transition-test-tween.js
  215. +0 −1 test/core/transition-test.js
  216. +0 −1 test/core/transpose-test.js
  217. +0 −1 test/core/values-test.js
  218. +0 −1 test/core/version-test.js
  219. +0 −1 test/core/xhr-test.js
  220. +0 −1 test/core/xml-test.js
  221. +0 −1 test/core/zip-test.js
  222. +0 −2 test/csv/csv-test.js
  223. +0 −2 test/csv/format-test.js
  224. +0 −2 test/csv/parse-test.js
  225. +2 −0 test/env.js
  226. +0 −2 test/geo/albers-test.js
  227. +0 −2 test/geo/azimuthal-test.js
  228. +0 −2 test/geo/bonne-test.js
  229. +0 −2 test/geo/equirectangular-test.js
  230. +0 −2 test/geo/greatArc-test.js
  231. +0 −2 test/geo/mercator-test.js
  232. +0 −2 test/geo/path-test.js
  233. +0 −2 test/geom/polygon-test.js
  234. +0 −2 test/layout/cluster-test.js
  235. +0 −2 test/layout/hierarchy-test.js
  236. +0 −2 test/layout/histogram-test.js
  237. +0 −2 test/layout/pack-test.js
  238. +0 −2 test/layout/partition-test.js
  239. +0 −2 test/layout/pie-test.js
  240. +0 −2 test/layout/tree-test.js
  241. +0 −2 test/layout/treemap-test.js
  242. +0 −1 test/scale/category-test.js
  243. +0 −1 test/scale/linear-test.js
  244. +0 −1 test/scale/log-test.js
  245. +0 −1 test/scale/ordinal-test.js
  246. +0 −1 test/scale/pow-test.js
  247. +0 −1 test/scale/quantile-test.js
  248. +0 −1 test/scale/quantize-test.js
  249. +0 −1 test/scale/sqrt-test.js
  250. +0 −1 test/svg/arc-test.js
  251. +0 −1 test/svg/area-radial-test.js
  252. +0 −1 test/svg/area-test.js
  253. +0 −1 test/svg/axis-test.js
  254. +0 −1 test/svg/line-radial-test.js
  255. +0 −1 test/svg/line-test.js
  256. +0 −1 test/svg/symbol-test.js
  257. +0 −2 test/time/day-test.js
  258. +0 −2 test/time/days-test.js
  259. +0 −2 test/time/format-test.js
  260. +0 −2 test/time/hour-test.js
  261. +0 −2 test/time/hours-test.js
  262. +0 −2 test/time/minute-test.js
  263. +0 −2 test/time/minutes-test.js
  264. +0 −2 test/time/month-test.js
  265. +0 −2 test/time/months-test.js
  266. +0 −2 test/time/scale-test.js
  267. +0 −2 test/time/second-test.js
  268. +0 −2 test/time/seconds-test.js
  269. +0 −2 test/time/week-test.js
  270. +0 −2 test/time/weeks-test.js
  271. +0 −2 test/time/year-test.js
  272. +0 −2 test/time/years-test.js
View
64 Makefile
@@ -4,37 +4,24 @@ NODE_PATH ?= ./node_modules
JS_COMPILER = $(NODE_PATH)/uglify-js/bin/uglifyjs
JS_TESTER = $(NODE_PATH)/vows/bin/vows
-JS_FILES = \
- d3.js \
- d3.chart.js \
- d3.layout.js \
- d3.csv.js \
- d3.geo.js \
- d3.geom.js \
- d3.time.js
-
all: \
- $(JS_FILES) \
- $(JS_FILES:.js=.min.js) \
+ d3.v2.js \
+ d3.v2.min.js \
package.json
# Modify this rule to build your own custom release.
-# Run `make d3.custom.min.js` to produce the minified version.
-
-d3.custom.js: \
- d3.js \
- d3.layout.js \
- d3.csv.js \
- d3.geo.js \
- d3.geom.js \
- d3.time.js
-.INTERMEDIATE d3.js: \
+.INTERMEDIATE d3.v2.js: \
src/start.js \
d3.core.js \
d3.scale.js \
d3.svg.js \
d3.behavior.js \
+ d3.layout.js \
+ d3.csv.js \
+ d3.geo.js \
+ d3.geom.js \
+ d3.time.js \
src/end.js
d3.core.js: \
@@ -163,17 +150,7 @@ d3.behavior.js: \
src/behavior/drag.js \
src/behavior/zoom.js
-d3.chart.js: \
- src/start.js \
- src/chart/chart.js \
- src/chart/box.js \
- src/chart/bullet.js \
- src/chart/horizon.js \
- src/chart/qq.js \
- src/end.js
-
d3.layout.js: \
- src/start.js \
src/layout/layout.js \
src/layout/bundle.js \
src/layout/chord.js \
@@ -186,11 +163,9 @@ d3.layout.js: \
src/layout/pack.js \
src/layout/cluster.js \
src/layout/tree.js \
- src/layout/treemap.js \
- src/end.js
+ src/layout/treemap.js
d3.geo.js: \
- src/start.js \
src/geo/geo.js \
src/geo/azimuthal.js \
src/geo/albers.js \
@@ -202,18 +177,14 @@ d3.geo.js: \
src/geo/bounds.js \
src/geo/circle.js \
src/geo/greatArc.js \
- src/geo/greatCircle.js \
- src/end.js
+ src/geo/greatCircle.js
d3.csv.js: \
- src/start.js \
src/csv/csv.js \
src/csv/parse.js \
- src/csv/format.js \
- src/end.js
+ src/csv/format.js
d3.time.js: \
- src/start.js \
src/time/time.js \
src/time/format.js \
src/time/format-utc.js \
@@ -234,19 +205,16 @@ d3.time.js: \
src/time/year.js \
src/time/years.js \
src/time/scale.js \
- src/time/scale-utc.js \
- src/end.js
+ src/time/scale-utc.js
d3.geom.js: \
- src/start.js \
src/geom/geom.js \
src/geom/contour.js \
src/geom/hull.js \
src/geom/polygon.js \
src/geom/voronoi.js \
src/geom/delaunay.js \
- src/geom/quadtree.js \
- src/end.js
+ src/geom/quadtree.js
test: all
@$(JS_TESTER)
@@ -255,7 +223,7 @@ test: all
@rm -f $@
$(JS_COMPILER) < $< > $@
-d3.%: Makefile
+d3%.js: Makefile
@rm -f $@
cat $(filter %.js,$^) > $@
@chmod a-w $@
@@ -264,10 +232,10 @@ install:
mkdir -p node_modules
npm install
-package.json: d3.js src/package.js
+package.json: d3.v2.js src/package.js
@rm -f $@
node src/package.js > $@
@chmod a-w $@
clean:
- rm -f d3*.js
+ rm -f d3*.js package.json
View
984 d3.chart.js
@@ -1,984 +0,0 @@
-(function(){d3.chart = {};
-// Inspired by http://informationandvisualization.de/blog/box-plot
-d3.chart.box = function() {
- var width = 1,
- height = 1,
- duration = 0,
- domain = null,
- value = Number,
- whiskers = d3_chart_boxWhiskers,
- quartiles = d3_chart_boxQuartiles,
- tickFormat = null;
-
- // For each small multiple…
- function box(g) {
- g.each(function(d, i) {
- d = d.map(value).sort(d3.ascending);
- var g = d3.select(this),
- n = d.length,
- min = d[0],
- max = d[n - 1];
-
- // Compute quartiles. Must return exactly 3 elements.
- var quartileData = d.quartiles = quartiles(d);
-
- // Compute whiskers. Must return exactly 2 elements, or null.
- var whiskerIndices = whiskers && whiskers.call(this, d, i),
- whiskerData = whiskerIndices && whiskerIndices.map(function(i) { return d[i]; });
-
- // Compute outliers. If no whiskers are specified, all data are "outliers".
- // We compute the outliers as indices, so that we can join across transitions!
- var outlierIndices = whiskerIndices
- ? d3.range(0, whiskerIndices[0]).concat(d3.range(whiskerIndices[1] + 1, n))
- : d3.range(n);
-
- // Compute the new x-scale.
- var x1 = d3.scale.linear()
- .domain(domain && domain.call(this, d, i) || [min, max])
- .range([height, 0]);
-
- // Retrieve the old x-scale, if this is an update.
- var x0 = this.__chart__ || d3.scale.linear()
- .domain([0, Infinity])
- .range(x1.range());
-
- // Stash the new scale.
- this.__chart__ = x1;
-
- // Note: the box, median, and box tick elements are fixed in number,
- // so we only have to handle enter and update. In contrast, the outliers
- // and other elements are variable, so we need to exit them! Variable
- // elements also fade in and out.
-
- // Update center line: the vertical line spanning the whiskers.
- var center = g.selectAll("line.center")
- .data(whiskerData ? [whiskerData] : []);
-
- center.enter().insert("svg:line", "rect")
- .attr("class", "center")
- .attr("x1", width / 2)
- .attr("y1", function(d) { return x0(d[0]); })
- .attr("x2", width / 2)
- .attr("y2", function(d) { return x0(d[1]); })
- .style("opacity", 1e-6)
- .transition()
- .duration(duration)
- .style("opacity", 1)
- .attr("y1", function(d) { return x1(d[0]); })
- .attr("y2", function(d) { return x1(d[1]); });
-
- center.transition()
- .duration(duration)
- .style("opacity", 1)
- .attr("y1", function(d) { return x1(d[0]); })
- .attr("y2", function(d) { return x1(d[1]); });
-
- center.exit().transition()
- .duration(duration)
- .style("opacity", 1e-6)
- .attr("y1", function(d) { return x1(d[0]); })
- .attr("y2", function(d) { return x1(d[1]); })
- .remove();
-
- // Update innerquartile box.
- var box = g.selectAll("rect.box")
- .data([quartileData]);
-
- box.enter().append("svg:rect")
- .attr("class", "box")
- .attr("x", 0)
- .attr("y", function(d) { return x0(d[2]); })
- .attr("width", width)
- .attr("height", function(d) { return x0(d[0]) - x0(d[2]); })
- .transition()
- .duration(duration)
- .attr("y", function(d) { return x1(d[2]); })
- .attr("height", function(d) { return x1(d[0]) - x1(d[2]); });
-
- box.transition()
- .duration(duration)
- .attr("y", function(d) { return x1(d[2]); })
- .attr("height", function(d) { return x1(d[0]) - x1(d[2]); });
-
- // Update median line.
- var medianLine = g.selectAll("line.median")
- .data([quartileData[1]]);
-
- medianLine.enter().append("svg:line")
- .attr("class", "median")
- .attr("x1", 0)
- .attr("y1", x0)
- .attr("x2", width)
- .attr("y2", x0)
- .transition()
- .duration(duration)
- .attr("y1", x1)
- .attr("y2", x1);
-
- medianLine.transition()
- .duration(duration)
- .attr("y1", x1)
- .attr("y2", x1);
-
- // Update whiskers.
- var whisker = g.selectAll("line.whisker")
- .data(whiskerData || []);
-
- whisker.enter().insert("svg:line", "circle, text")
- .attr("class", "whisker")
- .attr("x1", 0)
- .attr("y1", x0)
- .attr("x2", width)
- .attr("y2", x0)
- .style("opacity", 1e-6)
- .transition()
- .duration(duration)
- .attr("y1", x1)
- .attr("y2", x1)
- .style("opacity", 1);
-
- whisker.transition()
- .duration(duration)
- .attr("y1", x1)
- .attr("y2", x1)
- .style("opacity", 1);
-
- whisker.exit().transition()
- .duration(duration)
- .attr("y1", x1)
- .attr("y2", x1)
- .style("opacity", 1e-6)
- .remove();
-
- // Update outliers.
- var outlier = g.selectAll("circle.outlier")
- .data(outlierIndices, Number);
-
- outlier.enter().insert("svg:circle", "text")
- .attr("class", "outlier")
- .attr("r", 5)
- .attr("cx", width / 2)
- .attr("cy", function(i) { return x0(d[i]); })
- .style("opacity", 1e-6)
- .transition()
- .duration(duration)
- .attr("cy", function(i) { return x1(d[i]); })
- .style("opacity", 1);
-
- outlier.transition()
- .duration(duration)
- .attr("cy", function(i) { return x1(d[i]); })
- .style("opacity", 1);
-
- outlier.exit().transition()
- .duration(duration)
- .attr("cy", function(i) { return x1(d[i]); })
- .style("opacity", 1e-6)
- .remove();
-
- // Compute the tick format.
- var format = tickFormat || x1.tickFormat(8);
-
- // Update box ticks.
- var boxTick = g.selectAll("text.box")
- .data(quartileData);
-
- boxTick.enter().append("svg:text")
- .attr("class", "box")
- .attr("dy", ".3em")
- .attr("dx", function(d, i) { return i & 1 ? 6 : -6 })
- .attr("x", function(d, i) { return i & 1 ? width : 0 })
- .attr("y", x0)
- .attr("text-anchor", function(d, i) { return i & 1 ? "start" : "end"; })
- .text(format)
- .transition()
- .duration(duration)
- .attr("y", x1);
-
- boxTick.transition()
- .duration(duration)
- .text(format)
- .attr("y", x1);
-
- // Update whisker ticks. These are handled separately from the box
- // ticks because they may or may not exist, and we want don't want
- // to join box ticks pre-transition with whisker ticks post-.
- var whiskerTick = g.selectAll("text.whisker")
- .data(whiskerData || []);
-
- whiskerTick.enter().append("svg:text")
- .attr("class", "whisker")
- .attr("dy", ".3em")
- .attr("dx", 6)
- .attr("x", width)
- .attr("y", x0)
- .text(format)
- .style("opacity", 1e-6)
- .transition()
- .duration(duration)
- .attr("y", x1)
- .style("opacity", 1);
-
- whiskerTick.transition()
- .duration(duration)
- .text(format)
- .attr("y", x1)
- .style("opacity", 1);
-
- whiskerTick.exit().transition()
- .duration(duration)
- .attr("y", x1)
- .style("opacity", 1e-6)
- .remove();
- });
- d3.timer.flush();
- }
-
- box.width = function(x) {
- if (!arguments.length) return width;
- width = x;
- return box;
- };
-
- box.height = function(x) {
- if (!arguments.length) return height;
- height = x;
- return box;
- };
-
- box.tickFormat = function(x) {
- if (!arguments.length) return tickFormat;
- tickFormat = x;
- return box;
- };
-
- box.duration = function(x) {
- if (!arguments.length) return duration;
- duration = x;
- return box;
- };
-
- box.domain = function(x) {
- if (!arguments.length) return domain;
- domain = x == null ? x : d3.functor(x);
- return box;
- };
-
- box.value = function(x) {
- if (!arguments.length) return value;
- value = x;
- return box;
- };
-
- box.whiskers = function(x) {
- if (!arguments.length) return whiskers;
- whiskers = x;
- return box;
- };
-
- box.quartiles = function(x) {
- if (!arguments.length) return quartiles;
- quartiles = x;
- return box;
- };
-
- return box;
-};
-
-function d3_chart_boxWhiskers(d) {
- return [0, d.length - 1];
-}
-
-function d3_chart_boxQuartiles(d) {
- return [
- d3.quantile(d, .25),
- d3.quantile(d, .5),
- d3.quantile(d, .75)
- ];
-}
-// Chart design based on the recommendations of Stephen Few. Implementation
-// based on the work of Clint Ivy, Jamie Love, and Jason Davies.
-// http://projects.instantcognition.com/protovis/bulletchart/
-d3.chart.bullet = function() {
- var orient = "left", // TODO top & bottom
- reverse = false,
- duration = 0,
- ranges = d3_chart_bulletRanges,
- markers = d3_chart_bulletMarkers,
- measures = d3_chart_bulletMeasures,
- width = 380,
- height = 30,
- tickFormat = null;
-
- // For each small multiple…
- function bullet(g) {
- g.each(function(d, i) {
- var rangez = ranges.call(this, d, i).slice().sort(d3.descending),
- markerz = markers.call(this, d, i).slice().sort(d3.descending),
- measurez = measures.call(this, d, i).slice().sort(d3.descending),
- g = d3.select(this);
-
- // Compute the new x-scale.
- var x1 = d3.scale.linear()
- .domain([0, Math.max(rangez[0], markerz[0], measurez[0])])
- .range(reverse ? [width, 0] : [0, width]);
-
- // Retrieve the old x-scale, if this is an update.
- var x0 = this.__chart__ || d3.scale.linear()
- .domain([0, Infinity])
- .range(x1.range());
-
- // Stash the new scale.
- this.__chart__ = x1;
-
- // Derive width-scales from the x-scales.
- var w0 = d3_chart_bulletWidth(x0),
- w1 = d3_chart_bulletWidth(x1);
-
- // Update the range rects.
- var range = g.selectAll("rect.range")
- .data(rangez);
-
- range.enter().append("svg:rect")
- .attr("class", function(d, i) { return "range s" + i; })
- .attr("width", w0)
- .attr("height", height)
- .attr("x", reverse ? x0 : 0)
- .transition()
- .duration(duration)
- .attr("width", w1)
- .attr("x", reverse ? x1 : 0);
-
- range.transition()
- .duration(duration)
- .attr("x", reverse ? x1 : 0)
- .attr("width", w1)
- .attr("height", height);
-
- // Update the measure rects.
- var measure = g.selectAll("rect.measure")
- .data(measurez);
-
- measure.enter().append("svg:rect")
- .attr("class", function(d, i) { return "measure s" + i; })
- .attr("width", w0)
- .attr("height", height / 3)
- .attr("x", reverse ? x0 : 0)
- .attr("y", height / 3)
- .transition()
- .duration(duration)
- .attr("width", w1)
- .attr("x", reverse ? x1 : 0);
-
- measure.transition()
- .duration(duration)
- .attr("width", w1)
- .attr("height", height / 3)
- .attr("x", reverse ? x1 : 0)
- .attr("y", height / 3);
-
- // Update the marker lines.
- var marker = g.selectAll("line.marker")
- .data(markerz);
-
- marker.enter().append("svg:line")
- .attr("class", "marker")
- .attr("x1", x0)
- .attr("x2", x0)
- .attr("y1", height / 6)
- .attr("y2", height * 5 / 6)
- .transition()
- .duration(duration)
- .attr("x1", x1)
- .attr("x2", x1);
-
- marker.transition()
- .duration(duration)
- .attr("x1", x1)
- .attr("x2", x1)
- .attr("y1", height / 6)
- .attr("y2", height * 5 / 6);
-
- // Compute the tick format.
- var format = tickFormat || x1.tickFormat(8);
-
- // Update the tick groups.
- var tick = g.selectAll("g.tick")
- .data(x1.ticks(8), function(d) {
- return this.textContent || format(d);
- });
-
- // Initialize the ticks with the old scale, x0.
- var tickEnter = tick.enter().append("svg:g")
- .attr("class", "tick")
- .attr("transform", d3_chart_bulletTranslate(x0))
- .style("opacity", 1e-6);
-
- tickEnter.append("svg:line")
- .attr("y1", height)
- .attr("y2", height * 7 / 6);
-
- tickEnter.append("svg:text")
- .attr("text-anchor", "middle")
- .attr("dy", "1em")
- .attr("y", height * 7 / 6)
- .text(format);
-
- // Transition the entering ticks to the new scale, x1.
- tickEnter.transition()
- .duration(duration)
- .attr("transform", d3_chart_bulletTranslate(x1))
- .style("opacity", 1);
-
- // Transition the updating ticks to the new scale, x1.
- var tickUpdate = tick.transition()
- .duration(duration)
- .attr("transform", d3_chart_bulletTranslate(x1))
- .style("opacity", 1);
-
- tickUpdate.select("line")
- .attr("y1", height)
- .attr("y2", height * 7 / 6);
-
- tickUpdate.select("text")
- .attr("y", height * 7 / 6);
-
- // Transition the exiting ticks to the new scale, x1.
- tick.exit().transition()
- .duration(duration)
- .attr("transform", d3_chart_bulletTranslate(x1))
- .style("opacity", 1e-6)
- .remove();
- });
- d3.timer.flush();
- }
-
- // left, right, top, bottom
- bullet.orient = function(x) {
- if (!arguments.length) return orient;
- orient = x;
- reverse = orient == "right" || orient == "bottom";
- return bullet;
- };
-
- // ranges (bad, satisfactory, good)
- bullet.ranges = function(x) {
- if (!arguments.length) return ranges;
- ranges = x;
- return bullet;
- };
-
- // markers (previous, goal)
- bullet.markers = function(x) {
- if (!arguments.length) return markers;
- markers = x;
- return bullet;
- };
-
- // measures (actual, forecast)
- bullet.measures = function(x) {
- if (!arguments.length) return measures;
- measures = x;
- return bullet;
- };
-
- bullet.width = function(x) {
- if (!arguments.length) return width;
- width = x;
- return bullet;
- };
-
- bullet.height = function(x) {
- if (!arguments.length) return height;
- height = x;
- return bullet;
- };
-
- bullet.tickFormat = function(x) {
- if (!arguments.length) return tickFormat;
- tickFormat = x;
- return bullet;
- };
-
- bullet.duration = function(x) {
- if (!arguments.length) return duration;
- duration = x;
- return bullet;
- };
-
- return bullet;
-};
-
-function d3_chart_bulletRanges(d) {
- return d.ranges;
-}
-
-function d3_chart_bulletMarkers(d) {
- return d.markers;
-}
-
-function d3_chart_bulletMeasures(d) {
- return d.measures;
-}
-
-function d3_chart_bulletTranslate(x) {
- return function(d) {
- return "translate(" + x(d) + ",0)";
- };
-}
-
-function d3_chart_bulletWidth(x) {
- var x0 = x(0);
- return function(d) {
- return Math.abs(x(d) - x0);
- };
-}
-// Implements a horizon layout, which is a variation of a single-series
-// area chart where the area is folded into multiple bands. Color is used to
-// encode band, allowing the size of the chart to be reduced significantly
-// without impeding readability. This layout algorithm is based on the work of
-// J. Heer, N. Kong and M. Agrawala in "Sizing the Horizon: The Effects of Chart
-// Size and Layering on the Graphical Perception of Time Series Visualizations",
-// CHI 2009. http://hci.stanford.edu/publications/2009/heer-horizon-chi09.pdf
-d3.chart.horizon = function() {
- var bands = 1, // between 1 and 5, typically
- mode = "offset", // or mirror
- interpolate = "linear", // or basis, monotone, step-before, etc.
- x = d3_chart_horizonX,
- y = d3_chart_horizonY,
- w = 960,
- h = 40,
- duration = 0;
-
- var color = d3.scale.linear()
- .domain([-1, 0, 1])
- .range(["#d62728", "#fff", "#1f77b4"]);
-
- // For each small multiple…
- function horizon(g) {
- g.each(function(d, i) {
- var g = d3.select(this),
- n = 2 * bands + 1,
- xMin = Infinity,
- xMax = -Infinity,
- yMax = -Infinity,
- x0, // old x-scale
- y0, // old y-scale
- id; // unique id for paths
-
- // Compute x- and y-values along with extents.
- var data = d.map(function(d, i) {
- var xv = x.call(this, d, i),
- yv = y.call(this, d, i);
- if (xv < xMin) xMin = xv;
- if (xv > xMax) xMax = xv;
- if (-yv > yMax) yMax = -yv;
- if (yv > yMax) yMax = yv;
- return [xv, yv];
- });
-
- // Compute the new x- and y-scales.
- var x1 = d3.scale.linear().domain([xMin, xMax]).range([0, w]),
- y1 = d3.scale.linear().domain([0, yMax]).range([0, h * bands]);
-
- // Retrieve the old scales, if this is an update.
- if (this.__chart__) {
- x0 = this.__chart__.x;
- y0 = this.__chart__.y;
- id = this.__chart__.id;
- } else {
- x0 = d3.scale.linear().domain([0, Infinity]).range(x1.range());
- y0 = d3.scale.linear().domain([0, Infinity]).range(y1.range());
- id = ++d3_chart_horizonId;
- }
-
- // We'll use a defs to store the area path and the clip path.
- var defs = g.selectAll("defs")
- .data([data]);
-
- var defsEnter = defs.enter().append("svg:defs");
-
- // The clip path is a simple rect.
- defsEnter.append("svg:clipPath")
- .attr("id", "d3_chart_horizon_clip" + id)
- .append("svg:rect")
- .attr("width", w)
- .attr("height", h);
-
- defs.select("rect").transition()
- .duration(duration)
- .attr("width", w)
- .attr("height", h);
-
- // The area path is rendered with our resuable d3.svg.area.
- defsEnter.append("svg:path")
- .attr("id", "d3_chart_horizon_path" + id)
- .attr("d", d3_chart_horizonArea
- .interpolate(interpolate)
- .x(function(d) { return x0(d[0]); })
- .y0(h * bands)
- .y1(function(d) { return h * bands - y0(d[1]); }))
- .transition()
- .duration(duration)
- .attr("d", d3_chart_horizonArea
- .x(function(d) { return x1(d[0]); })
- .y1(function(d) { return h * bands - y1(d[1]); }));
-
- defs.select("path").transition()
- .duration(duration)
- .attr("d", d3_chart_horizonArea);
-
- // We'll use a container to clip all horizon layers at once.
- g.selectAll("g")
- .data([null])
- .enter().append("svg:g")
- .attr("clip-path", "url(#d3_chart_horizon_clip" + id + ")");
-
- // Define the transform function based on the mode.
- var transform = mode == "offset"
- ? function(d) { return "translate(0," + (d + (d < 0) - bands) * h + ")"; }
- : function(d) { return (d < 0 ? "scale(1,-1)" : "") + "translate(0," + (d - bands) * h + ")"; };
-
- // Instantiate each copy of the path with different transforms.
- var u = g.select("g").selectAll("use")
- .data(d3.range(-1, -bands - 1, -1).concat(d3.range(1, bands + 1)), Number);
-
- // TODO don't fudge the enter transition
- u.enter().append("svg:use")
- .attr("xlink:href", "#d3_chart_horizon_path" + id)
- .attr("transform", function(d) { return transform(d + (d > 0 ? 1 : -1)); })
- .style("fill", color)
- .transition()
- .duration(duration)
- .attr("transform", transform);
-
- u.transition()
- .duration(duration)
- .attr("transform", transform)
- .style("fill", color);
-
- u.exit().transition()
- .duration(duration)
- .attr("transform", transform)
- .remove();
-
- // Stash the new scales.
- this.__chart__ = {x: x1, y: y1, id: id};
- });
- d3.timer.flush();
- }
-
- horizon.duration = function(x) {
- if (!arguments.length) return duration;
- duration = +x;
- return horizon;
- };
-
- horizon.bands = function(x) {
- if (!arguments.length) return bands;
- bands = +x;
- color.domain([-bands, 0, bands]);
- return horizon;
- };
-
- horizon.mode = function(x) {
- if (!arguments.length) return mode;
- mode = x + "";
- return horizon;
- };
-
- horizon.colors = function(x) {
- if (!arguments.length) return color.range();
- color.range(x);
- return horizon;
- };
-
- horizon.interpolate = function(x) {
- if (!arguments.length) return interpolate;
- interpolate = x + "";
- return horizon;
- };
-
- horizon.x = function(z) {
- if (!arguments.length) return x;
- x = z;
- return horizon;
- };
-
- horizon.y = function(z) {
- if (!arguments.length) return y;
- y = z;
- return horizon;
- };
-
- horizon.width = function(x) {
- if (!arguments.length) return w;
- w = +x;
- return horizon;
- };
-
- horizon.height = function(x) {
- if (!arguments.length) return h;
- h = +x;
- return horizon;
- };
-
- return horizon;
-};
-
-var d3_chart_horizonArea = d3.svg.area(),
- d3_chart_horizonId = 0;
-
-function d3_chart_horizonX(d) {
- return d[0];
-}
-
-function d3_chart_horizonY(d) {
- return d[1];
-}
-// Based on http://vis.stanford.edu/protovis/ex/qqplot.html
-d3.chart.qq = function() {
- var width = 1,
- height = 1,
- duration = 0,
- domain = null,
- tickFormat = null,
- n = 100,
- x = d3_chart_qqX,
- y = d3_chart_qqY;
-
- // For each small multiple…
- function qq(g) {
- g.each(function(d, i) {
- var g = d3.select(this),
- qx = d3_chart_qqQuantiles(n, x.call(this, d, i)),
- qy = d3_chart_qqQuantiles(n, y.call(this, d, i)),
- xd = domain && domain.call(this, d, i) || [d3.min(qx), d3.max(qx)], // new x-domain
- yd = domain && domain.call(this, d, i) || [d3.min(qy), d3.max(qy)], // new y-domain
- x0, // old x-scale
- y0; // old y-scale
-
- // Compute the new x-scale.
- var x1 = d3.scale.linear()
- .domain(xd)
- .range([0, width]);
-
- // Compute the new y-scale.
- var y1 = d3.scale.linear()
- .domain(yd)
- .range([height, 0]);
-
- // Retrieve the old scales, if this is an update.
- if (this.__chart__) {
- x0 = this.__chart__.x;
- y0 = this.__chart__.y;
- } else {
- x0 = d3.scale.linear().domain([0, Infinity]).range(x1.range());
- y0 = d3.scale.linear().domain([0, Infinity]).range(y1.range());
- }
-
- // Stash the new scales.
- this.__chart__ = {x: x1, y: y1};
-
- // Update diagonal line.
- var diagonal = g.selectAll("line.diagonal")
- .data([null]);
-
- diagonal.enter().append("svg:line")
- .attr("class", "diagonal")
- .attr("x1", x1(yd[0]))
- .attr("y1", y1(xd[0]))
- .attr("x2", x1(yd[1]))
- .attr("y2", y1(xd[1]));
-
- diagonal.transition()
- .duration(duration)
- .attr("x1", x1(yd[0]))
- .attr("y1", y1(xd[0]))
- .attr("x2", x1(yd[1]))
- .attr("y2", y1(xd[1]));
-
- // Update quantile plots.
- var circle = g.selectAll("circle")
- .data(d3.range(n).map(function(i) {
- return {x: qx[i], y: qy[i]};
- }));
-
- circle.enter().append("svg:circle")
- .attr("class", "quantile")
- .attr("r", 4.5)
- .attr("cx", function(d) { return x0(d.x); })
- .attr("cy", function(d) { return y0(d.y); })
- .style("opacity", 1e-6)
- .transition()
- .duration(duration)
- .attr("cx", function(d) { return x1(d.x); })
- .attr("cy", function(d) { return y1(d.y); })
- .style("opacity", 1);
-
- circle.transition()
- .duration(duration)
- .attr("cx", function(d) { return x1(d.x); })
- .attr("cy", function(d) { return y1(d.y); })
- .style("opacity", 1);
-
- circle.exit().transition()
- .duration(duration)
- .attr("cx", function(d) { return x1(d.x); })
- .attr("cy", function(d) { return y1(d.y); })
- .style("opacity", 1e-6)
- .remove();
-
- var xformat = tickFormat || x1.tickFormat(4),
- yformat = tickFormat || y1.tickFormat(4),
- tx = function(d) { return "translate(" + x1(d) + "," + height + ")"; },
- ty = function(d) { return "translate(0," + y1(d) + ")"; };
-
- // Update x-ticks.
- var xtick = g.selectAll("g.x.tick")
- .data(x1.ticks(4), function(d) {
- return this.textContent || xformat(d);
- });
-
- var xtickEnter = xtick.enter().append("svg:g")
- .attr("class", "x tick")
- .attr("transform", function(d) { return "translate(" + x0(d) + "," + height + ")"; })
- .style("opacity", 1e-6);
-
- xtickEnter.append("svg:line")
- .attr("y1", 0)
- .attr("y2", -6);
-
- xtickEnter.append("svg:text")
- .attr("text-anchor", "middle")
- .attr("dy", "1em")
- .text(xformat);
-
- // Transition the entering ticks to the new scale, x1.
- xtickEnter.transition()
- .duration(duration)
- .attr("transform", tx)
- .style("opacity", 1);
-
- // Transition the updating ticks to the new scale, x1.
- xtick.transition()
- .duration(duration)
- .attr("transform", tx)
- .style("opacity", 1);
-
- // Transition the exiting ticks to the new scale, x1.
- xtick.exit().transition()
- .duration(duration)
- .attr("transform", tx)
- .style("opacity", 1e-6)
- .remove();
-
- // Update ticks.
- var ytick = g.selectAll("g.y.tick")
- .data(y1.ticks(4), function(d) {
- return this.textContent || yformat(d);
- });
-
- var ytickEnter = ytick.enter().append("svg:g")
- .attr("class", "y tick")
- .attr("transform", function(d) { return "translate(0," + y0(d) + ")"; })
- .style("opacity", 1e-6);
-
- ytickEnter.append("svg:line")
- .attr("x1", 0)
- .attr("x2", 6);
-
- ytickEnter.append("svg:text")
- .attr("text-anchor", "end")
- .attr("dx", "-.5em")
- .attr("dy", ".3em")
- .text(yformat);
-
- // Transition the entering ticks to the new scale, y1.
- ytickEnter.transition()
- .duration(duration)
- .attr("transform", ty)
- .style("opacity", 1);
-
- // Transition the updating ticks to the new scale, y1.
- ytick.transition()
- .duration(duration)
- .attr("transform", ty)
- .style("opacity", 1);
-
- // Transition the exiting ticks to the new scale, y1.
- ytick.exit().transition()
- .duration(duration)
- .attr("transform", ty)
- .style("opacity", 1e-6)
- .remove();
- });
- }
-
- qq.width = function(x) {
- if (!arguments.length) return width;
- width = x;
- return qq;
- };
-
- qq.height = function(x) {
- if (!arguments.length) return height;
- height = x;
- return qq;
- };
-
- qq.duration = function(x) {
- if (!arguments.length) return duration;
- duration = x;
- return qq;
- };
-
- qq.domain = function(x) {
- if (!arguments.length) return domain;
- domain = x == null ? x : d3.functor(x);
- return qq;
- };
-
- qq.count = function(z) {
- if (!arguments.length) return n;
- n = z;
- return qq;
- };
-
- qq.x = function(z) {
- if (!arguments.length) return x;
- x = z;
- return qq;
- };
-
- qq.y = function(z) {
- if (!arguments.length) return y;
- y = z;
- return qq;
- };
-
- qq.tickFormat = function(x) {
- if (!arguments.length) return tickFormat;
- tickFormat = x;
- return qq;
- };
-
- return qq;
-};
-
-function d3_chart_qqQuantiles(n, values) {
- var m = values.length - 1;
- values = values.slice().sort(d3.ascending);
- return d3.range(n).map(function(i) {
- return values[~~(i * m / n)];
- });
-}
-
-function d3_chart_qqX(d) {
- return d.x;
-}
-
-function d3_chart_qqY(d) {
- return d.y;
-}
-})();
View
1 d3.chart.min.js
@@ -1 +0,0 @@
-(function(){function a(a){return[0,a.length-1]}function b(a){return[d3.quantile(a,.25),d3.quantile(a,.5),d3.quantile(a,.75)]}function c(a){return a.ranges}function d(a){return a.markers}function e(a){return a.measures}function f(a){return function(b){return"translate("+a(b)+",0)"}}function g(a){var b=a(0);return function(c){return Math.abs(a(c)-b)}}function j(a){return a[0]}function k(a){return a[1]}function l(a,b){var c=b.length-1;return b=b.slice().sort(d3.ascending),d3.range(a).map(function(d){return b[~~(d*c/a)]})}function m(a){return a.x}function n(a){return a.y}d3.chart={},d3.chart.box=function(){function k(a){a.each(function(a,b){a=a.map(g).sort(d3.ascending);var k=d3.select(this),l=a.length,m=a[0],n=a[l-1],o=a.quartiles=i(a),p=h&&h.call(this,a,b),q=p&&p.map(function(b){return a[b]}),r=p?d3.range(0,p[0]).concat(d3.range(p[1]+1,l)):d3.range(l),s=d3.scale.linear().domain(f&&f.call(this,a,b)||[m,n]).range([d,0]),t=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(s.range());this.__chart__=s;var u=k.selectAll("line.center").data(q?[q]:[]);u.enter().insert("svg:line","rect").attr("class","center").attr("x1",c/2).attr("y1",function(a){return t(a[0])}).attr("x2",c/2).attr("y2",function(a){return t(a[1])}).style("opacity",1e-6).transition().duration(e).style("opacity",1).attr("y1",function(a){return s(a[0])}).attr("y2",function(a){return s(a[1])}),u.transition().duration(e).style("opacity",1).attr("y1",function(a){return s(a[0])}).attr("y2",function(a){return s(a[1])}),u.exit().transition().duration(e).style("opacity",1e-6).attr("y1",function(a){return s(a[0])}).attr("y2",function(a){return s(a[1])}).remove();var v=k.selectAll("rect.box").data([o]);v.enter().append("svg:rect").attr("class","box").attr("x",0).attr("y",function(a){return t(a[2])}).attr("width",c).attr("height",function(a){return t(a[0])-t(a[2])}).transition().duration(e).attr("y",function(a){return s(a[2])}).attr("height",function(a){return s(a[0])-s(a[2])}),v.transition().duration(e).attr("y",function(a){return s(a[2])}).attr("height",function(a){return s(a[0])-s(a[2])});var w=k.selectAll("line.median").data([o[1]]);w.enter().append("svg:line").attr("class","median").attr("x1",0).attr("y1",t).attr("x2",c).attr("y2",t).transition().duration(e).attr("y1",s).attr("y2",s),w.transition().duration(e).attr("y1",s).attr("y2",s);var x=k.selectAll("line.whisker").data(q||[]);x.enter().insert("svg:line","circle, text").attr("class","whisker").attr("x1",0).attr("y1",t).attr("x2",c).attr("y2",t).style("opacity",1e-6).transition().duration(e).attr("y1",s).attr("y2",s).style("opacity",1),x.transition().duration(e).attr("y1",s).attr("y2",s).style("opacity",1),x.exit().transition().duration(e).attr("y1",s).attr("y2",s).style("opacity",1e-6).remove();var y=k.selectAll("circle.outlier").data(r,Number);y.enter().insert("svg:circle","text").attr("class","outlier").attr("r",5).attr("cx",c/2).attr("cy",function(b){return t(a[b])}).style("opacity",1e-6).transition().duration(e).attr("cy",function(b){return s(a[b])}).style("opacity",1),y.transition().duration(e).attr("cy",function(b){return s(a[b])}).style("opacity",1),y.exit().transition().duration(e).attr("cy",function(b){return s(a[b])}).style("opacity",1e-6).remove();var z=j||s.tickFormat(8),A=k.selectAll("text.box").data(o);A.enter().append("svg:text").attr("class","box").attr("dy",".3em").attr("dx",function(a,b){return b&1?6:-6}).attr("x",function(a,b){return b&1?c:0}).attr("y",t).attr("text-anchor",function(a,b){return b&1?"start":"end"}).text(z).transition().duration(e).attr("y",s),A.transition().duration(e).text(z).attr("y",s);var B=k.selectAll("text.whisker").data(q||[]);B.enter().append("svg:text").attr("class","whisker").attr("dy",".3em").attr("dx",6).attr("x",c).attr("y",t).text(z).style("opacity",1e-6).transition().duration(e).attr("y",s).style("opacity",1),B.transition().duration(e).text(z).attr("y",s).style("opacity",1),B.exit().transition().duration(e).attr("y",s).style("opacity",1e-6).remove()}),d3.timer.flush()}var c=1,d=1,e=0,f=null,g=Number,h=a,i=b,j=null;return k.width=function(a){return arguments.length?(c=a,k):c},k.height=function(a){return arguments.length?(d=a,k):d},k.tickFormat=function(a){return arguments.length?(j=a,k):j},k.duration=function(a){return arguments.length?(e=a,k):e},k.domain=function(a){return arguments.length?(f=a==null?a:d3.functor(a),k):f},k.value=function(a){return arguments.length?(g=a,k):g},k.whiskers=function(a){return arguments.length?(h=a,k):h},k.quartiles=function(a){return arguments.length?(i=a,k):i},k},d3.chart.bullet=function(){function o(a){a.each(function(a,c){var d=i.call(this,a,c).slice().sort(d3.descending),e=j.call(this,a,c).slice().sort(d3.descending),o=k.call(this,a,c).slice().sort(d3.descending),p=d3.select(this),q=d3.scale.linear().domain([0,Math.max(d[0],e[0],o[0])]).range(b?[l,0]:[0,l]),r=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(q.range());this.__chart__=q;var s=g(r),t=g(q),u=p.selectAll("rect.range").data(d);u.enter().append("svg:rect").attr("class",function(a,b){return"range s"+b}).attr("width",s).attr("height",m).attr("x",b?r:0).transition().duration(h).attr("width",t).attr("x",b?q:0),u.transition().duration(h).attr("x",b?q:0).attr("width",t).attr("height",m);var v=p.selectAll("rect.measure").data(o);v.enter().append("svg:rect").attr("class",function(a,b){return"measure s"+b}).attr("width",s).attr("height",m/3).attr("x",b?r:0).attr("y",m/3).transition().duration(h).attr("width",t).attr("x",b?q:0),v.transition().duration(h).attr("width",t).attr("height",m/3).attr("x",b?q:0).attr("y",m/3);var w=p.selectAll("line.marker").data(e);w.enter().append("svg:line").attr("class","marker").attr("x1",r).attr("x2",r).attr("y1",m/6).attr("y2",m*5/6).transition().duration(h).attr("x1",q).attr("x2",q),w.transition().duration(h).attr("x1",q).attr("x2",q).attr("y1",m/6).attr("y2",m*5/6);var x=n||q.tickFormat(8),y=p.selectAll("g.tick").data(q.ticks(8),function(a){return this.textContent||x(a)}),z=y.enter().append("svg:g").attr("class","tick").attr("transform",f(r)).style("opacity",1e-6);z.append("svg:line").attr("y1",m).attr("y2",m*7/6),z.append("svg:text").attr("text-anchor","middle").attr("dy","1em").attr("y",m*7/6).text(x),z.transition().duration(h).attr("transform",f(q)).style("opacity",1);var A=y.transition().duration(h).attr("transform",f(q)).style("opacity",1);A.select("line").attr("y1",m).attr("y2",m*7/6),A.select("text").attr("y",m*7/6),y.exit().transition().duration(h).attr("transform",f(q)).style("opacity",1e-6).remove()}),d3.timer.flush()}var a="left",b=!1,h=0,i=c,j=d,k=e,l=380,m=30,n=null;return o.orient=function(c){return arguments.length?(a=c,b=a=="right"||a=="bottom",o):a},o.ranges=function(a){return arguments.length?(i=a,o):i},o.markers=function(a){return arguments.length?(j=a,o):j},o.measures=function(a){return arguments.length?(k=a,o):k},o.width=function(a){return arguments.length?(l=a,o):l},o.height=function(a){return arguments.length?(m=a,o):m},o.tickFormat=function(a){return arguments.length?(n=a,o):n},o.duration=function(a){return arguments.length?(h=a,o):h},o},d3.chart.horizon=function(){function n(j){j.each(function(j,k){var n=d3.select(this),o=2*a+1,p=Infinity,q=-Infinity,r=-Infinity,s,t,u,v=j.map(function(a,b){var c=d.call(this,a,b),f=e.call(this,a,b);return c<p&&(p=c),c>q&&(q=c),-f>r&&(r=-f),f>r&&(r=f),[c,f]}),z=d3.scale.linear().domain([p,q]).range([0,f]),A=d3.scale.linear().domain([0,r]).range([0,g*a]);this.__chart__?(s=this.__chart__.x,t=this.__chart__.y,u=this.__chart__.id):(s=d3.scale.linear().domain([0,Infinity]).range(z.range()),t=d3.scale.linear().domain([0,Infinity]).range(A.range()),u=++i);var B=n.selectAll("defs").data([v]),C=B.enter().append("svg:defs");C.append("svg:clipPath").attr("id","d3_chart_horizon_clip"+u).append("svg:rect").attr("width",f).attr("height",g),B.select("rect").transition().duration(l).attr("width",f).attr("height",g),C.append("svg:path").attr("id","d3_chart_horizon_path"+u).attr("d",h.interpolate(c).x(function(a){return s(a[0])}).y0(g*a).y1(function(b){return g*a-t(b[1])})).transition().duration(l).attr("d",h.x(function(a){return z(a[0])}).y1(function(b){return g*a-A(b[1])})),B.select("path").transition().duration(l).attr("d",h),n.selectAll("g").data([null]).enter().append("svg:g").attr("clip-path","url(#d3_chart_horizon_clip"+u+")");var D=b=="offset"?function(b){return"translate(0,"+(b+(b<0)-a)*g+")"}:function(b){return(b<0?"scale(1,-1)":"")+"translate(0,"+(b-a)*g+")"},E=n.select("g").selectAll("use").data(d3.range(-1,-a-1,-1).concat(d3.range(1,a+1)),Number);E.enter().append("svg:use").attr("xlink:href","#d3_chart_horizon_path"+u).attr("transform",function(a){return D(a+(a>0?1:-1))}).style("fill",m).transition().duration(l).attr("transform",D),E.transition().duration(l).attr("transform",D).style("fill",m),E.exit().transition().duration(l).attr("transform",D).remove(),this.__chart__={x:z,y:A,id:u}}),d3.timer.flush()}var a=1,b="offset",c="linear",d=j,e=k,f=960,g=40,l=0,m=d3.scale.linear().domain([-1,0,1]).range(["#d62728","#fff","#1f77b4"]);return n.duration=function(a){return arguments.length?(l=+a,n):l},n.bands=function(b){return arguments.length?(a=+b,m.domain([-a,0,a]),n):a},n.mode=function(a){return arguments.length?(b=a+"",n):b},n.colors=function(a){return arguments.length?(m.range(a),n):m.range()},n.interpolate=function(a){return arguments.length?(c=a+"",n):c},n.x=function(a){return arguments.length?(d=a,n):d},n.y=function(a){return arguments.length?(e=a,n):e},n.width=function(a){return arguments.length?(f=+a,n):f},n.height=function(a){return arguments.length?(g=+a,n):g},n};var h=d3.svg.area(),i=0;d3.chart.qq=function(){function i(i){i.each(function(i,j){var k=d3.select(this),m=l(f,g.call(this,i,j)),n=l(f,h.call(this,i,j)),o=d&&d.call(this,i,j)||[d3.min(m),d3.max(m)],p=d&&d.call(this,i,j)||[d3.min(n),d3.max(n)],q,r,s=d3.scale.linear().domain(o).range([0,a]),t=d3.scale.linear().domain(p).range([b,0]);this.__chart__?(q=this.__chart__.x,r=this.__chart__.y):(q=d3.scale.linear().domain([0,Infinity]).range(s.range()),r=d3.scale.linear().domain([0,Infinity]).range(t.range())),this.__chart__={x:s,y:t};var u=k.selectAll("line.diagonal").data([null]);u.enter().append("svg:line").attr("class","diagonal").attr("x1",s(p[0])).attr("y1",t(o[0])).attr("x2",s(p[1])).attr("y2",t(o[1])),u.transition().duration(c).attr("x1",s(p[0])).attr("y1",t(o[0])).attr("x2",s(p[1])).attr("y2",t(o[1]));var v=k.selectAll("circle").data(d3.range(f).map(function(a){return{x:m[a],y:n[a]}}));v.enter().append("svg:circle").attr("class","quantile").attr("r",4.5).attr("cx",function(a){return q(a.x)}).attr("cy",function(a){return r(a.y)}).style("opacity",1e-6).transition().duration(c).attr("cx",function(a){return s(a.x)}).attr("cy",function(a){return t(a.y)}).style("opacity",1),v.transition().duration(c).attr("cx",function(a){return s(a.x)}).attr("cy",function(a){return t(a.y)}).style("opacity",1),v.exit().transition().duration(c).attr("cx",function(a){return s(a.x)}).attr("cy",function(a){return t(a.y)}).style("opacity",1e-6).remove();var w=e||s.tickFormat(4),z=e||t.tickFormat(4),A=function(a){return"translate("+s(a)+","+b+")"},B=function(a){return"translate(0,"+t(a)+")"},C=k.selectAll("g.x.tick").data(s.ticks(4),function(a){return this.textContent||w(a)}),D=C.enter().append("svg:g").attr("class","x tick").attr("transform",function(a){return"translate("+q(a)+","+b+")"}).style("opacity",1e-6);D.append("svg:line").attr("y1",0).attr("y2",-6),D.append("svg:text").attr("text-anchor","middle").attr("dy","1em").text(w),D.transition().duration(c).attr("transform",A).style("opacity",1),C.transition().duration(c).attr("transform",A).style("opacity",1),C.exit().transition().duration(c).attr("transform",A).style("opacity",1e-6).remove();var E=k.selectAll("g.y.tick").data(t.ticks(4),function(a){return this.textContent||z(a)}),F=E.enter().append("svg:g").attr("class","y tick").attr("transform",function(a){return"translate(0,"+r(a)+")"}).style("opacity",1e-6);F.append("svg:line").attr("x1",0).attr("x2",6),F.append("svg:text").attr("text-anchor","end").attr("dx","-.5em").attr("dy",".3em").text(z),F.transition().duration(c).attr("transform",B).style("opacity",1),E.transition().duration(c).attr("transform",B).style("opacity",1),E.exit().transition().duration(c).attr("transform",B).style("opacity",1e-6).remove()})}var a=1,b=1,c=0,d=null,e=null,f=100,g=m,h=n;return i.width=function(b){return arguments.length?(a=b,i):a},i.height=function(a){return arguments.length?(b=a,i):b},i.duration=function(a){return arguments.length?(c=a,i):c},i.domain=function(a){return arguments.length?(d=a==null?a:d3.functor(a),i):d},i.count=function(a){return arguments.length?(f=a,i):f},i.x=function(a){return arguments.length?(g=a,i):g},i.y=function(a){return arguments.length?(h=a,i):h},i.tickFormat=function(a){return arguments.length?(e=a,i):e},i}})();
View
92 d3.csv.js
@@ -1,92 +0,0 @@
-(function(){d3.csv = function(url, callback) {
- d3.text(url, "text/csv", function(text) {
- callback(text && d3.csv.parse(text));
- });
-};
-d3.csv.parse = function(text) {
- var header;
- return d3.csv.parseRows(text, function(row, i) {
- if (i) {
- var o = {}, j = -1, m = header.length;
- while (++j < m) o[header[j]] = row[j];
- return o;
- } else {
- header = row;
- return null;
- }
- });
-};
-
-d3.csv.parseRows = function(text, f) {
- var EOL = {}, // sentinel value for end-of-line
- EOF = {}, // sentinel value for end-of-file
- rows = [], // output rows
- re = /\r\n|[,\r\n]/g, // field separator regex
- n = 0, // the current line number
- t, // the current token
- eol; // is the current token followed by EOL?
-
- re.lastIndex = 0; // work-around bug in FF 3.6
-
- /** @private Returns the next token. */
- function token() {
- if (re.lastIndex >= text.length) return EOF; // special case: end of file
- if (eol) { eol = false; return EOL; } // special case: end of line
-
- // special case: quotes
- var j = re.lastIndex;
- if (text.charCodeAt(j) === 34) {
- var i = j;
- while (i++ < text.length) {
- if (text.charCodeAt(i) === 34) {
- if (text.charCodeAt(i + 1) !== 34) break;
- i++;
- }
- }
- re.lastIndex = i + 2;
- var c = text.charCodeAt(i + 1);
- if (c === 13) {
- eol = true;
- if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
- } else if (c === 10) {
- eol = true;
- }
- return text.substring(j + 1, i).replace(/""/g, "\"");
- }
-
- // common case
- var m = re.exec(text);
- if (m) {
- eol = m[0].charCodeAt(0) !== 44;
- return text.substring(j, m.index);
- }
- re.lastIndex = text.length;
- return text.substring(j);
- }
-
- while ((t = token()) !== EOF) {
- var a = [];
- while ((t !== EOL) && (t !== EOF)) {
- a.push(t);
- t = token();
- }
- if (f && !(a = f(a, n++))) continue;
- rows.push(a);
- }
-
- return rows;
-};
-d3.csv.format = function(rows) {
- return rows.map(d3_csv_formatRow).join("\n");
-};
-
-function d3_csv_formatRow(row) {
- return row.map(d3_csv_formatValue).join(",");
-}
-
-function d3_csv_formatValue(text) {
- return /[",\n]/.test(text)
- ? "\"" + text.replace(/\"/g, "\"\"") + "\""
- : text;
-}
-})();
View
1 d3.csv.min.js
@@ -1 +0,0 @@
-(function(){function a(a){return a.map(b).join(",")}function b(a){return/[",\n]/.test(a)?'"'+a.replace(/\"/g,'""')+'"':a}d3.csv=function(a,b){d3.text(a,"text/csv",function(a){b(a&&d3.csv.parse(a))})},d3.csv.parse=function(a){var b;return d3.csv.parseRows(a,function(a,c){if(c){var d={},e=-1,f=b.length;while(++e<f)d[b[e]]=a[e];return d}return b=a,null})},d3.csv.parseRows=function(a,b){function j(){if(f.lastIndex>=a.length)return d;if(i)return i=!1,c;var b=f.lastIndex;if(a.charCodeAt(b)===34){var e=b;while(e++<a.length)if(a.charCodeAt(e)===34){if(a.charCodeAt(e+1)!==34)break;e++}f.lastIndex=e+2;var g=a.charCodeAt(e+1);return g===13?(i=!0,a.charCodeAt(e+2)===10&&f.lastIndex++):g===10&&(i=!0),a.substring(b+1,e).replace(/""/g,'"')}var h=f.exec(a);return h?(i=h[0].charCodeAt(0)!==44,a.substring(b,h.index)):(f.lastIndex=a.length,a.substring(b))}var c={},d={},e=[],f=/\r\n|[,\r\n]/g,g=0,h,i;f.lastIndex=0;while((h=j())!==d){var k=[];while(h!==c&&h!==d)k.push(h),h=j();if(b&&!(k=b(k,g++)))continue;e.push(k)}return e},d3.csv.format=function(b){return b.map(a).join("\n")}})();
View
938 d3.geo.js
@@ -1,938 +0,0 @@
-(function(){d3.geo = {};
-
-var d3_geo_radians = Math.PI / 180;
-// TODO clip input coordinates on opposite hemisphere
-d3.geo.azimuthal = function() {
- var mode = "orthographic", // or stereographic, gnomonic, equidistant or equalarea
- origin,
- scale = 200,
- translate = [480, 250],
- x0,
- y0,
- cy0,
- sy0;
-
- function azimuthal(coordinates) {
- var x1 = coordinates[0] * d3_geo_radians - x0,
- y1 = coordinates[1] * d3_geo_radians,
- cx1 = Math.cos(x1),
- sx1 = Math.sin(x1),
- cy1 = Math.cos(y1),
- sy1 = Math.sin(y1),
- cc = mode !== "orthographic" ? sy0 * sy1 + cy0 * cy1 * cx1 : null,
- c,
- k = mode === "stereographic" ? 1 / (1 + cc)
- : mode === "gnomonic" ? 1 / cc
- : mode === "equidistant" ? (c = Math.acos(cc), c ? c / Math.sin(c) : 0)
- : mode === "equalarea" ? Math.sqrt(2 / (1 + cc))
- : 1,
- x = k * cy1 * sx1,
- y = k * (sy0 * cy1 * cx1 - cy0 * sy1);
- return [
- scale * x + translate[0],
- scale * y + translate[1]
- ];
- }
-
- azimuthal.invert = function(coordinates) {
- var x = (coordinates[0] - translate[0]) / scale,
- y = (coordinates[1] - translate[1]) / scale,
- p = Math.sqrt(x * x + y * y),
- c = mode === "stereographic" ? 2 * Math.atan(p)
- : mode === "gnomonic" ? Math.atan(p)
- : mode === "equidistant" ? p
- : mode === "equalarea" ? 2 * Math.asin(.5 * p)
- : Math.asin(p),
- sc = Math.sin(c),
- cc = Math.cos(c);
- return [
- (x0 + Math.atan2(x * sc, p * cy0 * cc + y * sy0 * sc)) / d3_geo_radians,
- Math.asin(cc * sy0 - (p ? (y * sc * cy0) / p : 0)) / d3_geo_radians
- ];
- };
-
- azimuthal.mode = function(x) {
- if (!arguments.length) return mode;
- mode = x + "";
- return azimuthal;
- };
-
- azimuthal.origin = function(x) {
- if (!arguments.length) return origin;
- origin = x;
- x0 = origin[0] * d3_geo_radians;
- y0 = origin[1] * d3_geo_radians;
- cy0 = Math.cos(y0);
- sy0 = Math.sin(y0);
- return azimuthal;
- };
-
- azimuthal.scale = function(x) {
- if (!arguments.length) return scale;
- scale = +x;
- return azimuthal;
- };
-
- azimuthal.translate = function(x) {
- if (!arguments.length) return translate;
- translate = [+x[0], +x[1]];
- return azimuthal;
- };
-
- return azimuthal.origin([0, 0]);
-};
-// Derived from Tom Carden's Albers implementation for Protovis.
-// http://gist.github.com/476238
-// http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html
-
-d3.geo.albers = function() {
- var origin = [-98, 38],
- parallels = [29.5, 45.5],
- scale = 1000,
- translate = [480, 250],
- lng0, // d3_geo_radians * origin[0]
- n,
- C,
- p0;
-
- function albers(coordinates) {
- var t = n * (d3_geo_radians * coordinates[0] - lng0),
- p = Math.sqrt(C - 2 * n * Math.sin(d3_geo_radians * coordinates[1])) / n;
- return [
- scale * p * Math.sin(t) + translate[0],
- scale * (p * Math.cos(t) - p0) + translate[1]
- ];
- }
-
- albers.invert = function(coordinates) {
- var x = (coordinates[0] - translate[0]) / scale,
- y = (coordinates[1] - translate[1]) / scale,
- p0y = p0 + y,
- t = Math.atan2(x, p0y),
- p = Math.sqrt(x * x + p0y * p0y);
- return [
- (lng0 + t / n) / d3_geo_radians,
- Math.asin((C - p * p * n * n) / (2 * n)) / d3_geo_radians
- ];
- };
-
- function reload() {
- var phi1 = d3_geo_radians * parallels[0],
- phi2 = d3_geo_radians * parallels[1],
- lat0 = d3_geo_radians * origin[1],
- s = Math.sin(phi1),
- c = Math.cos(phi1);
- lng0 = d3_geo_radians * origin[0];
- n = .5 * (s + Math.sin(phi2));
- C = c * c + 2 * n * s;
- p0 = Math.sqrt(C - 2 * n * Math.sin(lat0)) / n;
- return albers;
- }
-
- albers.origin = function(x) {
- if (!arguments.length) return origin;
- origin = [+x[0], +x[1]];
- return reload();
- };
-
- albers.parallels = function(x) {
- if (!arguments.length) return parallels;
- parallels = [+x[0], +x[1]];
- return reload();
- };
-
- albers.scale = function(x) {
- if (!arguments.length) return scale;
- scale = +x;
- return albers;
- };
-
- albers.translate = function(x) {
- if (!arguments.length) return translate;
- translate = [+x[0], +x[1]];
- return albers;
- };
-
- return reload();
-};
-
-// A composite projection for the United States, 960x500. The set of standard
-// parallels for each region comes from USGS, which is published here:
-// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
-// TODO allow the composite projection to be rescaled?
-d3.geo.albersUsa = function() {
- var lower48 = d3.geo.albers();
-
- var alaska = d3.geo.albers()
- .origin([-160, 60])
- .parallels([55, 65]);
-
- var hawaii = d3.geo.albers()
- .origin([-160, 20])
- .parallels([8, 18]);
-
- var puertoRico = d3.geo.albers()
- .origin([-60, 10])
- .parallels([8, 18]);
-
- function albersUsa(coordinates) {
- var lon = coordinates[0],
- lat = coordinates[1];
- return (lat > 50 ? alaska
- : lon < -140 ? hawaii
- : lat < 21 ? puertoRico
- : lower48)(coordinates);
- }
-
- albersUsa.scale = function(x) {
- if (!arguments.length) return lower48.scale();
- lower48.scale(x);
- alaska.scale(x * .6);
- hawaii.scale(x);
- puertoRico.scale(x * 1.5);
- return albersUsa.translate(lower48.translate());
- };
-
- albersUsa.translate = function(x) {
- if (!arguments.length) return lower48.translate();
- var dz = lower48.scale() / 1000,
- dx = x[0],
- dy = x[1];
- lower48.translate(x);
- alaska.translate([dx - 400 * dz, dy + 170 * dz]);
- hawaii.translate([dx - 190 * dz, dy + 200 * dz]);
- puertoRico.translate([dx + 580 * dz, dy + 430 * dz]);
- return albersUsa;
- };
-
- return albersUsa.scale(lower48.scale());
-};
-d3.geo.bonne = function() {
- var scale = 200,
- translate = [480, 250],
- x0, // origin longitude in radians
- y0, // origin latitude in radians
- y1, // parallel latitude in radians
- c1; // cot(y1)
-
- function bonne(coordinates) {
- var x = coordinates[0] * d3_geo_radians - x0,
- y = coordinates[1] * d3_geo_radians - y0;
- if (y1) {
- var p = c1 + y1 - y, E = x * Math.cos(y) / p;
- x = p * Math.sin(E);
- y = p * Math.cos(E) - c1;
- } else {
- x *= Math.cos(y);
- y *= -1;
- }
- return [
- scale * x + translate[0],
- scale * y + translate[1]
- ];
- }
-
- bonne.invert = function(coordinates) {
- var x = (coordinates[0] - translate[0]) / scale,
- y = (coordinates[1] - translate[1]) / scale;
- if (y1) {
- var c = c1 + y, p = Math.sqrt(x * x + c * c);
- y = c1 + y1 - p;
- x = x0 + p * Math.atan2(x, c) / Math.cos(y);
- } else {
- y *= -1;
- x /= Math.cos(y);
- }
- return [
- x / d3_geo_radians,
- y / d3_geo_radians
- ];
- };
-
- // 90° for Werner, 0° for Sinusoidal
- bonne.parallel = function(x) {
- if (!arguments.length) return y1 / d3_geo_radians;
- c1 = 1 / Math.tan(y1 = x * d3_geo_radians);
- return bonne;
- };
-
- bonne.origin = function(x) {
- if (!arguments.length) return [x0 / d3_geo_radians, y0 / d3_geo_radians];
- x0 = x[0] * d3_geo_radians;
- y0 = x[1] * d3_geo_radians;
- return bonne;
- };
-
- bonne.scale = function(x) {
- if (!arguments.length) return scale;
- scale = +x;
- return bonne;
- };
-
- bonne.translate = function(x) {
- if (!arguments.length) return translate;
- translate = [+x[0], +x[1]];
- return bonne;
- };
-
- return bonne.origin([0, 0]).parallel(45);
-};
-d3.geo.equirectangular = function() {
- var scale = 500,
- translate = [480, 250];
-
- function equirectangular(coordinates) {
- var x = coordinates[0] / 360,
- y = -coordinates[1] / 360;
- return [
- scale * x + translate[0],
- scale * y + translate[1]
- ];
- }
-
- equirectangular.invert = function(coordinates) {
- var x = (coordinates[0] - translate[0]) / scale,
- y = (coordinates[1] - translate[1]) / scale;
- return [
- 360 * x,
- -360 * y
- ];
- };
-
- equirectangular.scale = function(x) {
- if (!arguments.length) return scale;
- scale = +x;
- return equirectangular;
- };
-
- equirectangular.translate = function(x) {
- if (!arguments.length) return translate;
- translate = [+x[0], +x[1]];
- return equirectangular;
- };
-
- return equirectangular;
-};
-d3.geo.mercator = function() {
- var scale = 500,
- translate = [480, 250];
-
- function mercator(coordinates) {
- var x = coordinates[0] / 360,
- y = -(Math.log(Math.tan(Math.PI / 4 + coordinates[1] * d3_geo_radians / 2)) / d3_geo_radians) / 360;
- return [
- scale * x + translate[0],
- scale * Math.max(-.5, Math.min(.5, y)) + translate[1]
- ];
- }
-
- mercator.invert = function(coordinates) {
- var x = (coordinates[0] - translate[0]) / scale,
- y = (coordinates[1] - translate[1]) / scale;
- return [
- 360 * x,
- 2 * Math.atan(Math.exp(-360 * y * d3_geo_radians)) / d3_geo_radians - 90
- ];
- };
-
- mercator.scale = function(x) {
- if (!arguments.length) return scale;
- scale = +x;
- return mercator;
- };
-
- mercator.translate = function(x) {
- if (!arguments.length) return translate;
- translate = [+x[0], +x[1]];
- return mercator;
- };
-
- return mercator;
-};
-function d3_geo_type(types, defaultValue) {
- return function(object) {
- return object && object.type in types ? types[object.type](object) : defaultValue;
- };
-}
-/**
- * Returns a function that, given a GeoJSON object (e.g., a feature), returns
- * the corresponding SVG path. The function can be customized by overriding the
- * projection. Point features are mapped to circles with a default radius of
- * 4.5px; the radius can be specified either as a constant or a function that
- * is evaluated per object.
- */
-d3.geo.path = function() {
- var pointRadius = 4.5,
- pointCircle = d3_path_circle(pointRadius),
- projection = d3.geo.albersUsa();
-
- function path(d, i) {
- if (typeof pointRadius === "function") {
- pointCircle = d3_path_circle(pointRadius.apply(this, arguments));
- }
- return pathType(d) || null;
- }
-
- function project(coordinates) {
- return projection(coordinates).join(",");
- }
-
- var pathType = d3_geo_type({
-
- FeatureCollection: function(o) {
- var path = [],
- features = o.features,
- i = -1, // features.index
- n = features.length;
- while (++i < n) path.push(pathType(features[i].geometry));
- return path.join("");
- },
-
- Feature: function(o) {
- return pathType(o.geometry);
- },
-
- Point: function(o) {
- return "M" + project(o.coordinates) + pointCircle;
- },
-
- MultiPoint: function(o) {
- var path = [],
- coordinates = o.coordinates,
- i = -1, // coordinates.index
- n = coordinates.length;
- while (++i < n) path.push("M", project(coordinates[i]), pointCircle);
- return path.join("");
- },
-
- LineString: function(o) {
- var path = ["M"],
- coordinates = o.coordinates,
- i = -1, // coordinates.index
- n = coordinates.length;
- while (++i < n) path.push(project(coordinates[i]), "L");
- path.pop();
- return path.join("");
- },
-
- MultiLineString: function(o) {
- var path = [],
- coordinates = o.coordinates,
- i = -1, // coordinates.index
- n = coordinates.length,
- subcoordinates, // coordinates[i]
- j, // subcoordinates.index
- m; // subcoordinates.length
- while (++i < n) {
- subcoordinates = coordinates[i];
- j = -1;
- m = subcoordinates.length;
- path.push("M");
- while (++j < m) path.push(project(subcoordinates[j]), "L");
- path.pop();
- }