@d3plus/core 3.0.15 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88482 -2998
  3. package/es/index.js +1 -1
  4. package/es/src/charts/AreaPlot.js +1 -3
  5. package/es/src/charts/BarChart.js +1 -3
  6. package/es/src/charts/BoxWhisker.js +2 -4
  7. package/es/src/charts/BumpChart.js +4 -5
  8. package/es/src/charts/Donut.js +1 -3
  9. package/es/src/charts/Geomap.js +47 -88
  10. package/es/src/charts/LinePlot.js +1 -3
  11. package/es/src/charts/Matrix.js +27 -46
  12. package/es/src/charts/Network.js +87 -81
  13. package/es/src/charts/Pack.js +21 -34
  14. package/es/src/charts/Pie.js +12 -24
  15. package/es/src/charts/Plot.js +226 -321
  16. package/es/src/charts/Priestley.js +18 -36
  17. package/es/src/charts/Radar.js +100 -47
  18. package/es/src/charts/RadialMatrix.js +35 -47
  19. package/es/src/charts/Rings.js +99 -90
  20. package/es/src/charts/Sankey.js +85 -75
  21. package/es/src/charts/StackedArea.js +1 -3
  22. package/es/src/charts/Tree.js +27 -28
  23. package/es/src/charts/Treemap.js +117 -71
  24. package/es/src/charts/Viz.js +297 -493
  25. package/es/src/charts/drawSteps/drawAttribution.js +1 -1
  26. package/es/src/charts/drawSteps/drawBack.js +1 -2
  27. package/es/src/charts/drawSteps/drawColorScale.js +1 -2
  28. package/es/src/charts/drawSteps/drawLegend.js +8 -10
  29. package/es/src/charts/drawSteps/drawSubtitle.js +1 -3
  30. package/es/src/charts/drawSteps/drawTimeline.js +12 -9
  31. package/es/src/charts/drawSteps/drawTitle.js +1 -3
  32. package/es/src/charts/drawSteps/drawTotal.js +1 -3
  33. package/es/src/charts/drawSteps/zoomControls.js +19 -21
  34. package/es/src/charts/events/click.legend.js +2 -3
  35. package/es/src/charts/events/click.shape.js +2 -4
  36. package/es/src/charts/events/mouseenter.js +7 -8
  37. package/es/src/charts/events/mouseleave.js +1 -3
  38. package/es/src/charts/events/mousemove.legend.js +3 -4
  39. package/es/src/charts/events/mousemove.shape.js +2 -4
  40. package/es/src/charts/events/touchstart.body.js +1 -1
  41. package/es/src/charts/helpers/matrixData.js +11 -4
  42. package/es/src/charts/helpers/tileAttributions.js +2 -1
  43. package/es/src/charts/plotBuffers/Bar.js +55 -12
  44. package/es/src/charts/plotBuffers/Box.js +55 -12
  45. package/es/src/charts/plotBuffers/Circle.js +9 -11
  46. package/es/src/charts/plotBuffers/Line.js +4 -6
  47. package/es/src/charts/plotBuffers/Rect.js +10 -12
  48. package/es/src/charts/plotBuffers/discreteBuffer.js +4 -2
  49. package/es/src/charts/plotBuffers/numericBuffer.js +7 -6
  50. package/es/src/components/Axis.js +298 -426
  51. package/es/src/components/AxisBottom.js +1 -3
  52. package/es/src/components/AxisLeft.js +1 -3
  53. package/es/src/components/AxisRight.js +1 -3
  54. package/es/src/components/AxisTop.js +1 -3
  55. package/es/src/components/ColorScale.js +80 -197
  56. package/es/src/components/Legend.js +82 -135
  57. package/es/src/components/Message.js +27 -19
  58. package/es/src/components/TextBox.js +106 -262
  59. package/es/src/components/Timeline.js +88 -155
  60. package/es/src/components/Tooltip.js +301 -330
  61. package/es/src/shapes/Area.js +95 -74
  62. package/es/src/shapes/Bar.js +46 -86
  63. package/es/src/shapes/Box.js +104 -118
  64. package/es/src/shapes/Circle.js +29 -30
  65. package/es/src/shapes/Image.js +44 -102
  66. package/es/src/shapes/Line.js +74 -40
  67. package/es/src/shapes/Path.js +23 -25
  68. package/es/src/shapes/Rect.js +29 -41
  69. package/es/src/shapes/Shape.js +152 -369
  70. package/es/src/shapes/Whisker.js +89 -90
  71. package/es/src/utils/AccessorFn.js +4 -0
  72. package/es/src/utils/BaseClass.js +53 -82
  73. package/es/src/utils/D3plusConfig.js +1 -0
  74. package/es/src/utils/RESET.js +2 -4
  75. package/es/src/utils/accessor.js +4 -5
  76. package/es/src/utils/configPrep.js +13 -12
  77. package/es/src/utils/constant.js +2 -3
  78. package/es/src/utils/getProp.js +4 -4
  79. package/es/src/utils/index.js +0 -1
  80. package/package.json +29 -22
  81. package/types/index.d.ts +5 -0
  82. package/types/src/charts/AreaPlot.d.ts +16 -0
  83. package/types/src/charts/BarChart.d.ts +16 -0
  84. package/types/src/charts/BoxWhisker.d.ts +11 -0
  85. package/types/src/charts/BumpChart.d.ts +36 -0
  86. package/types/src/charts/Donut.d.ts +11 -0
  87. package/types/src/charts/Geomap.d.ts +120 -0
  88. package/types/src/charts/LinePlot.d.ts +15 -0
  89. package/types/src/charts/Matrix.d.ts +74 -0
  90. package/types/src/charts/Network.d.ts +78 -0
  91. package/types/src/charts/Pack.d.ts +47 -0
  92. package/types/src/charts/Pie.d.ts +44 -0
  93. package/types/src/charts/Plot.d.ts +199 -0
  94. package/types/src/charts/Priestley.d.ts +37 -0
  95. package/types/src/charts/Radar.d.ts +38 -0
  96. package/types/src/charts/RadialMatrix.d.ts +78 -0
  97. package/types/src/charts/Rings.d.ts +74 -0
  98. package/types/src/charts/Sankey.d.ts +81 -0
  99. package/types/src/charts/StackedArea.d.ts +14 -0
  100. package/types/src/charts/Tree.d.ts +33 -0
  101. package/types/src/charts/Treemap.d.ts +51 -0
  102. package/types/src/charts/Viz.d.ts +402 -0
  103. package/types/src/charts/drawSteps/drawAttribution.d.ts +7 -0
  104. package/types/src/charts/drawSteps/drawBack.d.ts +6 -0
  105. package/types/src/charts/drawSteps/drawColorScale.d.ts +6 -0
  106. package/types/src/charts/drawSteps/drawLegend.d.ts +12 -0
  107. package/types/src/charts/drawSteps/drawSubtitle.d.ts +7 -0
  108. package/types/src/charts/drawSteps/drawTimeline.d.ts +7 -0
  109. package/types/src/charts/drawSteps/drawTitle.d.ts +7 -0
  110. package/types/src/charts/drawSteps/drawTotal.d.ts +7 -0
  111. package/types/src/charts/drawSteps/zoomControls.d.ts +7 -0
  112. package/types/src/charts/events/click.legend.d.ts +8 -0
  113. package/types/src/charts/events/click.shape.d.ts +8 -0
  114. package/types/src/charts/events/mouseenter.d.ts +8 -0
  115. package/types/src/charts/events/mouseleave.d.ts +8 -0
  116. package/types/src/charts/events/mousemove.legend.d.ts +9 -0
  117. package/types/src/charts/events/mousemove.shape.d.ts +9 -0
  118. package/types/src/charts/events/touchstart.body.d.ts +7 -0
  119. package/types/src/charts/helpers/matrixData.d.ts +11 -0
  120. package/types/src/charts/helpers/tileAttributions.d.ts +6 -0
  121. package/types/src/charts/index.d.ts +21 -0
  122. package/types/src/charts/plotBuffers/Bar.d.ts +16 -0
  123. package/types/src/charts/plotBuffers/Box.d.ts +16 -0
  124. package/types/src/charts/plotBuffers/Circle.d.ts +20 -0
  125. package/types/src/charts/plotBuffers/Line.d.ts +16 -0
  126. package/types/src/charts/plotBuffers/Rect.d.ts +19 -0
  127. package/types/src/charts/plotBuffers/discreteBuffer.d.ts +7 -0
  128. package/types/src/charts/plotBuffers/numericBuffer.d.ts +5 -0
  129. package/types/src/components/Axis.d.ts +309 -0
  130. package/types/src/components/AxisBottom.d.ts +11 -0
  131. package/types/src/components/AxisLeft.d.ts +11 -0
  132. package/types/src/components/AxisRight.d.ts +11 -0
  133. package/types/src/components/AxisTop.d.ts +11 -0
  134. package/types/src/components/ColorScale.d.ts +208 -0
  135. package/types/src/components/Legend.d.ts +157 -0
  136. package/types/src/components/Message.d.ts +40 -0
  137. package/types/src/components/TextBox.d.ts +278 -0
  138. package/types/src/components/Timeline.d.ts +157 -0
  139. package/types/src/components/Tooltip.d.ts +297 -0
  140. package/types/src/components/index.d.ts +11 -0
  141. package/types/src/shapes/Area.d.ts +81 -0
  142. package/types/src/shapes/Bar.d.ts +104 -0
  143. package/types/src/shapes/Box.d.ts +121 -0
  144. package/types/src/shapes/Circle.d.ts +44 -0
  145. package/types/src/shapes/Image.d.ts +124 -0
  146. package/types/src/shapes/Line.d.ts +48 -0
  147. package/types/src/shapes/Path.d.ts +38 -0
  148. package/types/src/shapes/Rect.d.ts +54 -0
  149. package/types/src/shapes/Shape.d.ts +378 -0
  150. package/types/src/shapes/Whisker.d.ts +96 -0
  151. package/types/src/shapes/index.d.ts +10 -0
  152. package/types/src/utils/AccessorFn.d.ts +6 -0
  153. package/types/src/utils/BaseClass.d.ts +76 -0
  154. package/types/src/utils/D3plusConfig.d.ts +164 -0
  155. package/types/src/utils/RESET.d.ts +3 -0
  156. package/types/src/utils/accessor.d.ts +13 -0
  157. package/types/src/utils/configPrep.d.ts +28 -0
  158. package/types/src/utils/constant.d.ts +11 -0
  159. package/types/src/utils/getProp.d.ts +9 -0
  160. package/types/src/utils/index.d.ts +8 -0
  161. package/umd/d3plus-core.full.js +20134 -18708
  162. package/umd/d3plus-core.full.js.map +1 -1
  163. package/umd/d3plus-core.full.min.js +2922 -5396
  164. package/umd/d3plus-core.js +1927 -4081
  165. package/umd/d3plus-core.js.map +1 -1
  166. package/umd/d3plus-core.min.js +1607 -3939
  167. package/es/src/utils/uuid.js +0 -13
