@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,312 @@
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 _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _get(target, property, receiver) {
44
+ if (typeof Reflect !== "undefined" && Reflect.get) {
45
+ _get = Reflect.get;
46
+ } else {
47
+ _get = function get(target, property, receiver) {
48
+ var base = _super_prop_base(target, property);
49
+ if (!base) return;
50
+ var desc = Object.getOwnPropertyDescriptor(base, property);
51
+ if (desc.get) {
52
+ return desc.get.call(receiver || target);
53
+ }
54
+ return desc.value;
55
+ };
56
+ }
57
+ return _get(target, property, receiver || target);
58
+ }
59
+ function _get_prototype_of(o) {
60
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
61
+ return o.__proto__ || Object.getPrototypeOf(o);
62
+ };
63
+ return _get_prototype_of(o);
64
+ }
65
+ function _inherits(subClass, superClass) {
66
+ if (typeof superClass !== "function" && superClass !== null) {
67
+ throw new TypeError("Super expression must either be null or a function");
68
+ }
69
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
70
+ constructor: {
71
+ value: subClass,
72
+ writable: true,
73
+ configurable: true
74
+ }
75
+ });
76
+ if (superClass) _set_prototype_of(subClass, superClass);
77
+ }
78
+ function _possible_constructor_return(self, call) {
79
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
80
+ return call;
81
+ }
82
+ return _assert_this_initialized(self);
83
+ }
84
+ function _set_prototype_of(o, p) {
85
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
86
+ o.__proto__ = p;
87
+ return o;
88
+ };
89
+ return _set_prototype_of(o, p);
90
+ }
91
+ function _super_prop_base(object, property) {
92
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
93
+ object = _get_prototype_of(object);
94
+ if (object === null) break;
95
+ }
96
+ return object;
97
+ }
98
+ function _type_of(obj) {
99
+ "@swc/helpers - typeof";
100
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
101
+ }
102
+ function _is_native_reflect_construct() {
103
+ try {
104
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
105
+ } catch (_) {}
106
+ return (_is_native_reflect_construct = function() {
107
+ return !!result;
108
+ })();
109
+ }
110
+ import { extent, min, max } from "d3-array";
111
+ import { hierarchy, tree } from "d3-hierarchy";
112
+ import { scaleLinear } from "d3-scale";
113
+ import { assign, elem } from "@d3plus/dom";
114
+ import { merge, nest } from "@d3plus/data";
115
+ import { configPrep, constant } from "../utils/index.js";
116
+ import { Circle, Path } from "../shapes/index.js";
117
+ import Viz from "./Viz.js";
118
+ var Tree = /*#__PURE__*/ function(Viz) {
119
+ "use strict";
120
+ _inherits(Tree, Viz);
121
+ function Tree() {
122
+ _class_call_check(this, Tree);
123
+ var _this;
124
+ _this = _call_super(this, Tree);
125
+ _this._orient = "vertical";
126
+ _this._separation = function(a, b) {
127
+ return a.parent === b.parent ? 1 : 2;
128
+ };
129
+ _this._shape = constant("Circle");
130
+ _this._shapeConfig = assign(_this._shapeConfig, {
131
+ ariaLabel: function(d, i) {
132
+ return _this._treeData ? "".concat(_this._treeData[i].depth, ". ").concat(_this._drawLabel(d, i), ".") : "";
133
+ },
134
+ labelConfig: {
135
+ fontColor: "#444"
136
+ },
137
+ Path: {
138
+ fill: "none",
139
+ stroke: "#ccc",
140
+ strokeWidth: 1
141
+ },
142
+ r: constant(5),
143
+ width: constant(10),
144
+ height: constant(10)
145
+ });
146
+ _this._tree = tree();
147
+ return _this;
148
+ }
149
+ _create_class(Tree, [
150
+ {
151
+ /**
152
+ Extends the draw behavior of the abstract Viz class.
153
+ @private
154
+ */ key: "_draw",
155
+ value: function _draw(callback) {
156
+ var _this = this;
157
+ _get(_get_prototype_of(Tree.prototype), "_draw", this).call(this, callback);
158
+ var height = this._orient === "vertical" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right, left = this._orient === "vertical" ? "left" : "top", that = this, transform = "translate(".concat(this._margin.left, ", ").concat(this._margin.top, ")"), width = this._orient === "horizontal" ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
159
+ var treeData = this._treeData = this._tree.separation(this._separation).size([
160
+ width,
161
+ height
162
+ ])(hierarchy({
163
+ key: "root",
164
+ values: nest(this._filteredData, this._groupBy.slice(0, this._drawDepth + 1))
165
+ }, function(d) {
166
+ return d.key && d.values ? d.values : null;
167
+ }).sort(this._sort)).descendants().filter(function(d) {
168
+ return d.depth <= _this._groupBy.length && d.parent;
169
+ });
170
+ /**
171
+ Merges the values of a given nest branch.
172
+ @private
173
+ */ function flattenBranchData(branch) {
174
+ return merge(branch.values.map(function(l) {
175
+ return l.key && l.values ? flattenBranchData(l) : l;
176
+ }), that._aggs);
177
+ }
178
+ treeData.forEach(function(d, i) {
179
+ if (d.data.key && d.data.values) d.data = flattenBranchData(d.data);
180
+ d.__d3plus__ = true;
181
+ d.i = i;
182
+ });
183
+ var r = this._shapeConfig.r;
184
+ if (typeof r !== "function") r = constant(r);
185
+ var rBufferRoot = max(treeData, function(d) {
186
+ return d.depth === 1 ? r(d.data, d.i) : 0;
187
+ });
188
+ var rBufferEnd = max(treeData, function(d) {
189
+ return d.children ? 0 : r(d.data, d.i);
190
+ });
191
+ var yExtent = extent(treeData, function(d) {
192
+ return d.y;
193
+ });
194
+ this._labelHeight = min([
195
+ this._orient === "vertical" ? 50 : 100,
196
+ (yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)
197
+ ]);
198
+ this._labelWidths = nest(treeData, function(d) {
199
+ return d.depth;
200
+ }).map(function(d) {
201
+ return d.values.reduce(function(num, v, i) {
202
+ var next = i < d.values.length - 1 ? d.values[i + 1].x : width + _this._margin[left], prev = i ? d.values[i - 1].x : _this._margin[left];
203
+ return min([
204
+ num,
205
+ next - v.x,
206
+ v.x - prev
207
+ ]);
208
+ }, width);
209
+ });
210
+ var yScale = scaleLinear().domain(yExtent).range([
211
+ rBufferRoot + this._labelHeight,
212
+ height - rBufferEnd - this._labelHeight
213
+ ]);
214
+ treeData.forEach(function(d) {
215
+ var val = yScale(d.y);
216
+ if (_this._orient === "horizontal") {
217
+ d.y = d.x;
218
+ d.x = val;
219
+ } else d.y = val;
220
+ });
221
+ var elemObject = {
222
+ parent: this._select,
223
+ enter: {
224
+ transform: transform
225
+ },
226
+ update: {
227
+ transform: transform
228
+ }
229
+ };
230
+ this._shapes.push(new Path().data(treeData.filter(function(d) {
231
+ return d.depth > 1;
232
+ })).select(elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
233
+ d: function(d) {
234
+ var r = _this._shapeConfig.r;
235
+ if (typeof r === "function") r = r(d.data, d.i);
236
+ var px = d.parent.x - d.x + (_this._orient === "vertical" ? 0 : r), py = d.parent.y - d.y + (_this._orient === "vertical" ? r : 0), x = _this._orient === "vertical" ? 0 : -r, y = _this._orient === "vertical" ? -r : 0;
237
+ return _this._orient === "vertical" ? "M".concat(x, ",").concat(y, "C").concat(x, ",").concat((y + py) / 2, " ").concat(px, ",").concat((y + py) / 2, " ").concat(px, ",").concat(py) : "M".concat(x, ",").concat(y, "C").concat((x + px) / 2, ",").concat(y, " ").concat((x + px) / 2, ",").concat(py, " ").concat(px, ",").concat(py);
238
+ },
239
+ id: function(d, i) {
240
+ return _this._ids(d, i).join("-");
241
+ }
242
+ }).render());
243
+ this._shapes.push(new Circle().data(treeData).select(elem("g.d3plus-Tree-Shapes", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Circle")).config({
244
+ id: function(d, i) {
245
+ return _this._ids(d, i).join("-");
246
+ },
247
+ label: function(d, i) {
248
+ if (_this._label) return _this._label(d.data, i);
249
+ var ids = _this._ids(d, i).slice(0, d.depth);
250
+ return ids[ids.length - 1];
251
+ },
252
+ labelConfig: {
253
+ textAnchor: function(d) {
254
+ return _this._orient === "vertical" ? "middle" : d.data.children && d.data.depth !== _this._groupBy.length ? "end" : "start";
255
+ },
256
+ verticalAlign: function(d) {
257
+ return _this._orient === "vertical" ? d.data.depth === 1 ? "bottom" : "top" : "middle";
258
+ }
259
+ },
260
+ hitArea: function(d, i, s) {
261
+ var h = _this._labelHeight, w = _this._labelWidths[d.depth - 1];
262
+ return {
263
+ width: _this._orient === "vertical" ? w : s.r * 2 + w,
264
+ height: _this._orient === "horizontal" ? h : s.r * 2 + h,
265
+ x: _this._orient === "vertical" ? -w / 2 : d.children && d.depth !== _this._groupBy.length ? -(s.r + w) : -s.r,
266
+ y: _this._orient === "horizontal" ? -h / 2 : d.children && d.depth !== _this._groupBy.length ? -(s.r + _this._labelHeight) : -s.r
267
+ };
268
+ },
269
+ labelBounds: function(d, i, s) {
270
+ var h = _this._labelHeight, height = _this._orient === "vertical" ? "height" : "width", w = _this._labelWidths[d.depth - 1], width = _this._orient === "vertical" ? "width" : "height", x = _this._orient === "vertical" ? "x" : "y", y = _this._orient === "vertical" ? "y" : "x";
271
+ var _obj;
272
+ return _obj = {}, _define_property(_obj, width, w), _define_property(_obj, height, h), _define_property(_obj, x, -w / 2), _define_property(_obj, y, d.children && d.depth !== _this._groupBy.length ? -(s.r + h) : s.r), _obj;
273
+ }
274
+ }).render());
275
+ return this;
276
+ }
277
+ },
278
+ {
279
+ /**
280
+ @memberof Tree
281
+ @desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
282
+ @param {String} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
283
+ */ key: "orient",
284
+ value: function orient(_) {
285
+ return arguments.length ? (this._orient = _, this) : this._orient;
286
+ }
287
+ },
288
+ {
289
+ /**
290
+ @memberof Tree
291
+ @desc If *value* is specified, sets the separation accessor to the specified function. If *value* is not specified, returns the current separation accessor.
292
+
293
+ From the [d3-hierarchy documentation](https://github.com/d3/d3-hierarchy#tree_separation):
294
+ > The separation accessor is used to separate neighboring nodes. The separation function is passed two nodes a and b, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
295
+ @param {Function} [*value*]
296
+ @example
297
+ function separation(a, b) {
298
+ return a.parent === b.parent ? 1 : 2;
299
+ }
300
+ */ key: "separation",
301
+ value: function separation(_) {
302
+ return arguments.length ? (this._separation = _, this) : this._separation;
303
+ }
304
+ }
305
+ ]);
306
+ return Tree;
307
+ }(Viz);
308
+ /**
309
+ @class Tree
310
+ @extends Viz
311
+ @desc Uses d3's [tree layout](https://github.com/d3/d3-hierarchy#tree) to create a tidy tree chart based on an array of data.
312
+ */ export { Tree as default };