d3-scatterplot-utils.js
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function D3ScatterPlotUtils(){}
// usage example deepExtend({}, objA, objB); => should work similar to $.extend(true, {}, objA, objB);
D3ScatterPlotUtils.prototype.deepExtend = function (out) {
var utils = this;
var emptyOut = {};
if (!out && arguments.length > 1 && Array.isArray(arguments[1])) {
out = [];
}
out = out || {};
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
if (!source)
continue;
for (var key in source) {
if (!source.hasOwnProperty(key)) {
continue;
}
var isArray = Array.isArray(out[key]);
var isObject = utils.isObject(out[key]);
var srcObj = utils.isObject(source[key]);
if (isObject && !isArray && srcObj) {
utils.deepExtend(out[key], source[key]);
} else {
out[key] = source[key];
}
}
}
return out;
};
D3ScatterPlotUtils.prototype.isObject = function(a) {
return a !== null && typeof a === 'object';
};
D3ScatterPlotUtils.prototype.isNumber = function(a) {
return !isNaN(a) && typeof a === 'number';
};
D3ScatterPlotUtils.prototype.isFunction = function(a) {
return typeof a === 'function';
};