Node-Red configuration
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

d3-zoom.js 18KB

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