Skip to content

Commit

Permalink
fix: fix createDimension result might container name:undefined when d…
Browse files Browse the repository at this point in the history
…imensions more than 30.
  • Loading branch information
100pah committed Aug 11, 2021
1 parent 2bf188f commit 10aed78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/data/helper/createDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default function createDimensions(
const dimDefItem = isObject(dimDefItemRaw) ? dimDefItemRaw : { name: dimDefItemRaw };
const resultItem = new SeriesDimensionDefine();
const userDimName = dimDefItem.name;
if (dataDimNameMap.get(userDimName) != null) {
if (userDimName != null && dataDimNameMap.get(userDimName) != null) {
// Only if `series.dimensions` is defined in option
// displayName, will be set, and dimension will be diplayed vertically in
// tooltip by default.
Expand Down Expand Up @@ -278,6 +278,13 @@ export default function createDimensions(
generateCoordCount = generateCoord ? (generateCoordCount || 1) : 0;
const extra = generateCoord || 'value';

function ifNoNameFillWithCoordName(resultItem: SeriesDimensionDefine): void {
if (resultItem.name == null) {
// Duplication will be removed in the next step.
resultItem.name = resultItem.coordDim;
}
}

// Set dim `name` and other `coordDim` and other props.
if (!omitUnusedDimensions) {
for (let resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
Expand All @@ -298,10 +305,7 @@ export default function createDimensions(
generateCoordCount--;
}

if (resultItem.name == null) {
// Duplication will be removed in the next step.
resultItem.name = resultItem.coordDim;
}
ifNoNameFillWithCoordName(resultItem);

if (resultItem.type == null
&& (
Expand Down Expand Up @@ -331,15 +335,17 @@ export default function createDimensions(
return removeDuplication(result);
}
else {
// Sort dimensions
const toSort = [];
// Sort dimensions: there are some rule that use the last dim as label.
const sortedResult: SeriesDimensionDefine[] = [];
for (let i = 0; i < indicesMap.length; i++) {
if (indicesMap[i] >= 0) {
toSort.push({ i, o: result[indicesMap[i]]});
const resultItem = result[indicesMap[i]];
// PENDING: guessOrdinal or let user specify type: 'ordinal' manually?
ifNoNameFillWithCoordName(resultItem);
sortedResult.push(resultItem);
}
}
toSort.sort((a, b) => a.i - b.i);
return removeDuplication(map(toSort, item => item.o));
return removeDuplication(sortedResult);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/data/helper/sourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
querySeriesUpstreamDatasetModel, queryDatasetUpstreamDatasetModels
} from './sourceHelper';
import { applyDataTransform } from './transform';
import DataStorage, { DataStorageDimensionDefine, DataStorageDimensionType } from '../DataStorage';
import DataStorage, { DataStorageDimensionDefine } from '../DataStorage';
import { DefaultDataProvider } from './dataProvider';
import SeriesDimensionDefine from '../SeriesDimensionDefine';
import WeakMap from 'zrender/src/core/WeakMap';
Expand Down

0 comments on commit 10aed78

Please sign in to comment.