123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- var zrUtil = require("zrender/lib/core/util");
- var env = require("zrender/lib/core/env");
- var each = zrUtil.each;
- var isObject = zrUtil.isObject;
- var isArray = zrUtil.isArray;
- var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
- function normalizeToArray(value) {
- return value instanceof Array ? value : value == null ? [] : [value];
- }
- function defaultEmphasis(opt, key, subOpts) {
-
- if (opt) {
- opt[key] = opt[key] || {};
- opt.emphasis = opt.emphasis || {};
- opt.emphasis[key] = opt.emphasis[key] || {};
- for (var i = 0, len = subOpts.length; i < len; i++) {
- var subOptName = subOpts[i];
- if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
- opt.emphasis[key][subOptName] = opt[key][subOptName];
- }
- }
- }
- }
- var TEXT_STYLE_OPTIONS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth', 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY', 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'];
- function getDataItemValue(dataItem) {
- return isObject(dataItem) && !isArray(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
- }
- function isDataItemOption(dataItem) {
- return isObject(dataItem) && !(dataItem instanceof Array);
-
- }
- function mappingToExists(exists, newCptOptions) {
-
-
-
-
-
-
- newCptOptions = (newCptOptions || []).slice();
- var result = zrUtil.map(exists || [], function (obj, index) {
- return {
- exist: obj
- };
- });
- each(newCptOptions, function (cptOption, index) {
- if (!isObject(cptOption)) {
- return;
- }
- for (var i = 0; i < result.length; i++) {
- if (!result[i].option
- && cptOption.id != null && result[i].exist.id === cptOption.id + '') {
- result[i].option = cptOption;
- newCptOptions[index] = null;
- return;
- }
- }
- for (var i = 0; i < result.length; i++) {
- var exist = result[i].exist;
- if (!result[i].option
-
- && (exist.id == null || cptOption.id == null) && cptOption.name != null && !isIdInner(cptOption) && !isIdInner(exist) && exist.name === cptOption.name + '') {
- result[i].option = cptOption;
- newCptOptions[index] = null;
- return;
- }
- }
- });
- each(newCptOptions, function (cptOption, index) {
- if (!isObject(cptOption)) {
- return;
- }
- var i = 0;
- for (; i < result.length; i++) {
- var exist = result[i].exist;
- if (!result[i].option
-
-
-
- && !isIdInner(exist)
-
-
-
-
- && cptOption.id == null) {
- result[i].option = cptOption;
- break;
- }
- }
- if (i >= result.length) {
- result.push({
- option: cptOption
- });
- }
- });
- return result;
- }
- function makeIdAndName(mapResult) {
-
-
-
-
-
-
-
-
-
- var idMap = zrUtil.createHashMap();
- each(mapResult, function (item, index) {
- var existCpt = item.exist;
- existCpt && idMap.set(existCpt.id, item);
- });
- each(mapResult, function (item, index) {
- var opt = item.option;
- zrUtil.assert(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
- opt && opt.id != null && idMap.set(opt.id, item);
- !item.keyInfo && (item.keyInfo = {});
- });
- each(mapResult, function (item, index) {
- var existCpt = item.exist;
- var opt = item.option;
- var keyInfo = item.keyInfo;
- if (!isObject(opt)) {
- return;
- }
-
-
-
- keyInfo.name = opt.name != null ? opt.name + '' : existCpt ? existCpt.name
-
- : DUMMY_COMPONENT_NAME_PREFIX + index;
- if (existCpt) {
- keyInfo.id = existCpt.id;
- } else if (opt.id != null) {
- keyInfo.id = opt.id + '';
- } else {
-
-
-
-
-
- var idNum = 0;
- do {
- keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
- } while (idMap.get(keyInfo.id));
- }
- idMap.set(keyInfo.id, item);
- });
- }
- function isNameSpecified(componentModel) {
- var name = componentModel.name;
- return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
- }
- function isIdInner(cptOption) {
- return isObject(cptOption) && cptOption.id && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
- }
- function compressBatches(batchA, batchB) {
- var mapA = {};
- var mapB = {};
- makeMap(batchA || [], mapA);
- makeMap(batchB || [], mapB, mapA);
- return [mapToArray(mapA), mapToArray(mapB)];
- function makeMap(sourceBatch, map, otherMap) {
- for (var i = 0, len = sourceBatch.length; i < len; i++) {
- var seriesId = sourceBatch[i].seriesId;
- var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
- var otherDataIndices = otherMap && otherMap[seriesId];
- for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
- var dataIndex = dataIndices[j];
- if (otherDataIndices && otherDataIndices[dataIndex]) {
- otherDataIndices[dataIndex] = null;
- } else {
- (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
- }
- }
- }
- }
- function mapToArray(map, isData) {
- var result = [];
- for (var i in map) {
- if (map.hasOwnProperty(i) && map[i] != null) {
- if (isData) {
- result.push(+i);
- } else {
- var dataIndices = mapToArray(map[i], true);
- dataIndices.length && result.push({
- seriesId: i,
- dataIndex: dataIndices
- });
- }
- }
- }
- return result;
- }
- }
- function queryDataIndex(data, payload) {
- if (payload.dataIndexInside != null) {
- return payload.dataIndexInside;
- } else if (payload.dataIndex != null) {
- return zrUtil.isArray(payload.dataIndex) ? zrUtil.map(payload.dataIndex, function (value) {
- return data.indexOfRawIndex(value);
- }) : data.indexOfRawIndex(payload.dataIndex);
- } else if (payload.name != null) {
- return zrUtil.isArray(payload.name) ? zrUtil.map(payload.name, function (value) {
- return data.indexOfName(value);
- }) : data.indexOfName(payload.name);
- }
- }
- function makeInner() {
-
- var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
- return function (hostObj) {
- return hostObj[key] || (hostObj[key] = {});
- };
- }
- var innerUniqueIndex = 0;
- function parseFinder(ecModel, finder, opt) {
- if (zrUtil.isString(finder)) {
- var obj = {};
- obj[finder + 'Index'] = 0;
- finder = obj;
- }
- var defaultMainType = opt && opt.defaultMainType;
- if (defaultMainType && !has(finder, defaultMainType + 'Index') && !has(finder, defaultMainType + 'Id') && !has(finder, defaultMainType + 'Name')) {
- finder[defaultMainType + 'Index'] = 0;
- }
- var result = {};
- each(finder, function (value, key) {
- var value = finder[key];
- if (key === 'dataIndex' || key === 'dataIndexInside') {
- result[key] = value;
- return;
- }
- var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
- var mainType = parsedKey[1];
- var queryType = (parsedKey[2] || '').toLowerCase();
- if (!mainType || !queryType || value == null || queryType === 'index' && value === 'none' || opt && opt.includeMainTypes && zrUtil.indexOf(opt.includeMainTypes, mainType) < 0) {
- return;
- }
- var queryParam = {
- mainType: mainType
- };
- if (queryType !== 'index' || value !== 'all') {
- queryParam[queryType] = value;
- }
- var models = ecModel.queryComponents(queryParam);
- result[mainType + 'Models'] = models;
- result[mainType + 'Model'] = models[0];
- });
- return result;
- }
- function has(obj, prop) {
- return obj && obj.hasOwnProperty(prop);
- }
- function setAttribute(dom, key, value) {
- dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
- }
- function getAttribute(dom, key) {
- return dom.getAttribute ? dom.getAttribute(key) : dom[key];
- }
- function getTooltipRenderMode(renderModeOption) {
- if (renderModeOption === 'auto') {
-
- return env.domSupported ? 'html' : 'richText';
- } else {
- return renderModeOption || 'html';
- }
- }
- function groupData(array, getKey) {
- var buckets = zrUtil.createHashMap();
- var keys = [];
- zrUtil.each(array, function (item) {
- var key = getKey(item);
- (buckets.get(key) || (keys.push(key), buckets.set(key, []))).push(item);
- });
- return {
- keys: keys,
- buckets: buckets
- };
- }
- exports.normalizeToArray = normalizeToArray;
- exports.defaultEmphasis = defaultEmphasis;
- exports.TEXT_STYLE_OPTIONS = TEXT_STYLE_OPTIONS;
- exports.getDataItemValue = getDataItemValue;
- exports.isDataItemOption = isDataItemOption;
- exports.mappingToExists = mappingToExists;
- exports.makeIdAndName = makeIdAndName;
- exports.isNameSpecified = isNameSpecified;
- exports.isIdInner = isIdInner;
- exports.compressBatches = compressBatches;
- exports.queryDataIndex = queryDataIndex;
- exports.makeInner = makeInner;
- exports.parseFinder = parseFinder;
- exports.setAttribute = setAttribute;
- exports.getAttribute = getAttribute;
- exports.getTooltipRenderMode = getTooltipRenderMode;
- exports.groupData = groupData;
|