first commit

This commit is contained in:
jefferyzhao
2025-07-31 17:44:12 +08:00
commit b9bdc8598b
42390 changed files with 4467935 additions and 0 deletions

161
node_modules/echarts/lib/data/DataDiffer.js generated vendored Normal file
View File

@ -0,0 +1,161 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
function defaultKeyGetter(item) {
return item;
}
/**
* @param {Array} oldArr
* @param {Array} newArr
* @param {Function} oldKeyGetter
* @param {Function} newKeyGetter
* @param {Object} [context] Can be visited by this.context in callback.
*/
function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
this._old = oldArr;
this._new = newArr;
this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
this._newKeyGetter = newKeyGetter || defaultKeyGetter;
this.context = context;
}
DataDiffer.prototype = {
constructor: DataDiffer,
/**
* Callback function when add a data
*/
add: function (func) {
this._add = func;
return this;
},
/**
* Callback function when update a data
*/
update: function (func) {
this._update = func;
return this;
},
/**
* Callback function when remove a data
*/
remove: function (func) {
this._remove = func;
return this;
},
execute: function () {
var oldArr = this._old;
var newArr = this._new;
var oldDataIndexMap = {};
var newDataIndexMap = {};
var oldDataKeyArr = [];
var newDataKeyArr = [];
var i;
initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
for (i = 0; i < oldArr.length; i++) {
var key = oldDataKeyArr[i];
var idx = newDataIndexMap[key]; // idx can never be empty array here. see 'set null' logic below.
if (idx != null) {
// Consider there is duplicate key (for example, use dataItem.name as key).
// We should make sure every item in newArr and oldArr can be visited.
var len = idx.length;
if (len) {
len === 1 && (newDataIndexMap[key] = null);
idx = idx.shift();
} else {
newDataIndexMap[key] = null;
}
this._update && this._update(idx, i);
} else {
this._remove && this._remove(i);
}
}
for (var i = 0; i < newDataKeyArr.length; i++) {
var key = newDataKeyArr[i];
if (newDataIndexMap.hasOwnProperty(key)) {
var idx = newDataIndexMap[key];
if (idx == null) {
continue;
} // idx can never be empty array here. see 'set null' logic above.
if (!idx.length) {
this._add && this._add(idx);
} else {
for (var j = 0, len = idx.length; j < len; j++) {
this._add && this._add(idx[j]);
}
}
}
}
}
};
function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
for (var i = 0; i < arr.length; i++) {
// Add prefix to avoid conflict with Object.prototype.
var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
var existence = map[key];
if (existence == null) {
keyArr.push(key);
map[key] = i;
} else {
if (!existence.length) {
map[key] = existence = [existence];
}
existence.push(i);
}
}
}
var _default = DataDiffer;
module.exports = _default;

157
node_modules/echarts/lib/data/DataDimensionInfo.js generated vendored Normal file
View File

@ -0,0 +1,157 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @class
* @param {Object|DataDimensionInfo} [opt] All of the fields will be shallow copied.
*/
function DataDimensionInfo(opt) {
if (opt != null) {
zrUtil.extend(this, opt);
}
/**
* Dimension name.
* Mandatory.
* @type {string}
*/
// this.name;
/**
* The origin name in dimsDef, see source helper.
* If displayName given, the tooltip will displayed vertically.
* Optional.
* @type {string}
*/
// this.displayName;
/**
* Which coordSys dimension this dimension mapped to.
* A `coordDim` can be a "coordSysDim" that the coordSys required
* (for example, an item in `coordSysDims` of `model/referHelper#CoordSysInfo`),
* or an generated "extra coord name" if does not mapped to any "coordSysDim"
* (That is determined by whether `isExtraCoord` is `true`).
* Mandatory.
* @type {string}
*/
// this.coordDim;
/**
* The index of this dimension in `series.encode[coordDim]`.
* Mandatory.
* @type {number}
*/
// this.coordDimIndex;
/**
* Dimension type. The enumerable values are the key of
* `dataCtors` of `data/List`.
* Optional.
* @type {string}
*/
// this.type;
/**
* This index of this dimension info in `data/List#_dimensionInfos`.
* Mandatory after added to `data/List`.
* @type {number}
*/
// this.index;
/**
* The format of `otherDims` is:
* ```js
* {
* tooltip: number optional,
* label: number optional,
* itemName: number optional,
* seriesName: number optional,
* }
* ```
*
* A `series.encode` can specified these fields:
* ```js
* encode: {
* // "3, 1, 5" is the index of data dimension.
* tooltip: [3, 1, 5],
* label: [0, 3],
* ...
* }
* ```
* `otherDims` is the parse result of the `series.encode` above, like:
* ```js
* // Suppose the index of this data dimension is `3`.
* this.otherDims = {
* // `3` is at the index `0` of the `encode.tooltip`
* tooltip: 0,
* // `3` is at the index `1` of the `encode.tooltip`
* label: 1
* };
* ```
*
* This prop should never be `null`/`undefined` after initialized.
* @type {Object}
*/
this.otherDims = {};
/**
* Be `true` if this dimension is not mapped to any "coordSysDim" that the
* "coordSys" required.
* Mandatory.
* @type {boolean}
*/
// this.isExtraCoord;
/**
* @type {module:data/OrdinalMeta}
*/
// this.ordinalMeta;
/**
* Whether to create inverted indices.
* @type {boolean}
*/
// this.createInvertedIndices;
}
;
var _default = DataDimensionInfo;
module.exports = _default;

566
node_modules/echarts/lib/data/Graph.js generated vendored Normal file
View File

