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

502 lines
16 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. // https://d3js.org/d3-zoom/ v1.7.3 Copyright 2018 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-selection'), require('d3-dispatch'), require('d3-drag'), require('d3-interpolate'), require('d3-transition')) :
  4. typeof define === 'function' && define.amd ? define(['exports', 'd3-selection', 'd3-dispatch', 'd3-drag', 'd3-interpolate', 'd3-transition'], factory) :
  5. (factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3,global.d3));
  6. }(this, (function (exports,d3Selection,d3Dispatch,d3Drag,d3Interpolate,d3Transition) { 'use strict';
  7. function constant(x) {
  8. return function() {
  9. return x;
  10. };
  11. }
  12. function ZoomEvent(target, type, transform) {
  13. this.target = target;
  14. this.type = type;
  15. this.transform = transform;
  16. }
  17. function Transform(k, x, y) {
  18. this.k = k;
  19. this.x = x;
  20. this.y = y;
  21. }
  22. Transform.prototype = {
  23. constructor: Transform,
  24. scale: function(k) {
  25. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  26. },
  27. translate: function(x, y) {
  28. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  29. },
  30. apply: function(point) {
  31. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  32. },
  33. applyX: function(x) {
  34. return x * this.k + this.x;
  35. },
  36. applyY: function(y) {
  37. return y * this.k + this.y;
  38. },
  39. invert: function(location) {
  40. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  41. },
  42. invertX: function(x) {
  43. return (x - this.x) / this.k;
  44. },
  45. invertY: function(y) {
  46. return (y - this.y) / this.k;
  47. },
  48. rescaleX: function(x) {
  49. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  50. },
  51. rescaleY: function(y) {
  52. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  53. },
  54. toString: function() {
  55. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  56. }
  57. };
  58. var identity = new Transform(1, 0, 0);
  59. transform.prototype = Transform.prototype;
  60. function transform(node) {
  61. return node.__zoom || identity;
  62. }
  63. function nopropagation() {
  64. d3Selection.event.stopImmediatePropagation();
  65. }
  66. function noevent() {
  67. d3Selection.event.preventDefault();
  68. d3Selection.event.stopImmediatePropagation();
  69. }
  70. // Ignore right-click, since that should open the context menu.
  71. function defaultFilter() {
  72. return !d3Selection.event.button;
  73. }
  74. function defaultExtent() {
  75. var e = this, w, h;
  76. if (e instanceof SVGElement) {
  77. e = e.ownerSVGElement || e;
  78. w = e.width.baseVal.value;
  79. h = e.height.baseVal.value;
  80. } else {
  81. w = e.clientWidth;
  82. h = e.clientHeight;
  83. }
  84. return [[0, 0], [w, h]];
  85. }
  86. function defaultTransform() {
  87. return this.__zoom || identity;
  88. }
  89. function defaultWheelDelta() {
  90. return -d3Selection.event.deltaY * (d3Selection.event.deltaMode ? 120 : 1) / 500;
  91. }
  92. function defaultTouchable() {
  93. return "ontouchstart" in this;
  94. }
  95. function defaultConstrain(transform$$1, extent, translateExtent) {
  96. var dx0 = transform$$1.invertX(extent[0][0]) - translateExtent[0][0],
  97. dx1 = transform$$1.invertX(extent[1][0]) - translateExtent[1][0],
  98. dy0 = transform$$1.invertY(extent[0][1]) - translateExtent[0][1],
  99. dy1 = transform$$1.invertY(extent[1][1]) - translateExtent[1][1];
  100. return transform$$1.translate(
  101. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  102. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  103. );
  104. }
  105. function zoom() {
  106. var filter = defaultFilter,
  107. extent = defaultExtent,
  108. constrain = defaultConstrain,
  109. wheelDelta = defaultWheelDelta,
  110. touchable = defaultTouchable,
  111. scaleExtent = [0, Infinity],
  112. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  113. duration = 250,
  114. interpolate = d3Interpolate.interpolateZoom,
  115. gestures = [],
  116. listeners = d3Dispatch.dispatch("start", "zoom", "end"),
  117. touchstarting,
  118. touchending,
  119. touchDelay = 500,
  120. wheelDelay = 150,
  121. clickDistance2 = 0;
  122. function zoom(selection) {
  123. selection
  124. .property("__zoom", defaultTransform)
  125. .on("wheel.zoom", wheeled)
  126. .on("mousedown.zoom", mousedowned)
  127. .on("dblclick.zoom", dblclicked)
  128. .filter(touchable)
  129. .on("touchstart.zoom", touchstarted)
  130. .on("touchmove.zoom", touchmoved)
  131. .on("touchend.zoom touchcancel.zoom", touchended)
  132. .style("touch-action", "none")
  133. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  134. }
  135. zoom.transform = function(collection, transform$$1) {
  136. var selection = collection.selection ? collection.selection() : collection;
  137. selection.property("__zoom", defaultTransform);
  138. if (collection !== selection) {
  139. schedule(collection, transform$$1);
  140. } else {
  141. selection.interrupt().each(function() {
  142. gesture(this, arguments)
  143. .start()
  144. .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
  145. .end();
  146. });
  147. }
  148. };
  149. zoom.scaleBy = function(selection, k) {
  150. zoom.scaleTo(selection, function() {
  151. var k0 = this.__zoom.k,
  152. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  153. return k0 * k1;
  154. });
  155. };
  156. zoom.scaleTo = function(selection, k) {
  157. zoom.transform(selection, function() {
  158. var e = extent.apply(this, arguments),
  159. t0 = this.__zoom,
  160. p0 = centroid(e),
  161. p1 = t0.invert(p0),
  162. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  163. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  164. });
  165. };
  166. zoom.translateBy = function(selection, x, y) {
  167. zoom.transform(selection, function() {
  168. return constrain(this.__zoom.translate(
  169. typeof x === "function" ? x.apply(this, arguments) : x,
  170. typeof y === "function" ? y.apply(this, arguments) : y
  171. ), extent.apply(this, arguments), translateExtent);
  172. });
  173. };
  174. zoom.translateTo = function(selection, x, y) {
  175. zoom.transform(selection, function() {
  176. var e = extent.apply(this, arguments),
  177. t = this.__zoom,
  178. p = centroid(e);
  179. return constrain(identity.translate(p[0], p[1]).scale(t.k).translate(
  180. typeof x === "function" ? -x.apply(this, arguments) : -x,
  181. typeof y === "function" ? -y.apply(this, arguments) : -y
  182. ), e, translateExtent);
  183. });
  184. };
  185. function scale(transform$$1, k) {
  186. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  187. return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
  188. }
  189. function translate(transform$$1, p0, p1) {
  190. var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
  191. return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
  192. }
  193. function centroid(extent) {
  194. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  195. }
  196. function schedule(transition, transform$$1, center) {
  197. transition
  198. .on("start.zoom", function() { gesture(this, arguments).start(); })
  199. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  200. .tween("zoom", function() {
  201. var that = this,
  202. args = arguments,
  203. g = gesture(that, args),
  204. e = extent.apply(that, args),
  205. p = center || centroid(e),
  206. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  207. a = that.__zoom,
  208. b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
  209. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  210. return function(t) {
  211. if (t === 1) t = b; // Avoid rounding error on end.
  212. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  213. g.zoom(null, t);
  214. };
  215. });
  216. }
  217. function gesture(that, args) {
  218. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  219. if ((g = gestures[i]).that === that) {
  220. return g;
  221. }
  222. }
  223. return new Gesture(that, args);
  224. }
  225. function Gesture(that, args) {
  226. this.that = that;
  227. this.args = args;
  228. this.index = -1;
  229. this.active = 0;
  230. this.extent = extent.apply(that, args);
  231. }
  232. Gesture.prototype = {
  233. start: function() {
  234. if (++this.active === 1) {
  235. this.index = gestures.push(this) - 1;
  236. this.emit("start");
  237. }
  238. return this;
  239. },
  240. zoom: function(key, transform$$1) {
  241. if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
  242. if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
  243. if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
  244. this.that.__zoom = transform$$1;
  245. this.emit("zoom");
  246. return this;
  247. },
  248. end: function() {
  249. if (--this.active === 0) {
  250. gestures.splice(this.index, 1);
  251. this.index = -1;
  252. this.emit("end");
  253. }
  254. return this;
  255. },
  256. emit: function(type) {
  257. d3Selection.customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  258. }
  259. };
  260. function wheeled() {
  261. if (!filter.apply(this, arguments)) return;
  262. var g = gesture(this, arguments),
  263. t = this.__zoom,
  264. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  265. p = d3Selection.mouse(this);
  266. // If the mouse is in the same location as before, reuse it.
  267. // If there were recent wheel events, reset the wheel idle timeout.
  268. if (g.wheel) {
  269. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  270. g.mouse[1] = t.invert(g.mouse[0] = p);
  271. }
  272. clearTimeout(g.wheel);
  273. }
  274. // If this wheel event won’t trigger a transform change, ignore it.
  275. else if (t.k === k) return;
  276. // Otherwise, capture the mouse point and location at the start.
  277. else {
  278. g.mouse = [p, t.invert(p)];
  279. d3Transition.interrupt(this);
  280. g.start();
  281. }
  282. noevent();
  283. g.wheel = setTimeout(wheelidled, wheelDelay);
  284. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  285. function wheelidled() {
  286. g.wheel = null;
  287. g.end();
  288. }
  289. }
  290. function mousedowned() {
  291. if (touchending || !filter.apply(this, arguments)) return;
  292. var g = gesture(this, arguments),
  293. v = d3Selection.select(d3Selection.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  294. p = d3Selection.mouse(this),
  295. x0 = d3Selection.event.clientX,
  296. y0 = d3Selection.event.clientY;
  297. d3Drag.dragDisable(d3Selection.event.view);
  298. nopropagation();
  299. g.mouse = [p, this.__zoom.invert(p)];
  300. d3Transition.interrupt(this);
  301. g.start();
  302. function mousemoved() {
  303. noevent();
  304. if (!g.moved) {
  305. var dx = d3Selection.event.clientX - x0, dy = d3Selection.event.clientY - y0;
  306. g.moved = dx * dx + dy * dy > clickDistance2;
  307. }
  308. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = d3Selection.mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  309. }
  310. function mouseupped() {
  311. v.on("mousemove.zoom mouseup.zoom", null);
  312. d3Drag.dragEnable(d3Selection.event.view, g.moved);
  313. noevent();
  314. g.end();
  315. }
  316. }
  317. function dblclicked() {
  318. if (!filter.apply(this, arguments)) return;
  319. var t0 = this.__zoom,
  320. p0 = d3Selection.mouse(this),
  321. p1 = t0.invert(p0),
  322. k1 = t0.k * (d3Selection.event.shiftKey ? 0.5 : 2),
  323. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  324. noevent();
  325. if (duration > 0) d3Selection.select(this).transition().duration(duration).call(schedule, t1, p0);
  326. else d3Selection.select(this).call(zoom.transform, t1);
  327. }
  328. function touchstarted() {
  329. if (!filter.apply(this, arguments)) return;
  330. var g = gesture(this, arguments),
  331. touches = d3Selection.event.changedTouches,
  332. started,
  333. n = touches.length, i, t, p;
  334. nopropagation();
  335. for (i = 0; i < n; ++i) {
  336. t = touches[i], p = d3Selection.touch(this, touches, t.identifier);
  337. p = [p, this.__zoom.invert(p), t.identifier];
  338. if (!g.touch0) g.touch0 = p, started = true;
  339. else if (!g.touch1) g.touch1 = p;
  340. }
  341. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  342. if (touchstarting) {
  343. touchstarting = clearTimeout(touchstarting);
  344. if (!g.touch1) {
  345. g.end();
  346. p = d3Selection.select(this).on("dblclick.zoom");
  347. if (p) p.apply(this, arguments);
  348. return;
  349. }
  350. }
  351. if (started) {
  352. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  353. d3Transition.interrupt(this);
  354. g.start();
  355. }
  356. }
  357. function touchmoved() {
  358. var g = gesture(this, arguments),
  359. touches = d3Selection.event.changedTouches,
  360. n = touches.length, i, t, p, l;
  361. noevent();
  362. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  363. for (i = 0; i < n; ++i) {
  364. t = touches[i], p = d3Selection.touch(this, touches, t.identifier);
  365. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  366. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  367. }
  368. t = g.that.__zoom;
  369. if (g.touch1) {
  370. var p0 = g.touch0[0], l0 = g.touch0[1],
  371. p1 = g.touch1[0], l1 = g.touch1[1],
  372. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  373. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  374. t = scale(t, Math.sqrt(dp / dl));
  375. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  376. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  377. }
  378. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  379. else return;
  380. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  381. }
  382. function touchended() {
  383. var g = gesture(this, arguments),
  384. touches = d3Selection.event.changedTouches,
  385. n = touches.length, i, t;
  386. nopropagation();
  387. if (touchending) clearTimeout(touchending);
  388. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  389. for (i = 0; i < n; ++i) {
  390. t = touches[i];
  391. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  392. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  393. }
  394. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  395. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  396. else g.end();
  397. }
  398. zoom.wheelDelta = function(_) {
  399. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
  400. };
  401. zoom.filter = function(_) {
  402. return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
  403. };
  404. zoom.touchable = function(_) {
  405. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
  406. };
  407. zoom.extent = function(_) {
  408. return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  409. };
  410. zoom.scaleExtent = function(_) {
  411. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  412. };
  413. zoom.translateExtent = function(_) {
  414. return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
  415. };
  416. zoom.constrain = function(_) {
  417. return arguments.length ? (constrain = _, zoom) : constrain;
  418. };
  419. zoom.duration = function(_) {
  420. return arguments.length ? (duration = +_, zoom) : duration;
  421. };
  422. zoom.interpolate = function(_) {
  423. return arguments.length ? (interpolate = _, zoom) : interpolate;
  424. };
  425. zoom.on = function() {
  426. var value = listeners.on.apply(listeners, arguments);
  427. return value === listeners ? zoom : value;
  428. };
  429. zoom.clickDistance = function(_) {
  430. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  431. };
  432. return zoom;
  433. }
  434. exports.zoom = zoom;
  435. exports.zoomTransform = transform;
  436. exports.zoomIdentity = identity;
  437. Object.defineProperty(exports, '__esModule', { value: true });
  438. })));