@d3plus/data 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.
@@ -0,0 +1,394 @@
1
+ /*
2
+ @d3plus/data v3.0.0
3
+ JavaScript data loading, manipulation, and analysis functions.
4
+ Copyright (c) 2025 D3plus - https://d3plus.org
5
+ @license MIT
6
+ */
7
+
8
+ (function (factory) {
9
+ typeof define === 'function' && define.amd ? define(factory) :
10
+ factory();
11
+ })((function () { 'use strict';
12
+
13
+ if (typeof window !== "undefined") {
14
+ (function () {
15
+ try {
16
+ if (typeof SVGElement === 'undefined' || Boolean(SVGElement.prototype.innerHTML)) {
17
+ return;
18
+ }
19
+ } catch (e) {
20
+ return;
21
+ }
22
+
23
+ function serializeNode (node) {
24
+ switch (node.nodeType) {
25
+ case 1:
26
+ return serializeElementNode(node);
27
+ case 3:
28
+ return serializeTextNode(node);
29
+ case 8:
30
+ return serializeCommentNode(node);
31
+ }
32
+ }
33
+
34
+ function serializeTextNode (node) {
35
+ return node.textContent.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
36
+ }
37
+
38
+ function serializeCommentNode (node) {
39
+ return '<!--' + node.nodeValue + '-->'
40
+ }
41
+
42
+ function serializeElementNode (node) {
43
+ var output = '';
44
+
45
+ output += '<' + node.tagName;
46
+
47
+ if (node.hasAttributes()) {
48
+ [].forEach.call(node.attributes, function(attrNode) {
49
+ output += ' ' + attrNode.name + '="' + attrNode.value + '"';
50
+ });
51
+ }
52
+
53
+ output += '>';
54
+
55
+ if (node.hasChildNodes()) {
56
+ [].forEach.call(node.childNodes, function(childNode) {
57
+ output += serializeNode(childNode);
58
+ });
59
+ }
60
+
61
+ output += '</' + node.tagName + '>';
62
+
63
+ return output;
64
+ }
65
+
66
+ Object.defineProperty(SVGElement.prototype, 'innerHTML', {
67
+ get: function () {
68
+ var output = '';
69
+
70
+ [].forEach.call(this.childNodes, function(childNode) {
71
+ output += serializeNode(childNode);
72
+ });
73
+
74
+ return output;
75
+ },
76
+ set: function (markup) {
77
+ while (this.firstChild) {
78
+ this.removeChild(this.firstChild);
79
+ }
80
+
81
+ try {
82
+ var dXML = new DOMParser();
83
+ dXML.async = false;
84
+
85
+ var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markup + '</svg>';
86
+ var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement;
87
+
88
+ [].forEach.call(svgDocElement.childNodes, function(childNode) {
89
+ this.appendChild(this.ownerDocument.importNode(childNode, true));
90
+ }.bind(this));
91
+ } catch (e) {
92
+ throw new Error('Error parsing markup string');
93
+ }
94
+ }
95
+ });
96
+
97
+ Object.defineProperty(SVGElement.prototype, 'innerSVG', {
98
+ get: function () {
99
+ return this.innerHTML;
100
+ },
101
+ set: function (markup) {
102
+ this.innerHTML = markup;
103
+ }
104
+ });
105
+
106
+ })();
107
+ }
108
+
109
+ }));
110
+
111
+ (function (global, factory) {
112
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-request'), require('@d3plus/dom'), require('d3-array'), require('d3-collection')) :
113
+ typeof define === 'function' && define.amd ? define('@d3plus/data', ['exports', 'd3-request', '@d3plus/dom', 'd3-array', 'd3-collection'], factory) :
114
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}, global.d3Request, global.dom, global.d3Array, global.d3Collection));
115
+ })(this, (function (exports, d3Request, dom, d3Array, d3Collection) { 'use strict';
116
+
117
+ /**
118
+ @function isData
119
+ @desc Returns true/false whether the argument provided to the function should be loaded using an internal XHR request. Valid data can either be a string URL or an Object with "url" and "headers" keys.
120
+ @param {*} dataItem The value to be tested
121
+ */ var isData = ((dataItem)=>typeof dataItem === "string" || typeof dataItem === "object" && dataItem.url && dataItem.headers);
122
+
123
+ /**
124
+ @function dataFold
125
+ @desc Given a JSON object where the data values and headers have been split into separate key lookups, this function will combine the data values with the headers and returns one large array of objects.
126
+ @param {Object} json A JSON data Object with `data` and `headers` keys.
127
+ @param {String} [data = "data"] The key used for the flat data array inside of the JSON object.
128
+ @param {String} [headers = "headers"] The key used for the flat headers array inside of the JSON object.
129
+ */ var fold = ((json, data = "data", headers = "headers")=>json[data].map((data)=>json[headers].reduce((obj, header, i)=>(obj[header] = data[i], obj), {})));
130
+
131
+ /**
132
+ @function dataConcat
133
+ @desc Reduce and concat all the elements included in arrayOfArrays if they are arrays. If it is a JSON object try to concat the array under given key data. If the key doesn't exists in object item, a warning message is lauched to the console. You need to implement DataFormat callback to concat the arrays manually.
134
+ @param {Array} arrayOfArray Array of elements
135
+ @param {String} [data = "data"] The key used for the flat data array if exists inside of the JSON object.
136
+ */ var concat = ((arrayOfArrays, data = "data")=>arrayOfArrays.reduce((acc, item)=>{
137
+ let dataArray = [];
138
+ if (Array.isArray(item)) {
139
+ dataArray = item;
140
+ } else {
141
+ if (item[data]) {
142
+ dataArray = item[data];
143
+ }
144
+ // else {
145
+ // console.warn(`d3plus-viz: Please implement a "dataFormat" callback to concat the arrays manually (consider using the d3plus.dataConcat method in your callback). Currently unable to concatenate (using key: "${data}") the following response:`, item);
146
+ // }
147
+ }
148
+ return acc.concat(dataArray);
149
+ }, []));
150
+
151
+ /**
152
+ @function dataLoad
153
+ @desc Loads data from a filepath or URL, converts it to a valid JSON object, and returns it to a callback function.
154
+ @param {Array|String} path The path to the file or url to be loaded. Also support array of paths strings. If an Array of objects is passed, the xhr request logic is skipped.
155
+ @param {Function} [formatter] An optional formatter function that is run on the loaded data.
156
+ @param {String} [key] The key in the `this` context to save the resulting data to.
157
+ @param {Function} [callback] A function that is called when the final data is loaded. It is passed 2 variables, any error present and the data loaded.
158
+ */ function load(path, formatter, key, callback) {
159
+ let parser;
160
+ const getParser = (path)=>{
161
+ const ext = path.slice(path.length - 4);
162
+ switch(ext){
163
+ case ".csv":
164
+ return d3Request.csv;
165
+ case ".tsv":
166
+ return d3Request.tsv;
167
+ case ".txt":
168
+ return d3Request.text;
169
+ default:
170
+ return d3Request.json;
171
+ }
172
+ };
173
+ const validateData = (err, parser, data)=>{
174
+ if (parser !== d3Request.json && !err && data && data instanceof Array) {
175
+ data.forEach((d)=>{
176
+ for(const k in d){
177
+ if (!isNaN(d[k])) d[k] = parseFloat(d[k]);
178
+ else if (d[k].toLowerCase() === "false") d[k] = false;
179
+ else if (d[k].toLowerCase() === "true") d[k] = true;
180
+ else if (d[k].toLowerCase() === "null") d[k] = null;
181
+ else if (d[k].toLowerCase() === "undefined") d[k] = undefined;
182
+ }
183
+ });
184
+ }
185
+ return data;
186
+ };
187
+ const loadedLength = (loadedArray)=>loadedArray.reduce((prev, current)=>current ? prev + 1 : prev, 0);
188
+ const getPathIndex = (url, array)=>array.indexOf(url);
189
+ // If path param is a not an Array then convert path to a 1 element Array to re-use logic
190
+ if (!(path instanceof Array)) path = [
191
+ path
192
+ ];
193
+ const needToLoad = path.find(isData);
194
+ let loaded = new Array(path.length);
195
+ const toLoad = [];
196
+ // If there is a string I'm assuming is a Array to merge, urls or data
197
+ if (needToLoad) {
198
+ path.forEach((dataItem, ix)=>{
199
+ if (isData(dataItem)) toLoad.push(dataItem);
200
+ else loaded[ix] = dataItem;
201
+ });
202
+ } else {
203
+ loaded[0] = path;
204
+ }
205
+ // Load all urls an combine them with data arrays
206
+ const alreadyLoaded = loadedLength(loaded);
207
+ toLoad.forEach((dataItem)=>{
208
+ let headers = {}, url = dataItem;
209
+ if (typeof dataItem === "object") {
210
+ url = dataItem.url;
211
+ headers = dataItem.headers;
212
+ }
213
+ parser = getParser(url);
214
+ const request = parser(url);
215
+ for(const key in headers){
216
+ if (({}).hasOwnProperty.call(headers, key)) {
217
+ request.header(key, headers[key]);
218
+ }
219
+ }
220
+ request.get((err, data)=>{
221
+ data = err ? [] : data;
222
+ if (data && !(data instanceof Array) && data.data && data.headers) data = fold(data);
223
+ data = validateData(err, parser, data);
224
+ loaded[getPathIndex(url, path)] = data;
225
+ if (loadedLength(loaded) - alreadyLoaded === toLoad.length) {
226
+ // Format data
227
+ data = loadedLength(loaded) === 1 ? loaded[0] : loaded;
228
+ if (this._cache) this._lrucache.set(`${key}_${url}`, data);
229
+ if (formatter) {
230
+ const formatterResponse = formatter(loadedLength(loaded) === 1 ? loaded[0] : loaded);
231
+ if (key === "data" && dom.isObject(formatterResponse)) {
232
+ data = formatterResponse.data || [];
233
+ delete formatterResponse.data;
234
+ this.config(formatterResponse);
235
+ } else data = formatterResponse || [];
236
+ } else if (key === "data") {
237
+ data = concat(loaded, "data");
238
+ }
239
+ if (key && `_${key}` in this) this[`_${key}`] = data;
240
+ if (callback) callback(err, data);
241
+ }
242
+ });
243
+ });
244
+ // If there is no data to Load response is immediately
245
+ if (toLoad.length === 0) {
246
+ loaded = loaded.map((data)=>{
247
+ if (data && !(data instanceof Array) && data.data && data.headers) data = fold(data);
248
+ return data;
249
+ });
250
+ // Format data
251
+ let data = loadedLength(loaded) === 1 ? loaded[0] : loaded;
252
+ if (formatter) {
253
+ const formatterResponse = formatter(loadedLength(loaded) === 1 ? loaded[0] : loaded);
254
+ if (key === "data" && dom.isObject(formatterResponse)) {
255
+ data = formatterResponse.data || [];
256
+ delete formatterResponse.data;
257
+ this.config(formatterResponse);
258
+ } else data = formatterResponse || [];
259
+ } else if (key === "data") {
260
+ data = concat(loaded, "data");
261
+ }
262
+ if (key && `_${key}` in this) this[`_${key}`] = data;
263
+ if (callback) callback(null, data);
264
+ }
265
+ }
266
+
267
+ /**
268
+ @function isData
269
+ @desc Adds the provided value to the internal queue to be loaded, if necessary. This is used internally in new d3plus visualizations that fold in additional data sources, like the nodes and links of Network or the topojson of Geomap.
270
+ @param {Array|String|Object} data The data to be loaded
271
+ @param {Function} [data] An optional data formatter/callback
272
+ @param {String} data The internal Viz method to be modified
273
+ */ function addToQueue(_, f, key) {
274
+ if (!(_ instanceof Array)) _ = [
275
+ _
276
+ ];
277
+ const needToLoad = _.find(isData);
278
+ if (needToLoad) {
279
+ const prev = this._queue.find((q)=>q[3] === key);
280
+ const d = [
281
+ load.bind(this),
282
+ _,
283
+ f,
284
+ key
285
+ ];
286
+ if (prev) this._queue[this._queue.indexOf(prev)] = d;
287
+ else this._queue.push(d);
288
+ } else {
289
+ this[`_${key}`] = _;
290
+ }
291
+ }
292
+
293
+ /**
294
+ @function unique
295
+ @desc ES5 implementation to reduce an Array of values to unique instances.
296
+ @param {Array} arr The Array of objects to be filtered.
297
+ @param {Function} [accessor] An optional accessor function used to extract data points from an Array of Objects.
298
+ @example <caption>this</caption>
299
+ unique(["apple", "banana", "apple"]);
300
+ @example <caption>returns this</caption>
301
+ ["apple", "banana"]
302
+ */ function unique(arr, accessor = (d)=>d) {
303
+ const values = arr.map(accessor).map((d)=>d instanceof Date ? +d : d);
304
+ return arr.filter((obj, i)=>{
305
+ const d = accessor(obj);
306
+ return values.indexOf(d instanceof Date ? +d : d) === i;
307
+ });
308
+ }
309
+
310
+ /**
311
+ @function merge
312
+ @desc Combines an Array of Objects together and returns a new Object.
313
+ @param {Array} objects The Array of objects to be merged together.
314
+ @param {Object} aggs An object containing specific aggregation methods (functions) for each key type. By default, numbers are summed and strings are returned as an array of unique values.
315
+ @example <caption>this</caption>
316
+ merge([
317
+ {id: "foo", group: "A", value: 10, links: [1, 2]},
318
+ {id: "bar", group: "A", value: 20, links: [1, 3]}
319
+ ]);
320
+ @example <caption>returns this</caption>
321
+ {id: ["bar", "foo"], group: "A", value: 30, links: [1, 2, 3]}
322
+ */ function objectMerge(objects, aggs = {}) {
323
+ const availableKeys = unique(d3Array.merge(objects.map((o)=>Object.keys(o)))), newObject = {};
324
+ availableKeys.forEach((k)=>{
325
+ let value;
326
+ if (aggs[k]) value = aggs[k](objects, (o)=>o[k]);
327
+ else {
328
+ const values = objects.map((o)=>o[k]);
329
+ const types = values.map((v)=>v || v === false ? v.constructor : v).filter((v)=>v !== void 0);
330
+ if (!types.length) value = undefined;
331
+ else if (types.indexOf(Array) >= 0) {
332
+ value = d3Array.merge(values.map((v)=>v instanceof Array ? v : [
333
+ v
334
+ ]));
335
+ value = unique(value);
336
+ if (value.length === 1) value = value[0];
337
+ } else if (types.indexOf(String) >= 0) {
338
+ value = unique(values);
339
+ if (value.length === 1) value = value[0];
340
+ } else if (types.indexOf(Number) >= 0) value = d3Array.sum(values);
341
+ else if (types.indexOf(Object) >= 0) {
342
+ value = unique(values.filter((v)=>v));
343
+ if (value.length === 1) value = value[0];
344
+ else value = objectMerge(value);
345
+ } else {
346
+ value = unique(values.filter((v)=>v !== void 0));
347
+ if (value.length === 1) value = value[0];
348
+ }
349
+ }
350
+ newObject[k] = value;
351
+ });
352
+ return newObject;
353
+ }
354
+
355
+ /**
356
+ @function nest
357
+ @summary Extends the base behavior of d3.nest to allow for multiple depth levels.
358
+ @param {Array} *data* The data array to be nested.
359
+ @param {Array} *keys* An array of key accessors that signify each nest level.
360
+ @private
361
+ */ function nest(data, keys) {
362
+ if (!(keys instanceof Array)) keys = [
363
+ keys
364
+ ];
365
+ const dataNest = d3Collection.nest();
366
+ for(let i = 0; i < keys.length; i++)dataNest.key(keys[i]);
367
+ const nestedData = dataNest.entries(data);
368
+ return bubble(nestedData);
369
+ }
370
+ /**
371
+ Bubbles up values that do not nest to the furthest key.
372
+ @param {Array} *values* The "values" of a nest object.
373
+ @private
374
+ */ function bubble(values) {
375
+ return values.map((d)=>{
376
+ if (d.key && d.values) {
377
+ if (d.values[0].key === "undefined") return d.values[0].values[0];
378
+ else d.values = bubble(d.values);
379
+ }
380
+ return d;
381
+ });
382
+ }
383
+
384
+ exports.addToQueue = addToQueue;
385
+ exports.concat = concat;
386
+ exports.fold = fold;
387
+ exports.isData = isData;
388
+ exports.load = load;
389
+ exports.merge = objectMerge;
390
+ exports.nest = nest;
391
+ exports.unique = unique;
392
+
393
+ }));
394
+ //# sourceMappingURL=d3plus-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d3plus-data.js","sources":["../src/isData.js","../src/fold.js","../src/concat.js","../src/load.js","../src/addToQueue.js","../src/unique.js","../src/merge.js","../src/nest.js"],"sourcesContent":["/**\n @function isData\n @desc Returns true/false whether the argument provided to the function should be loaded using an internal XHR request. Valid data can either be a string URL or an Object with \"url\" and \"headers\" keys.\n @param {*} dataItem The value to be tested\n*/\nexport default dataItem =>\n typeof dataItem === \"string\" ||\n typeof dataItem === \"object\" && dataItem.url && dataItem.headers;\n","/**\n @function dataFold\n @desc Given a JSON object where the data values and headers have been split into separate key lookups, this function will combine the data values with the headers and returns one large array of objects.\n @param {Object} json A JSON data Object with `data` and `headers` keys.\n @param {String} [data = \"data\"] The key used for the flat data array inside of the JSON object.\n @param {String} [headers = \"headers\"] The key used for the flat headers array inside of the JSON object.\n*/\nexport default (json, data = \"data\", headers = \"headers\") =>\n json[data].map(data =>\n json[headers].reduce((obj, header, i) =>\n (obj[header] = data[i], obj), {}));\n","/**\n @function dataConcat\n @desc Reduce and concat all the elements included in arrayOfArrays if they are arrays. If it is a JSON object try to concat the array under given key data. If the key doesn't exists in object item, a warning message is lauched to the console. You need to implement DataFormat callback to concat the arrays manually.\n @param {Array} arrayOfArray Array of elements\n @param {String} [data = \"data\"] The key used for the flat data array if exists inside of the JSON object.\n*/\nexport default (arrayOfArrays, data = \"data\") =>\n arrayOfArrays.reduce((acc, item) => {\n let dataArray = [];\n if (Array.isArray(item)) {\n dataArray = item;\n }\n else {\n if (item[data]) {\n dataArray = item[data];\n }\n // else {\n // console.warn(`d3plus-viz: Please implement a \"dataFormat\" callback to concat the arrays manually (consider using the d3plus.dataConcat method in your callback). Currently unable to concatenate (using key: \"${data}\") the following response:`, item);\n // }\n }\n return acc.concat(dataArray);\n }, []);\n\n","import {csv, json, text, tsv} from \"d3-request\";\nimport {isObject} from \"@d3plus/dom\";\n\nimport fold from \"./fold.js\";\nimport concat from \"./concat.js\";\nimport isData from \"./isData.js\";\n\n/**\n @function dataLoad\n @desc Loads data from a filepath or URL, converts it to a valid JSON object, and returns it to a callback function.\n @param {Array|String} path The path to the file or url to be loaded. Also support array of paths strings. If an Array of objects is passed, the xhr request logic is skipped.\n @param {Function} [formatter] An optional formatter function that is run on the loaded data.\n @param {String} [key] The key in the `this` context to save the resulting data to.\n @param {Function} [callback] A function that is called when the final data is loaded. It is passed 2 variables, any error present and the data loaded.\n*/\nexport default function(path, formatter, key, callback) {\n\n let parser;\n\n const getParser = path => {\n const ext = path.slice(path.length - 4);\n switch (ext) {\n case \".csv\":\n return csv;\n case \".tsv\":\n return tsv;\n case \".txt\":\n return text;\n default:\n return json;\n }\n };\n\n const validateData = (err, parser, data) => {\n if (parser !== json && !err && data && data instanceof Array) {\n data.forEach(d => {\n for (const k in d) {\n if (!isNaN(d[k])) d[k] = parseFloat(d[k]);\n else if (d[k].toLowerCase() === \"false\") d[k] = false;\n else if (d[k].toLowerCase() === \"true\") d[k] = true;\n else if (d[k].toLowerCase() === \"null\") d[k] = null;\n else if (d[k].toLowerCase() === \"undefined\") d[k] = undefined;\n }\n });\n }\n return data;\n };\n\n const loadedLength = loadedArray => loadedArray.reduce((prev, current) => current ? prev + 1 : prev, 0);\n\n const getPathIndex = (url, array) => array.indexOf(url);\n\n // If path param is a not an Array then convert path to a 1 element Array to re-use logic\n if (!(path instanceof Array)) path = [path];\n\n const needToLoad = path.find(isData);\n\n let loaded = new Array(path.length);\n const toLoad = [];\n\n // If there is a string I'm assuming is a Array to merge, urls or data\n if (needToLoad) {\n path.forEach((dataItem, ix) => {\n if (isData(dataItem)) toLoad.push(dataItem);\n else loaded[ix] = dataItem;\n });\n }\n // Data array itself\n else {\n loaded[0] = path;\n }\n\n // Load all urls an combine them with data arrays\n const alreadyLoaded = loadedLength(loaded);\n toLoad.forEach(dataItem => {\n let headers = {}, url = dataItem;\n if (typeof dataItem === \"object\") {\n url = dataItem.url;\n headers = dataItem.headers;\n }\n parser = getParser(url);\n const request = parser(url);\n for (const key in headers) {\n if ({}.hasOwnProperty.call(headers, key)) {\n request.header(key, headers[key]);\n }\n }\n request.get((err, data) => {\n data = err ? [] : data;\n if (data && !(data instanceof Array) && data.data && data.headers) data = fold(data);\n data = validateData(err, parser, data);\n loaded[getPathIndex(url, path)] = data;\n if (loadedLength(loaded) - alreadyLoaded === toLoad.length) { // All urls loaded\n\n // Format data\n data = loadedLength(loaded) === 1 ? loaded[0] : loaded;\n if (this._cache) this._lrucache.set(`${key}_${url}`, data);\n\n if (formatter) {\n const formatterResponse = formatter(loadedLength(loaded) === 1 ? loaded[0] : loaded);\n if (key === \"data\" && isObject(formatterResponse)) {\n data = formatterResponse.data || [];\n delete formatterResponse.data;\n this.config(formatterResponse);\n }\n else data = formatterResponse || [];\n }\n else if (key === \"data\") {\n data = concat(loaded, \"data\");\n }\n\n if (key && `_${key}` in this) this[`_${key}`] = data;\n if (callback) callback(err, data);\n }\n });\n });\n\n // If there is no data to Load response is immediately\n if (toLoad.length === 0) {\n loaded = loaded.map(data => {\n if (data && !(data instanceof Array) && data.data && data.headers) data = fold(data);\n return data;\n });\n\n // Format data\n let data = loadedLength(loaded) === 1 ? loaded[0] : loaded;\n if (formatter) {\n const formatterResponse = formatter(loadedLength(loaded) === 1 ? loaded[0] : loaded);\n if (key === \"data\" && isObject(formatterResponse)) {\n data = formatterResponse.data || [];\n delete formatterResponse.data;\n this.config(formatterResponse);\n }\n else data = formatterResponse || [];\n }\n else if (key === \"data\") {\n data = concat(loaded, \"data\");\n }\n\n if (key && `_${key}` in this) this[`_${key}`] = data;\n if (callback) callback(null, data);\n }\n\n}\n","import isData from \"./isData.js\";\nimport load from \"./load.js\";\n\n/**\n @function isData\n @desc Adds the provided value to the internal queue to be loaded, if necessary. This is used internally in new d3plus visualizations that fold in additional data sources, like the nodes and links of Network or the topojson of Geomap.\n @param {Array|String|Object} data The data to be loaded\n @param {Function} [data] An optional data formatter/callback\n @param {String} data The internal Viz method to be modified\n*/\nexport default function(_, f, key) {\n if (!(_ instanceof Array)) _ = [_];\n const needToLoad = _.find(isData);\n if (needToLoad) {\n const prev = this._queue.find(q => q[3] === key);\n const d = [load.bind(this), _, f, key];\n if (prev) this._queue[this._queue.indexOf(prev)] = d;\n else this._queue.push(d);\n }\n else {\n this[`_${key}`] = _;\n }\n}\n","/**\n @function unique\n @desc ES5 implementation to reduce an Array of values to unique instances.\n @param {Array} arr The Array of objects to be filtered.\n @param {Function} [accessor] An optional accessor function used to extract data points from an Array of Objects.\n @example <caption>this</caption>\nunique([\"apple\", \"banana\", \"apple\"]);\n @example <caption>returns this</caption>\n[\"apple\", \"banana\"]\n*/\nexport default function(arr, accessor = d => d) {\n\n const values = arr\n .map(accessor)\n .map(d => d instanceof Date ? +d : d);\n\n return arr.filter((obj, i) => {\n const d = accessor(obj);\n return values.indexOf(d instanceof Date ? +d : d) === i;\n });\n\n}\n","import {merge, sum} from \"d3-array\";\nimport unique from \"./unique.js\";\n\n/**\n @function merge\n @desc Combines an Array of Objects together and returns a new Object.\n @param {Array} objects The Array of objects to be merged together.\n @param {Object} aggs An object containing specific aggregation methods (functions) for each key type. By default, numbers are summed and strings are returned as an array of unique values.\n @example <caption>this</caption>\nmerge([\n {id: \"foo\", group: \"A\", value: 10, links: [1, 2]},\n {id: \"bar\", group: \"A\", value: 20, links: [1, 3]}\n]);\n @example <caption>returns this</caption>\n{id: [\"bar\", \"foo\"], group: \"A\", value: 30, links: [1, 2, 3]}\n*/\nfunction objectMerge(objects, aggs = {}) {\n\n const availableKeys = unique(merge(objects.map(o => Object.keys(o)))),\n newObject = {};\n\n availableKeys.forEach(k => {\n let value;\n if (aggs[k]) value = aggs[k](objects, o => o[k]);\n else {\n const values = objects.map(o => o[k]);\n const types = values.map(v => v || v === false ? v.constructor : v).filter(v => v !== void 0);\n if (!types.length) value = undefined;\n else if (types.indexOf(Array) >= 0) {\n value = merge(values.map(v => v instanceof Array ? v : [v]));\n value = unique(value);\n if (value.length === 1) value = value[0];\n }\n else if (types.indexOf(String) >= 0) {\n value = unique(values);\n if (value.length === 1) value = value[0];\n }\n else if (types.indexOf(Number) >= 0) value = sum(values);\n else if (types.indexOf(Object) >= 0) {\n value = unique(values.filter(v => v));\n if (value.length === 1) value = value[0];\n else value = objectMerge(value);\n\n }\n else {\n value = unique(values.filter(v => v !== void 0));\n if (value.length === 1) value = value[0];\n }\n }\n newObject[k] = value;\n });\n\n return newObject;\n\n}\n\nexport default objectMerge;\n","import {nest} from \"d3-collection\";\n\n/**\n @function nest\n @summary Extends the base behavior of d3.nest to allow for multiple depth levels.\n @param {Array} *data* The data array to be nested.\n @param {Array} *keys* An array of key accessors that signify each nest level.\n @private\n*/\nexport default function(data, keys) {\n\n if (!(keys instanceof Array)) keys = [keys];\n\n const dataNest = nest();\n for (let i = 0; i < keys.length; i++) dataNest.key(keys[i]);\n const nestedData = dataNest.entries(data);\n\n return bubble(nestedData);\n\n}\n\n/**\n Bubbles up values that do not nest to the furthest key.\n @param {Array} *values* The \"values\" of a nest object.\n @private\n*/\nfunction bubble(values) {\n\n return values.map(d => {\n\n if (d.key && d.values) {\n if (d.values[0].key === \"undefined\") return d.values[0].values[0];\n else d.values = bubble(d.values);\n }\n\n return d;\n\n });\n\n}\n"],"names":["dataItem","url","headers","json","data","map","reduce","obj","header","i","arrayOfArrays","acc","item","dataArray","Array","isArray","concat","path","formatter","key","callback","parser","getParser","ext","slice","length","csv","tsv","text","validateData","err","forEach","d","k","isNaN","parseFloat","toLowerCase","undefined","loadedLength","loadedArray","prev","current","getPathIndex","array","indexOf","needToLoad","find","isData","loaded","toLoad","ix","push","alreadyLoaded","request","hasOwnProperty","call","get","fold","_cache","_lrucache","set","formatterResponse","isObject","config","_","f","_queue","q","load","bind","arr","accessor","values","Date","filter","objectMerge","objects","aggs","availableKeys","unique","merge","o","Object","keys","newObject","value","types","v","constructor","String","Number","sum","dataNest","nest","nestedData","entries","bubble"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;EAIA,G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AEwC,MAAM,EAAE;EACrB,YAAA,IAAIxC,EAAEwC,MAAM,CAAC,CAAE,CAAA,CAACrD,GAAG,KAAK,WAAA,EAAa,OAAOa,CAAAA,CAAEwC,MAAM,CAAC,CAAA,CAAE,CAACA,MAAM,CAAC,CAAE,CAAA;EAC5DxC,iBAAAA,CAAAA,CAAEwC,MAAM,GAAGwB,MAAOhE,CAAAA,CAAAA,CAAEwC,MAAM,CAAA;EACjC;UAEA,OAAOxC,CAAAA;EAET,KAAA,CAAA;EAEF;;;;;;;;;;;;;;;"}
@@ -0,0 +1,81 @@
1
+ /*
2
+ @d3plus/data v3.0.0
3
+ JavaScript data loading, manipulation, and analysis functions.
4
+ Copyright (c) 2025 D3plus - https://d3plus.org
5
+ @license MIT
6
+ */
7
+ (e=>{"function"==typeof define&&define.amd?define(e):e()})(function(){if("undefined"!=typeof window){try{if("undefined"==typeof SVGElement||Boolean(SVGElement.prototype.innerHTML))return}catch(e){return}function r(e){switch(e.nodeType){case 1:var t=e,n="";return n+="<"+t.tagName,t.hasAttributes()&&[].forEach.call(t.attributes,function(e){n+=" "+e.name+'="'+e.value+'"'}),n+=">",t.hasChildNodes()&&[].forEach.call(t.childNodes,function(e){n+=r(e)}),n+="</"+t.tagName+">";case 3:return e.textContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");case 8:return"\x3c!--"+e.nodeValue+"--\x3e"}}Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t="";return[].forEach.call(this.childNodes,function(e){t+=r(e)}),t},set:function(e){for(;this.firstChild;)this.removeChild(this.firstChild);try{var t=new DOMParser,n=(t.async=!1,"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+e+"</svg>"),r=t.parseFromString(n,"text/xml").documentElement;[].forEach.call(r.childNodes,function(e){this.appendChild(this.ownerDocument.importNode(e,!0))}.bind(this))}catch(e){throw new Error("Error parsing markup string")}}}),Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(e){this.innerHTML=e}})}}),((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-request"),require("@d3plus/dom"),require("d3-array"),require("d3-collection")):"function"==typeof define&&define.amd?define("@d3plus/data",["exports","d3-request","@d3plus/dom","d3-array","d3-collection"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={},e.d3Request,e.dom,e.d3Array,e.d3Collection)})(this,function(e,m,y,d,r){
8
+ /**
9
+ @function isData
10
+ @desc Returns true/false whether the argument provided to the function should be loaded using an internal XHR request. Valid data can either be a string URL or an Object with "url" and "headers" keys.
11
+ @param {*} dataItem The value to be tested
12
+ */var a=e=>"string"==typeof e||"object"==typeof e&&e.url&&e.headers,g=(e,t="data",n="headers")=>e[t].map(r=>e[n].reduce((e,t,n)=>(e[t]=r[n],e),{})),v=(e,r="data")=>e.reduce((e,t)=>{let n=[];return Array.isArray(t)?n=t:t[r]&&(n=t[r]),e.concat(n)},[]);
13
+ /**
14
+ @function dataFold
15
+ @desc Given a JSON object where the data values and headers have been split into separate key lookups, this function will combine the data values with the headers and returns one large array of objects.
16
+ @param {Object} json A JSON data Object with `data` and `headers` keys.
17
+ @param {String} [data = "data"] The key used for the flat data array inside of the JSON object.
18
+ @param {String} [headers = "headers"] The key used for the flat headers array inside of the JSON object.
19
+ */
20
+ /**
21
+ @function dataLoad
22
+ @desc Loads data from a filepath or URL, converts it to a valid JSON object, and returns it to a callback function.
23
+ @param {Array|String} path The path to the file or url to be loaded. Also support array of paths strings. If an Array of objects is passed, the xhr request logic is skipped.
24
+ @param {Function} [formatter] An optional formatter function that is run on the loaded data.
25
+ @param {String} [key] The key in the `this` context to save the resulting data to.
26
+ @param {Function} [callback] A function that is called when the final data is loaded. It is passed 2 variables, any error present and the data loaded.
27
+ */function i(o,s,d,l){let u,c=e=>e.reduce((e,t)=>t?e+1:e,0);var t=(
28
+ // If path param is a not an Array then convert path to a 1 element Array to re-use logic
29
+ o=o instanceof Array?o:[o]).find(a);let f=new Array(o.length),h=[],p=(
30
+ // If there is a string I'm assuming is a Array to merge, urls or data
31
+ t?o.forEach((e,t)=>{a(e)?h.push(e):f[t]=e}):f[0]=o,c(f));
32
+ // If there is no data to Load response is immediately
33
+ if(h.forEach(e=>{let t={},i=e;"object"==typeof e&&(i=e.url,t=e.headers);var n=(u=(e=>{switch(e.slice(e.length-4)){case".csv":return m.csv;case".tsv":return m.tsv;case".txt":return m.text;default:return m.json}})(i))(i);for(let e in t)!{}.hasOwnProperty.call(t,e)||n.header(e,t[e]);n.get((e,t)=>{var n,r,a;(t=e?[]:t)&&!(t instanceof Array)&&t.data&&t.headers&&(t=g(t)),a=e,r=u,n=t,r!==m.json&&!a&&n&&n instanceof Array&&n.forEach(e=>{for(var t in e)isNaN(e[t])?"false"===e[t].toLowerCase()?e[t]=!1:"true"===e[t].toLowerCase()?e[t]=!0:"null"===e[t].toLowerCase()?e[t]=null:"undefined"===e[t].toLowerCase()&&(e[t]=void 0):e[t]=parseFloat(e[t])}),t=n,f[r=i,o.indexOf(r)]=t,c(f)-p===h.length&&(
34
+ // Format data
35
+ t=1===c(f)?f[0]:f,this._cache&&this._lrucache.set(d+"_"+i,t),s?(a=s(1===c(f)?f[0]:f),"data"===d&&y.isObject(a)?(t=a.data||[],delete a.data,this.config(a)):t=a||[]):"data"===d&&(t=v(f,"data")),d&&"_"+d in this&&(this["_"+d]=t),l)&&l(e,t)})}),0===h.length){f=f.map(e=>e=e&&!(e instanceof Array)&&e.data&&e.headers?g(e):e);
36
+ // Format data
37
+ let e=1===c(f)?f[0]:f;s?(t=s(1===c(f)?f[0]:f),"data"===d&&y.isObject(t)?(e=t.data||[],delete t.data,this.config(t)):e=t||[]):"data"===d&&(e=v(f,"data")),d&&"_"+d in this&&(this["_"+d]=e),l&&l(null,e)}}
38
+ /**
39
+ @function isData
40
+ @desc Adds the provided value to the internal queue to be loaded, if necessary. This is used internally in new d3plus visualizations that fold in additional data sources, like the nodes and links of Network or the topojson of Geomap.
41
+ @param {Array|String|Object} data The data to be loaded
42
+ @param {Function} [data] An optional data formatter/callback
43
+ @param {String} data The internal Viz method to be modified
44
+ */
45
+ /**
46
+ @function unique
47
+ @desc ES5 implementation to reduce an Array of values to unique instances.
48
+ @param {Array} arr The Array of objects to be filtered.
49
+ @param {Function} [accessor] An optional accessor function used to extract data points from an Array of Objects.
50
+ @example <caption>this</caption>
51
+ unique(["apple", "banana", "apple"]);
52
+ @example <caption>returns this</caption>
53
+ ["apple", "banana"]
54
+ */function l(e,n=e=>e){let r=e.map(n).map(e=>e instanceof Date?+e:e);return e.filter((e,t)=>{e=n(e);return r.indexOf(e instanceof Date?+e:e)===t})}
55
+ /**
56
+ @function merge
57
+ @desc Combines an Array of Objects together and returns a new Object.
58
+ @param {Array} objects The Array of objects to be merged together.
59
+ @param {Object} aggs An object containing specific aggregation methods (functions) for each key type. By default, numbers are summed and strings are returned as an array of unique values.
60
+ @example <caption>this</caption>
61
+ merge([
62
+ {id: "foo", group: "A", value: 10, links: [1, 2]},
63
+ {id: "bar", group: "A", value: 20, links: [1, 3]}
64
+ ]);
65
+ @example <caption>returns this</caption>
66
+ {id: ["bar", "foo"], group: "A", value: 30, links: [1, 2, 3]}
67
+ */e.addToQueue=function(e,t,n){var r;(e=e instanceof Array?e:[e]).find(a)?(r=this._queue.find(e=>e[3]===n),t=[i.bind(this),e,t,n],r?this._queue[this._queue.indexOf(r)]=t:this._queue.push(t)):this["_"+n]=e},e.concat=v,e.fold=g,e.isData=a,e.load=i,e.merge=function a(i,o={}){let e=l(d.merge(i.map(e=>Object.keys(e)))),s={};return e.forEach(t=>{let e;var n,r;o[t]?e=o[t](i,e=>e[t]):(r=(n=i.map(e=>e[t])).map(e=>e||!1===e?e.constructor:e).filter(e=>void 0!==e)).length?0<=r.indexOf(Array)?1===(e=l(e=d.merge(n.map(e=>e instanceof Array?e:[e])))).length&&(e=e[0]):0<=r.indexOf(String)?1===(e=l(n)).length&&(e=e[0]):0<=r.indexOf(Number)?e=d.sum(n):0<=r.indexOf(Object)?e=1===(e=l(n.filter(e=>e))).length?e[0]:a(e):1===(e=l(n.filter(e=>void 0!==e))).length&&(e=e[0]):e=void 0,s[t]=e}),s}
68
+ /**
69
+ @function nest
70
+ @summary Extends the base behavior of d3.nest to allow for multiple depth levels.
71
+ @param {Array} *data* The data array to be nested.
72
+ @param {Array} *keys* An array of key accessors that signify each nest level.
73
+ @private
74
+ */,e.nest=function(e,t){t instanceof Array||(t=[t]);var n=r.nest();for(let e=0;e<t.length;e++)n.key(t[e]);
75
+ /**
76
+ Bubbles up values that do not nest to the furthest key.
77
+ @param {Array} *values* The "values" of a nest object.
78
+ @private
79
+ */
80
+ return function t(e){return e.map(e=>{if(e.key&&e.values){if("undefined"===e.values[0].key)return e.values[0].values[0];e.values=t(e.values)}return e})}(n.entries(e))},e.unique=l});
81
+ //# sourceMappingURL=d3plus-data.js.map