@ -0,0 +1,566 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _config = require("../config");
var __DEV__ = _config.__DEV__;
var zrUtil = require("zrender/lib/core/util");
var _clazz = require("../util/clazz");
var enableClassCheck = _clazz.enableClassCheck;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// id may be function name of Object, add a prefix to avoid this problem.
function generateNodeKey(id) {
return '_EC_' + id;
}
/**
* @alias module:echarts/data/Graph
* @constructor
* @param {boolean} directed
*/
var Graph = function (directed) {
/**
* 是否是有向图
* @type {boolean}
* @private
*/
this._directed = directed || false;
/**
* @type {Array.<module:echarts/data/Graph.Node>}
* @readOnly
*/
this.nodes = [];
/**
* @type {Array.<module:echarts/data/Graph.Edge>}
* @readOnly
*/
this.edges = [];
/**
* @type {Object.<string, module:echarts/data/Graph.Node>}
* @private
*/
this._nodesMap = {};
/**
* @type {Object.<string, module:echarts/data/Graph.Edge>}
* @private
*/
this._edgesMap = {};
/**
* @type {module:echarts/data/List}
* @readOnly
*/
this.data;
/**
* @type {module:echarts/data/List}
* @readOnly
*/
this.edgeData;
};
var graphProto = Graph.prototype;
/**
* @type {string}
*/
graphProto.type = 'graph';
/**
* If is directed graph
* @return {boolean}
*/
graphProto.isDirected = function () {
return this._directed;
};
/**
* Add a new node
* @param {string} id
* @param {number} [dataIndex]
*/
graphProto.addNode = function (id, dataIndex) {
id = id == null ? '' + dataIndex : '' + id;
var nodesMap = this._nodesMap;
if (nodesMap[generateNodeKey(id)]) {
return;
}
var node = new Node(id, dataIndex);
node.hostGraph = this;
this.nodes.push(node);
nodesMap[generateNodeKey(id)] = node;
return node;
};
/**
* Get node by data index
* @param {number} dataIndex
* @return {module:echarts/data/Graph~Node}
*/
graphProto.getNodeByIndex = function (dataIndex) {
var rawIdx = this.data.getRawIndex(dataIndex);
return this.nodes[rawIdx];
};
/**
* Get node by id
* @param {string} id
* @return {module:echarts/data/Graph.Node}
*/
graphProto.getNodeById = function (id) {
return this._nodesMap[generateNodeKey(id)];
};
/**
* Add a new edge
* @param {number|string|module:echarts/data/Graph.Node} n1
* @param {number|string|module:echarts/data/Graph.Node} n2
* @param {number} [dataIndex=-1]
* @return {module:echarts/data/Graph.Edge}
*/
graphProto.addEdge = function (n1, n2, dataIndex) {
var nodesMap = this._nodesMap;
var edgesMap = this._edgesMap; // PNEDING
if (typeof n1 === 'number') {
n1 = this.nodes[n1];
}
if (typeof n2 === 'number') {
n2 = this.nodes[n2];
}
if (!Node.isInstance(n1)) {
n1 = nodesMap[generateNodeKey(n1)];
}
if (!Node.isInstance(n2)) {
n2 = nodesMap[generateNodeKey(n2)];
}
if (!n1 || !n2) {
return;
}
var key = n1.id + '-' + n2.id;
var edge = new Edge(n1, n2, dataIndex);
edge.hostGraph = this;
if (this._directed) {
n1.outEdges.push(edge);
n2.inEdges.push(edge);
}
n1.edges.push(edge);
if (n1 !== n2) {
n2.edges.push(edge);
}
this.edges.push(edge);
edgesMap[key] = edge;
return edge;
};
/**
* Get edge by data index
* @param {number} dataIndex
* @return {module:echarts/data/Graph~Node}
*/
graphProto.getEdgeByIndex = function (dataIndex) {
var rawIdx = this.edgeData.getRawIndex(dataIndex);
return this.edges[rawIdx];
};
/**
* Get edge by two linked nodes
* @param {module:echarts/data/Graph.Node|string} n1
* @param {module:echarts/data/Graph.Node|string} n2
* @return {module:echarts/data/Graph.Edge}
*/
graphProto.getEdge = function (n1, n2) {
if (Node.isInstance(n1)) {
n1 = n1.id;
}
if (Node.isInstance(n2)) {
n2 = n2.id;
}
var edgesMap = this._edgesMap;
if (this._directed) {
return edgesMap[n1 + '-' + n2];
} else {
return edgesMap[n1 + '-' + n2] || edgesMap[n2 + '-' + n1];
}
};
/**
* Iterate all nodes
* @param {Function} cb
* @param {*} [context]
*/
graphProto.eachNode = function (cb, context) {
var nodes = this.nodes;
var len = nodes.length;
for (var i = 0; i < len; i++) {
if (nodes[i].dataIndex >= 0) {
cb.call(context, nodes[i], i);
}
}
};
/**
* Iterate all edges
* @param {Function} cb
* @param {*} [context]
*/
graphProto.eachEdge = function (cb, context) {
var edges = this.edges;
var len = edges.length;
for (var i = 0; i < len; i++) {
if (edges[i].dataIndex >= 0 && edges[i].node1.dataIndex >= 0 && edges[i].node2.dataIndex >= 0) {
cb.call(context, edges[i], i);
}
}
};
/**
* Breadth first traverse
* @param {Function} cb
* @param {module:echarts/data/Graph.Node} startNode
* @param {string} [direction='none'] 'none'|'in'|'out'
* @param {*} [context]
*/
graphProto.breadthFirstTraverse = function (cb, startNode, direction, context) {
if (!Node.isInstance(startNode)) {
startNode = this._nodesMap[generateNodeKey(startNode)];
}
if (!startNode) {
return;
}
var edgeType = direction === 'out' ? 'outEdges' : direction === 'in' ? 'inEdges' : 'edges';
for (var i = 0; i < this.nodes.length; i++) {
this.nodes[i].__visited = false;
}
if (cb.call(context, startNode, null)) {
return;
}
var queue = [startNode];
while (queue.length) {
var currentNode = queue.shift();
var edges = currentNode[edgeType];
for (var i = 0; i < edges.length; i++) {
var e = edges[i];
var otherNode = e.node1 === currentNode ? e.node2 : e.node1;
if (!otherNode.__visited) {
if (cb.call(context, otherNode, currentNode)) {
// Stop traversing
return;
}
queue.push(otherNode);
otherNode.__visited = true;
}
}
}
}; // TODO
// graphProto.depthFirstTraverse = function (
// cb, startNode, direction, context
// ) {
// };
// Filter update
graphProto.update = function () {
var data = this.data;
var edgeData = this.edgeData;
var nodes = this.nodes;
var edges = this.edges;
for (var i = 0, len = nodes.length; i < len; i++) {
nodes[i].dataIndex = -1;
}
for (var i = 0, len = data.count(); i < len; i++) {
nodes[data.getRawIndex(i)].dataIndex = i;
}
edgeData.filterSelf(function (idx) {
var edge = edges[edgeData.getRawIndex(idx)];
return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
}); // Update edge
for (var i = 0, len = edges.length; i < len; i++) {
edges[i].dataIndex = -1;
}
for (var i = 0, len = edgeData.count(); i < len; i++) {
edges[edgeData.getRawIndex(i)].dataIndex = i;
}
};
/**
* @return {module:echarts/data/Graph}
*/
graphProto.clone = function () {
var graph = new Graph(this._directed);
var nodes = this.nodes;
var edges = this.edges;
for (var i = 0; i < nodes.length; i++) {
graph.addNode(nodes[i].id, nodes[i].dataIndex);
}
for (var i = 0; i < edges.length; i++) {
var e = edges[i];
graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
}
return graph;
};
/**
* @alias module:echarts/data/Graph.Node
*/
function Node(id, dataIndex) {
/**
* @type {string}
*/
this.id = id == null ? '' : id;
/**
* @type {Array.<module:echarts/data/Graph.Edge>}
*/
this.inEdges = [];
/**
* @type {Array.<module:echarts/data/Graph.Edge>}
*/
this.outEdges = [];
/**
* @type {Array.<module:echarts/data/Graph.Edge>}
*/
this.edges = [];
/**
* @type {module:echarts/data/Graph}
*/
this.hostGraph;
/**
* @type {number}
*/
this.dataIndex = dataIndex == null ? -1 : dataIndex;
}
Node.prototype = {
constructor: Node,
/**
* @return {number}
*/
degree: function () {
return this.edges.length;
},
/**
* @return {number}
*/
inDegree: function () {
return this.inEdges.length;
},
/**
* @return {number}
*/
outDegree: function () {
return this.outEdges.length;
},
/**
* @param {string} [path]
* @return {module:echarts/model/Model}
*/
getModel: function (path) {
if (this.dataIndex < 0) {
return;
}
var graph = this.hostGraph;
var itemModel = graph.data.getItemModel(this.dataIndex);
return itemModel.getModel(path);
}
};
/**
* 图边
* @alias module:echarts/data/Graph.Edge
* @param {module:echarts/data/Graph.Node} n1
* @param {module:echarts/data/Graph.Node} n2
* @param {number} [dataIndex=-1]
*/
function Edge(n1, n2, dataIndex) {
/**
* 节点1如果是有向图则为源节点
* @type {module:echarts/data/Graph.Node}
*/
this.node1 = n1;
/**
* 节点2如果是有向图则为目标节点
* @type {module:echarts/data/Graph.Node}
*/
this.node2 = n2;
this.dataIndex = dataIndex == null ? -1 : dataIndex;
}
/**
* @param {string} [path]
* @return {module:echarts/model/Model}
*/
Edge.prototype.getModel = function (path) {
if (this.dataIndex < 0) {
return;
}
var graph = this.hostGraph;
var itemModel = graph.edgeData.getItemModel(this.dataIndex);
return itemModel.getModel(path);
};
var createGraphDataProxyMixin = function (hostName, dataName) {
return {
/**
* @param {string=} [dimension='value'] Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
* @return {number}
*/
getValue: function (dimension) {
var data = this[hostName][dataName];
return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
},
/**
* @param {Object|string} key
* @param {*} [value]
*/
setVisual: function (key, value) {
this.dataIndex >= 0 && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
},
/**
* @param {string} key
* @return {boolean}
*/
getVisual: function (key, ignoreParent) {
return this[hostName][dataName].getItemVisual(this.dataIndex, key, ignoreParent);
},
/**
* @param {Object} layout
* @return {boolean} [merge=false]
*/
setLayout: function (layout, merge) {
this.dataIndex >= 0 && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge);
},
/**
* @return {Object}
*/
getLayout: function () {
return this[hostName][dataName].getItemLayout(this.dataIndex);
},
/**
* @return {module:zrender/Element}
*/
getGraphicEl: function () {
return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
},
/**
* @return {number}
*/
getRawIndex: function () {
return this[hostName][dataName].getRawIndex(this.dataIndex);
}
};
};
zrUtil.mixin(Node, createGraphDataProxyMixin('hostGraph', 'data'));
zrUtil.mixin(Edge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
Graph.Node = Node;
Graph.Edge = Edge;
enableClassCheck(Node);
enableClassCheck(Edge);
var _default = Graph;
module.exports = _default;

2085
node_modules/echarts/lib/data/List.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

167
node_modules/echarts/lib/data/OrdinalMeta.js generated vendored Normal file
View File

@ -0,0 +1,167 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _util = require("zrender/lib/core/util");
var createHashMap = _util.createHashMap;
var isObject = _util.isObject;
var map = _util.map;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @constructor
* @param {Object} [opt]
* @param {Object} [opt.categories=[]]
* @param {Object} [opt.needCollect=false]
* @param {Object} [opt.deduplication=false]
*/
function OrdinalMeta(opt) {
/**
* @readOnly
* @type {Array.<string>}
*/
this.categories = opt.categories || [];
/**
* @private
* @type {boolean}
*/
this._needCollect = opt.needCollect;
/**
* @private
* @type {boolean}
*/
this._deduplication = opt.deduplication;
/**
* @private
* @type {boolean}
*/
this._map;
}
/**
* @param {module:echarts/model/Model} axisModel
* @return {module:echarts/data/OrdinalMeta}
*/
OrdinalMeta.createByAxisModel = function (axisModel) {
var option = axisModel.option;
var data = option.data;
var categories = data && map(data, getName);
return new OrdinalMeta({
categories: categories,
needCollect: !categories,
// deduplication is default in axis.
deduplication: option.dedplication !== false
});
};
var proto = OrdinalMeta.prototype;
/**
* @param {string} category
* @return {number} ordinal
*/
proto.getOrdinal = function (category) {
return getOrCreateMap(this).get(category);
};
/**
* @param {*} category
* @return {number} The ordinal. If not found, return NaN.
*/
proto.parseAndCollect = function (category) {
var index;
var needCollect = this._needCollect; // The value of category dim can be the index of the given category set.
// This feature is only supported when !needCollect, because we should
// consider a common case: a value is 2017, which is a number but is
// expected to be tread as a category. This case usually happen in dataset,
// where it happent to be no need of the index feature.
if (typeof category !== 'string' && !needCollect) {
return category;
} // Optimize for the scenario:
// category is ['2012-01-01', '2012-01-02', ...], where the input
// data has been ensured not duplicate and is large data.
// Notice, if a dataset dimension provide categroies, usually echarts
// should remove duplication except user tell echarts dont do that
// (set axis.deduplication = false), because echarts do not know whether
// the values in the category dimension has duplication (consider the
// parallel-aqi example)
if (needCollect && !this._deduplication) {
index = this.categories.length;
this.categories[index] = category;
return index;
}
var map = getOrCreateMap(this);
index = map.get(category);
if (index == null) {
if (needCollect) {
index = this.categories.length;
this.categories[index] = category;
map.set(category, index);
} else {
index = NaN;
}
}
return index;
}; // Consider big data, do not create map until needed.
function getOrCreateMap(ordinalMeta) {
return ordinalMeta._map || (ordinalMeta._map = createHashMap(ordinalMeta.categories));
}
function getName(obj) {
if (isObject(obj) && obj.value != null) {
return obj.value;
} else {
return obj + '';
}
}
var _default = OrdinalMeta;
module.exports = _default;

172
node_modules/echarts/lib/data/Source.js generated vendored Normal file
View File

@ -0,0 +1,172 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _util = require("zrender/lib/core/util");
var createHashMap = _util.createHashMap;
var isTypedArray = _util.isTypedArray;
var _clazz = require("../util/clazz");
var enableClassCheck = _clazz.enableClassCheck;
var _sourceType = require("./helper/sourceType");
var SOURCE_FORMAT_ORIGINAL = _sourceType.SOURCE_FORMAT_ORIGINAL;
var SERIES_LAYOUT_BY_COLUMN = _sourceType.SERIES_LAYOUT_BY_COLUMN;
var SOURCE_FORMAT_UNKNOWN = _sourceType.SOURCE_FORMAT_UNKNOWN;
var SOURCE_FORMAT_TYPED_ARRAY = _sourceType.SOURCE_FORMAT_TYPED_ARRAY;
var SOURCE_FORMAT_KEYED_COLUMNS = _sourceType.SOURCE_FORMAT_KEYED_COLUMNS;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* [sourceFormat]
*
* + "original":
* This format is only used in series.data, where
* itemStyle can be specified in data item.
*
* + "arrayRows":
* [
* ['product', 'score', 'amount'],
* ['Matcha Latte', 89.3, 95.8],
* ['Milk Tea', 92.1, 89.4],
* ['Cheese Cocoa', 94.4, 91.2],
* ['Walnut Brownie', 85.4, 76.9]
* ]
*
* + "objectRows":
* [
* {product: 'Matcha Latte', score: 89.3, amount: 95.8},
* {product: 'Milk Tea', score: 92.1, amount: 89.4},
* {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},
* {product: 'Walnut Brownie', score: 85.4, amount: 76.9}
* ]
*
* + "keyedColumns":
* {
* 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
* 'count': [823, 235, 1042, 988],
* 'score': [95.8, 81.4, 91.2, 76.9]
* }
*
* + "typedArray"
*
* + "unknown"
*/
/**
* @constructor
* @param {Object} fields
* @param {string} fields.sourceFormat
* @param {Array|Object} fields.fromDataset
* @param {Array|Object} [fields.data]
* @param {string} [seriesLayoutBy='column']
* @param {Array.<Object|string>} [dimensionsDefine]
* @param {Objet|HashMap} [encodeDefine]
* @param {number} [startIndex=0]
* @param {number} [dimensionsDetectCount]
*/
function Source(fields) {
/**
* @type {boolean}
*/
this.fromDataset = fields.fromDataset;
/**
* Not null/undefined.
* @type {Array|Object}
*/
this.data = fields.data || (fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []);
/**
* See also "detectSourceFormat".
* Not null/undefined.
* @type {string}
*/
this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
/**
* 'row' or 'column'
* Not null/undefined.
* @type {string} seriesLayoutBy
*/
this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
/**
* dimensions definition in option.
* can be null/undefined.
* @type {Array.<Object|string>}
*/
this.dimensionsDefine = fields.dimensionsDefine;
/**
* encode definition in option.
* can be null/undefined.
* @type {Objet|HashMap}
*/
this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);
/**
* Not null/undefined, uint.
* @type {number}
*/
this.startIndex = fields.startIndex || 0;
/**
* Can be null/undefined (when unknown), uint.
* @type {number}
*/
this.dimensionsDetectCount = fields.dimensionsDetectCount;
}
/**
* Wrap original series data for some compatibility cases.
*/
Source.seriesDataToSource = function (data) {
return new Source({
data: data,
sourceFormat: isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL,
fromDataset: false
});
};
enableClassCheck(Source);
var _default = Source;
module.exports = _default;

