@d3plus/core 3.0.0-alpha.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 (87) hide show
  1. package/README.md +6219 -0
  2. package/es/index.js +4 -0
  3. package/es/src/charts/AreaPlot.js +86 -0
  4. package/es/src/charts/BarChart.js +93 -0
  5. package/es/src/charts/BoxWhisker.js +97 -0
  6. package/es/src/charts/BumpChart.js +148 -0
  7. package/es/src/charts/Donut.js +84 -0
  8. package/es/src/charts/Geomap.js +833 -0
  9. package/es/src/charts/LinePlot.js +84 -0
  10. package/es/src/charts/Matrix.js +358 -0
  11. package/es/src/charts/Network.js +787 -0
  12. package/es/src/charts/Pack.js +318 -0
  13. package/es/src/charts/Pie.js +242 -0
  14. package/es/src/charts/Plot.js +2212 -0
  15. package/es/src/charts/Priestley.js +312 -0
  16. package/es/src/charts/Radar.js +365 -0
  17. package/es/src/charts/RadialMatrix.js +393 -0
  18. package/es/src/charts/Rings.js +777 -0
  19. package/es/src/charts/Sankey.js +413 -0
  20. package/es/src/charts/StackedArea.js +80 -0
  21. package/es/src/charts/Tree.js +312 -0
  22. package/es/src/charts/Treemap.js +406 -0
  23. package/es/src/charts/Viz.js +2017 -0
  24. package/es/src/charts/drawSteps/drawAttribution.js +14 -0
  25. package/es/src/charts/drawSteps/drawBack.js +23 -0
  26. package/es/src/charts/drawSteps/drawColorScale.js +69 -0
  27. package/es/src/charts/drawSteps/drawLegend.js +120 -0
  28. package/es/src/charts/drawSteps/drawSubtitle.js +31 -0
  29. package/es/src/charts/drawSteps/drawTimeline.js +80 -0
  30. package/es/src/charts/drawSteps/drawTitle.js +31 -0
  31. package/es/src/charts/drawSteps/drawTotal.js +32 -0
  32. package/es/src/charts/drawSteps/zoomControls.js +254 -0
  33. package/es/src/charts/events/click.legend.js +76 -0
  34. package/es/src/charts/events/click.shape.js +26 -0
  35. package/es/src/charts/events/mouseenter.js +31 -0
  36. package/es/src/charts/events/mouseleave.js +21 -0
  37. package/es/src/charts/events/mousemove.legend.js +64 -0
  38. package/es/src/charts/events/mousemove.shape.js +42 -0
  39. package/es/src/charts/events/touchstart.body.js +7 -0
  40. package/es/src/charts/helpers/matrixData.js +104 -0
  41. package/es/src/charts/helpers/tileAttributions.js +34 -0
  42. package/es/src/charts/index.js +21 -0
  43. package/es/src/charts/plotBuffers/Bar.js +65 -0
  44. package/es/src/charts/plotBuffers/Box.js +60 -0
  45. package/es/src/charts/plotBuffers/Circle.js +39 -0
  46. package/es/src/charts/plotBuffers/Line.js +30 -0
  47. package/es/src/charts/plotBuffers/Rect.js +40 -0
  48. package/es/src/charts/plotBuffers/discreteBuffer.js +24 -0
  49. package/es/src/charts/plotBuffers/numericBuffer.js +111 -0
  50. package/es/src/components/Axis.js +1567 -0
  51. package/es/src/components/AxisBottom.js +77 -0
  52. package/es/src/components/AxisLeft.js +77 -0
  53. package/es/src/components/AxisRight.js +77 -0
  54. package/es/src/components/AxisTop.js +77 -0
  55. package/es/src/components/ColorScale.js +958 -0
  56. package/es/src/components/Legend.js +673 -0
  57. package/es/src/components/Message.js +95 -0
  58. package/es/src/components/TextBox.js +752 -0
  59. package/es/src/components/Timeline.js +760 -0
  60. package/es/src/components/Tooltip.js +726 -0
  61. package/es/src/components/index.js +11 -0
  62. package/es/src/shapes/Area.js +361 -0
  63. package/es/src/shapes/Bar.js +342 -0
  64. package/es/src/shapes/Box.js +482 -0
  65. package/es/src/shapes/Circle.js +201 -0
  66. package/es/src/shapes/Image.js +255 -0
  67. package/es/src/shapes/Line.js +289 -0
  68. package/es/src/shapes/Path.js +186 -0
  69. package/es/src/shapes/Rect.js +215 -0
  70. package/es/src/shapes/Shape.js +1156 -0
  71. package/es/src/shapes/Whisker.js +330 -0
  72. package/es/src/shapes/index.js +10 -0
  73. package/es/src/utils/BaseClass.js +204 -0
  74. package/es/src/utils/RESET.js +4 -0
  75. package/es/src/utils/accessor.js +19 -0
  76. package/es/src/utils/configPrep.js +76 -0
  77. package/es/src/utils/constant.js +15 -0
  78. package/es/src/utils/getProp.js +9 -0
  79. package/es/src/utils/index.js +7 -0
  80. package/es/src/utils/uuid.js +13 -0
  81. package/package.json +68 -0
  82. package/umd/d3plus-core.full.js +56459 -0
  83. package/umd/d3plus-core.full.js.map +1 -0
  84. package/umd/d3plus-core.full.min.js +7241 -0
  85. package/umd/d3plus-core.js +14422 -0
  86. package/umd/d3plus-core.js.map +1 -0
  87. package/umd/d3plus-core.min.js +4564 -0
