* Work for data like [{name: ..., value: ...}, ...]. * * @param {module:model/Series} seriesModel * @param {module:data/Source} source * @return {Object} encode Never be `null/undefined`.
(seriesModel, source, dimCount)
| 20988 | * @return {Object} encode Never be `null/undefined`. |
| 20989 | */ |
| 20990 | function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) { |
| 20991 | var encode = {}; |
| 20992 | |
| 20993 | var datasetModel = getDatasetModel(seriesModel); |
| 20994 | // Currently only make default when using dataset, util more reqirements occur. |
| 20995 | if (!datasetModel) { |
| 20996 | return encode; |
| 20997 | } |
| 20998 | |
| 20999 | var sourceFormat = source.sourceFormat; |
| 21000 | var dimensionsDefine = source.dimensionsDefine; |
| 21001 | |
| 21002 | var potentialNameDimIndex; |
| 21003 | if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) { |
| 21004 | each$1(dimensionsDefine, function (dim, idx) { |
| 21005 | if ((isObject$1(dim) ? dim.name : dim) === 'name') { |
| 21006 | potentialNameDimIndex = idx; |
| 21007 | } |
| 21008 | }); |
| 21009 | } |
| 21010 | |
| 21011 | // idxResult: {v, n}. |
| 21012 | var idxResult = (function () { |
| 21013 | |
| 21014 | var idxRes0 = {}; |
| 21015 | var idxRes1 = {}; |
| 21016 | var guessRecords = []; |
| 21017 | |
| 21018 | // 5 is an experience value. |
| 21019 | for (var i = 0, len = Math.min(5, dimCount); i < len; i++) { |
| 21020 | var guessResult = doGuessOrdinal( |
| 21021 | source.data, sourceFormat, source.seriesLayoutBy, |
| 21022 | dimensionsDefine, source.startIndex, i |
| 21023 | ); |
| 21024 | guessRecords.push(guessResult); |
| 21025 | var isPureNumber = guessResult === BE_ORDINAL.Not; |
| 21026 | |
| 21027 | // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim, |
| 21028 | // and then find a name dim with the priority: |
| 21029 | // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself". |
| 21030 | if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) { |
| 21031 | idxRes0.v = i; |
| 21032 | } |
| 21033 | if (idxRes0.n == null |
| 21034 | || (idxRes0.n === idxRes0.v) |
| 21035 | || (!isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) |
| 21036 | ) { |
| 21037 | idxRes0.n = i; |
| 21038 | } |
| 21039 | if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) { |
| 21040 | return idxRes0; |
| 21041 | } |
| 21042 | |
| 21043 | // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not), |
| 21044 | // find the first BE_ORDINAL.Might as the value dim, |
| 21045 | // and then find a name dim with the priority: |
| 21046 | // "other dim" > "the value dim itself". |
| 21047 | // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be |
nothing calls this directly
no test coverage detected