532
node_modules/echarts/lib/data/Tree.js generated vendored Normal file
View File

@ -0,0 +1,532 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
var linkList = require("./helper/linkList");
var List = require("./List");
var createDimensions = require("./helper/createDimensions");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Tree data structure
*
* @module echarts/data/Tree
*/
/**
* @constructor module:echarts/data/Tree~TreeNode
* @param {string} name
* @param {module:echarts/data/Tree} hostTree
*/
var TreeNode = function (name, hostTree) {
/**
* @type {string}
*/
this.name = name || '';
/**
* Depth of node
*
* @type {number}
* @readOnly
*/
this.depth = 0;
/**
* Height of the subtree rooted at this node.
* @type {number}
* @readOnly
*/
this.height = 0;
/**
* @type {module:echarts/data/Tree~TreeNode}
* @readOnly
*/
this.parentNode = null;
/**
* Reference to list item.
* Do not persistent dataIndex outside,
* besause it may be changed by list.
* If dataIndex -1,
* this node is logical deleted (filtered) in list.
*
* @type {Object}
* @readOnly
*/
this.dataIndex = -1;
/**
* @type {Array.<module:echarts/data/Tree~TreeNode>}
* @readOnly
*/
this.children = [];
/**
* @type {Array.<module:echarts/data/Tree~TreeNode>}
* @pubilc
*/
this.viewChildren = [];
/**
* @type {moduel:echarts/data/Tree}
* @readOnly
*/
this.hostTree = hostTree;
};
TreeNode.prototype = {
constructor: TreeNode,
/**
* The node is removed.
* @return {boolean} is removed.
*/
isRemoved: function () {
return this.dataIndex < 0;
},
/**
* Travel this subtree (include this node).
* Usage:
* node.eachNode(function () { ... }); // preorder
* node.eachNode('preorder', function () { ... }); // preorder
* node.eachNode('postorder', function () { ... }); // postorder
* node.eachNode(
* {order: 'postorder', attr: 'viewChildren'},
* function () { ... }
* ); // postorder
*
* @param {(Object|string)} options If string, means order.
* @param {string=} options.order 'preorder' or 'postorder'
* @param {string=} options.attr 'children' or 'viewChildren'
* @param {Function} cb If in preorder and return false,
* its subtree will not be visited.
* @param {Object} [context]
*/
eachNode: function (options, cb, context) {
if (typeof options === 'function') {
context = cb;
cb = options;
options = null;
}
options = options || {};
if (zrUtil.isString(options)) {
options = {
order: options
};
}
var order = options.order || 'preorder';
var children = this[options.attr || 'children'];
var suppressVisitSub;
order === 'preorder' && (suppressVisitSub = cb.call(context, this));
for (var i = 0; !suppressVisitSub && i < children.length; i++) {
children[i].eachNode(options, cb, context);
}
order === 'postorder' && cb.call(context, this);
},
/**
* Update depth and height of this subtree.
*
* @param {number} depth
*/
updateDepthAndHeight: function (depth) {
var height = 0;
this.depth = depth;
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];
child.updateDepthAndHeight(depth + 1);
if (child.height > height) {
height = child.height;
}
}
this.height = height + 1;
},
/**
* @param {string} id
* @return {module:echarts/data/Tree~TreeNode}
*/
getNodeById: function (id) {
if (this.getId() === id) {
return this;
}
for (var i = 0, children = this.children, len = children.length; i < len; i++) {
var res = children[i].getNodeById(id);
if (res) {
return res;
}
}
},
/**
* @param {module:echarts/data/Tree~TreeNode} node
* @return {boolean}
*/
contains: function (node) {
if (node === this) {
return true;
}
for (var i = 0, children = this.children, len = children.length; i < len; i++) {
var res = children[i].contains(node);
if (res) {
return res;
}
}
},
/**
* @param {boolean} includeSelf Default false.
* @return {Array.<module:echarts/data/Tree~TreeNode>} order: [root, child, grandchild, ...]
*/
getAncestors: function (includeSelf) {
var ancestors = [];
var node = includeSelf ? this : this.parentNode;
while (node) {
ancestors.push(node);
node = node.parentNode;
}
ancestors.reverse();
return ancestors;
},
/**
* @param {string|Array=} [dimension='value'] Default 'value'. can be 0, 1, 2, 3
* @return {number} Value.
*/
getValue: function (dimension) {
var data = this.hostTree.data;
return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
},
/**
* @param {Object} layout
* @param {boolean=} [merge=false]
*/
setLayout: function (layout, merge) {
this.dataIndex >= 0 && this.hostTree.data.setItemLayout(this.dataIndex, layout, merge);
},
/**
* @return {Object} layout
*/
getLayout: function () {
return this.hostTree.data.getItemLayout(this.dataIndex);
},
/**
* @param {string} [path]
* @return {module:echarts/model/Model}
*/
getModel: function (path) {
if (this.dataIndex < 0) {
return;
}
var hostTree = this.hostTree;
var itemModel = hostTree.data.getItemModel(this.dataIndex);
return itemModel.getModel(path);
},
/**
* @example
* setItemVisual('color', color);
* setItemVisual({
* 'color': color
* });
*/
setVisual: function (key, value) {
this.dataIndex >= 0 && this.hostTree.data.setItemVisual(this.dataIndex, key, value);
},
/**
* Get item visual
*/
getVisual: function (key, ignoreParent) {
return this.hostTree.data.getItemVisual(this.dataIndex, key, ignoreParent);
},
/**
* @public
* @return {number}
*/
getRawIndex: function () {
return this.hostTree.data.getRawIndex(this.dataIndex);
},
/**
* @public
* @return {string}
*/
getId: function () {
return this.hostTree.data.getId(this.dataIndex);
},
/**
* if this is an ancestor of another node
*
* @public
* @param {TreeNode} node another node
* @return {boolean} if is ancestor
*/
isAncestorOf: function (node) {
var parent = node.parentNode;
while (parent) {
if (parent === this) {
return true;
}
parent = parent.parentNode;
}
return false;
},
/**
* if this is an descendant of another node
*
* @public
* @param {TreeNode} node another node
* @return {boolean} if is descendant
*/
isDescendantOf: function (node) {
return node !== this && node.isAncestorOf(this);
}
};
/**
* @constructor
* @alias module:echarts/data/Tree
* @param {module:echarts/model/Model} hostModel
*/
function Tree(hostModel) {
/**
* @type {module:echarts/data/Tree~TreeNode}
* @readOnly
*/
this.root;
/**
* @type {module:echarts/data/List}
* @readOnly
*/
this.data;
/**
* Index of each item is the same as the raw index of coresponding list item.
* @private
* @type {Array.<module:echarts/data/Tree~TreeNode}
*/
this._nodes = [];
/**
* @private
* @readOnly
* @type {module:echarts/model/Model}
*/
this.hostModel = hostModel;
}
Tree.prototype = {
constructor: Tree,
type: 'tree',
/**
* Travel this subtree (include this node).
* Usage:
* node.eachNode(function () { ... }); // preorder
* node.eachNode('preorder', function () { ... }); // preorder
* node.eachNode('postorder', function () { ... }); // postorder
* node.eachNode(
* {order: 'postorder', attr: 'viewChildren'},
* function () { ... }
* ); // postorder
*
* @param {(Object|string)} options If string, means order.
* @param {string=} options.order 'preorder' or 'postorder'
* @param {string=} options.attr 'children' or 'viewChildren'
* @param {Function} cb
* @param {Object} [context]
*/
eachNode: function (options, cb, context) {
this.root.eachNode(options, cb, context);
},
/**
* @param {number} dataIndex
* @return {module:echarts/data/Tree~TreeNode}
*/
getNodeByDataIndex: function (dataIndex) {
var rawIndex = this.data.getRawIndex(dataIndex);
return this._nodes[rawIndex];
},
/**
* @param {string} name
* @return {module:echarts/data/Tree~TreeNode}
*/
getNodeByName: function (name) {
return this.root.getNodeByName(name);
},
/**
* Update item available by list,
* when list has been performed options like 'filterSelf' or 'map'.
*/
update: function () {
var data = this.data;
var nodes = this._nodes;
for (var i = 0, len = nodes.length; i < len; i++) {
nodes[i].dataIndex = -1;
}
for (var i = 0, len = data.count(); i < len; i++) {
nodes[data.getRawIndex(i)].dataIndex = i;
}
},
/**
* Clear all layouts
*/
clearLayouts: function () {
this.data.clearItemLayouts();
}
};
/**
* data node format:
* {
* name: ...
* value: ...
* children: [
* {
* name: ...
* value: ...
* children: ...
* },
* ...
* ]
* }
*
* @static
* @param {Object} dataRoot Root node.
* @param {module:echarts/model/Model} hostModel
* @return module:echarts/data/Tree
*/
Tree.createTree = function (dataRoot, hostModel, beforeLink) {
var tree = new Tree(hostModel);
var listData = [];
var dimMax = 1;
buildHierarchy(dataRoot);
function buildHierarchy(dataNode, parentNode) {
var value = dataNode.value;
dimMax = Math.max(dimMax, zrUtil.isArray(value) ? value.length : 1);
listData.push(dataNode);
var node = new TreeNode(dataNode.name, tree);
parentNode ? addChild(node, parentNode) : tree.root = node;
tree._nodes.push(node);
var children = dataNode.children;
if (children) {
for (var i = 0; i < children.length; i++) {
buildHierarchy(children[i], node);
}
}
}
tree.root.updateDepthAndHeight(0);
var dimensionsInfo = createDimensions(listData, {
coordDimensions: ['value'],
dimensionsCount: dimMax
});
var list = new List(dimensionsInfo, hostModel);
list.initData(listData);
beforeLink && beforeLink(list);
linkList({
mainData: list,
struct: tree,
structAttr: 'tree'
});
tree.update();
return tree;
};
/**
* It is needed to consider the mess of 'list', 'hostModel' when creating a TreeNote,
* so this function is not ready and not necessary to be public.
*
* @param {(module:echarts/data/Tree~TreeNode|Object)} child
*/
function addChild(child, node) {
var children = node.children;
if (child.parentNode === node) {
return;
}
children.push(child);
child.parentNode = node;
}
var _default = Tree;
module.exports = _default;