@@ -0,0 +1,752 @@
1
+ function _assert_this_initialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
5
+ return self;
6
+ }
7
+ function _call_super(_this, derived, args) {
8
+ derived = _get_prototype_of(derived);
9
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
10
+ }
11
+ function _class_call_check(instance, Constructor) {
12
+ if (!(instance instanceof Constructor)) {
13
+ throw new TypeError("Cannot call a class as a function");
14
+ }
15
+ }
16
+ function _defineProperties(target, props) {
17
+ for(var i = 0; i < props.length; i++){
18
+ var descriptor = props[i];
19
+ descriptor.enumerable = descriptor.enumerable || false;
20
+ descriptor.configurable = true;
21
+ if ("value" in descriptor) descriptor.writable = true;
22
+ Object.defineProperty(target, descriptor.key, descriptor);
23
+ }
24
+ }
25
+ function _create_class(Constructor, protoProps, staticProps) {
26
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
27
+ if (staticProps) _defineProperties(Constructor, staticProps);
28
+ return Constructor;
29
+ }
30
+ function _get_prototype_of(o) {
31
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
32
+ return o.__proto__ || Object.getPrototypeOf(o);
33
+ };
34
+ return _get_prototype_of(o);
35
+ }
36
+ function _inherits(subClass, superClass) {
37
+ if (typeof superClass !== "function" && superClass !== null) {
38
+ throw new TypeError("Super expression must either be null or a function");
39
+ }
40
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
41
+ constructor: {
42
+ value: subClass,
43
+ writable: true,
44
+ configurable: true
45
+ }
46
+ });
47
+ if (superClass) _set_prototype_of(subClass, superClass);
48
+ }
49
+ function _possible_constructor_return(self, call) {
50
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
51
+ return call;
52
+ }
53
+ return _assert_this_initialized(self);
54
+ }
55
+ function _set_prototype_of(o, p) {
56
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
57
+ o.__proto__ = p;
58
+ return o;
59
+ };
60
+ return _set_prototype_of(o, p);
61
+ }
62
+ function _type_of(obj) {
63
+ "@swc/helpers - typeof";
64
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
65
+ }
66
+ function _is_native_reflect_construct() {
67
+ try {
68
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
69
+ } catch (_) {}
70
+ return (_is_native_reflect_construct = function() {
71
+ return !!result;
72
+ })();
73
+ }
74
+ import { max, min, sum } from "d3-array";
75
+ import { select } from "d3-selection";
76
+ // leave this import in here!
77
+ import { transition } from "d3-transition";
78
+ import { fontExists, parseSides, rtl as detectRTL, textWidth } from "@d3plus/dom";
79
+ import { fontFamily, strip, textSplit, textWrap, trim, trimRight } from "@d3plus/text";
80
+ import { accessor, BaseClass, constant } from "../utils/index.js";
81
+ var defaultHtmlLookup = {
82
+ i: "font-style: italic;",
83
+ em: "font-style: italic;",
84
+ b: "font-weight: bold;",
85
+ strong: "font-weight: bold;"
86
+ };
87
+ var TextBox = /*#__PURE__*/ function(BaseClass) {
88
+ "use strict";
89
+ _inherits(TextBox, BaseClass);
90
+ function TextBox() {
91
+ _class_call_check(this, TextBox);
92
+ var _this;
93
+ _this = _call_super(this, TextBox);
94
+ _this._ariaHidden = constant("false");
95
+ _this._delay = 0;
96
+ _this._duration = 0;
97
+ _this._ellipsis = function(text, line) {
98
+ return line ? "".concat(text.replace(/\.|,$/g, ""), "...") : "";
99
+ };
100
+ _this._fontColor = constant("black");
101
+ _this._fontFamily = constant(fontFamily);
102
+ _this._fontMax = constant(50);
103
+ _this._fontMin = constant(8);
104
+ _this._fontOpacity = constant(1);
105
+ _this._fontResize = constant(false);
106
+ _this._fontSize = constant(10);
107
+ _this._fontStroke = constant("transparent");
108
+ _this._fontStrokeWidth = constant(0);
109
+ _this._fontWeight = constant(400);
110
+ _this._height = accessor("height", 200);
111
+ _this._html = defaultHtmlLookup;
112
+ _this._id = function(d, i) {
113
+ return d.id || "".concat(i);
114
+ };
115
+ _this._lineHeight = function(d, i) {
116
+ return _this._fontSize(d, i) * 1.2;
117
+ };
118
+ _this._maxLines = constant(null);
119
+ _this._on = {};
120
+ _this._overflow = constant(false);
121
+ _this._padding = constant(0);
122
+ _this._pointerEvents = constant("auto");
123
+ _this._rotate = constant(0);
124
+ _this._rotateAnchor = function(d) {
125
+ return [
126
+ d.w / 2,
127
+ d.h / 2
128
+ ];
129
+ };
130
+ _this._split = textSplit;
131
+ _this._text = accessor("text");
132
+ _this._textAnchor = constant("start");
133
+ _this._verticalAlign = constant("top");
134
+ _this._width = accessor("width", 200);
135
+ _this._x = accessor("x", 0);
136
+ _this._y = accessor("y", 0);
137
+ return _this;
138
+ }
139
+ _create_class(TextBox, [
140
+ {
141
+ /**
142
+ @memberof TextBox
143
+ @desc Renders the text boxes. If a *callback* is specified, it will be called once the shapes are done drawing.
144
+ @param {Function} [*callback* = undefined]
145
+ */ key: "render",
146
+ value: function render(callback) {
147
+ var _this = this;
148
+ if (this._select === void 0) this.select(select("body").append("svg").style("width", "".concat(window.innerWidth, "px")).style("height", "".concat(window.innerHeight, "px")).node());
149
+ var that = this;
150
+ var boxes = this._select.selectAll(".d3plus-textBox").data(this._data.reduce(function(arr, d, i) {
151
+ var t = _this._text(d, i);
152
+ if (t === void 0) return arr;
153
+ t = trim(t);
154
+ var resize = _this._fontResize(d, i);
155
+ var lHRatio = _this._lineHeight(d, i) / _this._fontSize(d, i);
156
+ var fS = resize ? _this._fontMax(d, i) : _this._fontSize(d, i), lH = resize ? fS * lHRatio : _this._lineHeight(d, i), line = 1, lineData = [], sizes, wrapResults;
157
+ var style = {
158
+ "font-family": fontExists(_this._fontFamily(d, i)),
159
+ "font-size": fS,
160
+ "font-weight": _this._fontWeight(d, i),
161
+ "line-height": lH
162
+ };
163
+ var padding = parseSides(_this._padding(d, i));
164
+ var h = _this._height(d, i) - (padding.top + padding.bottom), w = _this._width(d, i) - (padding.left + padding.right);
165
+ var wrapper = textWrap().fontFamily(style["font-family"]).fontSize(fS).fontWeight(style["font-weight"]).lineHeight(lH).maxLines(_this._maxLines(d, i)).height(h).overflow(_this._overflow(d, i)).width(w).split(_this._split);
166
+ var fMax = _this._fontMax(d, i), fMin = _this._fontMin(d, i), vA = _this._verticalAlign(d, i), words = _this._split(t, i);
167
+ /**
168
+ Figures out the lineData to be used for wrapping.
169
+ @private
170
+ */ function checkSize() {
171
+ var truncate = function() {
172
+ if (line < 1) lineData = [
173
+ that._ellipsis("", line)
174
+ ];
175
+ else lineData[line - 1] = that._ellipsis(lineData[line - 1], line);
176
+ };
177
+ // Constraint the font size
178
+ fS = max([
179
+ fS,
180
+ fMin
181
+ ]);
182
+ fS = min([
183
+ fS,
184
+ fMax
185
+ ]);
186
+ if (resize) {
187
+ lH = fS * lHRatio;
188
+ wrapper.fontSize(fS).lineHeight(lH);
189
+ style["font-size"] = fS;
190
+ style["line-height"] = lH;
191
+ }
192
+ wrapResults = wrapper(t);
193
+ lineData = wrapResults.lines.filter(function(l) {
194
+ return l !== "";
195
+ });
196
+ line = lineData.length;
197
+ if (wrapResults.truncated) {
198
+ if (resize) {
199
+ fS--;
200
+ if (fS < fMin) {
201
+ fS = fMin;
202
+ truncate();
203
+ return;
204
+ } else checkSize();
205
+ } else truncate();
206
+ }
207
+ }
208
+ if (w > fMin && (h > lH || resize && h > fMin * lHRatio)) {
209
+ if (resize) {
210
+ sizes = textWidth(words, style);
211
+ var areaMod = 1.165 + w / h * 0.1, boxArea = w * h, maxWidth = max(sizes), textArea = sum(sizes, function(d) {
212
+ return d * lH;
213
+ }) * areaMod;
214
+ if (maxWidth > w || textArea > boxArea) {
215
+ var areaRatio = Math.sqrt(boxArea / textArea), widthRatio = w / maxWidth;
216
+ var sizeRatio = min([
217
+ areaRatio,
218
+ widthRatio
219
+ ]);
220
+ fS = Math.floor(fS * sizeRatio);
221
+ }
222
+ var heightMax = Math.floor(h * 0.8);
223
+ if (fS > heightMax) fS = heightMax;
224
+ }
225
+ checkSize();
226
+ }
227
+ if (lineData.length) {
228
+ var tH = line * lH;
229
+ var r = _this._rotate(d, i);
230
+ var yP = r === 0 ? vA === "top" ? 0 : vA === "middle" ? h / 2 - tH / 2 : h - tH : 0;
231
+ yP -= lH * 0.1;
232
+ arr.push({
233
+ aH: _this._ariaHidden(d, i),
234
+ data: d,
235
+ i: i,
236
+ lines: lineData,
237
+ fC: _this._fontColor(d, i),
238
+ fStroke: _this._fontStroke(d, i),
239
+ fSW: _this._fontStrokeWidth(d, i),
240
+ fF: style["font-family"],
241
+ fO: _this._fontOpacity(d, i),
242
+ fW: style["font-weight"],
243
+ id: _this._id(d, i),
244
+ tA: _this._textAnchor(d, i),
245
+ vA: _this._verticalAlign(d, i),
246
+ widths: wrapResults.widths,
247
+ fS: fS,
248
+ lH: lH,
249
+ w: w,
250
+ h: h,
251
+ r: r,
252
+ x: _this._x(d, i) + padding.left,
253
+ y: _this._y(d, i) + yP + padding.top
254
+ });
255
+ }
256
+ return arr;
257
+ }, []), function(d) {
258
+ return _this._id(d.data, d.i);
259
+ });
260
+ var t = this._select.transition().duration(this._duration);
261
+ if (this._duration === 0) {
262
+ boxes.exit().remove();
263
+ } else {
264
+ boxes.exit().transition().delay(this._duration).remove();
265
+ boxes.exit().selectAll("text").transition(t).attr("opacity", 0).style("opacity", 0);
266
+ }
267
+ /**
268
+ * Applies translate and rotate to a text element.
269
+ * @param {D3Selection} text
270
+ * @private
271
+ */ function rotate(text) {
272
+ text.attr("transform", function(d, i) {
273
+ var rotateAnchor = that._rotateAnchor(d, i);
274
+ return "translate(".concat(d.x, ", ").concat(d.y, ") rotate(").concat(d.r, ", ").concat(rotateAnchor[0], ", ").concat(rotateAnchor[1], ")");
275
+ });
276
+ }
277
+ var update = boxes.enter().append("g").attr("class", "d3plus-textBox").attr("id", function(d) {
278
+ return "d3plus-textBox-".concat(strip(d.id));
279
+ }).call(rotate).merge(boxes);
280
+ var rtl = detectRTL();
281
+ update.order().style("pointer-events", function(d) {
282
+ return _this._pointerEvents(d.data, d.i);
283
+ }).each(function(d) {
284
+ /**
285
+ Sets the inner text content of each <text> element.
286
+ @private
287
+ */ function textContent(text) {
288
+ var tag = false;
289
+ text[that._html ? "html" : "text"](function(t) {
290
+ var cleaned = trimRight(t).replace(/&([^;&]*)/g, function(str, a) {
291
+ return a === "amp" ? str : "&amp;".concat(a);
292
+ }) // replaces all non-HTML ampersands with escaped entity
293
+ .replace(/<([^A-z^/]+)/g, function(str, a) {
294
+ return "&lt;".concat(a);
295
+ }).replace(/<$/g, "&lt;") // replaces all non-HTML left angle brackets with escaped entity
296
+ .replace(/(<[^>^/]+>)([^<^>]+)$/g, function(str, a, b) {
297
+ return "".concat(a).concat(b).concat(a.replace("<", "</"));
298
+ }) // ands end tag to lines before mid-HTML break
299
+ .replace(/^([^<^>]+)(<\/[^>]+>)/g, function(str, a, b) {
300
+ return "".concat(b.replace("</", "<")).concat(a).concat(b);
301
+ }); // ands start tag to lines after mid-HTML break
302
+ var tagRegex = new RegExp(/<([A-z]+)[^>]*>([^<^>]+)<\/[^>]+>/g);
303
+ if (cleaned.match(tagRegex)) {
304
+ cleaned = cleaned.replace(tagRegex, function(str, a, b) {
305
+ tag = that._html[a] ? a : false;
306
+ if (tag) {
307
+ var style = that._html[tag];
308
+ if (t.includes("</".concat(tag, ">"))) tag = false;
309
+ return '<tspan style="'.concat(style, '">').concat(b, "</tspan>");
310
+ }
311
+ return b;
312
+ });
313
+ } else if (tag.length) {
314
+ cleaned = '<tspan style="'.concat(that._html[tag], '">').concat(cleaned, "</tspan>");
315
+ }
316
+ return cleaned;
317
+ });
318
+ }
319
+ /**
320
+ Styles to apply to each <text> element.
321
+ @private
322
+ */ function textStyle(text) {
323
+ text.attr("aria-hidden", d.aH).attr("dir", rtl ? "rtl" : "ltr").attr("fill", d.fC).attr("stroke", d.fStroke).attr("stroke-width", d.fSW).attr("text-anchor", d.tA).attr("font-family", d.fF).style("font-family", d.fF).attr("font-size", "".concat(d.fS, "px")).style("font-size", "".concat(d.fS, "px")).attr("font-weight", d.fW).style("font-weight", d.fW).attr("x", "".concat(d.tA === "middle" ? d.w / 2 : rtl ? d.tA === "start" ? d.w : 0 : d.tA === "end" ? d.w : 2 * Math.sin(Math.PI * d.r / 180), "px")).attr("y", function(t, i) {
324
+ return d.r === 0 || d.vA === "top" ? "".concat((i + 1) * d.lH - (d.lH - d.fS), "px") : d.vA === "middle" ? "".concat((d.h + d.fS) / 2 - (d.lH - d.fS) + (i - d.lines.length / 2 + 0.5) * d.lH, "px") : "".concat(d.h - 2 * (d.lH - d.fS) - (d.lines.length - (i + 1)) * d.lH + 2 * Math.cos(Math.PI * d.r / 180), "px");
325
+ });
326
+ }
327
+ var texts = select(this).selectAll("text").data(d.lines);
328
+ if (that._duration === 0) {
329
+ texts.call(textContent).call(textStyle);
330
+ texts.exit().remove();
331
+ texts.enter().append("text").attr("dominant-baseline", "alphabetic").style("baseline-shift", "0%").attr("unicode-bidi", "bidi-override").call(textContent).call(textStyle).attr("opacity", d.fO).style("opacity", d.fO);
332
+ } else {
333
+ texts.call(textContent).transition(t).call(textStyle);
334
+ texts.exit().transition(t).attr("opacity", 0).remove();
335
+ texts.enter().append("text").attr("dominant-baseline", "alphabetic").style("baseline-shift", "0%").attr("opacity", 0).style("opacity", 0).call(textContent).call(textStyle).merge(texts).transition(t).delay(that._delay).call(textStyle).attr("opacity", d.fO).style("opacity", d.fO);
336
+ }
337
+ }).transition(t).call(rotate);
338
+ var events = Object.keys(this._on), on = events.reduce(function(obj, e) {
339
+ obj[e] = function(d, i) {
340
+ return _this._on[e](d.data, i);
341
+ };
342
+ return obj;
343
+ }, {});
344
+ for(var e = 0; e < events.length; e++)update.on(events[e], on[events[e]]);
345
+ if (callback) setTimeout(callback, this._duration + 100);
346
+ return this;
347
+ }
348
+ },
349
+ {
350
+ /**
351
+ @memberof TextBox
352
+ @desc If *value* is specified, sets the aria-hidden attribute to the specified function or string and returns the current class instance.
353
+ @param {Function|String} *value*
354
+ @chainable
355
+ */ key: "ariaHidden",
356
+ value: function ariaHidden(_) {
357
+ return _ !== undefined ? (this._ariaHidden = typeof _ === "function" ? _ : constant(_), this) : this._ariaHidden;
358
+ }
359
+ },
360
+ {
361
+ /**
362
+ @memberof TextBox
363
+ @desc Sets the data array to the specified array. A text box will be drawn for each object in the array.
364
+ @param {Array} [*data* = []]
365
+ @chainable
366
+ */ key: "data",
367
+ value: function data(_) {
368
+ return arguments.length ? (this._data = _, this) : this._data;
369
+ }
370
+ },
371
+ {
372
+ /**
373
+ @memberof TextBox
374
+ @desc Sets the animation delay to the specified number in milliseconds.
375
+ @param {Number} [*value* = 0]
376
+ @chainable
377
+ */ key: "delay",
378
+ value: function delay(_) {
379
+ return arguments.length ? (this._delay = _, this) : this._delay;
380
+ }
381
+ },
382
+ {
383
+ /**
384
+ @memberof TextBox
385
+ @desc Sets the animation duration to the specified number in milliseconds.
386
+ @param {Number} [*value* = 0]
387
+ @chainable
388
+ */ key: "duration",
389
+ value: function duration(_) {
390
+ return arguments.length ? (this._duration = _, this) : this._duration;
391
+ }
392
+ },
393
+ {
394
+ /**
395
+ @memberof TextBox
396
+ @desc Sets the function that handles what to do when a line is truncated. It should return the new value for the line, and is passed 2 arguments: the String of text for the line in question, and the number of the line. By default, an ellipsis is added to the end of any line except if it is the first word that cannot fit (in that case, an empty string is returned).
397
+ @param {Function|String} [*value*]
398
+ @chainable
399
+ @example <caption>default accessor</caption>
400
+ function(text, line) {
401
+ return line ? text.replace(/\.|,$/g, "") + "..." : "";
402
+ }
403
+ */ key: "ellipsis",
404
+ value: function ellipsis(_) {
405
+ return arguments.length ? (this._ellipsis = typeof _ === "function" ? _ : constant(_), this) : this._ellipsis;
406
+ }
407
+ },
408
+ {
409
+ /**
410
+ @memberof TextBox
411
+ @desc Sets the font color to the specified accessor function or static string, which is inferred from the [DOM selection](#textBox.select) by default.
412
+ @param {Function|String} [*value* = "black"]
413
+ @chainable
414
+ */ key: "fontColor",
415
+ value: function fontColor(_) {
416
+ return arguments.length ? (this._fontColor = typeof _ === "function" ? _ : constant(_), this) : this._fontColor;
417
+ }
418
+ },
419
+ {
420
+ /**
421
+ @memberof TextBox
422
+ @desc Defines the font-family to be used. The value passed can be either a *String* name of a font, a comma-separated list of font-family fallbacks, an *Array* of fallbacks, or a *Function* that returns either a *String* or an *Array*. If supplying multiple fallback fonts, the [fontExists](#fontExists) function will be used to determine the first available font on the client's machine.
423
+ @param {Array|Function|String} [*value* = ["Inter", "Helvetica Neue", "HelveticaNeue", "Helvetica", "Arial", "sans-serif"]]
424
+ @chainable
425
+ */ key: "fontFamily",
426
+ value: function fontFamily(_) {
427
+ return arguments.length ? (this._fontFamily = typeof _ === "function" ? _ : constant(_), this) : this._fontFamily;
428
+ }
429
+ },
430
+ {
431
+ /**
432
+ @memberof TextBox
433
+ @desc Sets the maximum font size to the specified accessor function or static number (which corresponds to pixel units), which is used when [dynamically resizing fonts](#textBox.fontResize).
434
+ @param {Function|Number} [*value* = 50]
435
+ @chainable
436
+ */ key: "fontMax",
437
+ value: function fontMax(_) {
438
+ return arguments.length ? (this._fontMax = typeof _ === "function" ? _ : constant(_), this) : this._fontMax;
439
+ }
440
+ },
441
+ {
442
+ /**
443
+ @memberof TextBox
444
+ @desc Sets the minimum font size to the specified accessor function or static number (which corresponds to pixel units), which is used when [dynamically resizing fonts](#textBox.fontResize).
445
+ @param {Function|Number} [*value* = 8]
446
+ @chainable
447
+ */ key: "fontMin",
448
+ value: function fontMin(_) {
449
+ return arguments.length ? (this._fontMin = typeof _ === "function" ? _ : constant(_), this) : this._fontMin;
450
+ }
451
+ },
452
+ {
453
+ /**
454
+ @memberof TextBox
455
+ @desc Sets the font opacity to the specified accessor function or static number between 0 and 1.
456
+ @param {Function|Number} [*value* = 1]
457
+ @chainable
458
+ */ key: "fontOpacity",
459
+ value: function fontOpacity(_) {
460
+ return arguments.length ? (this._fontOpacity = typeof _ === "function" ? _ : constant(_), this) : this._fontOpacity;
461
+ }
462
+ },
463
+ {
464
+ /**
465
+ @memberof TextBox
466
+ @desc Toggles font resizing, which can either be defined as a static boolean for all data points, or an accessor function that returns a boolean. See [this example](http://d3plus.org/examples/d3plus-text/resizing-text/) for a side-by-side comparison.
467
+ @param {Function|Boolean} [*value* = false]
468
+ @chainable
469
+ */ key: "fontResize",
470
+ value: function fontResize(_) {
471
+ return arguments.length ? (this._fontResize = typeof _ === "function" ? _ : constant(_), this) : this._fontResize;
472
+ }
473
+ },
474
+ {
475
+ /**
476
+ @memberof TextBox
477
+ @desc Sets the font size to the specified accessor function or static number (which corresponds to pixel units), which is inferred from the [DOM selection](#textBox.select) by default.
478
+ @param {Function|Number} [*value* = 10]
479
+ @chainable
480
+ */ key: "fontSize",
481
+ value: function fontSize(_) {
482
+ return arguments.length ? (this._fontSize = typeof _ === "function" ? _ : constant(_), this) : this._fontSize;
483
+ }
484
+ },
485
+ {
486
+ /**
487
+ @memberof TextBox
488
+ @desc Sets the font stroke color for the rendered text.
489
+ @param {Function|String} [*value* = "transparent"]
490
+ @chainable
491
+ */ key: "fontStroke",
492
+ value: function fontStroke(_) {
493
+ return arguments.length ? (this._fontStroke = typeof _ === "function" ? _ : constant(_), this) : this._fontStroke;
494
+ }
495
+ },
496
+ {
497
+ /**
498
+ @memberof TextBox
499
+ @desc Sets the font stroke width for the rendered text.
500
+ @param {Function|Number} [*value* = 0]
501
+ @chainable
502
+ */ key: "fontStrokeWidth",
503
+ value: function fontStrokeWidth(_) {
504
+ return arguments.length ? (this._fontStrokeWidth = typeof _ === "function" ? _ : constant(_), this) : this._fontStrokeWidth;
505
+ }
506
+ },
507
+ {
508
+ /**
509
+ @memberof TextBox
510
+ @desc Sets the font weight to the specified accessor function or static number, which is inferred from the [DOM selection](#textBox.select) by default.
511
+ @param {Function|Number|String} [*value* = 400]
512
+ @chainable
513
+ */ key: "fontWeight",
514
+ value: function fontWeight(_) {
515
+ return arguments.length ? (this._fontWeight = typeof _ === "function" ? _ : constant(_), this) : this._fontWeight;
516
+ }
517
+ },
518
+ {
519
+ /**
520
+ @memberof TextBox
521
+ @desc Sets the height for each box to the specified accessor function or static number.
522
+ @param {Function|Number} [*value*]
523
+ @chainable
524
+ @example <caption>default accessor</caption>
525
+ function(d) {
526
+ return d.height || 200;
527
+ }
528
+ */ key: "height",
529
+ value: function height(_) {
530
+ return arguments.length ? (this._height = typeof _ === "function" ? _ : constant(_), this) : this._height;
531
+ }
532
+ },
533
+ {
534
+ /**
535
+ @memberof TextBox
536
+ @desc Configures the ability to render simple HTML tags. Defaults to supporting `<b>`, `<strong>`, `<i>`, and `<em>`, set to false to disable or provide a mapping of tags to svg styles
537
+ @param {Object|Boolean} [*value* = {
538
+ i: 'font-style: italic;',
539
+ em: 'font-style: italic;',
540
+ b: 'font-weight: bold;',
541
+ strong: 'font-weight: bold;'
542
+ }]
543
+ @chainable
544
+ */ key: "html",
545
+ value: function html(_) {
546
+ return arguments.length ? (this._html = typeof _ === "boolean" ? _ ? defaultHtmlLookup : false : _, this) : this._html;
547
+ }
548
+ },
549
+ {
550
+ /**
551
+ @memberof TextBox
552
+ @desc Defines the unique id for each box to the specified accessor function or static number.
553
+ @param {Function|Number} [*value*]
554
+ @chainable
555
+ @example <caption>default accessor</caption>
556
+ function(d, i) {
557
+ return d.id || i + "";
558
+ }
559
+ */ key: "id",
560
+ value: function id(_) {
561
+ return arguments.length ? (this._id = typeof _ === "function" ? _ : constant(_), this) : this._id;
562
+ }
563
+ },
564
+ {
565
+ /**
566
+ @memberof TextBox
567
+ @desc Sets the line height to the specified accessor function or static number, which is 1.2 times the [font size](#textBox.fontSize) by default.
568
+ @param {Function|Number} [*value*]
569
+ @chainable
570
+ */ key: "lineHeight",
571
+ value: function lineHeight(_) {
572
+ return arguments.length ? (this._lineHeight = typeof _ === "function" ? _ : constant(_), this) : this._lineHeight;
573
+ }
574
+ },
575
+ {
576
+ /**
577
+ @memberof TextBox
578
+ @desc Restricts the maximum number of lines to wrap onto, which is null (unlimited) by default.
579
+ @param {Function|Number} [*value*]
580
+ @chainable
581
+ */ key: "maxLines",
582
+ value: function maxLines(_) {
583
+ return arguments.length ? (this._maxLines = typeof _ === "function" ? _ : constant(_), this) : this._maxLines;
584
+ }
585
+ },
586
+ {
587
+ /**
588
+ @memberof TextBox
589
+ @desc Sets the text overflow to the specified accessor function or static boolean.
590
+ @param {Function|Boolean} [*value* = false]
591
+ @chainable
592
+ */ key: "overflow",
593
+ value: function overflow(_) {
594
+ return arguments.length ? (this._overflow = typeof _ === "function" ? _ : constant(_), this) : this._overflow;
595
+ }
596
+ },
597
+ {
598
+ /**
599
+ @memberof TextBox
600
+ @desc Sets the padding to the specified accessor function, CSS shorthand string, or static number, which is 0 by default.
601
+ @param {Function|Number|String} [*value*]
602
+ @chainable
603
+ */ key: "padding",
604
+ value: function padding(_) {
605
+ return arguments.length ? (this._padding = typeof _ === "function" ? _ : constant(_), this) : this._padding;
606
+ }
607
+ },
608
+ {
609
+ /**
610
+ @memberof TextBox
611
+ @desc Sets the pointer-events to the specified accessor function or static string.
612
+ @param {Function|String} [*value* = "auto"]
613
+ @chainable
614
+ */ key: "pointerEvents",
615
+ value: function pointerEvents(_) {
616
+ return arguments.length ? (this._pointerEvents = typeof _ === "function" ? _ : constant(_), this) : this._pointerEvents;
617
+ }
618
+ },
619
+ {
620
+ /**
621
+ @memberof TextBox
622
+ @desc Sets the rotate percentage for each box to the specified accessor function or static string.
623
+ @param {Function|Number} [*value* = 0]
624
+ @chainable
625
+ */ key: "rotate",
626
+ value: function rotate(_) {
627
+ return arguments.length ? (this._rotate = typeof _ === "function" ? _ : constant(_), this) : this._rotate;
628
+ }
629
+ },
630
+ {
631
+ /**
632
+ @memberof TextBox
633
+ @desc Sets the anchor point around which to rotate the text box.
634
+ @param {Function|Number[]}
635
+ @chainable
636
+ */ key: "rotateAnchor",
637
+ value: function rotateAnchor(_) {
638
+ return arguments.length ? (this._rotateAnchor = typeof _ === "function" ? _ : constant(_), this) : this._rotateAnchor;
639
+ }
640
+ },
641
+ {
642
+ /**
643
+ @memberof TextBox
644
+ @desc Sets the SVG container element to the specified d3 selector or DOM element. If not explicitly specified, an SVG element will be added to the page for use.
645
+ @param {String|HTMLElement} [*selector*]
646
+ @chainable
647
+ */ key: "select",
648
+ value: function select1(_) {
649
+ return arguments.length ? (this._select = select(_), this) : this._select;
650
+ }
651
+ },
652
+ {
653
+ /**
654
+ @memberof TextBox
655
+ @desc Sets the word split behavior to the specified function, which when passed a string is expected to return that string split into an array of words.
656
+ @param {Function} [*value*]
657
+ @chainable
658
+ */ key: "split",
659
+ value: function split(_) {
660
+ return arguments.length ? (this._split = _, this) : this._split;
661
+ }
662
+ },
663
+ {
664
+ /**
665
+ @memberof TextBox
666
+ @desc Sets the text for each box to the specified accessor function or static string.
667
+ @param {Function|String} [*value*]
668
+ @chainable
669
+ @example <caption>default accessor</caption>
670
+ function(d) {
671
+ return d.text;
672
+ }
673
+ */ key: "text",
674
+ value: function text(_) {
675
+ return arguments.length ? (this._text = typeof _ === "function" ? _ : constant(_), this) : this._text;
676
+ }
677
+ },
678
+ {
679
+ /**
680
+ @memberof TextBox
681
+ @desc Sets the horizontal text anchor to the specified accessor function or static string, whose values are analagous to the SVG [text-anchor](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor) property.
682
+ @param {Function|String} [*value* = "start"]
683
+ @chainable
684
+ */ key: "textAnchor",
685
+ value: function textAnchor(_) {
686
+ return arguments.length ? (this._textAnchor = typeof _ === "function" ? _ : constant(_), this) : this._textAnchor;
687
+ }
688
+ },
689
+ {
690
+ /**
691
+ @memberof TextBox
692
+ @desc Sets the vertical alignment to the specified accessor function or static string. Accepts `"top"`, `"middle"`, and `"bottom"`.
693
+ @param {Function|String} [*value* = "top"]
694
+ @chainable
695
+ */ key: "verticalAlign",
696
+ value: function verticalAlign(_) {
697
+ return arguments.length ? (this._verticalAlign = typeof _ === "function" ? _ : constant(_), this) : this._verticalAlign;
698
+ }
699
+ },
700
+ {
701
+ /**
702
+ @memberof TextBox
703
+ @desc Sets the width for each box to the specified accessor function or static number.
704
+ @param {Function|Number} [*value*]
705
+ @chainable
706
+ @example <caption>default accessor</caption>
707
+ function(d) {
708
+ return d.width || 200;
709
+ }
710
+ */ key: "width",
711
+ value: function width(_) {
712
+ return arguments.length ? (this._width = typeof _ === "function" ? _ : constant(_), this) : this._width;
713
+ }
714
+ },
715
+ {
716
+ /**
717
+ @memberof TextBox
718
+ @desc Sets the x position for each box to the specified accessor function or static number. The number given should correspond to the left side of the textBox.
719
+ @param {Function|Number} [*value*]
720
+ @chainable
721
+ @example <caption>default accessor</caption>
722
+ function(d) {
723
+ return d.x || 0;
724
+ }
725
+ */ key: "x",
726
+ value: function x(_) {
727
+ return arguments.length ? (this._x = typeof _ === "function" ? _ : constant(_), this) : this._x;
728
+ }
729
+ },
730
+ {
731
+ /**
732
+ @memberof TextBox
733
+ @desc Sets the y position for each box to the specified accessor function or static number. The number given should correspond to the top side of the textBox.
734
+ @param {Function|Number} [*value*]
735
+ @chainable
736
+ @example <caption>default accessor</caption>
737
+ function(d) {
738
+ return d.y || 0;
739
+ }
740
+ */ key: "y",
741
+ value: function y(_) {
742
+ return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y;
743
+ }
744
+ }
745
+ ]);
746
+ return TextBox;
747
+ }(BaseClass);
748
+ /**
749
+ @class TextBox
750
+ @extends BaseClass
751
+ @desc Creates a wrapped text box for each point in an array of data. See [this example](https://d3plus.org/examples/d3plus-text/getting-started/) for help getting started using the TextBox class.
752
+ */ export { TextBox as default };