123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- var _util = require("zrender/lib/core/util");
- var createHashMap = _util.createHashMap;
- var isObject = _util.isObject;
- var map = _util.map;
- function OrdinalMeta(opt) {
-
- this.categories = opt.categories || [];
-
- this._needCollect = opt.needCollect;
-
- this._deduplication = opt.deduplication;
-
- this._map;
- }
- 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
- });
- };
- var proto = OrdinalMeta.prototype;
- proto.getOrdinal = function (category) {
- return getOrCreateMap(this).get(category);
- };
- proto.parseAndCollect = function (category) {
- var index;
- var needCollect = this._needCollect;
-
-
-
-
- if (typeof category !== 'string' && !needCollect) {
- return category;
- }
-
-
-
-
-
-
-
- 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;
- };
- 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;
|