View File

@ -0,0 +1,324 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _util = require("zrender/lib/core/util");
var createHashMap = _util.createHashMap;
var each = _util.each;
var isString = _util.isString;
var defaults = _util.defaults;
var extend = _util.extend;
var isObject = _util.isObject;
var clone = _util.clone;
var _model = require("../../util/model");
var normalizeToArray = _model.normalizeToArray;
var _sourceHelper = require("./sourceHelper");
var guessOrdinal = _sourceHelper.guessOrdinal;
var BE_ORDINAL = _sourceHelper.BE_ORDINAL;
var Source = require("../Source");
var _dimensionHelper = require("./dimensionHelper");
var OTHER_DIMENSIONS = _dimensionHelper.OTHER_DIMENSIONS;
var DataDimensionInfo = require("../DataDimensionInfo");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @deprecated
* Use `echarts/data/helper/createDimensions` instead.
*/
/**
* @see {module:echarts/test/ut/spec/data/completeDimensions}
*
* This method builds the relationship between:
* + "what the coord sys or series requires (see `sysDims`)",
* + "what the user defines (in `encode` and `dimensions`, see `opt.dimsDef` and `opt.encodeDef`)"
* + "what the data source provids (see `source`)".
*
* Some guess strategy will be adapted if user does not define something.
* If no 'value' dimension specified, the first no-named dimension will be
* named as 'value'.
*
* @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
* provides not only dim template, but also default order.
* properties: 'name', 'type', 'displayName'.
* `name` of each item provides default coord name.
* [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
* provide dims count that the sysDim required.
* [{ordinalMeta}] can be specified.
* @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
* @param {Object} [opt]
* @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
* For example: ['asdf', {name, type}, ...].
* @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
* @param {Function} [opt.encodeDefaulter] Called if no `opt.encodeDef` exists.
* If not specified, auto find the next available data dim.
* param source {module:data/Source}
* param dimCount {number}
* return {Object} encode Never be `null/undefined`.
* @param {string} [opt.generateCoord] Generate coord dim with the given name.
* If not specified, extra dim names will be:
* 'value', 'value0', 'value1', ...
* @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
* If `generateCoordCount` specified, the generated dim names will be:
* `generateCoord` + 0, `generateCoord` + 1, ...
* can be Infinity, indicate that use all of the remain columns.
* @param {number} [opt.dimCount] If not specified, guess by the first data item.
* @return {Array.<module:data/DataDimensionInfo>}
*/
function completeDimensions(sysDims, source, opt) {
if (!Source.isInstance(source)) {
source = Source.seriesDataToSource(source);
}
opt = opt || {};
sysDims = (sysDims || []).slice();
var dimsDef = (opt.dimsDef || []).slice();
var dataDimNameMap = createHashMap();
var coordDimNameMap = createHashMap(); // var valueCandidate;
var result = [];
var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimCount); // Apply user defined dims (`name` and `type`) and init result.
for (var i = 0; i < dimCount; i++) {
var dimDefItem = dimsDef[i] = extend({}, isObject(dimsDef[i]) ? dimsDef[i] : {
name: dimsDef[i]
});
var userDimName = dimDefItem.name;
var resultItem = result[i] = new DataDimensionInfo(); // Name will be applied later for avoiding duplication.
if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
// Only if `series.dimensions` is defined in option
// displayName, will be set, and dimension will be diplayed vertically in
// tooltip by default.
resultItem.name = resultItem.displayName = userDimName;
dataDimNameMap.set(userDimName, i);
}
dimDefItem.type != null && (resultItem.type = dimDefItem.type);
dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
}
var encodeDef = opt.encodeDef;
if (!encodeDef && opt.encodeDefaulter) {
encodeDef = opt.encodeDefaulter(source, dimCount);
}
encodeDef = createHashMap(encodeDef); // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
encodeDef.each(function (dataDims, coordDim) {
dataDims = normalizeToArray(dataDims).slice(); // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
// `{encode: {x: -1, y: 1}}`. Should not filter anything in
// this case.
if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
encodeDef.set(coordDim, false);
return;
}
var validDataDims = encodeDef.set(coordDim, []);
each(dataDims, function (resultDimIdx, idx) {
// The input resultDimIdx can be dim name or index.
isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
if (resultDimIdx != null && resultDimIdx < dimCount) {
validDataDims[idx] = resultDimIdx;
applyDim(result[resultDimIdx], coordDim, idx);
}
});
}); // Apply templetes and default order from `sysDims`.
var availDimIdx = 0;
each(sysDims, function (sysDimItem, sysDimIndex) {
var coordDim;
var sysDimItem;
var sysDimItemDimsDef;
var sysDimItemOtherDims;
if (isString(sysDimItem)) {
coordDim = sysDimItem;
sysDimItem = {};
} else {
coordDim = sysDimItem.name;
var ordinalMeta = sysDimItem.ordinalMeta;
sysDimItem.ordinalMeta = null;
sysDimItem = clone(sysDimItem);
sysDimItem.ordinalMeta = ordinalMeta; // `coordDimIndex` should not be set directly.
sysDimItemDimsDef = sysDimItem.dimsDef;
sysDimItemOtherDims = sysDimItem.otherDims;
sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
}
var dataDims = encodeDef.get(coordDim); // negative resultDimIdx means no need to mapping.
if (dataDims === false) {
return;
}
var dataDims = normalizeToArray(dataDims); // dimensions provides default dim sequences.
if (!dataDims.length) {
for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
availDimIdx++;
}
availDimIdx < result.length && dataDims.push(availDimIdx++);
}
} // Apply templates.
each(dataDims, function (resultDimIdx, coordDimIndex) {
var resultItem = result[resultDimIdx];
applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
if (resultItem.name == null && sysDimItemDimsDef) {
var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
!isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
name: sysDimItemDimsDefItem
});
resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
} // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
});
});
function applyDim(resultItem, coordDim, coordDimIndex) {
if (OTHER_DIMENSIONS.get(coordDim) != null) {
resultItem.otherDims[coordDim] = coordDimIndex;
} else {
resultItem.coordDim = coordDim;
resultItem.coordDimIndex = coordDimIndex;
coordDimNameMap.set(coordDim, true);
}
} // Make sure the first extra dim is 'value'.
var generateCoord = opt.generateCoord;
var generateCoordCount = opt.generateCoordCount;
var fromZero = generateCoordCount != null;
generateCoordCount = generateCoord ? generateCoordCount || 1 : 0;
var extra = generateCoord || 'value'; // Set dim `name` and other `coordDim` and other props.
for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
var resultItem = result[resultDimIdx] = result[resultDimIdx] || new DataDimensionInfo();
var coordDim = resultItem.coordDim;
if (coordDim == null) {
resultItem.coordDim = genName(extra, coordDimNameMap, fromZero);
resultItem.coordDimIndex = 0;
if (!generateCoord || generateCoordCount <= 0) {
resultItem.isExtraCoord = true;
}
generateCoordCount--;
}
resultItem.name == null && (resultItem.name = genName(resultItem.coordDim, dataDimNameMap));
if (resultItem.type == null && (guessOrdinal(source, resultDimIdx, resultItem.name) === BE_ORDINAL.Must // Consider the case:
// {
// dataset: {source: [
// ['2001', 123],
// ['2002', 456],
// ...
// ['The others', 987],
// ]},
// series: {type: 'pie'}
// }
// The first colum should better be treated as a "ordinal" although it
// might not able to be detected as an "ordinal" by `guessOrdinal`.
|| resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
resultItem.type = 'ordinal';
}
}
return result;
} // ??? TODO
// Originally detect dimCount by data[0]. Should we
// optimize it to only by sysDims and dimensions and encode.
// So only necessary dims will be initialized.
// But
// (1) custom series should be considered. where other dims
// may be visited.
// (2) sometimes user need to calcualte bubble size or use visualMap
// on other dimensions besides coordSys needed.
// So, dims that is not used by system, should be shared in storage?
function getDimCount(source, sysDims, dimsDef, optDimCount) {
// Note that the result dimCount should not small than columns count
// of data, otherwise `dataDimNameMap` checking will be incorrect.
var dimCount = Math.max(source.dimensionsDetectCount || 1, sysDims.length, dimsDef.length, optDimCount || 0);
each(sysDims, function (sysDimItem) {
var sysDimItemDimsDef = sysDimItem.dimsDef;
sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
});
return dimCount;
}
function genName(name, map, fromZero) {
if (fromZero || map.get(name) != null) {
var i = 0;
while (map.get(name + i) != null) {
i++;
}
name += i;
}
map.set(name, true);
return name;
}
var _default = completeDimensions;
module.exports = _default;

