MCPcopy Index your code
hub / github.com/apache/echarts / parseAndCollect

Method parseAndCollect

src/data/OrdinalMeta.ts:98–142  ·  view source on GitHub ↗

* @return The ordinal. If not found, return NaN.

(category: OrdinalRawValue | OrdinalNumber)

Source from the content-addressed store, hash-verified

96 * @return The ordinal. If not found, return NaN.
97 */
98 parseAndCollect(category: OrdinalRawValue | OrdinalNumber): OrdinalNumber {
99 let index;
100 const needCollect = this._needCollect;
101
102 // The value of category dim can be the index of the given category set.
103 // This feature is only supported when !needCollect, because we should
104 // consider a common case: a value is 2017, which is a number but is
105 // expected to be tread as a category. This case usually happen in dataset,
106 // where it happent to be no need of the index feature.
107 if (!isString(category) && !needCollect) {
108 return category;
109 }
110
111 // Optimize for the scenario:
112 // category is ['2012-01-01', '2012-01-02', ...], where the input
113 // data has been ensured not duplicate and is large data.
114 // Notice, if a dataset dimension provide categroies, usually echarts
115 // should remove duplication except user tell echarts dont do that
116 // (set axis.deduplication = false), because echarts do not know whether
117 // the values in the category dimension has duplication (consider the
118 // parallel-aqi example)
119 if (needCollect && !this._deduplication) {
120 index = this.categories.length;
121 this.categories[index] = category;
122 this._onCollect && this._onCollect(category, index);
123 return index;
124 }
125
126 const map = this._getOrCreateMap();
127 index = map.get(category);
128
129 if (index == null) {
130 if (needCollect) {
131 index = this.categories.length;
132 this.categories[index] = category;
133 map.set(category, index);
134 this._onCollect && this._onCollect(category, index);
135 }
136 else {
137 index = NaN;
138 }
139 }
140
141 return index;
142 }
143
144 // Consider big data, do not create map until needed.
145 private _getOrCreateMap(): HashMap<OrdinalNumber> {

Callers 1

collectOrdinalMetaMethod · 0.80

Calls 2

_getOrCreateMapMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected