@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,406 @@
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(target, property, receiver) {
31
+ if (typeof Reflect !== "undefined" && Reflect.get) {
32
+ _get = Reflect.get;
33
+ } else {
34
+ _get = function get(target, property, receiver) {
35
+ var base = _super_prop_base(target, property);
36
+ if (!base) return;
37
+ var desc = Object.getOwnPropertyDescriptor(base, property);
38
+ if (desc.get) {
39
+ return desc.get.call(receiver || target);
40
+ }
41
+ return desc.value;
42
+ };
43
+ }
44
+ return _get(target, property, receiver || target);
45
+ }
46
+ function _get_prototype_of(o) {
47
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
48
+ return o.__proto__ || Object.getPrototypeOf(o);
49
+ };
50
+ return _get_prototype_of(o);
51
+ }
52
+ function _inherits(subClass, superClass) {
53
+ if (typeof superClass !== "function" && superClass !== null) {
54
+ throw new TypeError("Super expression must either be null or a function");
55
+ }
56
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
57
+ constructor: {
58
+ value: subClass,
59
+ writable: true,
60
+ configurable: true
61
+ }
62
+ });
63
+ if (superClass) _set_prototype_of(subClass, superClass);
64
+ }
65
+ function _possible_constructor_return(self, call) {
66
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
67
+ return call;
68
+ }
69
+ return _assert_this_initialized(self);
70
+ }
71
+ function _set_prototype_of(o, p) {
72
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
73
+ o.__proto__ = p;
74
+ return o;
75
+ };
76
+ return _set_prototype_of(o, p);
77
+ }
78
+ function _super_prop_base(object, property) {
79
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
80
+ object = _get_prototype_of(object);
81
+ if (object === null) break;
82
+ }
83
+ return object;
84
+ }
85
+ function _type_of(obj) {
86
+ "@swc/helpers - typeof";
87
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
88
+ }
89
+ function _is_native_reflect_construct() {
90
+ try {
91
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
92
+ } catch (_) {}
93
+ return (_is_native_reflect_construct = function() {
94
+ return !!result;
95
+ })();
96
+ }
97
+ import { sum } from "d3-array";
98
+ import { nest } from "d3-collection";
99
+ import { hierarchy, treemap } from "d3-hierarchy";
100
+ import { treemapBinary, treemapDice, treemapSlice, treemapSliceDice, treemapSquarify, treemapResquarify } from "d3-hierarchy";
101
+ var tileMethods = {
102
+ treemapBinary: treemapBinary,
103
+ treemapDice: treemapDice,
104
+ treemapSlice: treemapSlice,
105
+ treemapSliceDice: treemapSliceDice,
106
+ treemapSquarify: treemapSquarify,
107
+ treemapResquarify: treemapResquarify
108
+ };
109
+ import { merge } from "@d3plus/data";
110
+ import { assign, elem } from "@d3plus/dom";
111
+ import { formatAbbreviate } from "@d3plus/format";
112
+ import { Rect } from "../shapes/index.js";
113
+ import { accessor, configPrep, constant } from "../utils/index.js";
114
+ import Viz from "./Viz.js";
115
+ var Treemap = /*#__PURE__*/ function(Viz) {
116
+ "use strict";
117
+ _inherits(Treemap, Viz);
118
+ function Treemap() {
119
+ _class_call_check(this, Treemap);
120
+ var _this;
121
+ _this = _call_super(this, Treemap);
122
+ _this._layoutPadding = 1;
123
+ var defaultLegend = _this._legend;
124
+ _this._legend = function(config, arr) {
125
+ if (arr.length === _this._filteredData.length) return false;
126
+ return defaultLegend.bind(_this)(config, arr);
127
+ };
128
+ _this._legendSort = function(a, b) {
129
+ return _this._sum(b) - _this._sum(a);
130
+ };
131
+ _this._legendTooltip = assign({}, _this._legendTooltip, {
132
+ tbody: []
133
+ });
134
+ _this._shapeConfig = assign({}, _this._shapeConfig, {
135
+ ariaLabel: function(d, i) {
136
+ var rank = _this._rankData ? "".concat(_this._rankData.indexOf(d) + 1, ". ") : "";
137
+ return "".concat(rank).concat(_this._drawLabel(d, i), ", ").concat(_this._sum(d, i), ".");
138
+ },
139
+ labelConfig: {
140
+ fontMax: 32,
141
+ fontMin: 8,
142
+ fontResize: true,
143
+ padding: 5
144
+ }
145
+ });
146
+ _this._sort = function(a, b) {
147
+ var aggA = isAggregated(a);
148
+ var aggB = isAggregated(b);
149
+ return aggA && !aggB ? 1 : !aggA && aggB ? -1 : b.value - a.value;
150
+ };
151
+ _this._sum = accessor("value");
152
+ _this._thresholdKey = _this._sum;
153
+ _this._tile = treemapSquarify;
154
+ _this._tooltipConfig = assign({}, _this._tooltipConfig, {
155
+ tbody: [
156
+ [
157
+ function() {
158
+ return _this._translate("Share");
159
+ },
160
+ function(d, i, x) {
161
+ return "".concat(formatAbbreviate(x.share * 100, _this._locale), "%");
162
+ }
163
+ ]
164
+ ]
165
+ });
166
+ _this._treemap = treemap().round(true);
167
+ var isAggregated = function(leaf) {
168
+ return leaf.children && leaf.children.length === 1 && leaf.children[0].data._isAggregation;
169
+ };
170
+ return _this;
171
+ }
172
+ _create_class(Treemap, [
173
+ {
174
+ /**
175
+ @memberof Treemap
176
+ @desc Extends the draw behavior of the abstract Viz class.
177
+ @private
178
+ */ key: "_draw",
179
+ value: function _draw(callback) {
180
+ var _this = this;
181
+ _get(_get_prototype_of(Treemap.prototype), "_draw", this).call(this, callback);
182
+ var nestedData = nest();
183
+ for(var i = 0; i <= this._drawDepth; i++)nestedData.key(this._groupBy[i]);
184
+ nestedData = nestedData.entries(this._filteredData);
185
+ var tmapData = this._treemap.padding(this._layoutPadding).size([
186
+ this._width - this._margin.left - this._margin.right,
187
+ this._height - this._margin.top - this._margin.bottom
188
+ ]).tile(this._tile)(hierarchy({
189
+ values: nestedData
190
+ }, function(d) {
191
+ return d.values;
192
+ }).sum(this._sum).sort(this._sort));
193
+ var shapeData = [], that = this;
194
+ /**
195
+ @memberof Treemap
196
+ @desc Flattens and merges treemap data.
197
+ @private
198
+ */ function extractLayout(children) {
199
+ for(var i = 0; i < children.length; i++){
200
+ var node = children[i];
201
+ if (node.depth <= that._drawDepth) extractLayout(node.children);
202
+ else {
203
+ var index = node.data.values.length === 1 ? that._filteredData.indexOf(node.data.values[0]) : undefined;
204
+ node.__d3plus__ = true;
205
+ node.id = node.data.key;
206
+ node.i = index > -1 ? index : undefined;
207
+ node.data = merge(node.data.values, that._aggs);
208
+ node.x = node.x0 + (node.x1 - node.x0) / 2;
209
+ node.y = node.y0 + (node.y1 - node.y0) / 2;
210
+ shapeData.push(node);
211
+ }
212
+ }
213
+ }
214
+ if (tmapData.children) extractLayout(tmapData.children);
215
+ this._rankData = shapeData.sort(this._sort).map(function(d) {
216
+ return d.data;
217
+ });
218
+ var total = tmapData.value;
219
+ shapeData.forEach(function(d) {
220
+ d.share = _this._sum(d.data, d.i) / total;
221
+ });
222
+ var transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")");
223
+ var rectConfig = configPrep.bind(this)(this._shapeConfig, "shape", "Rect");
224
+ var fontMax = rectConfig.labelConfig.fontMax;
225
+ var fontMin = rectConfig.labelConfig.fontMin;
226
+ var padding = rectConfig.labelConfig.padding;
227
+ this._shapes.push(new Rect().data(shapeData).label(function(d) {
228
+ return [
229
+ _this._drawLabel(d.data, d.i),
230
+ "".concat(formatAbbreviate(d.share * 100, _this._locale), "%")
231
+ ];
232
+ }).select(elem("g.d3plus-Treemap", {
233
+ parent: this._select,
234
+ enter: {
235
+ transform: transform
236
+ },
237
+ update: {
238
+ transform: transform
239
+ }
240
+ }).node()).config({
241
+ height: function(d) {
242
+ return d.y1 - d.y0;
243
+ },
244
+ labelBounds: function(d, i, s) {
245
+ var h = s.height;
246
+ var sh = Math.min(fontMax, (h - padding * 2) * 0.5);
247
+ if (sh < fontMin) sh = 0;
248
+ return [
249
+ {
250
+ width: s.width,
251
+ height: h - sh,
252
+ x: -s.width / 2,
253
+ y: -h / 2
254
+ },
255
+ {
256
+ width: s.width,
257
+ height: sh + padding * 2,
258
+ x: -s.width / 2,
259
+ y: h / 2 - sh - padding * 2
260
+ }
261
+ ];
262
+ },
263
+ labelConfig: {
264
+ textAnchor: function(d, i, x) {
265
+ var line, parent = x;
266
+ while(typeof line === "undefined" && parent){
267
+ if (typeof parent.l !== "undefined") line = parent.l;
268
+ parent = parent.__d3plusParent__;
269
+ }
270
+ return line ? "middle" : "start";
271
+ },
272
+ verticalAlign: function(d, i, x) {
273
+ var line, parent = x;
274
+ while(typeof line === "undefined" && parent){
275
+ if (typeof parent.l !== "undefined") line = parent.l;
276
+ parent = parent.__d3plusParent__;
277
+ }
278
+ return line ? "bottom" : "top";
279
+ }
280
+ },
281
+ width: function(d) {
282
+ return d.x1 - d.x0;
283
+ }
284
+ }).config(rectConfig).render());
285
+ return this;
286
+ }
287
+ },
288
+ {
289
+ /**
290
+ * Applies the threshold algorithm for Treemaps.
291
+ * @param {Array} data The data to process.
292
+ * @private
293
+ */ key: "_thresholdFunction",
294
+ value: function _thresholdFunction(data) {
295
+ var aggs = this._aggs;
296
+ var drawDepth = this._drawDepth;
297
+ var groupBy = this._groupBy;
298
+ var threshold = this._threshold;
299
+ var thresholdKey = this._thresholdKey;
300
+ var totalSum = sum(data, thresholdKey);
301
+ if (threshold && thresholdKey) {
302
+ return thresholdByDepth(data, 0);
303
+ }
304
+ /**
305
+ * @memberof Treemap
306
+ * @desc Explores the data tree recursively and merges elements under the indicated threshold.
307
+ * @param {object[]} branchData The current subset of the dataset to work on.
308
+ * @param {number} depth The depth of the current branch.
309
+ * @private
310
+ */ function thresholdByDepth(branchData, depth) {
311
+ if (depth < drawDepth) {
312
+ return nest().key(groupBy[depth]).entries(branchData).reduce(function(bulk, leaf) {
313
+ var subBranchData = thresholdByDepth(leaf.values, depth + 1);
314
+ return bulk.concat(subBranchData);
315
+ }, []);
316
+ }
317
+ if (depth === drawDepth) {
318
+ var thresholdPercent = Math.min(1, Math.max(0, threshold(branchData)));
319
+ if (!isFinite(thresholdPercent) || isNaN(thresholdPercent)) return null;
320
+ var removedItems = [];
321
+ var branchDataCopy = branchData.slice();
322
+ var thresholdValue = thresholdPercent * totalSum;
323
+ var n = branchDataCopy.length;
324
+ while(n--){
325
+ var datum = branchDataCopy[n];
326
+ if (thresholdKey(datum) < thresholdValue) {
327
+ var index = branchDataCopy.indexOf(datum);
328
+ branchDataCopy.splice(index, 1);
329
+ removedItems.push(datum);
330
+ }
331
+ }
332
+ if (removedItems.length > 0) {
333
+ var mergedItem = merge(removedItems, aggs);
334
+ mergedItem._isAggregation = true;
335
+ mergedItem._threshold = thresholdPercent;
336
+ branchDataCopy.push(mergedItem);
337
+ }
338
+ return branchDataCopy;
339
+ }
340
+ throw new Error("Depth is higher than the amount of grouping levels.");
341
+ }
342
+ return data;
343
+ }
344
+ },
345
+ {
346
+ /**
347
+ @memberof Treemap
348
+ @desc If *value* is specified, sets the inner and outer padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current padding accessor.
349
+ @param {Function|Number} [*value*]
350
+ */ key: "layoutPadding",
351
+ value: function layoutPadding(_) {
352
+ return arguments.length ? (this._layoutPadding = typeof _ === "function" ? _ : constant(_), this) : this._layoutPadding;
353
+ }
354
+ },
355
+ {
356
+ /**
357
+ @memberof Treemap
358
+ @desc If *comparator* is specified, sets the sort order for the treemap using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
359
+ @param {Array} [*comparator*]
360
+ @example
361
+ function comparator(a, b) {
362
+ return b.value - a.value;
363
+ }
364
+ */ key: "sort",
365
+ value: function sort(_) {
366
+ return arguments.length ? (this._sort = _, this) : this._sort;
367
+ }
368
+ },
369
+ {
370
+ /**
371
+ @memberof Treemap
372
+ @desc If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor.
373
+ @param {Function|Number} [*value*]
374
+ @example
375
+ function sum(d) {
376
+ return d.sum;
377
+ }
378
+ */ key: "sum",
379
+ value: function sum(_) {
380
+ if (arguments.length) {
381
+ this._sum = typeof _ === "function" ? _ : accessor(_);
382
+ this._thresholdKey = this._sum;
383
+ return this;
384
+ } else return this._sum;
385
+ }
386
+ },
387
+ {
388
+ /**
389
+ @memberof Treemap
390
+ @desc Sets the tiling method used when calcuating the size and position of the rectangles.
391
+
392
+ Can either be a string referring to a d3-hierarchy [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling), or a custom function in the same format.
393
+ @param {String|Function} [*value* = "squarify"]
394
+ */ key: "tile",
395
+ value: function tile(_) {
396
+ return arguments.length ? (this._tile = typeof _ === "string" ? tileMethods["treemap".concat(_.charAt(0).toUpperCase()).concat(_.slice(1))] || treemapSquarify : _, this) : this._tile;
397
+ }
398
+ }
399
+ ]);
400
+ return Treemap;
401
+ }(Viz);
402
+ /**
403
+ @class Treemap
404
+ @extends Viz
405
+ @desc Uses the [d3 treemap layout](https://github.com/mbostock/d3/wiki/Treemap-Layout) to creates SVG rectangles based on an array of data. See [this example](https://d3plus.org/examples/d3plus-hierarchy/getting-started/) for help getting started using the treemap generator.
406
+ */ export { Treemap as default };