View File

@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var completeDimensions = require("./completeDimensions");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Substitute `completeDimensions`.
* `completeDimensions` is to be deprecated.
*/
/**
* @param {module:echarts/data/Source|module:echarts/data/List} source or data.
* @param {Object|Array} [opt]
* @param {Array.<string|Object>} [opt.coordDimensions=[]]
* @param {number} [opt.dimensionsCount]
* @param {string} [opt.generateCoord]
* @param {string} [opt.generateCoordCount]
* @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
* @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
* @param {Function} [opt.encodeDefaulter] Make default encode if user not specified.
* @return {Array.<Object>} dimensionsInfo
*/
function _default(source, opt) {
opt = opt || {};
return completeDimensions(opt.coordDimensions || [], source, {
dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
encodeDef: opt.encodeDefine || source.encodeDefine,
dimCount: opt.dimensionsCount,
encodeDefaulter: opt.encodeDefaulter,
generateCoord: opt.generateCoord,
generateCoordCount: opt.generateCoordCount
});
}
module.exports = _default;

378
node_modules/echarts/lib/data/helper/dataProvider.js generated vendored Normal file
View File

@ -0,0 +1,378 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _config = require("../../config");
var __DEV__ = _config.__DEV__;
var _util = require("zrender/lib/core/util");
var isTypedArray = _util.isTypedArray;
var extend = _util.extend;
var assert = _util.assert;
var each = _util.each;
var isObject = _util.isObject;
var _model = require("../../util/model");
var getDataItemValue = _model.getDataItemValue;
var isDataItemOption = _model.isDataItemOption;
var _number = require("../../util/number");
var parseDate = _number.parseDate;
var Source = require("../Source");
var _sourceType = require("./sourceType");
var SOURCE_FORMAT_TYPED_ARRAY = _sourceType.SOURCE_FORMAT_TYPED_ARRAY;
var SOURCE_FORMAT_ARRAY_ROWS = _sourceType.SOURCE_FORMAT_ARRAY_ROWS;
var SOURCE_FORMAT_ORIGINAL = _sourceType.SOURCE_FORMAT_ORIGINAL;
var SOURCE_FORMAT_OBJECT_ROWS = _sourceType.SOURCE_FORMAT_OBJECT_ROWS;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// TODO
// ??? refactor? check the outer usage of data provider.
// merge with defaultDimValueGetter?
/**
* If normal array used, mutable chunk size is supported.
* If typed array used, chunk size must be fixed.
*/
function DefaultDataProvider(source, dimSize) {
if (!Source.isInstance(source)) {
source = Source.seriesDataToSource(source);
}
this._source = source;
var data = this._data = source.data;
var sourceFormat = source.sourceFormat; // Typed array. TODO IE10+?
if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
this._offset = 0;
this._dimSize = dimSize;
this._data = data;
}
var methods = providerMethods[sourceFormat === SOURCE_FORMAT_ARRAY_ROWS ? sourceFormat + '_' + source.seriesLayoutBy : sourceFormat];
extend(this, methods);
}
var providerProto = DefaultDataProvider.prototype; // If data is pure without style configuration
providerProto.pure = false; // If data is persistent and will not be released after use.
providerProto.persistent = true; // ???! FIXME legacy data provider do not has method getSource
providerProto.getSource = function () {
return this._source;
};
var providerMethods = {
'arrayRows_column': {
pure: true,
count: function () {
return Math.max(0, this._data.length - this._source.startIndex);
},
getItem: function (idx) {
return this._data[idx + this._source.startIndex];
},
appendData: appendDataSimply
},
'arrayRows_row': {
pure: true,
count: function () {
var row = this._data[0];
return row ? Math.max(0, row.length - this._source.startIndex) : 0;
},
getItem: function (idx) {
idx += this._source.startIndex;
var item = [];
var data = this._data;
for (var i = 0; i < data.length; i++) {
var row = data[i];
item.push(row ? row[idx] : null);
}
return item;
},
appendData: function () {
throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
}
},
'objectRows': {
pure: true,
count: countSimply,
getItem: getItemSimply,
appendData: appendDataSimply
},
'keyedColumns': {
pure: true,
count: function () {
var dimName = this._source.dimensionsDefine[0].name;
var col = this._data[dimName];
return col ? col.length : 0;
},
getItem: function (idx) {
var item = [];
var dims = this._source.dimensionsDefine;
for (var i = 0; i < dims.length; i++) {
var col = this._data[dims[i].name];
item.push(col ? col[idx] : null);
}
return item;
},
appendData: function (newData) {
var data = this._data;
each(newData, function (newCol, key) {
var oldCol = data[key] || (data[key] = []);
for (var i = 0; i < (newCol || []).length; i++) {
oldCol.push(newCol[i]);
}
});
}
},
'original': {
count: countSimply,
getItem: getItemSimply,
appendData: appendDataSimply
},
'typedArray': {
persistent: false,
pure: true,
count: function () {
return this._data ? this._data.length / this._dimSize : 0;
},
getItem: function (idx, out) {
idx = idx - this._offset;
out = out || [];
var offset = this._dimSize * idx;
for (var i = 0; i < this._dimSize; i++) {
out[i] = this._data[offset + i];
}
return out;
},
appendData: function (newData) {
this._data = newData;
},
// Clean self if data is already used.
clean: function () {
// PENDING
this._offset += this.count();
this._data = null;
}
}
};
function countSimply() {
return this._data.length;
}
function getItemSimply(idx) {
return this._data[idx];
}
function appendDataSimply(newData) {
for (var i = 0; i < newData.length; i++) {
this._data.push(newData[i]);
}
}
var rawValueGetters = {
arrayRows: getRawValueSimply,
objectRows: function (dataItem, dataIndex, dimIndex, dimName) {
return dimIndex != null ? dataItem[dimName] : dataItem;
},
keyedColumns: getRawValueSimply,
original: function (dataItem, dataIndex, dimIndex, dimName) {
// FIXME
// In some case (markpoint in geo (geo-map.html)), dataItem
// is {coord: [...]}
var value = getDataItemValue(dataItem);
return dimIndex == null || !(value instanceof Array) ? value : value[dimIndex];
},
typedArray: getRawValueSimply
};
function getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {
return dimIndex != null ? dataItem[dimIndex] : dataItem;
}
var defaultDimValueGetters = {
arrayRows: getDimValueSimply,
objectRows: function (dataItem, dimName, dataIndex, dimIndex) {
return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);
},
keyedColumns: getDimValueSimply,
original: function (dataItem, dimName, dataIndex, dimIndex) {
// Performance sensitive, do not use modelUtil.getDataItemValue.
// If dataItem is an plain object with no value field, the var `value`
// will be assigned with the object, but it will be tread correctly
// in the `convertDataValue`.
var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value); // If any dataItem is like { value: 10 }
if (!this._rawData.pure && isDataItemOption(dataItem)) {
this.hasItemOption = true;
}
return converDataValue(value instanceof Array ? value[dimIndex] // If value is a single number or something else not array.
: value, this._dimensionInfos[dimName]);
},
typedArray: function (dataItem, dimName, dataIndex, dimIndex) {
return dataItem[dimIndex];
}
};
function getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {
return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);
}
/**
* This helper method convert value in data.
* @param {string|number|Date} value
* @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
* If "dimInfo.ordinalParseAndSave", ordinal value can be parsed.
*/
function converDataValue(value, dimInfo) {
// Performance sensitive.
var dimType = dimInfo && dimInfo.type;
if (dimType === 'ordinal') {
// If given value is a category string
var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
return ordinalMeta ? ordinalMeta.parseAndCollect(value) : value;
}
if (dimType === 'time' // spead up when using timestamp
&& typeof value !== 'number' && value != null && value !== '-') {
value = +parseDate(value);
} // dimType defaults 'number'.
// If dimType is not ordinal and value is null or undefined or NaN or '-',
// parse to NaN.
return value == null || value === '' ? NaN // If string (like '-'), using '+' parse to NaN
// If object, also parse to NaN
: +value;
} // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
// Consider persistent.
// Caution: why use raw value to display on label or tooltip?
// A reason is to avoid format. For example time value we do not know
// how to format is expected. More over, if stack is used, calculated
// value may be 0.91000000001, which have brings trouble to display.
// TODO: consider how to treat null/undefined/NaN when display?
/**
* @param {module:echarts/data/List} data
* @param {number} dataIndex
* @param {string|number} [dim] dimName or dimIndex
* @return {Array.<number>|string|number} can be null/undefined.
*/
function retrieveRawValue(data, dataIndex, dim) {
if (!data) {
return;
} // Consider data may be not persistent.
var dataItem = data.getRawDataItem(dataIndex);
if (dataItem == null) {
return;
}
var sourceFormat = data.getProvider().getSource().sourceFormat;
var dimName;
var dimIndex;
var dimInfo = data.getDimensionInfo(dim);
if (dimInfo) {
dimName = dimInfo.name;
dimIndex = dimInfo.index;
}
return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
}
/**
* Compatible with some cases (in pie, map) like:
* data: [{name: 'xx', value: 5, selected: true}, ...]
* where only sourceFormat is 'original' and 'objectRows' supported.
*
* ??? TODO
* Supported detail options in data item when using 'arrayRows'.
*
* @param {module:echarts/data/List} data
* @param {number} dataIndex
* @param {string} attr like 'selected'
*/
function retrieveRawAttr(data, dataIndex, attr) {
if (!data) {
return;
}
var sourceFormat = data.getProvider().getSource().sourceFormat;
if (sourceFormat !== SOURCE_FORMAT_ORIGINAL && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS) {
return;
}
var dataItem = data.getRawDataItem(dataIndex);
if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject(dataItem)) {
dataItem = null;
}
if (dataItem) {
return dataItem[attr];
}
}
exports.DefaultDataProvider = DefaultDataProvider;
exports.defaultDimValueGetters = defaultDimValueGetters;
exports.retrieveRawValue = retrieveRawValue;
exports.retrieveRawAttr = retrieveRawAttr;

182
node_modules/echarts/lib/data/helper/dataStackHelper.js generated vendored Normal file
View File

