@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/es/src/addToQueue.js
CHANGED
|
@@ -14,17 +14,17 @@ import load from "./load.js";
|
|
|
14
14
|
@param {Function} [data] An optional data formatter/callback
|
|
15
15
|
@param {String} data The internal Viz method to be modified
|
|
16
16
|
*/ export default function(_, f, key) {
|
|
17
|
-
|
|
17
|
+
var paths = _instanceof(_, Array) ? _ : [
|
|
18
18
|
_
|
|
19
19
|
];
|
|
20
|
-
var needToLoad =
|
|
20
|
+
var needToLoad = paths.find(isData);
|
|
21
21
|
if (needToLoad) {
|
|
22
22
|
var prev = this._queue.find(function(q) {
|
|
23
23
|
return q[3] === key;
|
|
24
24
|
});
|
|
25
25
|
var d = [
|
|
26
26
|
load.bind(this),
|
|
27
|
-
|
|
27
|
+
paths,
|
|
28
28
|
f,
|
|
29
29
|
key
|
|
30
30
|
];
|
package/es/src/isData.js
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
8
8
|
}
|
|
9
9
|
export default function(dataItem) {
|
|
10
|
-
return typeof dataItem === "string" || (typeof dataItem === "undefined" ? "undefined" : _type_of(dataItem)) === "object" && dataItem.url
|
|
10
|
+
return typeof dataItem === "string" || (typeof dataItem === "undefined" ? "undefined" : _type_of(dataItem)) === "object" && dataItem.url;
|
|
11
11
|
};
|
package/es/src/load.js
CHANGED
|
@@ -9,7 +9,7 @@ function _type_of(obj) {
|
|
|
9
9
|
"@swc/helpers - typeof";
|
|
10
10
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
11
11
|
}
|
|
12
|
-
import { csv, json, text, tsv } from "d3-
|
|
12
|
+
import { csv, json, text, tsv } from "d3-fetch";
|
|
13
13
|
import { isObject } from "@d3plus/dom";
|
|
14
14
|
import fold from "./fold.js";
|
|
15
15
|
import concat from "./concat.js";
|
|
@@ -23,22 +23,22 @@ import isData from "./isData.js";
|
|
|
23
23
|
@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.
|
|
24
24
|
*/ export default function(path, formatter, key, callback) {
|
|
25
25
|
var _this = this;
|
|
26
|
-
var
|
|
27
|
-
|
|
26
|
+
var fetchData = function(path) {
|
|
27
|
+
var init = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
28
28
|
var ext = path.slice(path.length - 4);
|
|
29
29
|
switch(ext){
|
|
30
30
|
case ".csv":
|
|
31
|
-
return csv;
|
|
31
|
+
return csv(path, init);
|
|
32
32
|
case ".tsv":
|
|
33
|
-
return tsv;
|
|
33
|
+
return tsv(path, init);
|
|
34
34
|
case ".txt":
|
|
35
|
-
return text;
|
|
35
|
+
return text(path, init);
|
|
36
36
|
default:
|
|
37
|
-
return json;
|
|
37
|
+
return json(path, init);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
var validateData = function(
|
|
41
|
-
if (
|
|
40
|
+
var validateData = function(data) {
|
|
41
|
+
if (data && _instanceof(data, Array)) {
|
|
42
42
|
data.forEach(function(d) {
|
|
43
43
|
for(var k in d){
|
|
44
44
|
if (!isNaN(d[k])) d[k] = parseFloat(d[k]);
|
|
@@ -56,9 +56,6 @@ import isData from "./isData.js";
|
|
|
56
56
|
return current ? prev + 1 : prev;
|
|
57
57
|
}, 0);
|
|
58
58
|
};
|
|
59
|
-
var getPathIndex = function(url, array) {
|
|
60
|
-
return array.indexOf(url);
|
|
61
|
-
};
|
|
62
59
|
// If path param is a not an Array then convert path to a 1 element Array to re-use logic
|
|
63
60
|
if (!_instanceof(path, Array)) path = [
|
|
64
61
|
path
|
|
@@ -78,23 +75,18 @@ import isData from "./isData.js";
|
|
|
78
75
|
// Load all urls an combine them with data arrays
|
|
79
76
|
var alreadyLoaded = loadedLength(loaded);
|
|
80
77
|
toLoad.forEach(function(dataItem) {
|
|
81
|
-
var
|
|
82
|
-
if ((typeof dataItem === "undefined" ? "undefined" : _type_of(dataItem)) === "object") {
|
|
78
|
+
var url = dataItem, init = {};
|
|
79
|
+
if ((typeof dataItem === "undefined" ? "undefined" : _type_of(dataItem)) === "object" && dataItem.url) {
|
|
83
80
|
url = dataItem.url;
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
parser = getParser(url);
|
|
87
|
-
var request = parser(url);
|
|
88
|
-
for(var _$key in headers){
|
|
89
|
-
if (({}).hasOwnProperty.call(headers, _$key)) {
|
|
90
|
-
request.header(_$key, headers[_$key]);
|
|
91
|
-
}
|
|
81
|
+
init = dataItem;
|
|
92
82
|
}
|
|
93
|
-
|
|
94
|
-
data
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
fetchData(url, init).then(function(data) {
|
|
84
|
+
if (!_instanceof(data, Array) && data.data && data.headers) data = fold(data);
|
|
85
|
+
data = validateData(data);
|
|
86
|
+
loaded[path.findIndex(function(d) {
|
|
87
|
+
return JSON.stringify(d) == JSON.stringify(dataItem);
|
|
88
|
+
})] = data;
|
|
89
|
+
// All urls loaded
|
|
98
90
|
if (loadedLength(loaded) - alreadyLoaded === toLoad.length) {
|
|
99
91
|
// Format data
|
|
100
92
|
data = loadedLength(loaded) === 1 ? loaded[0] : loaded;
|
|
@@ -110,8 +102,11 @@ import isData from "./isData.js";
|
|
|
110
102
|
data = concat(loaded, "data");
|
|
111
103
|
}
|
|
112
104
|
if (key && "_".concat(key) in _this) _this["_".concat(key)] = data;
|
|
113
|
-
if (callback) callback(
|
|
105
|
+
if (callback) callback(undefined, data);
|
|
114
106
|
}
|
|
107
|
+
}).catch(function(err) {
|
|
108
|
+
console.log(err);
|
|
109
|
+
if (callback) callback(err, undefined);
|
|
115
110
|
});
|
|
116
111
|
});
|
|
117
112
|
// If there is no data to Load response is immediately
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3plus/data",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
4
4
|
"description": "JavaScript data loading, manipulation, and analysis functions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"test": "eslint index.js src/**/*.js && eslint --global=it test && mocha 'test/**/*-test.js'"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@d3plus/dom": "3.0.
|
|
37
|
+
"@d3plus/dom": "3.0.13",
|
|
38
38
|
"d3-array": "^3.2.4",
|
|
39
39
|
"d3-collection": "^1.0.7",
|
|
40
|
-
"d3-
|
|
40
|
+
"d3-fetch": "^3.0.1"
|
|
41
41
|
}
|
|
42
42
|
}
|