Node-Red configuration
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

d3-path.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // https://d3js.org/d3-path/ v3.1.0 Copyright 2015-2022 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
  6. })(this, (function (exports) { 'use strict';
  7. const pi = Math.PI,
  8. tau = 2 * pi,
  9. epsilon = 1e-6,
  10. tauEpsilon = tau - epsilon;
  11. function append(strings) {
  12. this._ += strings[0];
  13. for (let i = 1, n = strings.length; i < n; ++i) {
  14. this._ += arguments[i] + strings[i];
  15. }
  16. }
  17. function appendRound(digits) {
  18. let d = Math.floor(digits);
  19. if (!(d >= 0)) throw new Error(`invalid digits: ${digits}`);
  20. if (d > 15) return append;
  21. const k = 10 ** d;
  22. return function(strings) {
  23. this._ += strings[0];
  24. for (let i = 1, n = strings.length; i < n; ++i) {
  25. this._ += Math.round(arguments[i] * k) / k + strings[i];
  26. }
  27. };
  28. }
  29. class Path {
  30. constructor(digits) {
  31. this._x0 = this._y0 = // start of current subpath
  32. this._x1 = this._y1 = null; // end of current subpath
  33. this._ = "";
  34. this._append = digits == null ? append : appendRound(digits);
  35. }
  36. moveTo(x, y) {
  37. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
  38. }
  39. closePath() {
  40. if (this._x1 !== null) {
  41. this._x1 = this._x0, this._y1 = this._y0;
  42. this._append`Z`;
  43. }
  44. }
  45. lineTo(x, y) {
  46. this._append`L${this._x1 = +x},${this._y1 = +y}`;
  47. }
  48. quadraticCurveTo(x1, y1, x, y) {
  49. this._append`Q${+x1},${+y1},${this._x1 = +x},${this._y1 = +y}`;
  50. }
  51. bezierCurveTo(x1, y1, x2, y2, x, y) {
  52. this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`;
  53. }
  54. arcTo(x1, y1, x2, y2, r) {
  55. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  56. // Is the radius negative? Error.
  57. if (r < 0) throw new Error(`negative radius: ${r}`);
  58. let x0 = this._x1,
  59. y0 = this._y1,
  60. x21 = x2 - x1,
  61. y21 = y2 - y1,
  62. x01 = x0 - x1,
  63. y01 = y0 - y1,
  64. l01_2 = x01 * x01 + y01 * y01;
  65. // Is this path empty? Move to (x1,y1).
  66. if (this._x1 === null) {
  67. this._append`M${this._x1 = x1},${this._y1 = y1}`;
  68. }
  69. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  70. else if (!(l01_2 > epsilon));
  71. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  72. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  73. // Or, is the radius zero? Line to (x1,y1).
  74. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
  75. this._append`L${this._x1 = x1},${this._y1 = y1}`;
  76. }
  77. // Otherwise, draw an arc!
  78. else {
  79. let x20 = x2 - x0,
  80. y20 = y2 - y0,
  81. l21_2 = x21 * x21 + y21 * y21,
  82. l20_2 = x20 * x20 + y20 * y20,
  83. l21 = Math.sqrt(l21_2),
  84. l01 = Math.sqrt(l01_2),
  85. l = r * Math.tan((pi - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  86. t01 = l / l01,
  87. t21 = l / l21;
  88. // If the start tangent is not coincident with (x0,y0), line to.
  89. if (Math.abs(t01 - 1) > epsilon) {
  90. this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`;
  91. }
  92. this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`;
  93. }
  94. }
  95. arc(x, y, r, a0, a1, ccw) {
  96. x = +x, y = +y, r = +r, ccw = !!ccw;
  97. // Is the radius negative? Error.
  98. if (r < 0) throw new Error(`negative radius: ${r}`);
  99. let dx = r * Math.cos(a0),
  100. dy = r * Math.sin(a0),
  101. x0 = x + dx,
  102. y0 = y + dy,
  103. cw = 1 ^ ccw,
  104. da = ccw ? a0 - a1 : a1 - a0;
  105. // Is this path empty? Move to (x0,y0).
  106. if (this._x1 === null) {
  107. this._append`M${x0},${y0}`;
  108. }
  109. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  110. else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
  111. this._append`L${x0},${y0}`;
  112. }
  113. // Is this arc empty? We’re done.
  114. if (!r) return;
  115. // Does the angle go the wrong way? Flip the direction.
  116. if (da < 0) da = da % tau + tau;
  117. // Is this a complete circle? Draw two arcs to complete the circle.
  118. if (da > tauEpsilon) {
  119. this._append`A${r},${r},0,1,${cw},${x - dx},${y - dy}A${r},${r},0,1,${cw},${this._x1 = x0},${this._y1 = y0}`;
  120. }
  121. // Is this arc non-empty? Draw an arc!
  122. else if (da > epsilon) {
  123. this._append`A${r},${r},0,${+(da >= pi)},${cw},${this._x1 = x + r * Math.cos(a1)},${this._y1 = y + r * Math.sin(a1)}`;
  124. }
  125. }
  126. rect(x, y, w, h) {
  127. this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${w = +w}v${+h}h${-w}Z`;
  128. }
  129. toString() {
  130. return this._;
  131. }
  132. }
  133. function path() {
  134. return new Path;
  135. }
  136. // Allow instanceof d3.path
  137. path.prototype = Path.prototype;
  138. function pathRound(digits = 3) {
  139. return new Path(+digits);
  140. }
  141. exports.Path = Path;
  142. exports.path = path;
  143. exports.pathRound = pathRound;
  144. }));