@ -0,0 +1,182 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _util = require("zrender/lib/core/util");
var each = _util.each;
var isString = _util.isString;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Note that it is too complicated to support 3d stack by value
* (have to create two-dimension inverted index), so in 3d case
* we just support that stacked by index.
*
* @param {module:echarts/model/Series} seriesModel
* @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
* The input dimensionInfoList will be modified.
* @param {Object} [opt]
* @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
* @param {boolean} [opt.byIndex=false]
* @return {Object} calculationInfo
* {
* stackedDimension: string
* stackedByDimension: string
* isStackedByIndex: boolean
* stackedOverDimension: string
* stackResultDimension: string
* }
*/
function enableDataStack(seriesModel, dimensionInfoList, opt) {
opt = opt || {};
var byIndex = opt.byIndex;
var stackedCoordDimension = opt.stackedCoordDimension; // Compatibal: when `stack` is set as '', do not stack.
var mayStack = !!(seriesModel && seriesModel.get('stack'));
var stackedByDimInfo;
var stackedDimInfo;
var stackResultDimension;
var stackedOverDimension;
each(dimensionInfoList, function (dimensionInfo, index) {
if (isString(dimensionInfo)) {
dimensionInfoList[index] = dimensionInfo = {
name: dimensionInfo
};
}
if (mayStack && !dimensionInfo.isExtraCoord) {
// Find the first ordinal dimension as the stackedByDimInfo.
if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
stackedByDimInfo = dimensionInfo;
} // Find the first stackable dimension as the stackedDimInfo.
if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
stackedDimInfo = dimensionInfo;
}
}
});
if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
// Compatible with previous design, value axis (time axis) only stack by index.
// It may make sense if the user provides elaborately constructed data.
byIndex = true;
} // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
// That put stack logic in List is for using conveniently in echarts extensions, but it
// might not be a good way.
if (stackedDimInfo) {
// Use a weird name that not duplicated with other names.
stackResultDimension = '__\0ecstackresult';
stackedOverDimension = '__\0ecstackedover'; // Create inverted index to fast query index by value.
if (stackedByDimInfo) {
stackedByDimInfo.createInvertedIndices = true;
}
var stackedDimCoordDim = stackedDimInfo.coordDim;
var stackedDimType = stackedDimInfo.type;
var stackedDimCoordIndex = 0;
each(dimensionInfoList, function (dimensionInfo) {
if (dimensionInfo.coordDim === stackedDimCoordDim) {
stackedDimCoordIndex++;
}
});
dimensionInfoList.push({
name: stackResultDimension,
coordDim: stackedDimCoordDim,
coordDimIndex: stackedDimCoordIndex,
type: stackedDimType,
isExtraCoord: true,
isCalculationCoord: true
});
stackedDimCoordIndex++;
dimensionInfoList.push({
name: stackedOverDimension,
// This dimension contains stack base (generally, 0), so do not set it as
// `stackedDimCoordDim` to avoid extent calculation, consider log scale.
coordDim: stackedOverDimension,
coordDimIndex: stackedDimCoordIndex,
type: stackedDimType,
isExtraCoord: true,
isCalculationCoord: true
});
}
return {
stackedDimension: stackedDimInfo && stackedDimInfo.name,
stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
isStackedByIndex: byIndex,
stackedOverDimension: stackedOverDimension,
stackResultDimension: stackResultDimension
};
}
/**
* @param {module:echarts/data/List} data
* @param {string} stackedDim
*/
function isDimensionStacked(data, stackedDim
/*, stackedByDim*/
) {
// Each single series only maps to one pair of axis. So we do not need to
// check stackByDim, whatever stacked by a dimension or stacked by index.
return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension'); // && (
// stackedByDim != null
// ? stackedByDim === data.getCalculationInfo('stackedByDimension')
// : data.getCalculationInfo('isStackedByIndex')
// );
}
/**
* @param {module:echarts/data/List} data
* @param {string} targetDim
* @param {string} [stackedByDim] If not input this parameter, check whether
* stacked by index.
* @return {string} dimension
*/
function getStackedDimension(data, targetDim) {
return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
}
exports.enableDataStack = enableDataStack;
exports.isDimensionStacked = isDimensionStacked;
exports.getStackedDimension = getStackedDimension;

165
node_modules/echarts/lib/data/helper/dimensionHelper.js generated vendored Normal file
View File

@ -0,0 +1,165 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _util = require("zrender/lib/core/util");
var each = _util.each;
var createHashMap = _util.createHashMap;
var assert = _util.assert;
var _config = require("../../config");
var __DEV__ = _config.__DEV__;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var OTHER_DIMENSIONS = createHashMap(['tooltip', 'label', 'itemName', 'itemId', 'seriesName']);
function summarizeDimensions(data) {
var summary = {};
var encode = summary.encode = {};
var notExtraCoordDimMap = createHashMap();
var defaultedLabel = [];
var defaultedTooltip = []; // See the comment of `List.js#userOutput`.
var userOutput = summary.userOutput = {
dimensionNames: data.dimensions.slice(),
encode: {}
};
each(data.dimensions, function (dimName) {
var dimItem = data.getDimensionInfo(dimName);
var coordDim = dimItem.coordDim;
if (coordDim) {
var coordDimIndex = dimItem.coordDimIndex;
getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
if (!dimItem.isExtraCoord) {
notExtraCoordDimMap.set(coordDim, 1); // Use the last coord dim (and label friendly) as default label,
// because when dataset is used, it is hard to guess which dimension
// can be value dimension. If both show x, y on label is not look good,
// and conventionally y axis is focused more.
if (mayLabelDimType(dimItem.type)) {
defaultedLabel[0] = dimName;
} // User output encode do not contain generated coords.
// And it only has index. User can use index to retrieve value from the raw item array.
getOrCreateEncodeArr(userOutput.encode, coordDim)[coordDimIndex] = dimItem.index;
}
if (dimItem.defaultTooltip) {
defaultedTooltip.push(dimName);
}
}
OTHER_DIMENSIONS.each(function (v, otherDim) {
var encodeArr = getOrCreateEncodeArr(encode, otherDim);
var dimIndex = dimItem.otherDims[otherDim];
if (dimIndex != null && dimIndex !== false) {
encodeArr[dimIndex] = dimItem.name;
}
});
});
var dataDimsOnCoord = [];
var encodeFirstDimNotExtra = {};
notExtraCoordDimMap.each(function (v, coordDim) {
var dimArr = encode[coordDim]; // ??? FIXME extra coord should not be set in dataDimsOnCoord.
// But should fix the case that radar axes: simplify the logic
// of `completeDimension`, remove `extraPrefix`.
encodeFirstDimNotExtra[coordDim] = dimArr[0]; // Not necessary to remove duplicate, because a data
// dim canot on more than one coordDim.
dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
});
summary.dataDimsOnCoord = dataDimsOnCoord;
summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
var encodeLabel = encode.label; // FIXME `encode.label` is not recommanded, because formatter can not be set
// in this way. Use label.formatter instead. May be remove this approach someday.
if (encodeLabel && encodeLabel.length) {
defaultedLabel = encodeLabel.slice();
}
var encodeTooltip = encode.tooltip;
if (encodeTooltip && encodeTooltip.length) {
defaultedTooltip = encodeTooltip.slice();
} else if (!defaultedTooltip.length) {
defaultedTooltip = defaultedLabel.slice();
}
encode.defaultedLabel = defaultedLabel;
encode.defaultedTooltip = defaultedTooltip;
return summary;
}
function getOrCreateEncodeArr(encode, dim) {
if (!encode.hasOwnProperty(dim)) {
encode[dim] = [];
}
return encode[dim];
}
function getDimensionTypeByAxis(axisType) {
return axisType === 'category' ? 'ordinal' : axisType === 'time' ? 'time' : 'float';
}
function mayLabelDimType(dimType) {
// In most cases, ordinal and time do not suitable for label.
// Ordinal info can be displayed on axis. Time is too long.
return !(dimType === 'ordinal' || dimType === 'time');
} // function findTheLastDimMayLabel(data) {
// // Get last value dim
// var dimensions = data.dimensions.slice();
// var valueType;
// var valueDim;
// while (dimensions.length && (
// valueDim = dimensions.pop(),
// valueType = data.getDimensionInfo(valueDim).type,
// valueType === 'ordinal' || valueType === 'time'
// )) {} // jshint ignore:line
// return valueDim;
// }
exports.OTHER_DIMENSIONS = OTHER_DIMENSIONS;
exports.summarizeDimensions = summarizeDimensions;
exports.getDimensionTypeByAxis = getDimensionTypeByAxis;

167
node_modules/echarts/lib/data/helper/linkList.js generated vendored Normal file
View File

