123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import { createHashMap, isObject, map, isString } from 'zrender/lib/core/util.js';
- var uidBase = 0;
- var OrdinalMeta = function () {
- function OrdinalMeta(opt) {
- this.categories = opt.categories || [];
- this._needCollect = opt.needCollect;
- this._deduplication = opt.deduplication;
- this.uid = ++uidBase;
- }
- 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: option.dedplication !== false
- });
- };
- ;
- OrdinalMeta.prototype.getOrdinal = function (category) {
-
- return this._getOrCreateMap().get(category);
- };
-
- OrdinalMeta.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 map = this._getOrCreateMap();
-
- 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;
- };
-
- OrdinalMeta.prototype._getOrCreateMap = function () {
- return this._map || (this._map = createHashMap(this.categories));
- };
- return OrdinalMeta;
- }();
- function getName(obj) {
- if (isObject(obj) && obj.value != null) {
- return obj.value;
- } else {
- return obj + '';
- }
- }
- export default OrdinalMeta;
|