@@ -4,6 +4,35 @@ function _assert_this_initialized(self) {
4
4
  }
5
5
  return self;
6
6
  }
7
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
+ try {
9
+ var info = gen[key](arg);
10
+ var value = info.value;
11
+ } catch (error) {
12
+ reject(error);
13
+ return;
14
+ }
15
+ if (info.done) {
16
+ resolve(value);
17
+ } else {
18
+ Promise.resolve(value).then(_next, _throw);
19
+ }
20
+ }
21
+ function _async_to_generator(fn) {
22
+ return function() {
23
+ var self = this, args = arguments;
24
+ return new Promise(function(resolve, reject) {
25
+ var gen = fn.apply(self, args);
26
+ function _next(value) {
27
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
28
+ }
29
+ function _throw(err) {
30
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
31
+ }
32
+ _next(undefined);
33
+ });
34
+ };
35
+ }
7
36
  function _call_super(_this, derived, args) {
8
37
  derived = _get_prototype_of(derived);
9
38
  return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
@@ -27,6 +56,19 @@ function _create_class(Constructor, protoProps, staticProps) {
27
56
  if (staticProps) _defineProperties(Constructor, staticProps);
28
57
  return Constructor;
29
58
  }
59
+ function _define_property(obj, key, value) {
60
+ if (key in obj) {
61
+ Object.defineProperty(obj, key, {
62
+ value: value,
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true
66
+ });
67
+ } else {
68
+ obj[key] = value;
69
+ }
70
+ return obj;
71
+ }
30
72
  function _get_prototype_of(o) {
31
73
  _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
32
74
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -71,50 +113,209 @@ function _is_native_reflect_construct() {
71
113
  return !!result;
72
114
  })();
73
115
  }