@ -0,0 +1,167 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var zrUtil = require("zrender/lib/core/util");
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Link lists and struct (graph or tree)
*/
var each = zrUtil.each;
var DATAS = '\0__link_datas';
var MAIN_DATA = '\0__link_mainData'; // Caution:
// In most case, either list or its shallow clones (see list.cloneShallow)
// is active in echarts process. So considering heap memory consumption,
// we do not clone tree or graph, but share them among list and its shallow clones.
// But in some rare case, we have to keep old list (like do animation in chart). So
// please take care that both the old list and the new list share the same tree/graph.
/**
* @param {Object} opt
* @param {module:echarts/data/List} opt.mainData
* @param {Object} [opt.struct] For example, instance of Graph or Tree.
* @param {string} [opt.structAttr] designation: list[structAttr] = struct;
* @param {Object} [opt.datas] {dataType: data},
* like: {node: nodeList, edge: edgeList}.
* Should contain mainData.
* @param {Object} [opt.datasAttr] {dataType: attr},
* designation: struct[datasAttr[dataType]] = list;
*/
function linkList(opt) {
var mainData = opt.mainData;
var datas = opt.datas;
if (!datas) {
datas = {
main: mainData
};
opt.datasAttr = {
main: 'data'
};
}
opt.datas = opt.mainData = null;
linkAll(mainData, datas, opt); // Porxy data original methods.
each(datas, function (data) {
each(mainData.TRANSFERABLE_METHODS, function (methodName) {
data.wrapMethod(methodName, zrUtil.curry(transferInjection, opt));
});
}); // Beyond transfer, additional features should be added to `cloneShallow`.
mainData.wrapMethod('cloneShallow', zrUtil.curry(cloneShallowInjection, opt)); // Only mainData trigger change, because struct.update may trigger
// another changable methods, which may bring about dead lock.
each(mainData.CHANGABLE_METHODS, function (methodName) {
mainData.wrapMethod(methodName, zrUtil.curry(changeInjection, opt));
}); // Make sure datas contains mainData.
zrUtil.assert(datas[mainData.dataType] === mainData);
}
function transferInjection(opt, res) {
if (isMainData(this)) {
// Transfer datas to new main data.
var datas = zrUtil.extend({}, this[DATAS]);
datas[this.dataType] = res;
linkAll(res, datas, opt);
} else {
// Modify the reference in main data to point newData.
linkSingle(res, this.dataType, this[MAIN_DATA], opt);
}
return res;
}
function changeInjection(opt, res) {
opt.struct && opt.struct.update(this);
return res;
}
function cloneShallowInjection(opt, res) {
// cloneShallow, which brings about some fragilities, may be inappropriate
// to be exposed as an API. So for implementation simplicity we can make
// the restriction that cloneShallow of not-mainData should not be invoked
// outside, but only be invoked here.
each(res[DATAS], function (data, dataType) {
data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
});
return res;
}
/**
* Supplement method to List.
*
* @public
* @param {string} [dataType] If not specified, return mainData.
* @return {module:echarts/data/List}
*/
function getLinkedData(dataType) {
var mainData = this[MAIN_DATA];
return dataType == null || mainData == null ? mainData : mainData[DATAS][dataType];
}
function isMainData(data) {
return data[MAIN_DATA] === data;
}
function linkAll(mainData, datas, opt) {
mainData[DATAS] = {};
each(datas, function (data, dataType) {
linkSingle(data, dataType, mainData, opt);
});
}
function linkSingle(data, dataType, mainData, opt) {
mainData[DATAS][dataType] = data;
data[MAIN_DATA] = mainData;
data.dataType = dataType;
if (opt.struct) {
data[opt.structAttr] = opt.struct;
opt.struct[opt.datasAttr[dataType]] = data;
} // Supplement method.
data.getLinkedData = getLinkedData;
}
var _default = linkList;
module.exports = _default;

690
node_modules/echarts/lib/data/helper/sourceHelper.js generated vendored Normal file
View File

