* Work for data like [{name: ..., value: ...}, ...]. * * @return encode Never be `null/undefined`.
(seriesModel, source, dimCount)
| 17567 | */ |
| 17568 | |
| 17569 | function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) { |
| 17570 | var encode = {}; |
| 17571 | var datasetModel = querySeriesUpstreamDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur. |
| 17572 | |
| 17573 | if (!datasetModel) { |
| 17574 | return encode; |
| 17575 | } |
| 17576 | |
| 17577 | var sourceFormat = source.sourceFormat; |
| 17578 | var dimensionsDefine = source.dimensionsDefine; |
| 17579 | var potentialNameDimIndex; |
| 17580 | |
| 17581 | if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) { |
| 17582 | each(dimensionsDefine, function (dim, idx) { |
| 17583 | if ((isObject(dim) ? dim.name : dim) === 'name') { |
| 17584 | potentialNameDimIndex = idx; |
| 17585 | } |
| 17586 | }); |
| 17587 | } |
| 17588 | |
| 17589 | var idxResult = function () { |
| 17590 | var idxRes0 = {}; |
| 17591 | var idxRes1 = {}; |
| 17592 | var guessRecords = []; // 5 is an experience value. |
| 17593 | |
| 17594 | for (var i = 0, len = Math.min(5, dimCount); i < len; i++) { |
| 17595 | var guessResult = doGuessOrdinal(source.data, sourceFormat, source.seriesLayoutBy, dimensionsDefine, source.startIndex, i); |
| 17596 | guessRecords.push(guessResult); |
| 17597 | var isPureNumber = guessResult === BE_ORDINAL.Not; // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim, |
| 17598 | // and then find a name dim with the priority: |
| 17599 | // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself". |
| 17600 | |
| 17601 | if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) { |
| 17602 | idxRes0.v = i; |
| 17603 | } |
| 17604 | |
| 17605 | if (idxRes0.n == null || idxRes0.n === idxRes0.v || !isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) { |
| 17606 | idxRes0.n = i; |
| 17607 | } |
| 17608 | |
| 17609 | if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) { |
| 17610 | return idxRes0; |
| 17611 | } // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not), |
| 17612 | // find the first BE_ORDINAL.Might as the value dim, |
| 17613 | // and then find a name dim with the priority: |
| 17614 | // "other dim" > "the value dim itself". |
| 17615 | // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be |
| 17616 | // treated as number. |
| 17617 | |
| 17618 | |
| 17619 | if (!isPureNumber) { |
| 17620 | if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) { |
| 17621 | idxRes1.v = i; |
| 17622 | } |
| 17623 | |
| 17624 | if (idxRes1.n == null || idxRes1.n === idxRes1.v) { |
| 17625 | idxRes1.n = i; |
| 17626 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…