MCPcopy
hub / github.com/apache/echarts / makeSeriesEncodeForNameBased

Function makeSeriesEncodeForNameBased

src/data/helper/sourceHelper.ts:192–284  ·  view source on GitHub ↗
(
    seriesModel: SeriesModel,
    source: Source,
    dimCount: number
)

Source from the content-addressed store, hash-verified

190 * @return encode Never be `null/undefined`.
191 */
192export function makeSeriesEncodeForNameBased(
193 seriesModel: SeriesModel,
194 source: Source,
195 dimCount: number
196): SeriesEncodeInternal {
197 const encode: SeriesEncodeInternal = {};
198
199 const datasetModel = querySeriesUpstreamDatasetModel(seriesModel);
200 // Currently only make default when using dataset, util more reqirements occur.
201 if (!datasetModel) {
202 return encode;
203 }
204
205 const sourceFormat = source.sourceFormat;
206 const dimensionsDefine = source.dimensionsDefine;
207
208 let potentialNameDimIndex;
209 if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
210 each(dimensionsDefine, function (dim, idx) {
211 if ((isObject(dim) ? dim.name : dim) === 'name') {
212 potentialNameDimIndex = idx;
213 }
214 });
215 }
216
217 type IdxResult = { v: number, n: number };
218
219 const idxResult = (function () {
220
221 const idxRes0 = {} as IdxResult;
222 const idxRes1 = {} as IdxResult;
223 const guessRecords = [];
224
225 // 5 is an experience value.
226 for (let i = 0, len = Math.min(5, dimCount); i < len; i++) {
227 const guessResult = doGuessOrdinal(
228 source.data, sourceFormat, source.seriesLayoutBy,
229 dimensionsDefine, source.startIndex, i
230 );
231 guessRecords.push(guessResult);
232 const isPureNumber = guessResult === BE_ORDINAL.Not;
233
234 // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
235 // and then find a name dim with the priority:
236 // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
237 if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
238 idxRes0.v = i;
239 }
240 if (idxRes0.n == null
241 || (idxRes0.n === idxRes0.v)
242 || (!isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not)
243 ) {
244 idxRes0.n = i;
245 }
246 if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
247 return idxRes0;
248 }
249

Callers

nothing calls this directly

Calls 5

doGuessOrdinalFunction · 0.85
fulfilledFunction · 0.85
eachFunction · 0.50
isObjectFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…