@ -0,0 +1,690 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var _config = require("../../config");
var __DEV__ = _config.__DEV__;
var _model = require("../../util/model");
var makeInner = _model.makeInner;
var getDataItemValue = _model.getDataItemValue;
var _util = require("zrender/lib/core/util");
var createHashMap = _util.createHashMap;
var each = _util.each;
var map = _util.map;
var isArray = _util.isArray;
var isString = _util.isString;
var isObject = _util.isObject;
var isTypedArray = _util.isTypedArray;
var isArrayLike = _util.isArrayLike;
var extend = _util.extend;
var assert = _util.assert;
var Source = require("../Source");
var _sourceType = require("./sourceType");
var SOURCE_FORMAT_ORIGINAL = _sourceType.SOURCE_FORMAT_ORIGINAL;
var SOURCE_FORMAT_ARRAY_ROWS = _sourceType.SOURCE_FORMAT_ARRAY_ROWS;
var SOURCE_FORMAT_OBJECT_ROWS = _sourceType.SOURCE_FORMAT_OBJECT_ROWS;
var SOURCE_FORMAT_KEYED_COLUMNS = _sourceType.SOURCE_FORMAT_KEYED_COLUMNS;
var SOURCE_FORMAT_UNKNOWN = _sourceType.SOURCE_FORMAT_UNKNOWN;
var SOURCE_FORMAT_TYPED_ARRAY = _sourceType.SOURCE_FORMAT_TYPED_ARRAY;
var SERIES_LAYOUT_BY_ROW = _sourceType.SERIES_LAYOUT_BY_ROW;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// The result of `guessOrdinal`.
var BE_ORDINAL = {
Must: 1,
// Encounter string but not '-' and not number-like.
Might: 2,
// Encounter string but number-like.
Not: 3 // Other cases
};
var inner = makeInner();
/**
* @see {module:echarts/data/Source}
* @param {module:echarts/component/dataset/DatasetModel} datasetModel
* @return {string} sourceFormat
*/
function detectSourceFormat(datasetModel) {
var data = datasetModel.option.source;
var sourceFormat = SOURCE_FORMAT_UNKNOWN;
if (isTypedArray(data)) {
sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
} else if (isArray(data)) {
// FIXME Whether tolerate null in top level array?
if (data.length === 0) {
sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
}
for (var i = 0, len = data.length; i < len; i++) {
var item = data[i];
if (item == null) {
continue;
} else if (isArray(item)) {
sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
break;
} else if (isObject(item)) {
sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
break;
}
}
} else if (isObject(data)) {
for (var key in data) {
if (data.hasOwnProperty(key) && isArrayLike(data[key])) {
sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
break;
}
}
} else if (data != null) {
throw new Error('Invalid data');
}
inner(datasetModel).sourceFormat = sourceFormat;
}
/**
* [Scenarios]:
* (1) Provide source data directly:
* series: {
* encode: {...},
* dimensions: [...]
* seriesLayoutBy: 'row',
* data: [[...]]
* }
* (2) Refer to datasetModel.
* series: [{
* encode: {...}
* // Ignore datasetIndex means `datasetIndex: 0`
* // and the dimensions defination in dataset is used
* }, {
* encode: {...},
* seriesLayoutBy: 'column',
* datasetIndex: 1
* }]
*
* Get data from series itself or datset.
* @return {module:echarts/data/Source} source
*/
function getSource(seriesModel) {
return inner(seriesModel).source;
}
/**
* MUST be called before mergeOption of all series.
* @param {module:echarts/model/Global} ecModel
*/
function resetSourceDefaulter(ecModel) {
// `datasetMap` is used to make default encode.
inner(ecModel).datasetMap = createHashMap();
}
/**
* [Caution]:
* MUST be called after series option merged and
* before "series.getInitailData()" called.
*
* [The rule of making default encode]:
* Category axis (if exists) alway map to the first dimension.
* Each other axis occupies a subsequent dimension.
*
* [Why make default encode]:
* Simplify the typing of encode in option, avoiding the case like that:
* series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],
* where the "y" have to be manually typed as "1, 2, 3, ...".
*
* @param {module:echarts/model/Series} seriesModel
*/
function prepareSource(seriesModel) {
var seriesOption = seriesModel.option;
var data = seriesOption.data;
var sourceFormat = isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
var fromDataset = false;
var seriesLayoutBy = seriesOption.seriesLayoutBy;
var sourceHeader = seriesOption.sourceHeader;
var dimensionsDefine = seriesOption.dimensions;
var datasetModel = getDatasetModel(seriesModel);
if (datasetModel) {
var datasetOption = datasetModel.option;
data = datasetOption.source;
sourceFormat = inner(datasetModel).sourceFormat;
fromDataset = true; // These settings from series has higher priority.
seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;
sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);
dimensionsDefine = dimensionsDefine || datasetOption.dimensions;
}
var completeResult = completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine);
inner(seriesModel).source = new Source({
data: data,
fromDataset: fromDataset,
seriesLayoutBy: seriesLayoutBy,
sourceFormat: sourceFormat,
dimensionsDefine: completeResult.dimensionsDefine,
startIndex: completeResult.startIndex,
dimensionsDetectCount: completeResult.dimensionsDetectCount,
// Note: dataset option does not have `encode`.
encodeDefine: seriesOption.encode
});
} // return {startIndex, dimensionsDefine, dimensionsCount}
function completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {
if (!data) {
return {
dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)
};
}
var dimensionsDetectCount;
var startIndex;
if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
// Rule: Most of the first line are string: it is header.
// Caution: consider a line with 5 string and 1 number,
// it still can not be sure it is a head, because the
// 5 string may be 5 values of category columns.
if (sourceHeader === 'auto' || sourceHeader == null) {
arrayRowsTravelFirst(function (val) {
// '-' is regarded as null/undefined.
if (val != null && val !== '-') {
if (isString(val)) {
startIndex == null && (startIndex = 1);
} else {
startIndex = 0;
}
} // 10 is an experience number, avoid long loop.
}, seriesLayoutBy, data, 10);
} else {
startIndex = sourceHeader ? 1 : 0;
}
if (!dimensionsDefine && startIndex === 1) {
dimensionsDefine = [];
arrayRowsTravelFirst(function (val, index) {
dimensionsDefine[index] = val != null ? val : '';
}, seriesLayoutBy, data);
}
dimensionsDetectCount = dimensionsDefine ? dimensionsDefine.length : seriesLayoutBy === SERIES_LAYOUT_BY_ROW ? data.length : data[0] ? data[0].length : null;
} else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
if (!dimensionsDefine) {
dimensionsDefine = objectRowsCollectDimensions(data);
}
} else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
if (!dimensionsDefine) {
dimensionsDefine = [];
each(data, function (colArr, key) {
dimensionsDefine.push(key);
});
}
} else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
var value0 = getDataItemValue(data[0]);
dimensionsDetectCount = isArray(value0) && value0.length || 1;
} else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {}
return {
startIndex: startIndex,
dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),
dimensionsDetectCount: dimensionsDetectCount
};
} // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
// which is reasonable. But dimension name is duplicated.
// Returns undefined or an array contains only object without null/undefiend or string.
function normalizeDimensionsDefine(dimensionsDefine) {
if (!dimensionsDefine) {
// The meaning of null/undefined is different from empty array.
return;
}
var nameMap = createHashMap();
return map(dimensionsDefine, function (item, index) {
item = extend({}, isObject(item) ? item : {
name: item
}); // User can set null in dimensions.
// We dont auto specify name, othewise a given name may
// cause it be refered unexpectedly.
if (item.name == null) {
return item;
} // Also consider number form like 2012.
item.name += ''; // User may also specify displayName.
// displayName will always exists except user not
// specified or dim name is not specified or detected.
// (A auto generated dim name will not be used as
// displayName).
if (item.displayName == null) {
item.displayName = item.name;
}
var exist = nameMap.get(item.name);
if (!exist) {
nameMap.set(item.name, {
count: 1
});
} else {
item.name += '-' + exist.count++;
}
return item;
});
}
function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
maxLoop == null && (maxLoop = Infinity);
if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
for (var i = 0; i < data.length && i < maxLoop; i++) {
cb(data[i] ? data[i][0] : null, i);
}
} else {
var value0 = data[0] || [];
for (var i = 0; i < value0.length && i < maxLoop; i++) {
cb(value0[i], i);
}
}
}
function objectRowsCollectDimensions(data) {
var firstIndex = 0;
var obj;
while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
if (obj) {
var dimensions = [];
each(obj, function (value, key) {
dimensions.push(key);
});
return dimensions;
}
}
/**
* [The strategy of the arrengment of data dimensions for dataset]:
* "value way": all axes are non-category axes. So series one by one take
* several (the number is coordSysDims.length) dimensions from dataset.
* The result of data arrengment of data dimensions like:
* | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
* "category way": at least one axis is category axis. So the the first data
* dimension is always mapped to the first category axis and shared by
* all of the series. The other data dimensions are taken by series like
* "value way" does.
* The result of data arrengment of data dimensions like:
* | ser_shared_x | ser0_y | ser1_y | ser2_y |
*
* @param {Array.<Object|string>} coordDimensions [{name: <string>, type: <string>, dimsDef: <Array>}, ...]
* @param {module:model/Series} seriesModel
* @param {module:data/Source} source
* @return {Object} encode Never be `null/undefined`.
*/
function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
var encode = {};
var datasetModel = getDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
if (!datasetModel || !coordDimensions) {
return encode;
}
var encodeItemName = [];
var encodeSeriesName = [];
var ecModel = seriesModel.ecModel;
var datasetMap = inner(ecModel).datasetMap;
var key = datasetModel.uid + '_' + source.seriesLayoutBy;
var baseCategoryDimIndex;
var categoryWayValueDimStart;
coordDimensions = coordDimensions.slice();
each(coordDimensions, function (coordDimInfo, coordDimIdx) {
!isObject(coordDimInfo) && (coordDimensions[coordDimIdx] = {
name: coordDimInfo
});
if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
baseCategoryDimIndex = coordDimIdx;
categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimensions[coordDimIdx]);
}
encode[coordDimInfo.name] = [];
});
var datasetRecord = datasetMap.get(key) || datasetMap.set(key, {
categoryWayDim: categoryWayValueDimStart,
valueWayDim: 0
}); // TODO
// Auto detect first time axis and do arrangement.
each(coordDimensions, function (coordDimInfo, coordDimIdx) {
var coordDimName = coordDimInfo.name;
var count = getDataDimCountOnCoordDim(coordDimInfo); // In value way.
if (baseCategoryDimIndex == null) {
var start = datasetRecord.valueWayDim;
pushDim(encode[coordDimName], start, count);
pushDim(encodeSeriesName, start, count);
datasetRecord.valueWayDim += count; // ??? TODO give a better default series name rule?
// especially when encode x y specified.
// consider: when mutiple series share one dimension
// category axis, series name should better use
// the other dimsion name. On the other hand, use
// both dimensions name.
} // In category way, the first category axis.
else if (baseCategoryDimIndex === coordDimIdx) {
pushDim(encode[coordDimName], 0, count);
pushDim(encodeItemName, 0, count);
} // In category way, the other axis.
else {
var start = datasetRecord.categoryWayDim;
pushDim(encode[coordDimName], start, count);
pushDim(encodeSeriesName, start, count);
datasetRecord.categoryWayDim += count;
}
});
function pushDim(dimIdxArr, idxFrom, idxCount) {
for (var i = 0; i < idxCount; i++) {
dimIdxArr.push(idxFrom + i);
}
}
function getDataDimCountOnCoordDim(coordDimInfo) {
var dimsDef = coordDimInfo.dimsDef;
return dimsDef ? dimsDef.length : 1;
}
encodeItemName.length && (encode.itemName = encodeItemName);
encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
return encode;
}
/**
* Work for data like [{name: ..., value: ...}, ...].
*
* @param {module:model/Series} seriesModel
* @param {module:data/Source} source
* @return {Object} encode Never be `null/undefined`.
*/
function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {
var encode = {};
var datasetModel = getDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
if (!datasetModel) {
return encode;
}
var sourceFormat = source.sourceFormat;
var dimensionsDefine = source.dimensionsDefine;
var potentialNameDimIndex;
if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
each(dimensionsDefine, function (dim, idx) {
if ((isObject(dim) ? dim.name : dim) === 'name') {
potentialNameDimIndex = idx;
}
});
} // idxResult: {v, n}.
var idxResult = function () {
var idxRes0 = {};
var idxRes1 = {};
var guessRecords = []; // 5 is an experience value.
for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {
var guessResult = doGuessOrdinal(source.data, sourceFormat, source.seriesLayoutBy, dimensionsDefine, source.startIndex, i);
guessRecords.push(guessResult);
var isPureNumber = guessResult === BE_ORDINAL.Not; // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
// and then find a name dim with the priority:
// "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
idxRes0.v = i;
}
if (idxRes0.n == null || idxRes0.n === idxRes0.v || !isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) {
idxRes0.n = i;
}
if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
return idxRes0;
} // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),
// find the first BE_ORDINAL.Might as the value dim,
// and then find a name dim with the priority:
// "other dim" > "the value dim itself".
// That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be
// treated as number.
if (!isPureNumber) {
if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {
idxRes1.v = i;
}
if (idxRes1.n == null || idxRes1.n === idxRes1.v) {
idxRes1.n = i;
}
}
}
function fulfilled(idxResult) {
return idxResult.v != null && idxResult.n != null;
}
return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;
}();
if (idxResult) {
encode.value = idxResult.v; // `potentialNameDimIndex` has highest priority.
var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n; // By default, label use itemName in charts.
// So we dont set encodeLabel here.
encode.itemName = [nameDimIndex];
encode.seriesName = [nameDimIndex];
}
return encode;
}
/**
* If return null/undefined, indicate that should not use datasetModel.
*/
function getDatasetModel(seriesModel) {
var option = seriesModel.option; // Caution: consider the scenario:
// A dataset is declared and a series is not expected to use the dataset,
// and at the beginning `setOption({series: { noData })` (just prepare other
// option but no data), then `setOption({series: {data: [...]}); In this case,
// the user should set an empty array to avoid that dataset is used by default.
var thisData = option.data;
if (!thisData) {
return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);
}
}
/**
* The rule should not be complex, otherwise user might not
* be able to known where the data is wrong.
* The code is ugly, but how to make it neat?
*
* @param {module:echars/data/Source} source
* @param {number} dimIndex
* @return {BE_ORDINAL} guess result.
*/
function guessOrdinal(source, dimIndex) {
return doGuessOrdinal(source.data, source.sourceFormat, source.seriesLayoutBy, source.dimensionsDefine, source.startIndex, dimIndex);
} // dimIndex may be overflow source data.
// return {BE_ORDINAL}
function doGuessOrdinal(data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex) {
var result; // Experience value.
var maxLoop = 5;
if (isTypedArray(data)) {
return BE_ORDINAL.Not;
} // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
// always exists in source.
var dimName;
var dimType;
if (dimensionsDefine) {
var dimDefItem = dimensionsDefine[dimIndex];
if (isObject(dimDefItem)) {
dimName = dimDefItem.name;
dimType = dimDefItem.type;
} else if (isString(dimDefItem)) {
dimName = dimDefItem;
}
}
if (dimType != null) {
return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
}
if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
var sample = data[dimIndex];
for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
if ((result = detectValue(sample[startIndex + i])) != null) {
return result;
}
}
} else {
for (var i = 0; i < data.length && i < maxLoop; i++) {
var row = data[startIndex + i];
if (row && (result = detectValue(row[dimIndex])) != null) {
return result;
}
}
}
} else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
if (!dimName) {
return BE_ORDINAL.Not;
}
for (var i = 0; i < data.length && i < maxLoop; i++) {
var item = data[i];
if (item && (result = detectValue(item[dimName])) != null) {
return result;
}
}
} else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
if (!dimName) {
return BE_ORDINAL.Not;
}
var sample = data[dimName];
if (!sample || isTypedArray(sample)) {
return BE_ORDINAL.Not;
}
for (var i = 0; i < sample.length && i < maxLoop; i++) {
if ((result = detectValue(sample[i])) != null) {
return result;
}
}
} else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
for (var i = 0; i < data.length && i < maxLoop; i++) {
var item = data[i];
var val = getDataItemValue(item);
if (!isArray(val)) {
return BE_ORDINAL.Not;
}
if ((result = detectValue(val[dimIndex])) != null) {
return result;
}
}
}
function detectValue(val) {
var beStr = isString(val); // Consider usage convenience, '1', '2' will be treated as "number".
// `isFinit('')` get `true`.
if (val != null && isFinite(val) && val !== '') {
return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
} else if (beStr && val !== '-') {
return BE_ORDINAL.Must;
}
}
return BE_ORDINAL.Not;
}
exports.BE_ORDINAL = BE_ORDINAL;
exports.detectSourceFormat = detectSourceFormat;
exports.getSource = getSource;
exports.resetSourceDefaulter = resetSourceDefaulter;
exports.prepareSource = prepareSource;
exports.makeSeriesEncodeForAxisCoordSys = makeSeriesEncodeForAxisCoordSys;
exports.makeSeriesEncodeForNameBased = makeSeriesEncodeForNameBased;
exports.guessOrdinal = guessOrdinal;

56
node_modules/echarts/lib/data/helper/sourceType.js generated vendored Normal file
View File

@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Avoid typo.
var SOURCE_FORMAT_ORIGINAL = 'original';
var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
var SOURCE_FORMAT_UNKNOWN = 'unknown'; // ??? CHANGE A NAME
var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
var SERIES_LAYOUT_BY_COLUMN = 'column';
var SERIES_LAYOUT_BY_ROW = 'row';
exports.SOURCE_FORMAT_ORIGINAL = SOURCE_FORMAT_ORIGINAL;
exports.SOURCE_FORMAT_ARRAY_ROWS = SOURCE_FORMAT_ARRAY_ROWS;
exports.SOURCE_FORMAT_OBJECT_ROWS = SOURCE_FORMAT_OBJECT_ROWS;
exports.SOURCE_FORMAT_KEYED_COLUMNS = SOURCE_FORMAT_KEYED_COLUMNS;
exports.SOURCE_FORMAT_UNKNOWN = SOURCE_FORMAT_UNKNOWN;
exports.SOURCE_FORMAT_TYPED_ARRAY = SOURCE_FORMAT_TYPED_ARRAY;
exports.SERIES_LAYOUT_BY_COLUMN = SERIES_LAYOUT_BY_COLUMN;
exports.SERIES_LAYOUT_BY_ROW = SERIES_LAYOUT_BY_ROW;