@d3plus/data 3.0.12 → 3.0.13
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.
- package/es/src/addToQueue.js +3 -3
- package/es/src/isData.js +1 -1
- package/es/src/load.js +23 -28
- package/package.json +3 -3
- package/umd/d3plus-data.full.js +211 -422
- package/umd/d3plus-data.full.js.map +1 -1
- package/umd/d3plus-data.full.min.js +25 -44
- package/umd/d3plus-data.js +28 -34
- package/umd/d3plus-data.js.map +1 -1
- package/umd/d3plus-data.min.js +14 -12
package/umd/d3plus-data.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/data v3.0.
|
|
2
|
+
@d3plus/data v3.0.13
|
|
3
3
|
JavaScript data loading, manipulation, and analysis functions.
|
|
4
4
|
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -109,16 +109,16 @@
|
|
|
109
109
|
}));
|
|
110
110
|
|
|
111
111
|
(function (global, factory) {
|
|
112
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-
|
|
113
|
-
typeof define === 'function' && define.amd ? define('@d3plus/data', ['exports', 'd3-
|
|
114
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}, global.
|
|
115
|
-
})(this, (function (exports,
|
|
112
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-fetch'), require('@d3plus/dom'), require('d3-array'), require('d3-collection')) :
|
|
113
|
+
typeof define === 'function' && define.amd ? define('@d3plus/data', ['exports', 'd3-fetch', '@d3plus/dom', 'd3-array', 'd3-collection'], factory) :
|
|
114
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}, global.d3Fetch, global.dom, global.d3Array, global.d3Collection));
|
|
115
|
+
})(this, (function (exports, d3Fetch, dom, d3Array, d3Collection) { 'use strict';
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
@function isData
|
|
119
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
120
|
@param {*} dataItem The value to be tested
|
|
121
|
-
*/ var isData = ((dataItem)=>typeof dataItem === "string" || typeof dataItem === "object" && dataItem.url
|
|
121
|
+
*/ var isData = ((dataItem)=>typeof dataItem === "string" || typeof dataItem === "object" && dataItem.url);
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
@function dataFold
|
|
@@ -156,22 +156,21 @@
|
|
|
156
156
|
@param {String} [key] The key in the `this` context to save the resulting data to.
|
|
157
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
158
|
*/ function load(path, formatter, key, callback) {
|
|
159
|
-
|
|
160
|
-
const getParser = (path)=>{
|
|
159
|
+
const fetchData = (path, init = {})=>{
|
|
161
160
|
const ext = path.slice(path.length - 4);
|
|
162
161
|
switch(ext){
|
|
163
162
|
case ".csv":
|
|
164
|
-
return
|
|
163
|
+
return d3Fetch.csv(path, init);
|
|
165
164
|
case ".tsv":
|
|
166
|
-
return
|
|
165
|
+
return d3Fetch.tsv(path, init);
|
|
167
166
|
case ".txt":
|
|
168
|
-
return
|
|
167
|
+
return d3Fetch.text(path, init);
|
|
169
168
|
default:
|
|
170
|
-
return
|
|
169
|
+
return d3Fetch.json(path, init);
|
|
171
170
|
}
|
|
172
171
|
};
|
|
173
|
-
const validateData = (
|
|
174
|
-
if (
|
|
172
|
+
const validateData = (data)=>{
|
|
173
|
+
if (data && data instanceof Array) {
|
|
175
174
|
data.forEach((d)=>{
|
|
176
175
|
for(const k in d){
|
|
177
176
|
if (!isNaN(d[k])) d[k] = parseFloat(d[k]);
|
|
@@ -185,7 +184,6 @@
|
|
|
185
184
|
return data;
|
|
186
185
|
};
|
|
187
186
|
const loadedLength = (loadedArray)=>loadedArray.reduce((prev, current)=>current ? prev + 1 : prev, 0);
|
|
188
|
-
const getPathIndex = (url, array)=>array.indexOf(url);
|
|
189
187
|
// If path param is a not an Array then convert path to a 1 element Array to re-use logic
|
|
190
188
|
if (!(path instanceof Array)) path = [
|
|
191
189
|
path
|
|
@@ -205,23 +203,16 @@
|
|
|
205
203
|
// Load all urls an combine them with data arrays
|
|
206
204
|
const alreadyLoaded = loadedLength(loaded);
|
|
207
205
|
toLoad.forEach((dataItem)=>{
|
|
208
|
-
let
|
|
209
|
-
if (typeof dataItem === "object") {
|
|
206
|
+
let url = dataItem, init = {};
|
|
207
|
+
if (typeof dataItem === "object" && dataItem.url) {
|
|
210
208
|
url = dataItem.url;
|
|
211
|
-
|
|
209
|
+
init = dataItem;
|
|
212
210
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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;
|
|
211
|
+
fetchData(url, init).then((data)=>{
|
|
212
|
+
if (!(data instanceof Array) && data.data && data.headers) data = fold(data);
|
|
213
|
+
data = validateData(data);
|
|
214
|
+
loaded[path.findIndex((d)=>JSON.stringify(d) == JSON.stringify(dataItem))] = data;
|
|
215
|
+
// All urls loaded
|
|
225
216
|
if (loadedLength(loaded) - alreadyLoaded === toLoad.length) {
|
|
226
217
|
// Format data
|
|
227
218
|
data = loadedLength(loaded) === 1 ? loaded[0] : loaded;
|
|
@@ -237,8 +228,11 @@
|
|
|
237
228
|
data = concat(loaded, "data");
|
|
238
229
|
}
|
|
239
230
|
if (key && `_${key}` in this) this[`_${key}`] = data;
|
|
240
|
-
if (callback) callback(
|
|
231
|
+
if (callback) callback(undefined, data);
|
|
241
232
|
}
|
|
233
|
+
}).catch((err)=>{
|
|
234
|
+
console.log(err);
|
|
235
|
+
if (callback) callback(err, undefined);
|
|
242
236
|
});
|
|
243
237
|
});
|
|
244
238
|
// If there is no data to Load response is immediately
|
|
@@ -271,15 +265,15 @@
|
|
|
271
265
|
@param {Function} [data] An optional data formatter/callback
|
|
272
266
|
@param {String} data The internal Viz method to be modified
|
|
273
267
|
*/ function addToQueue(_, f, key) {
|
|
274
|
-
|
|
268
|
+
const paths = _ instanceof Array ? _ : [
|
|
275
269
|
_
|
|
276
270
|
];
|
|
277
|
-
const needToLoad =
|
|
271
|
+
const needToLoad = paths.find(isData);
|
|
278
272
|
if (needToLoad) {
|
|
279
273
|
const prev = this._queue.find((q)=>q[3] === key);
|
|
280
274
|
const d = [
|
|
281
275
|
load.bind(this),
|
|
282
|
-
|
|
276
|
+
paths,
|
|
283
277
|
f,
|
|
284
278
|
key
|
|
285
279
|
];
|
package/umd/d3plus-data.js.map
CHANGED
|
@@ -1 +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,GACA,aAAeA,CAAAA,CAAAA,QACb,GAAA,OAAOA,aAAa,QACpB,IAAA,OAAOA,QAAa,KAAA,QAAA,IAAYA,SAASC,GAAG,IAAID,QAASE,CAAAA,OAAO;;ECPlE;;;;;;EAMA,GACA,WAAe,CAAA,CAACC,MAAMC,IAAO,GAAA,MAAM,EAAEF,OAAU,GAAA,SAAS,GACtDC,IAAI,CAACC,IAAK,CAAA,CAACC,GAAG,CAACD,CAAAA,OACbD,IAAI,CAACD,OAAQ,CAAA,CAACI,MAAM,CAAC,CAACC,KAAKC,MAAQC,EAAAA,CAAAA,IAChCF,GAAG,CAACC,OAAO,GAAGJ,IAAI,CAACK,CAAE,CAAA,EAAEF,GAAE,CAAI,EAAA,IAAG;;ECVvC;;;;;EAKA,GACA,aAAe,CAAA,CAACG,aAAeN,EAAAA,IAAAA,GAAO,MAAM,GAC1CM,aAAcJ,CAAAA,MAAM,CAAC,CAACK,GAAK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AAI,EAAE+E,IAAI,EAAA;EAEhC,IAAA,IAAI,EAAEA,IAAgBrE,YAAAA,KAAI,GAAIqE,IAAO,GAAA;EAACA,QAAAA;EAAK,KAAA;EAE3C,IAAA,MAAMS,QAAWC,GAAAA,iBAAAA,EAAAA;EACjB,IAAA,IAAK,IAAIpF,CAAAA,GAAI,CAAGA,EAAAA,CAAAA,GAAI0E,IAAK1D,CAAAA,MAAM,EAAEhB,CAAAA,EAAAA,CAAKmF,QAASzE,CAAAA,GAAG,CAACgE,IAAI,CAAC1E,CAAE,CAAA,CAAA;MAC1D,MAAMqF,UAAAA,GAAaF,QAASG,CAAAA,OAAO,CAAC3F,IAAAA,CAAAA;EAEpC,IAAA,OAAO4F,MAAOF,CAAAA,UAAAA,CAAAA;EAEhB;EAEA;;;;EAIA,GACA,SAASE,OAAOxB,MAAM,EAAA;MAEpB,OAAOA,MAAAA,CAAOnE,GAAG,CAAC2B,CAAAA,CAAAA,GAAAA;EAEhB,QAAA,IAAIA,CAAEb,CAAAA,GAAG,IAAIa,CAAAA,CAAEwC,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;;;;;;;;;;;;;;;"}
|
|
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);\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-fetch\";\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 const fetchData = (path, init = {}) => {\n const ext = path.slice(path.length - 4);\n switch (ext) {\n case \".csv\":\n return csv(path, init);\n case \".tsv\":\n return tsv(path, init);\n case \".txt\":\n return text(path, init);\n default:\n return json(path, init);\n }\n };\n\n const validateData = data => {\n if (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 =>\n loadedArray.reduce((prev, current) => (current ? prev + 1 : prev), 0);\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 url = dataItem,\n init = {};\n if (typeof dataItem === \"object\" && dataItem.url) {\n url = dataItem.url;\n init = dataItem;\n }\n fetchData(url, init)\n .then(data => {\n if (!(data instanceof Array) && data.data && data.headers)\n data = fold(data);\n data = validateData(data);\n loaded[\n path.findIndex(d => JSON.stringify(d) == JSON.stringify(dataItem))\n ] = data;\n // All urls loaded\n if (loadedLength(loaded) - alreadyLoaded === toLoad.length) {\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(\n loadedLength(loaded) === 1 ? loaded[0] : loaded\n );\n if (key === \"data\" && isObject(formatterResponse)) {\n data = formatterResponse.data || [];\n delete formatterResponse.data;\n this.config(formatterResponse);\n } else data = formatterResponse || [];\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(undefined, data);\n }\n })\n .catch(err => {\n console.log(err);\n if (callback) callback(err, undefined);\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)\n 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(\n loadedLength(loaded) === 1 ? loaded[0] : loaded\n );\n if (key === \"data\" && isObject(formatterResponse)) {\n data = formatterResponse.data || [];\n delete formatterResponse.data;\n this.config(formatterResponse);\n } else data = formatterResponse || [];\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","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 const paths = _ instanceof Array ? _ : [_];\n const needToLoad = paths.find(isData);\n if (needToLoad) {\n const prev = this._queue.find(q => q[3] === key);\n const d = [load.bind(this), paths, f, key];\n if (prev) this._queue[this._queue.indexOf(prev)] = d;\n else this._queue.push(d);\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","json","data","headers","map","reduce","obj","header","i","arrayOfArrays","acc","item","dataArray","Array","isArray","concat","path","formatter","key","callback","fetchData","init","ext","slice","length","csv","tsv","text","validateData","forEach","d","k","isNaN","parseFloat","toLowerCase","undefined","loadedLength","loadedArray","prev","current","needToLoad","find","isData","loaded","toLoad","ix","push","alreadyLoaded","then","fold","findIndex","JSON","stringify","_cache","_lrucache","set","formatterResponse","isObject","config","catch","err","console","log","_","f","paths","_queue","q","load","bind","indexOf","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,GACA,aAAeA,CAAAA,CAAAA,QAAAA,GACb,OAAOA,QAAAA,KAAa,QACnB,IAAA,OAAOA,QAAa,KAAA,QAAA,IAAYA,QAASC,CAAAA,GAAG;;ECP/C;;;;;;EAMA,GACA,WAAe,CAAA,CAACC,MAAMC,IAAO,GAAA,MAAM,EAAEC,OAAU,GA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/umd/d3plus-data.min.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/data v3.0.
|
|
2
|
+
@d3plus/data v3.0.13
|
|
3
3
|
JavaScript data loading, manipulation, and analysis functions.
|
|
4
4
|
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
6
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,"&").replace(/</g,"<").replace(/>/g,">");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-
|
|
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,"&").replace(/</g,"<").replace(/>/g,">");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-fetch"),require("@d3plus/dom"),require("d3-array"),require("d3-collection")):"function"==typeof define&&define.amd?define("@d3plus/data",["exports","d3-fetch","@d3plus/dom","d3-array","d3-collection"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={},e.d3Fetch,e.dom,e.d3Array,e.d3Collection)})(this,function(e,f,h,d,r){
|
|
8
8
|
/**
|
|
9
9
|
@function isData
|
|
10
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
11
|
@param {*} dataItem The value to be tested
|
|
12
|
-
*/var
|
|
12
|
+
*/var p=e=>"string"==typeof e||"object"==typeof e&&e.url,y=(e,t="data",n="headers")=>e[t].map(r=>e[n].reduce((e,t,n)=>(e[t]=r[n],e),{})),g=(e,r="data")=>e.reduce((e,t)=>{let n=[];return Array.isArray(t)?n=t:t[r]&&(n=t[r]),e.concat(n)},[]);
|
|
13
13
|
/**
|
|
14
14
|
@function dataFold
|
|
15
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.
|
|
@@ -24,17 +24,19 @@
|
|
|
24
24
|
@param {Function} [formatter] An optional formatter function that is run on the loaded data.
|
|
25
25
|
@param {String} [key] The key in the `this` context to save the resulting data to.
|
|
26
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
|
|
27
|
+
*/function i(a,i,o,s){let d=e=>e.reduce((e,t)=>t?e+1:e,0);var t=(
|
|
28
28
|
// If path param is a not an Array then convert path to a 1 element Array to re-use logic
|
|
29
|
-
|
|
29
|
+
a=a instanceof Array?a:[a]).find(p);let c=new Array(a.length),l=[],u=(
|
|
30
30
|
// If there is a string I'm assuming is a Array to merge, urls or data
|
|
31
|
-
t?
|
|
31
|
+
t?a.forEach((e,t)=>{p(e)?l.push(e):c[t]=e}):c[0]=a,d(c));
|
|
32
32
|
// If there is no data to Load response is immediately
|
|
33
|
-
if(
|
|
33
|
+
if(l.forEach(n=>{let r=n,e={};"object"==typeof n&&n.url&&(r=n.url,e=n),((e,t={})=>{switch(e.slice(e.length-4)){case".csv":return f.csv(e,t);case".tsv":return f.tsv(e,t);case".txt":return f.text(e,t);default:return f.json(e,t)}})(r,e).then(e=>{var t;e instanceof Array||!e.data||!e.headers||(e=y(e)),(t=e)&&t instanceof Array&&t.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])}),e=t,c[a.findIndex(e=>JSON.stringify(e)==JSON.stringify(n))]=e,
|
|
34
|
+
// All urls loaded
|
|
35
|
+
d(c)-u===l.length&&(
|
|
34
36
|
// Format data
|
|
35
|
-
|
|
37
|
+
e=1===d(c)?c[0]:c,this._cache&&this._lrucache.set(o+"_"+r,e),i?(t=i(1===d(c)?c[0]:c),"data"===o&&h.isObject(t)?(e=t.data||[],delete t.data,this.config(t)):e=t||[]):"data"===o&&(e=g(c,"data")),o&&"_"+o in this&&(this["_"+o]=e),s)&&s(void 0,e)}).catch(e=>{console.log(e),s&&s(e,void 0)})}),0===l.length){c=c.map(e=>e=e&&!(e instanceof Array)&&e.data&&e.headers?y(e):e);
|
|
36
38
|
// Format data
|
|
37
|
-
let e=1===c
|
|
39
|
+
let e=1===d(c)?c[0]:c;i?(t=i(1===d(c)?c[0]:c),"data"===o&&h.isObject(t)?(e=t.data||[],delete t.data,this.config(t)):e=t||[]):"data"===o&&(e=g(c,"data")),o&&"_"+o in this&&(this["_"+o]=e),s&&s(null,e)}}
|
|
38
40
|
/**
|
|
39
41
|
@function isData
|
|
40
42
|
@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.
|
|
@@ -51,7 +53,7 @@ let e=1===c(f)?f[0]:f;s?(t=s(1===c(f)?f[0]:f),"data"===d&&y.isObject(t)?(e=t.dat
|
|
|
51
53
|
unique(["apple", "banana", "apple"]);
|
|
52
54
|
@example <caption>returns this</caption>
|
|
53
55
|
["apple", "banana"]
|
|
54
|
-
*/function
|
|
56
|
+
*/function c(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
57
|
/**
|
|
56
58
|
@function merge
|
|
57
59
|
@desc Combines an Array of Objects together and returns a new Object.
|
|
@@ -64,7 +66,7 @@ let e=1===c(f)?f[0]:f;s?(t=s(1===c(f)?f[0]:f),"data"===d&&y.isObject(t)?(e=t.dat
|
|
|
64
66
|
]);
|
|
65
67
|
@example <caption>returns this</caption>
|
|
66
68
|
{id: ["bar", "foo"], group: "A", value: 30, links: [1, 2, 3]}
|
|
67
|
-
*/e.addToQueue=function(e,t,n){var r
|
|
69
|
+
*/e.addToQueue=function(e,t,n){var r,a=e instanceof Array?e:[e];a.find(p)?(r=this._queue.find(e=>e[3]===n),a=[i.bind(this),a,t,n],r?this._queue[this._queue.indexOf(r)]=a:this._queue.push(a)):this["_"+n]=e},e.concat=g,e.fold=y,e.isData=p,e.load=i,e.merge=function a(i,o={}){let e=c(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=c(e=d.merge(n.map(e=>e instanceof Array?e:[e])))).length&&(e=e[0]):0<=r.indexOf(String)?1===(e=c(n)).length&&(e=e[0]):0<=r.indexOf(Number)?e=d.sum(n):0<=r.indexOf(Object)?e=1===(e=c(n.filter(e=>e))).length?e[0]:a(e):1===(e=c(n.filter(e=>void 0!==e))).length&&(e=e[0]):e=void 0,s[t]=e}),s}
|
|
68
70
|
/**
|
|
69
71
|
@function nest
|
|
70
72
|
@summary Extends the base behavior of d3.nest to allow for multiple depth levels.
|
|
@@ -77,5 +79,5 @@ let e=1===c(f)?f[0]:f;s?(t=s(1===c(f)?f[0]:f),"data"===d&&y.isObject(t)?(e=t.dat
|
|
|
77
79
|
@param {Array} *values* The "values" of a nest object.
|
|
78
80
|
@private
|
|
79
81
|
*/
|
|
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=
|
|
82
|
+
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=c});
|
|
81
83
|
//# sourceMappingURL=d3plus-data.js.map
|