UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

61 lines (60 loc) 1.77 kB
import { map, isString, createHashMap, isObject } from "../../../zrender/lib/core/util.mjs"; var uidBase = 0; var OrdinalMeta = function() { function OrdinalMeta2(opt) { this.categories = opt.categories || []; this._needCollect = opt.needCollect; this._deduplication = opt.deduplication; this.uid = ++uidBase; } OrdinalMeta2.createByAxisModel = function(axisModel) { var option = axisModel.option; var data = option.data; var categories = data && map(data, getName); return new OrdinalMeta2({ categories, needCollect: !categories, deduplication: option.dedplication !== false }); }; OrdinalMeta2.prototype.getOrdinal = function(category) { return this._getOrCreateMap().get(category); }; OrdinalMeta2.prototype.parseAndCollect = function(category) { var index; var needCollect = this._needCollect; if (!isString(category) && !needCollect) { return category; } if (needCollect && !this._deduplication) { index = this.categories.length; this.categories[index] = category; return index; } var map2 = this._getOrCreateMap(); index = map2.get(category); if (index == null) { if (needCollect) { index = this.categories.length; this.categories[index] = category; map2.set(category, index); } else { index = NaN; } } return index; }; OrdinalMeta2.prototype._getOrCreateMap = function() { return this._map || (this._map = createHashMap(this.categories)); }; return OrdinalMeta2; }(); function getName(obj) { if (isObject(obj) && obj.value != null) { return obj.value; } else { return obj + ""; } } var OrdinalMeta$1 = OrdinalMeta; export { OrdinalMeta$1 as default };