@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,330 @@
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 { nest } from "d3-collection";
75
+ import { select } from "d3-selection";
76
+ import { assign, elem } from "@d3plus/dom";
77
+ import { accessor, BaseClass, configPrep, constant } from "../utils/index.js";
78
+ import Circle from "./Circle.js";
79
+ import Line from "./Line.js";
80
+ import Rect from "./Rect.js";
81
+ var shapes = {
82
+ Circle: Circle,
83
+ Rect: Rect
84
+ };
85
+ var Whisker = /*#__PURE__*/ function(BaseClass) {
86
+ "use strict";
87
+ _inherits(Whisker, BaseClass);
88
+ function Whisker() {
89
+ _class_call_check(this, Whisker);
90
+ var _this;
91
+ _this = _call_super(this, Whisker);
92
+ _this._endpoint = accessor("endpoint", "Rect");
93
+ _this._endpointConfig = {
94
+ Circle: {
95
+ r: accessor("r", 5)
96
+ }
97
+ };
98
+ _this._length = accessor("length", 25);
99
+ _this._lineConfig = {};
100
+ _this._orient = accessor("orient", "top");
101
+ _this._x = accessor("x", 0);
102
+ _this._y = accessor("y", 0);
103
+ return _this;
104
+ }
105
+ _create_class(Whisker, [
106
+ {
107
+ /**
108
+ @memberof Whisker
109
+ @desc Draws the whisker.
110
+ @param {Function} [*callback*]
111
+ @chainable
112
+ */ key: "render",
113
+ value: function render(callback) {
114
+ var _this = this;
115
+ if (this._select === void 0) {
116
+ this.select(select("body").append("svg").style("width", "".concat(window.innerWidth, "px")).style("height", "".concat(window.innerHeight, "px")).style("display", "block").node());
117
+ }
118
+ var lineData = [];
119
+ this._data.forEach(function(d, i) {
120
+ var orient = _this._orient(d, i);
121
+ var x = _this._x(d, i);
122
+ var y = _this._y(d, i);
123
+ var endpointX = x;
124
+ if (orient === "left") endpointX -= _this._length(d, i);
125
+ else if (orient === "right") endpointX += _this._length(d, i);
126
+ var endpointY = y;
127
+ if (orient === "top") endpointY -= _this._length(d, i);
128
+ else if (orient === "bottom") endpointY += _this._length(d, i);
129
+ lineData.push({
130
+ __d3plus__: true,
131
+ data: d,
132
+ i: i,
133
+ id: i,
134
+ x: x,
135
+ y: y
136
+ });
137
+ lineData.push({
138
+ __d3plus__: true,
139
+ data: d,
140
+ i: i,
141
+ id: i,
142
+ x: endpointX,
143
+ y: endpointY
144
+ });
145
+ });
146
+ // Draw whisker line.
147
+ this._line = new Line().data(lineData).select(elem("g.d3plus-Whisker", {
148
+ parent: this._select
149
+ }).node()).config(configPrep.bind(this)(this._lineConfig, "shape")).render(callback);
150
+ var whiskerData = this._data.map(function(d, i) {
151
+ var dataObj = {};
152
+ dataObj.__d3plus__ = true;
153
+ dataObj.data = d;
154
+ dataObj.i = i;
155
+ dataObj.endpoint = _this._endpoint(d, i);
156
+ dataObj.length = _this._length(d, i);
157
+ dataObj.orient = _this._orient(d, i);
158
+ var endpointX = _this._x(d, i);
159
+ if (dataObj.orient === "left") endpointX -= dataObj.length;
160
+ else if (dataObj.orient === "right") endpointX += dataObj.length;
161
+ var endpointY = _this._y(d, i);
162
+ if (dataObj.orient === "top") endpointY -= dataObj.length;
163
+ else if (dataObj.orient === "bottom") endpointY += dataObj.length;
164
+ dataObj.x = endpointX;
165
+ dataObj.y = endpointY;
166
+ return dataObj;
167
+ });
168
+ // Draw whisker endpoint.
169
+ this._whiskerEndpoint = [];
170
+ nest().key(function(d) {
171
+ return d.endpoint;
172
+ }).entries(whiskerData).forEach(function(shapeData) {
173
+ var shapeName = shapeData.key;
174
+ _this._whiskerEndpoint.push(new shapes[shapeName]().data(shapeData.values).select(elem("g.d3plus-Whisker-Endpoint-".concat(shapeName), {
175
+ parent: _this._select
176
+ }).node()).config({
177
+ height: function(d) {
178
+ return d.orient === "top" || d.orient === "bottom" ? 5 : 20;
179
+ },
180
+ width: function(d) {
181
+ return d.orient === "top" || d.orient === "bottom" ? 20 : 5;
182
+ }
183
+ }).config(configPrep.bind(_this)(_this._endpointConfig, "shape", shapeName)).render());
184
+ });
185
+ return this;
186
+ }
187
+ },
188
+ {
189
+ /**
190
+ @memberof Whisker
191
+ @desc Sets the highlight accessor to the Shape class's active function.
192
+ @param {Function} [*value*]
193
+ @chainable
194
+ */ key: "active",
195
+ value: function active(_) {
196
+ if (this._line) this._line.active(_);
197
+ if (this._whiskerEndpoint) this._whiskerEndpoint.forEach(function(endPoint) {
198
+ return endPoint.active(_);
199
+ });
200
+ }
201
+ },
202
+ {
203
+ /**
204
+ @memberof Whisker
205
+ @desc If *data* is specified, sets the data array to the specified array and returns the current class instance. If *data* is not specified, returns the current data array.
206
+ @param {Array} [*data* = []]
207
+ @chainable
208
+ */ key: "data",
209
+ value: function data(_) {
210
+ return arguments.length ? (this._data = _, this) : this._data;
211
+ }
212
+ },
213
+ {
214
+ /**
215
+ @memberof Whisker
216
+ @desc If *value* is specified, sets the endpoint accessor to the specified function or string and returns the current class instance.
217
+ @param {Function|String}
218
+ @chainable
219
+ */ key: "endpoint",
220
+ value: function endpoint(_) {
221
+ return arguments.length ? (this._endpoint = typeof _ === "function" ? _ : constant(_), this) : this._endpoint;
222
+ }
223
+ },
224
+ {
225
+ /**
226
+ @memberof Whisker
227
+ @desc If *value* is specified, sets the config method for each endpoint and returns the current class instance.
228
+ @param {Object} [*value*]
229
+ @chainable
230
+ */ key: "endpointConfig",
231
+ value: function endpointConfig(_) {
232
+ return arguments.length ? (this._endpointConfig = assign(this._endpointConfig, _), this) : this._endpointConfig;
233
+ }
234
+ },
235
+ {
236
+ /**
237
+ @memberof Whisker
238
+ @desc Sets the highlight accessor to the Shape class's hover function.
239
+ @param {Function} [*value*]
240
+ @chainable
241
+ */ key: "hover",
242
+ value: function hover(_) {
243
+ if (this._line) this._line.hover(_);
244
+ if (this._whiskerEndpoint) this._whiskerEndpoint.forEach(function(endPoint) {
245
+ return endPoint.hover(_);
246
+ });
247
+ }
248
+ },
249
+ {
250
+ /**
251
+ @memberof Whisker
252
+ @desc If *value* is specified, sets the length accessor for whisker and returns the current class instance.
253
+ @param {Function|Number} [*value*]
254
+ @chainable
255
+ */ key: "length",
256
+ value: function length(_) {
257
+ return arguments.length ? (this._length = typeof _ === "function" ? _ : constant(_), this) : this._length;
258
+ }
259
+ },
260
+ {
261
+ /**
262
+ @memberof Whisker
263
+ @desc If *value* is specified, sets the config method for line shape and returns the current class instance.
264
+ @param {Object} [*value*]
265
+ @chainable
266
+ */ key: "lineConfig",
267
+ value: function lineConfig(_) {
268
+ return arguments.length ? (this._lineConfig = assign(this._lineConfig, _), this) : this._lineConfig;
269
+ }
270
+ },
271
+ {
272
+ /**
273
+ @memberof Whisker
274
+ @desc If *value* is specified, sets the orientation to the specified value. If *value* is not specified, returns the current orientation.
275
+ @param {Function|String} [*value* = "top"] Accepts "top", "right", "bottom" or "left"
276
+ @chainable
277
+ */ key: "orient",
278
+ value: function orient(_) {
279
+ return arguments.length ? (this._orient = typeof _ === "function" ? _ : constant(_), this) : this._orient;
280
+ }
281
+ },
282
+ {
283
+ /**
284
+ @memberof Whisker
285
+ @desc If *selector* is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If *selector* is not specified, returns the current SVG container element.
286
+ @param {String|HTMLElement} [*selector* = d3.select("body").append("svg")]
287
+ @chainable
288
+ */ key: "select",
289
+ value: function select1(_) {
290
+ return arguments.length ? (this._select = select(_), this) : this._select;
291
+ }
292
+ },
293
+ {
294
+ /**
295
+ @memberof Whisker
296
+ @desc If *value* is specified, sets the x axis to the specified function or number and returns the current class instance.
297
+ @param {Function|Number} [*value*]
298
+ @chainable
299
+ @example
300
+ function(d) {
301
+ return d.x;
302
+ }
303
+ */ key: "x",
304
+ value: function x(_) {
305
+ return arguments.length ? (this._x = typeof _ === "function" ? _ : constant(_), this) : this._x;
306
+ }
307
+ },
308
+ {
309
+ /**
310
+ @memberof Whisker
311
+ @desc If *value* is specified, sets the y axis to the specified function or number and returns the current class instance.
312
+ @param {Function|Number} [*value*]
313
+ @chainable
314
+ @example
315
+ function(d) {
316
+ return d.y;
317
+ }
318
+ */ key: "y",
319
+ value: function y(_) {
320
+ return arguments.length ? (this._y = typeof _ === "function" ? _ : constant(_), this) : this._y;
321
+ }
322
+ }
323
+ ]);
324
+ return Whisker;
325
+ }(BaseClass);
326
+ /**
327
+ @class Whisker
328
+ @extends BaseClass
329
+ @desc Creates SVG whisker based on an array of data.
330
+ */ export { Whisker as default };
@@ -0,0 +1,10 @@
1
+ export { default as Shape } from "./Shape.js";
2
+ export { default as Area } from "./Area.js";
3
+ export { default as Bar } from "./Bar.js";
4
+ export { default as Box } from "./Box.js";
5
+ export { default as Circle } from "./Circle.js";
6
+ export { default as Image } from "./Image.js";
7
+ export { default as Line } from "./Line.js";
8
+ export { default as Path } from "./Path.js";
9
+ export { default as Rect } from "./Rect.js";
10
+ export { default as Whisker } from "./Whisker.js";
@@ -0,0 +1,204 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ import { assign, isObject } from "@d3plus/dom";
21
+ import { findLocale, translateLocale as dictionaries } from "@d3plus/locales";
22
+ import RESET from "./RESET.js";
23
+ import uuid from "./uuid.js";
24
+ /**
25
+ @desc Recursive function that resets nested Object configs.
26
+ @param {Object} obj
27
+ @param {Object} defaults
28
+ @private
29
+ */ function nestedReset(obj, defaults) {
30
+ if (isObject(obj)) {
31
+ for(var nestedKey in obj){
32
+ if (({}).hasOwnProperty.call(obj, nestedKey) && !nestedKey.startsWith("_")) {
33
+ var defaultValue = defaults && isObject(defaults) ? defaults[nestedKey] : undefined;
34
+ if (obj[nestedKey] === RESET) {
35
+ if (defaultValue) obj[nestedKey] = defaultValue;
36
+ else delete obj[nestedKey];
37
+ } else if (isObject(obj[nestedKey])) {
38
+ nestedReset(obj[nestedKey], defaultValue);
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * @desc finds all prototype methods of a class and it's parent classes
46
+ * @param {*} obj
47
+ * @private
48
+ */ function getAllMethods(obj) {
49
+ var props = [];
50
+ do {
51
+ props = props.concat(Object.getOwnPropertyNames(obj));
52
+ obj = Object.getPrototypeOf(obj);
53
+ }while (obj && obj !== Object.prototype);
54
+ return props.filter(function(e) {
55
+ return e.indexOf("_") !== 0 && ![
56
+ "config",
57
+ "constructor",
58
+ "parent",
59
+ "render"
60
+ ].includes(e);
61
+ });
62
+ }
63
+ var BaseClass = /*#__PURE__*/ function() {
64
+ "use strict";
65
+ function BaseClass() {
66
+ var _this = this;
67
+ _class_call_check(this, BaseClass);
68
+ this._locale = "en-US";
69
+ this._on = {};
70
+ this._parent = {};
71
+ this._translate = function(d) {
72
+ var locale = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : _this._locale;
73
+ var dictionary = dictionaries[locale];
74
+ return dictionary && dictionary[d] ? dictionary[d] : d;
75
+ };
76
+ this._uuid = uuid();
77
+ }
78
+ _create_class(BaseClass, [
79
+ {
80
+ /**
81
+ @memberof BaseClass
82
+ @desc If *value* is specified, sets the methods that correspond to the key/value pairs and returns this class. If *value* is not specified, returns the current configuration.
83
+ @param {Object} [*value*]
84
+ @chainable
85
+ */ key: "config",
86
+ value: function config(_) {
87
+ var _this = this;
88
+ if (!this._configDefault) {
89
+ var config = {};
90
+ getAllMethods(this.__proto__).forEach(function(k) {
91
+ var v = _this[k]();
92
+ if (v !== _this) config[k] = isObject(v) ? assign({}, v) : v;
93
+ });
94
+ this._configDefault = config;
95
+ }
96
+ if (arguments.length) {
97
+ for(var k in _){
98
+ if (({}).hasOwnProperty.call(_, k) && k in this) {
99
+ var v = _[k];
100
+ if (v === RESET) {
101
+ if (k === "on") this._on = this._configDefault[k];
102
+ else this[k](this._configDefault[k]);
103
+ } else {
104
+ nestedReset(v, this._configDefault[k]);
105
+ this[k](v);
106
+ }
107
+ }
108
+ }
109
+ return this;
110
+ } else {
111
+ var config1 = {};
112
+ getAllMethods(this.__proto__).forEach(function(k) {
113
+ config1[k] = _this[k]();
114
+ });
115
+ return config1;
116
+ }
117
+ }
118
+ },
119
+ {
120
+ /**
121
+ @memberof BaseClass
122
+ @desc Sets the locale used for all text and number formatting. This method supports the locales defined in [d3plus-format](https://github.com/d3plus/d3plus-format/blob/master/src/locale.js). The locale can be defined as a complex Object (like in d3plus-format), a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale from d3plus-format.
123
+ @param {Object|String} [*value* = "en-US"]
124
+ @chainable
125
+ @example
126
+ {
127
+ separator: "",
128
+ suffixes: ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "B", "t", "q", "Q", "Z", "Y"],
129
+ grouping: [3],
130
+ delimiters: {
131
+ thousands: ",",
132
+ decimal: "."
133
+ },
134
+ currency: ["$", ""]
135
+ }
136
+ */ key: "locale",
137
+ value: function locale(_) {
138
+ return arguments.length ? (this._locale = findLocale(_), this) : this._locale;
139
+ }
140
+ },
141
+ {
142
+ /**
143
+ @memberof BaseClass
144
+ @desc Adds or removes a *listener* to each object for the specified event *typenames*. If a *listener* is not specified, returns the currently assigned listener for the specified event *typename*. Mirrors the core [d3-selection](https://github.com/d3/d3-selection#selection_on) behavior.
145
+ @param {String} [*typenames*]
146
+ @param {Function} [*listener*]
147
+ @chainable
148
+ @example <caption>By default, listeners apply globally to all objects, however, passing a namespace with the class name gives control over specific elements:</caption>
149
+ new Plot
150
+ .on("click.Shape", function(d) {
151
+ console.log("data for shape clicked:", d);
152
+ })
153
+ .on("click.Legend", function(d) {
154
+ console.log("data for legend clicked:", d);
155
+ })
156
+ */ key: "on",
157
+ value: function on(_, f) {
158
+ return arguments.length === 2 ? (this._on[_] = f, this) : arguments.length ? typeof _ === "string" ? this._on[_] : (this._on = Object.assign({}, this._on, _), this) : this._on;
159
+ }
160
+ },
161
+ {
162
+ /**
163
+ @memberof Viz
164
+ @desc If *value* is specified, sets the parent config used by the wrapper and returns the current class instance.
165
+ @param {Object} [*value*]
166
+ @chainable
167
+ */ key: "parent",
168
+ value: function parent(_) {
169
+ return arguments.length ? (this._parent = _, this) : this._parent;
170
+ }
171
+ },
172
+ {
173
+ /**
174
+ @memberof BaseClass
175
+ @desc Defines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.
176
+ @param {Function} [*value*]
177
+ @chainable
178
+ @example <caption>For example, if we wanted to only change the string "Back" and allow all other string to return in English:</caption>
179
+ .translate(function(d) {
180
+ return d === "Back" ? "Get outta here" : d;
181
+ })
182
+ */ key: "translate",
183
+ value: function translate(_) {
184
+ return arguments.length ? (this._translate = _, this) : this._translate;
185
+ }
186
+ },
187
+ {
188
+ /**
189
+ @memberof Viz
190
+ @desc If *value* is specified, sets the config method for each shape and returns the current class instance.
191
+ @param {Object} [*value*]
192
+ @chainable
193
+ */ key: "shapeConfig",
194
+ value: function shapeConfig(_) {
195
+ return arguments.length ? (this._shapeConfig = assign(this._shapeConfig, _), this) : this._shapeConfig;
196
+ }
197
+ }
198
+ ]);
199
+ return BaseClass;
200
+ }();
201
+ /**
202
+ @class BaseClass
203
+ @summary An abstract class that contains some global methods and functionality.
204
+ */ export { BaseClass as default };
@@ -0,0 +1,4 @@
1
+ /**
2
+ @constant RESET
3
+ @desc String constant used to reset an individual config property.
4
+ */ export default "D3PLUS-COMMON-RESET";
@@ -0,0 +1,19 @@
1
+ /**
2
+ @function accessor
3
+ @desc Wraps an object key in a simple accessor function.
4
+ @param {String} key The key to be returned from each Object passed to the function.
5
+ @param {*} [def] A default value to be returned if the key is not present.
6
+ @example <caption>this</caption>
7
+ accessor("id");
8
+ @example <caption>returns this</caption>
9
+ function(d) {
10
+ return d["id"];
11
+ }
12
+ */ export default function(key, def) {
13
+ if (def === undefined) return function(d) {
14
+ return d[key];
15
+ };
16
+ return function(d) {
17
+ return d[key] === undefined ? def : d[key];
18
+ };
19
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ @function configPrep
3
+ @desc Preps a config object for d3plus data, and optionally bubbles up a specific nested type. When using this function, you must bind a d3plus class' `this` context.
4
+ @param {Object} [config = this._shapeConfig] The configuration object to parse.
5
+ @param {String} [type = "shape"] The event classifier to user for "on" events. For example, the default event type of "shape" will apply all events in the "on" config object with that key, like "click.shape" and "mouseleave.shape", in addition to any gloval events like "click" and "mouseleave".
6
+ @param {String} [nest] An optional nested key to bubble up to the parent config level.
7
+ */ function _instanceof(left, right) {
8
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
9
+ return !!right[Symbol.hasInstance](left);
10
+ } else {
11
+ return left instanceof right;
12
+ }
13
+ }
14
+ function _type_of(obj) {
15
+ "@swc/helpers - typeof";
16
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
17
+ }
18
+ export default function configPrep() {
19
+ var _this = this;
20
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this._shapeConfig, type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "shape", nest = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
21
+ var newConfig = {
22
+ duration: this._duration,
23
+ on: {}
24
+ };
25
+ var wrapFunction = function(func) {
26
+ return function(d, i, s, e) {
27
+ if (!func) return func;
28
+ var parent;
29
+ while(d.__d3plus__){
30
+ if (parent) d.__d3plusParent__ = parent;
31
+ parent = d;
32
+ i = d.i;
33
+ d = d.data || d.feature;
34
+ }
35
+ return func.bind(_this)(d, i, s || parent, e);
36
+ };
37
+ };
38
+ var parseEvents = function(newObj, on) {
39
+ for(var event in on){
40
+ if (({}).hasOwnProperty.call(on, event) && !event.includes(".") || event.includes(".".concat(type))) {
41
+ newObj.on[event] = wrapFunction(on[event]);
42
+ }
43
+ }
44
+ };
45
+ var arrayEval = function(arr) {
46
+ return arr.map(function(d) {
47
+ if (_instanceof(d, Array)) return arrayEval(d);
48
+ else if ((typeof d === "undefined" ? "undefined" : _type_of(d)) === "object") return keyEval({}, d);
49
+ else if (typeof d === "function") return wrapFunction(d);
50
+ else return d;
51
+ });
52
+ };
53
+ var keyEval = function(newObj, obj) {
54
+ for(var key in obj){
55
+ if (({}).hasOwnProperty.call(obj, key)) {
56
+ if (key === "on") parseEvents(newObj, obj[key]);
57
+ else if (typeof obj[key] === "function") {
58
+ newObj[key] = wrapFunction(obj[key]);
59
+ } else if (_instanceof(obj[key], Array)) {
60
+ newObj[key] = arrayEval(obj[key]);
61
+ } else if (_type_of(obj[key]) === "object") {
62
+ if (!newObj[key]) newObj[key] = {};
63
+ newObj[key].on = {};
64
+ keyEval(newObj[key], obj[key]);
65
+ } else newObj[key] = obj[key];
66
+ }
67
+ }
68
+ };
69
+ keyEval(newConfig, config);
70
+ if (this._on) parseEvents(newConfig, this._on);
71
+ if (nest && config[nest]) {
72
+ keyEval(newConfig, config[nest]);
73
+ if (config[nest].on) parseEvents(newConfig, config[nest].on);
74
+ }
75
+ return newConfig;
76
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ @function constant
3
+ @desc Wraps non-function variables in a simple return function.
4
+ @param {Array|Number|Object|String} value The value to be returned from the function.
5
+ @example <caption>this</caption>
6
+ constant(42);
7
+ @example <caption>returns this</caption>
8
+ function() {
9
+ return 42;
10
+ }
11
+ */ export default function(value) {
12
+ return function constant() {
13
+ return value;
14
+ };
15
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ @module getProp
3
+ @param {String} type
4
+ @param {Object} d
5
+ @param {Number} i
6
+ @private
7
+ */ export default function(type, d, i) {
8
+ return d[type] || this["_".concat(type)](d, i);
9
+ }
@@ -0,0 +1,7 @@
1
+ export { default as accessor } from "./accessor.js";
2
+ export { default as BaseClass } from "./BaseClass.js";
3
+ export { default as configPrep } from "./configPrep.js";
4
+ export { default as constant } from "./constant.js";
5
+ export { default as getProp } from "./getProp.js";
6
+ export { default as RESET } from "./RESET.js";
7
+ export { default as uuid } from "./uuid.js";