116
+ function _ts_generator(thisArg, body) {
117
+ var f, y, t, _ = {
118
+ label: 0,
119
+ sent: function() {
120
+ if (t[0] & 1) throw t[1];
121
+ return t[1];
122
+ },
123
+ trys: [],
124
+ ops: []
125
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
126
+ return d(g, "next", {
127
+ value: verb(0)
128
+ }), d(g, "throw", {
129
+ value: verb(1)
130
+ }), d(g, "return", {
131
+ value: verb(2)
132
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
133
+ value: function() {
134
+ return this;
135
+ }
136
+ }), g;
137
+ function verb(n) {
138
+ return function(v) {
139
+ return step([
140
+ n,
141
+ v
142
+ ]);
143
+ };
144
+ }
145
+ function step(op) {
146
+ if (f) throw new TypeError("Generator is already executing.");
147
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
148
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
149
+ if (y = 0, t) op = [
150
+ op[0] & 2,
151
+ t.value
152
+ ];
153
+ switch(op[0]){
154
+ case 0:
155
+ case 1:
156
+ t = op;
157
+ break;
158
+ case 4:
159
+ _.label++;
160
+ return {
161
+ value: op[1],
162
+ done: false
163
+ };
164
+ case 5:
165
+ _.label++;
166
+ y = op[1];
167
+ op = [
168
+ 0
169
+ ];
170
+ continue;
171
+ case 7:
172
+ op = _.ops.pop();
173
+ _.trys.pop();
174
+ continue;
175
+ default:
176
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
177
+ _ = 0;
178
+ continue;
179
+ }
180
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
181
+ _.label = op[1];
182
+ break;
183
+ }
184
+ if (op[0] === 6 && _.label < t[1]) {
185
+ _.label = t[1];
186
+ t = op;
187
+ break;
188
+ }
189
+ if (t && _.label < t[2]) {
190
+ _.label = t[2];
191
+ _.ops.push(op);
192
+ break;
193
+ }
194
+ if (t[2]) _.ops.pop();
195
+ _.trys.pop();
196
+ continue;
197
+ }
198
+ op = body.call(thisArg, _);
199
+ } catch (e) {
200
+ op = [
201
+ 6,
202
+ e
203
+ ];
204
+ y = 0;
205
+ } finally{
206
+ f = t = 0;
207
+ }
208
+ if (op[0] & 5) throw op[1];
209
+ return {
210
+ value: op[0] ? op[1] : void 0,
211
+ done: true
212
+ };
213
+ }
214
+ }
74
215
  import { select } from "d3-selection";
75
- import { createPopper } from '@popperjs/core';
76
- import { colorDefaults } from "@d3plus/color";
77
- import { elem, prefix, stylize } from "@d3plus/dom";
216
+ import { computePosition, arrow as arrowMiddleware, offset, flip, shift } from "@floating-ui/dom";
217
+ import { colorContrast, colorDefaults } from "@d3plus/color";
218
+ import { elem, stylize } from "@d3plus/dom";
78
219
  import { fontFamily, fontFamilyStringify } from "@d3plus/text";
79
220
  import { accessor, BaseClass, constant } from "../utils/index.js";
80
221
  /**
81
- * Creates a reference element for popper.
222
+ * Creates a virtual reference element for Floating UI.
82
223
  * @param {Number[]} position
83
224
  * @private
84
- */ function generateReference() {
225
+ */ function generateReference() {
85
226
  var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [
86
227
  0,
87
228
  0
88
229
  ];
89
- return function() {
90
- return {
91
- width: 0,
92
- height: 0,
93
- top: position[1],
94
- right: position[0],
95
- bottom: position[1],
96
- left: position[0]
97
- };
230
+ return {
231
+ getBoundingClientRect: function getBoundingClientRect() {
232
+ return {
233
+ width: 0,
234
+ height: 0,
235
+ x: position[0],
236
+ y: position[1],
237
+ top: position[1],
238
+ right: position[0],
239
+ bottom: position[1],
240
+ left: position[0]
241
+ };
242
+ }
98
243
  };
99
244
  }
245
+ /**
246
+ * Positions a tooltip using Floating UI.
247
+ * @private
248
+ */ function positionTooltip(reference, tooltip, arrowEl, offsetVal, arrowDistance, arrowHeight) {
249
+ return _async_to_generator(function() {
250
+ var _middlewareData_arrow, _ref, x, y, placement, middlewareData, flipped, border;
251
+ return _ts_generator(this, function(_state) {
252
+ switch(_state.label){
253
+ case 0:
254
+ return [
255
+ 4,
256
+ computePosition(reference, tooltip, {
257
+ placement: "top",
258
+ middleware: [
259
+ offset(offsetVal + arrowDistance),
260
+ flip({
261
+ fallbackPlacements: [
262
+ "bottom"
263
+ ],
264
+ padding: 5
265
+ }),
266
+ shift({
267
+ padding: 5
268
+ }),
269
+ arrowMiddleware({
270
+ element: arrowEl
271
+ })
272
+ ]
273
+ })
274
+ ];
275
+ case 1:
276
+ _ref = _state.sent(), x = _ref.x, y = _ref.y, placement = _ref.placement, middlewareData = _ref.middlewareData;
277
+ Object.assign(tooltip.style, {
278
+ position: "absolute",
279
+ left: "".concat(x, "px"),
280
+ top: "".concat(y, "px"),
281
+ visibility: "visible"
282
+ });
283
+ flipped = placement === "bottom";
284
+ border = parseFloat(arrowEl.style.borderRightWidth) || 0;
285
+ if (flipped) {
286
+ arrowEl.style.transform = "rotate(225deg)";
287
+ arrowEl.style.top = "-".concat(arrowHeight / 2 + border, "px");
288
+ arrowEl.style.bottom = "";
289
+ } else {
290
+ arrowEl.style.transform = "rotate(45deg)";
291
+ arrowEl.style.bottom = "-".concat(arrowHeight / 2 + border, "px");
292
+ arrowEl.style.top = "";
293
+ }
294
+ arrowEl.style.left = ((_middlewareData_arrow = middlewareData.arrow) === null || _middlewareData_arrow === void 0 ? void 0 : _middlewareData_arrow.x) != null ? "".concat(middlewareData.arrow.x, "px") : "";
295
+ return [
296
+ 2
297
+ ];
298
+ }
299
+ });
300
+ })();
301
+ }
100
302
  var Tooltip = /*#__PURE__*/ function(BaseClass) {
101
303
  "use strict";
102
304
  _inherits(Tooltip, BaseClass);
103
305
  function Tooltip() {
104
306
  _class_call_check(this, Tooltip);
105
307
  var _this;
106
- _this = _call_super(this, Tooltip);
308
+ _this = _call_super(this, Tooltip), _define_property(_this, "_arrow", void 0), _define_property(_this, "_arrowStyle", void 0), _define_property(_this, "_background", void 0), _define_property(_this, "_body", void 0), _define_property(_this, "_bodyStyle", void 0), _define_property(_this, "_border", void 0), _define_property(_this, "_borderRadius", void 0), _define_property(_this, "_className", void 0), _define_property(_this, "_data", void 0), _define_property(_this, "_footer", void 0), _define_property(_this, "_footerStyle", void 0), _define_property(_this, "_height", void 0), _define_property(_this, "_id", void 0), _define_property(_this, "_offset", void 0), _define_property(_this, "_padding", void 0), _define_property(_this, "_pointerEvents", void 0), _define_property(_this, "_tooltipRefs", void 0), _define_property(_this, "_position", void 0), _define_property(_this, "_tableStyle", void 0), _define_property(_this, "_tbody", void 0), _define_property(_this, "_tbodyStyle", void 0), _define_property(_this, "_thead", void 0), _define_property(_this, "_theadStyle", void 0), _define_property(_this, "_title", void 0), _define_property(_this, "_titleStyle", void 0), _define_property(_this, "_tooltipStyle", void 0), _define_property(_this, "_trStyle", void 0), _define_property(_this, "_tdStyle", void 0), _define_property(_this, "_maxWidth", void 0), _define_property(_this, "_minWidth", void 0), _define_property(_this, "_width", void 0);
107
309
  _this._arrow = accessor("arrow", "");
108
310
  _this._arrowStyle = {
109
- "content": "",
110
- "background": "inherit",
111
- "border": "inherit",
311
+ content: "",
312
+ background: "inherit",
313
+ border: "inherit",
112
314
  "border-width": "0 1px 1px 0",
113
- "height": "10px",
114
- "position": "absolute",
115
- "transform": "rotate(45deg)",
116
- "width": "10px",
117
- "z-index": "-1"
315
+ height: "10px",
316
+ position: "absolute",
317
+ transform: "rotate(45deg)",
318
+ width: "10px"
118
319
  };
119
320
  _this._background = constant(colorDefaults.light);
120
321
  _this._body = accessor("body", "");
@@ -141,18 +342,17 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
141
342
  _this._offset = constant(5);
142
343
  _this._padding = constant("10px");
143
344
  _this._pointerEvents = constant("auto");
144
- _this._popperClasses = {};
345
+ _this._tooltipRefs = {};
145
346
  _this._position = function(d) {
146
347
  return [
147
348
  d.x,
148
349
  d.y
149
350
  ];
150
351
  };
151
- _this._prefix = prefix();
152
352
  _this._tableStyle = {
153
353
  "border-collapse": "collapse",
154
354
  "border-spacing": "0",
155
- "width": "100%"
355
+ width: "100%"
156
356
  };
157
357
  _this._tbody = [];
158
358
  _this._tbodyStyle = {
@@ -169,11 +369,14 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
169
369
  _this._titleStyle = {
170
370
  "font-size": "14px",
171
371
  "font-weight": "600",
172
- "margin-bottom": "5px"
372
+ "margin-bottom": "5px",
373
+ "text-align": "center"
173
374
  };
174
375
  _this._tooltipStyle = {
175
376
  "box-shadow": "0 1px 5px rgba(0, 0, 0, 0.25)",
176
- "color": colorDefaults.dark,
377
+ color: function color(d, i) {
378
+ return colorContrast(_this._background(d, i));
379
+ },
177
380
  "font-family": fontFamilyStringify(fontFamily)
178
381
  };
179
382
  _this._trStyle = {
@@ -182,7 +385,9 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
182
385
  }
183
386
  };
184
387
  _this._tdStyle = {};
185
- _this._width = constant("150px");
388
+ _this._maxWidth = constant("200px");
389
+ _this._minWidth = constant("100px");
390
+ _this._width = constant("auto");
186
391
  return _this;
187
392
  }
188
393
  _create_class(Tooltip, [
@@ -190,19 +395,20 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
190
395
  /**
191
396
  The inner return object and draw function that gets assigned the public methods.
192
397
  @private
193
- */ key: "render",
398
+ */ key: "render",
194
399
  value: function render(callback) {
195
400
  var _this = this;
196
401
  var that = this;
197
402
  var portal = elem("div#d3plus-portal");
198
- var tooltips = portal.selectAll(".".concat(this._className)).data(this._data, this._id);
403
+ var tooltips = portal.selectAll(".".concat(this._className))// eslint-disable-next-line @typescript-eslint/no-explicit-any
404
+ .data(this._data, this._id);
199
405
  var enter = tooltips.enter().append("div").attr("class", this._className);
200
406
  var update = tooltips.merge(enter);
201
407
  stylize(update, this._tooltipStyle);
202
408
  /**
203
409
  Creates DIV elements with a unique class and styles.
204
410
  @private
205
- */ function divElement(cat) {
411
+ */ function divElement(cat) {
206
412
  enter.append("div").attr("class", "d3plus-tooltip-".concat(cat)).attr("id", function(d, i) {
207
413
  return "d3plus-tooltip-".concat(cat, "-").concat(d ? that._id(d, i) : "");
208
414
  });
@@ -218,7 +424,7 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
218
424
  /**
219
425
  Fetches table contents given functions or values.
220
426
  @private
221
- */ function cellContent(d) {
427
+ */ function cellContent(d) {
222
428
  if (typeof d === "function") {
223
429
  var datum = select(this.parentNode.parentNode).datum();
224
430
  return d(datum, that._data.indexOf(datum));
@@ -227,8 +433,8 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
227
433
  /**
228
434
  Sets styles for both enter and update.
229
435
  @private
230
- */ function boxStyles(box) {
231
- box.style("background", that._background).style("".concat(that._prefix, "border-radius"), that._borderRadius).style("pointer-events", that._pointerEvents).style("padding", that._padding).style("width", that._width).style("height", that._height).style("border", that._border);
436
+ */ function boxStyles(box) {
437
+ box.style("background", that._background).style("border-radius", that._borderRadius).style("pointer-events", that._pointerEvents).style("padding", that._padding).style("max-width", that._maxWidth).style("min-width", that._minWidth).style("width", that._width).style("height", that._height).style("border", that._border);
232
438
  }
233
439
  divElement("title");
234
440
  divElement("body");
@@ -265,301 +471,139 @@ var Tooltip = /*#__PURE__*/ function(BaseClass) {
265
471
  divElement("arrow");
266
472
  enter.attr("id", function(d, i) {
267
473
  return "d3plus-tooltip-".concat(d ? _this._id(d, i) : "");
268
- }).call(boxStyles).each(function(d, i) {
474
+ }).style("visibility", "hidden").call(boxStyles).each(function(d, i) {
269
475
  var id = that._id(d, i);
270
476
  var tooltip = document.getElementById("d3plus-tooltip-".concat(id));
271
- var arrow = document.getElementById("d3plus-tooltip-arrow-".concat(id));
272
- var arrowHeight = arrow.offsetHeight;
273
- var arrowDistance = arrow.getBoundingClientRect().height / 2;
274
- arrow.style.bottom = "-".concat(arrowHeight / 2, "px");
477
+ var arrowEl = document.getElementById("d3plus-tooltip-arrow-".concat(id));
478
+ var arrowHeight = arrowEl.offsetHeight;
479
+ var arrowDistance = arrowEl.getBoundingClientRect().height / 2;
480
+ arrowEl.style.bottom = "-".concat(arrowHeight / 2, "px");
275
481
  var position = that._position(d, i);
276
- var referenceObject = Array.isArray(position) ? {
277
- getBoundingClientRect: generateReference(position)
278
- } : position;
279
- _this._popperClasses[id] = createPopper(referenceObject, tooltip, {
280
- placement: "top",
281
- modifiers: [
282
- {
283
- name: "arrow",
284
- options: {
285
- element: arrow
286
- }
287
- },
288
- {
289
- name: "offset",
290
- options: {
291
- offset: [
292
- 0,
293
- that._offset(d, i) + arrowDistance
294
- ]
295
- }
296
- },
297
- {
298
- name: "preventOverflow",
299
- options: {
300
- boundary: "scrollParent",
301
- padding: 5
302
- }
303
- },
304
- {
305
- name: "flip",
306
- options: {
307
- behavior: "flip",
308
- boundary: "viewport",
309
- fallbackPlacements: [
310
- "bottom"
311
- ],
312
- padding: 5
313
- }
314
- },
315
- {
316
- name: "update",
317
- enabled: true,
318
- phase: "afterWrite",
319
- fn: function fn(x) {
320
- var state = x.state;
321
- var arrowElement = state.elements.arrow;
322
- var arrowStyles = state.styles.arrow;
323
- var flipped = state.modifiersData.flip._skip;
324
- var border = parseFloat(arrowElement.style.borderRightWidth, 10);
325
- if (flipped) {
326
- arrowElement.style.transform = "".concat(arrowStyles.transform, "rotate(225deg)");
327
- arrowElement.style.top = "-".concat(arrowHeight / 2 + border, "px");
328
- } else {
329
- arrowElement.style.transform = "".concat(arrowStyles.transform, "rotate(45deg)");
330
- arrowElement.style.bottom = "-".concat(arrowHeight / 2 + border, "px");
331
- }
332
- }
333
- }
334
- ],
335
- removeOnDestroy: true
336
- });
482
+ var reference = Array.isArray(position) ? generateReference(position) : position;
483
+ _this._tooltipRefs[id] = {
484
+ reference: reference,
485
+ arrowEl: arrowEl,
486
+ tooltip: tooltip,
487
+ arrowHeight: arrowHeight,
488
+ arrowDistance: arrowDistance
489
+ };
490
+ positionTooltip(reference, tooltip, arrowEl, that._offset(d, i), arrowDistance, arrowHeight);
337
491
  });
338
492
  update.each(function(d, i) {
339
493
  var id = that._id(d, i);
340
494
  var position = that._position(d, i);
341
- var instance = _this._popperClasses[id];
342
- if (instance) {
343
- instance.state.elements.reference.getBoundingClientRect = Array.isArray(position) ? generateReference(position) : position;
344
- instance.update();
495
+ var ref = _this._tooltipRefs[id];
496
+ if (ref) {
497
+ ref.reference = Array.isArray(position) ? generateReference(position) : position;
498
+ positionTooltip(ref.reference, ref.tooltip, ref.arrowEl, that._offset(d, i), ref.arrowDistance, ref.arrowHeight);
345
499
  }
346
500
  }).call(boxStyles);
347
501
  tooltips.exit().each(function(d, i) {
348
502
  var id = that._id(d, i);
349
- var instance = _this._popperClasses[id];
350
- if (instance) {
351
- instance.destroy();
352
- delete _this._popperClasses[id];
353
- }
503
+ delete _this._tooltipRefs[id];
354
504
  }).remove();
355
505
  if (callback) setTimeout(callback, 100);
356
506
  return this;
357
507
  }
358
508
  },
359
509
  {
360
- /**
361
- @memberof Tooltip
362
- @desc Sets the inner HTML content of the arrow element, which by default is empty.
363
- @param {Function|String} [*value*]
364
- @example <caption>default accessor</caption>
365
- function value(d) {
366
- return d.arrow || "";
367
- }
368
- */ key: "arrow",
510
+ key: "arrow",
369
511
  value: function arrow(_) {
370
512
  return arguments.length ? (this._arrow = typeof _ === "function" ? _ : constant(_), this) : this._arrow;
371
513
  }
372
514
  },
373
515
  {
374
- /**
375
- @memberof Tooltip
376
- @desc If *value* is specified, sets the arrow styles to the specified values and returns this generator. If *value* is not specified, returns the current arrow styles.
377
- @param {Object} [*value*]
378
- @example <caption>default styles</caption>
379
- {
380
- "content": "",
381
- "border-width": "10px",
382
- "border-style": "solid",
383
- "border-color": "rgba(255, 255, 255, 0.75) transparent transparent transparent",
384
- "position": "absolute"
385
- }
386
- */ key: "arrowStyle",
516
+ key: "arrowStyle",
387
517
  value: function arrowStyle(_) {
388
518
  return arguments.length ? (this._arrowStyle = Object.assign(this._arrowStyle, _), this) : this._arrowStyle;
389
519
  }
390
520
  },
391
521
  {
392
- /**
393
- @memberof Tooltip
394
- @desc If *value* is specified, sets the background accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current background accessor.
395
- @param {Function|String} [*value* = colorDefaults.light]
396
- */ key: "background",
522
+ key: "background",
397
523
  value: function background(_) {
398
524
  return arguments.length ? (this._background = typeof _ === "function" ? _ : constant(_), this) : this._background;
399
525
  }
400
526
  },
401
527
  {
402
- /**
403
- @memberof Tooltip
404
- @desc If *value* is specified, sets the body accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current body accessor.
405
- @param {Function|String} [*value*]
406
- @example <caption>default accessor</caption>
407
- function value(d) {
408
- return d.body || "";
409
- }
410
- */ key: "body",
528
+ key: "body",
411
529
  value: function body(_) {
412
530
  return arguments.length ? (this._body = typeof _ === "function" ? _ : constant(_), this) : this._body;
413
531
  }
414
532
  },
415
533
  {
416
- /**
417
- @memberof Tooltip
418
- @desc If *value* is specified, sets the body styles to the specified values and returns this generator. If *value* is not specified, returns the current body styles.
419
- @param {Object} [*value*]
420
- @example <caption>default styles</caption>
421
- {
422
- "font-size": "12px",
423
- "font-weight": "400"
424
- }
425
- */ key: "bodyStyle",
534
+ key: "bodyStyle",
426
535
  value: function bodyStyle(_) {
427
536
  return arguments.length ? (this._bodyStyle = Object.assign(this._bodyStyle, _), this) : this._bodyStyle;
428
537
  }
429
538
  },
430
539
  {
431
- /**
432
- @memberof Tooltip
433
- @desc If *value* is specified, sets the border accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current border accessor.
434
- @param {Function|String} [*value* = "1px solid rgba(0, 0, 0, 0.1)"]
435
- */ key: "border",
540
+ key: "border",
436
541
  value: function border(_) {
437
542
  return arguments.length ? (this._border = typeof _ === "function" ? _ : constant(_), this) : this._border;
438
543
  }
439
544
  },
440
545
  {
441
- /**
442
- @memberof Tooltip
443
- @desc If *value* is specified, sets the border-radius accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current border-radius accessor.
444
- @param {Function|String} [*value* = "2px"]
445
- */ key: "borderRadius",
546
+ key: "borderRadius",
446
547
  value: function borderRadius(_) {
447
548
  return arguments.length ? (this._borderRadius = typeof _ === "function" ? _ : constant(_), this) : this._borderRadius;
448
549
  }
449
550
  },
450
551
  {
451
- /**
452
- @memberof Tooltip
453
- @desc If *value* is specified, sets the class name to the specified string and returns this generator. If *value* is not specified, returns the current class name.
454
- @param {String} [*value* = "d3plus-tooltip"]
455
- */ key: "className",
552
+ key: "className",
456
553
  value: function className(_) {
457
554
  return arguments.length ? (this._className = _, this) : this._className;
458
555
  }
459
556
  },
460
557
  {
461
- /**
462
- @memberof Tooltip
463
- @desc If *data* is specified, sets the data array to the specified array and returns this generator. If *data* is not specified, returns the current data array.
464
- @param {Array} [*data* = []]
465
- */ key: "data",
558
+ key: "data",
466
559
  value: function data(_) {
467
560
  return arguments.length ? (this._data = _, this) : this._data;
468
561
  }
469
562
  },
470
563
  {
471
- /**
472
- @memberof Tooltip
473
- @desc If *value* is specified, sets the footer accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current footer accessor.
474
- @param {Function|String} [*value*]
475
- @example <caption>default accessor</caption>
476
- function value(d) {
477
- return d.footer || "";
478
- }
479
- */ key: "footer",
564
+ key: "footer",
480
565
  value: function footer(_) {
481
566
  return arguments.length ? (this._footer = typeof _ === "function" ? _ : constant(_), this) : this._footer;
482
567
  }
483
568
  },
484
569
  {
485
- /**
486
- @memberof Tooltip
487
- @desc If *value* is specified, sets the footer styles to the specified values and returns this generator. If *value* is not specified, returns the current footer styles.
488
- @param {Object} [*value*]
489
- @example <caption>default styles</caption>
490
- {
491
- "font-size": "12px",
492
- "font-weight": "400"
493
- }
494
- */ key: "footerStyle",
570
+ key: "footerStyle",
495
571
  value: function footerStyle(_) {
496
572
  return arguments.length ? (this._footerStyle = Object.assign(this._footerStyle, _), this) : this._footerStyle;
497
573
  }
498
574
  },
499
575
  {
500
- /**
501
- @memberof Tooltip
502
- @desc If *value* is specified, sets the height accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current height accessor.
503
- @param {Function|String} [*value* = "auto"]
504
- */ key: "height",
576
+ key: "height",
505
577
  value: function height(_) {
506
578
  return arguments.length ? (this._height = typeof _ === "function" ? _ : constant(_), this) : this._height;
507
579
  }
508
580
  },
509
581
  {
510
- /**
511
- @memberof Tooltip
512
- @desc If *value* is specified, sets the id accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current id accessor.
513
- @param {Function|String} [*value*]
514
- @example <caption>default accessor</caption>
515
- function value(d, i) {
516
- return d.id || "" + i;
517
- }
518
- */ key: "id",
582
+ key: "id",
519
583
  value: function id(_) {
520
584
  return arguments.length ? (this._id = typeof _ === "function" ? _ : constant(_), this) : this._id;
521
585
  }
522
586
  },
523
587
  {
524
- /**
525
- @memberof Tooltip
526
- @desc If *value* is specified, sets the offset accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current offset accessor.
527
- @param {Function|Number} [*value* = 10]
528
- */ key: "offset",
588
+ key: "offset",
529
589
  value: function offset(_) {
530
590
  return arguments.length ? (this._offset = typeof _ === "function" ? _ : constant(_), this) : this._offset;
531
591
  }
532
592
  },
533
593
  {
534
- /**
535
- @memberof Tooltip
536
- @desc If *value* is specified, sets the padding accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current padding accessor.
537
- @param {Function|String} [*value* = "5px"]
538
- */ key: "padding",
594
+ key: "padding",
539
595
  value: function padding(_) {
540
596
  return arguments.length ? (this._padding = typeof _ === "function" ? _ : constant(_), this) : this._padding;
541
597
  }
542
598
  },
543
599
  {
544
- /**
545
- @memberof Tooltip
546
- @desc If *value* is specified, sets the pointer-events accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current pointer-events accessor.
547
- @param {Function|String} [*value* = "auto"]
548
- */ key: "pointerEvents",
600
+ key: "pointerEvents",
549
601
  value: function pointerEvents(_) {
550
602
  return arguments.length ? (this._pointerEvents = typeof _ === "function" ? _ : constant(_), this) : this._pointerEvents;
551
603
  }
552
604
  },
553
605
  {
554
- /**
555
- @memberof Tooltip
556
- @desc If *value* is specified, sets the position accessor to the specified function or array and returns this generator. If *value* is not specified, returns the current position accessor. If *value* is an HTMLElement, anchors the Tooltip to that HTMLElement. If *value* is a selection string, anchors the Tooltip to the HTMLElement selected by that string. Otherwise, coordinate points must be in reference to the client viewport, not the overall page.
557
- @param {Function|Array|HTMLElement|String} [*value*]
558
- @example <caption>default accessor</caption>
559
- function value(d) {
560
- return [d.x, d.y];
561
- }
562
- */ key: "position",
606
+ key: "position",
563
607
  value: function position(_) {
564
608
  return arguments.length ? (this._position = typeof _ === "string" ? constant(select(_).node() || [
565
609
  0,
@@ -568,150 +612,79 @@ function value(d, i) {
568
612
  }
569
613
  },
570
614
  {
571
- /**
572
- @memberof Tooltip
573
- @desc If *value* is specified, sets the table styles to the specified values and returns this generator. If *value* is not specified, returns the current table styles.
574
- @param {Object} [*value*]
575
- @example <caption>default styles</caption>
576
- {
577
- "border-collapse": "collapse",
578
- "border-spacing": "0",
579
- "width": "100%"
580
- }
581
- */ key: "tableStyle",
615
+ key: "tableStyle",
582
616
  value: function tableStyle(_) {
583
617
  return arguments.length ? (this._tableStyle = Object.assign(this._tableStyle, _), this) : this._tableStyle;
584
618
  }
585
619
  },
586
620
  {
587
- /**
588
- @memberof Tooltip
589
- @desc If *value* is specified, sets the contents of the table body to the specified array of functions or strings and returns this generator. If *value* is not specified, returns the current table body data.
590
- @param {Array} [*value* = []]
591
- */ key: "tbody",
621
+ key: "tbody",
592
622
  value: function tbody(_) {
593
623
  return arguments.length ? (this._tbody = _, this) : this._tbody;
594
624
  }
595
625
  },
596
626
  {
597
- /**
598
- @memberof Tooltip
599
- @desc If *value* is specified, sets the table body styles to the specified values and returns this generator. If *value* is not specified, returns the current table body styles.
600
- @param {Object} [*value*]
601
- @example <caption>default styles</caption>
602
- {
603
- "font-size": "12px",
604
- "font-weight": "600",
605
- "text-align": "center"
606
- }
607
- */ key: "tbodyStyle",
627
+ key: "tbodyStyle",
608
628
  value: function tbodyStyle(_) {
609
629
  return arguments.length ? (this._tbodyStyle = Object.assign(this._tbodyStyle, _), this) : this._tbodyStyle;
610
630
  }
611
631
  },
612
632
  {
613
- /**
614
- @memberof Tooltip
615
- @desc If *value* is specified, sets the contents of the table head to the specified array of functions or strings and returns this generator. If *value* is not specified, returns the current table head data.
616
- @param {Array} [*value* = []]
617
- */ key: "thead",
633
+ key: "thead",
618
634
  value: function thead(_) {
619
635
  return arguments.length ? (this._thead = _, this) : this._thead;
620
636
  }
621
637
  },
622
638
  {
623
- /**
624
- @memberof Tooltip
625
- @desc If *value* is specified, sets the table head styles to the specified values and returns this generator. If *value* is not specified, returns the current table head styles.
626
- @param {Object} [*value*]
627
- @example <caption>default styles</caption>
628
- {
629
- "font-size": "12px",
630
- "font-weight": "600",
631
- "text-align": "center"
632
- }
633
- */ key: "theadStyle",
639
+ key: "theadStyle",
634
640
  value: function theadStyle(_) {
635
641
  return arguments.length ? (this._theadStyle = Object.assign(this._theadStyle, _), this) : this._theadStyle;
636
642
  }
637
643
  },
638
644
  {
639
- /**
640
- @memberof Tooltip
641
- @desc If *value* is specified, sets the title accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current title accessor.
642
- @param {Function|String} [*value*]
643
- @example <caption>default accessor</caption>
644
- function value(d) {
645
- return d.title || "";
646
- }
647
- */ key: "title",
645
+ key: "title",
648
646
  value: function title(_) {
649
647
  return arguments.length ? (this._title = typeof _ === "function" ? _ : constant(_), this) : this._title;
650
648
  }
651
649
  },
652
650
  {
653
- /**
654
- @memberof Tooltip
655
- @desc If *value* is specified, sets the title styles to the specified values and returns this generator. If *value* is not specified, returns the current title styles.
656
- @param {Object} [*value*]
657
- @example <caption>default styles</caption>
658
- {
659
- "font-size": "14px",
660
- "font-weight": "600",
661
- "padding-bottom": "5px"
662
- }
663
- */ key: "titleStyle",
651
+ key: "titleStyle",
664
652
  value: function titleStyle(_) {
665
653
  return arguments.length ? (this._titleStyle = Object.assign(this._titleStyle, _), this) : this._titleStyle;
666
654
  }
667
655
  },
668
656
  {
669
- /**
670
- @memberof Tooltip
671
- @desc If *value* is specified, sets the overall tooltip styles to the specified values and returns this generator. If *value* is not specified, returns the current title styles.
672
- @param {Object} [*value*]
673
- @example <caption>default styles</caption>
674
- {
675
- "font-family": "'Inter', 'Helvetica Neue', 'HelveticaNeue', 'Helvetica', 'Arial', sans-serif",
676
- "font-size": "14px",
677
- "font-weight": "600",
678
- "padding-bottom": "5px"
679
- }
680
- */ key: "tooltipStyle",
657
+ key: "tooltipStyle",
681
658
  value: function tooltipStyle(_) {
682
659
  return arguments.length ? (this._tooltipStyle = Object.assign(this._tooltipStyle, _), this) : this._tooltipStyle;
683
660
  }
684
661
  },
685
662
  {
686
- /**
687
- @memberof Tooltip
688
- @desc An object with CSS keys and values to be applied to all <tr> elements inside of each <tbody>.
689
- @param {Object} [*value*]
690
- @example <caption>default styles</caption>
691
- {
692
- "border-top": "1px solid rgba(0, 0, 0, 0.1)"
693
- }
694
- */ key: "trStyle",
663
+ key: "trStyle",
695
664
  value: function trStyle(_) {
696
665
  return arguments.length ? (this._trStyle = Object.assign(this._trStyle, _), this) : this._trStyle;
697
666
  }
698
667
  },
699
668
  {
700
- /**
701
- @memberof Tooltip
702
- @desc An object with CSS keys and values to be applied to all <td> elements inside of each <tr>.
703
- @param {Object} [*value*]
704
- */ key: "tdStyle",
669
+ key: "tdStyle",
705
670
  value: function tdStyle(_) {
706
671
  return arguments.length ? (this._tdStyle = Object.assign(this._tdStyle, _), this) : this._tdStyle;
707
672
  }
708
673
  },
709
674
  {
710
- /**
711
- @memberof Tooltip
712
- @desc If *value* is specified, sets the width accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current width accessor.
713
- @param {Function|String} [*value* = "auto"]
714
- */ key: "width",
675
+ key: "maxWidth",
676
+ value: function maxWidth(_) {
677
+ return arguments.length ? (this._maxWidth = typeof _ === "function" ? _ : constant(_), this) : this._maxWidth;
678
+ }
679
+ },
680
+ {
681
+ key: "minWidth",
682
+ value: function minWidth(_) {
683
+ return arguments.length ? (this._minWidth = typeof _ === "function" ? _ : constant(_), this) : this._minWidth;
684
+ }
685
+ },
686
+ {
687
+ key: "width",
715
688
  value: function width(_) {
716
689
  return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width;
717
690
  }
@@ -720,7 +693,5 @@ function value(d) {
720
693
  return Tooltip;
721
694
  }(BaseClass);
722
695
  /**
723
- @class Tooltip
724
- @extends BaseClass
725
- @desc Creates HTML tooltips in the body of a webpage.
696
+ Creates HTML tooltips in the body of a webpage.
726
697
  */ export { Tooltip as default };