Skip to content

Commit

Permalink
refact(data): reverse the optimization of genName
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jul 23, 2021
1 parent c91d711 commit b785031
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/chart/helper/createSeriesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {getDimensionTypeByAxis} from '../../data/helper/dimensionHelper';
import {getDataItemValue} from '../../util/model';
import CoordinateSystem from '../../core/CoordinateSystem';
import {getCoordSysInfoBySeries} from '../../model/referHelper';
import { createSourceFromSeriesDataOption, isSourceInstance, Source } from '../../data/Source';
import { createSourceFromSeriesDataOption, Source } from '../../data/Source';
import {enableDataStack} from '../../data/helper/dataStackHelper';
import {makeSeriesEncodeForAxisCoordSys} from '../../data/helper/sourceHelper';
import {
Expand Down
32 changes: 13 additions & 19 deletions src/data/helper/createDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export default function createDimensions(
const resultItem = new SeriesDimensionDefine();
const userDimName = dimDefItem.name;
if (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.
resultItem.name = resultItem.displayName = userDimName;
}
dimDefItem.type != null && (resultItem.type = dimDefItem.type);
Expand All @@ -154,9 +157,6 @@ export default function createDimensions(
const userDimName = isObject(dimDefItemRaw) ? dimDefItemRaw.name : dimDefItemRaw;
// Name will be applied later for avoiding duplication.
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.
dataDimNameMap.set(userDimName, i);
}
}
Expand Down Expand Up @@ -249,7 +249,9 @@ export default function createDimensions(
applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
if (resultItem.name == null && sysDimItemDimsDef) {
let sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
!isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {name: sysDimItemDimsDefItem});
!isObject(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
name: sysDimItemDimsDefItem
});
resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
}
Expand All @@ -275,8 +277,6 @@ export default function createDimensions(
const fromZero = generateCoordCount != null;
generateCoordCount = generateCoord ? (generateCoordCount || 1) : 0;
const extra = generateCoord || 'value';
let coordDimNameAutoIdx = 0;
let dataDimNameAutoIdx = 0;

// Set dim `name` and other `coordDim` and other props.
if (!omitUnusedDimensions) {
Expand All @@ -285,11 +285,9 @@ export default function createDimensions(
const coordDim = resultItem.coordDim;

if (coordDim == null) {
const res = genName(
extra, coordDimNameMap, coordDimNameAutoIdx, fromZero
resultItem.coordDim = genName(
extra, coordDimNameMap, fromZero
);
coordDimNameAutoIdx = res.autoIdx;
resultItem.coordDim = res.name;
resultItem.coordDimIndex = 0;
// Series specified generateCoord is using out.
if (!generateCoord || generateCoordCount <= 0) {
Expand All @@ -299,11 +297,9 @@ export default function createDimensions(
}

if (resultItem.name == null) {
const res = genName(
resultItem.coordDim, dataDimNameMap, dataDimNameAutoIdx, false
resultItem.name = genName(
resultItem.coordDim, dataDimNameMap, false
);
resultItem.name = res.name;
dataDimNameAutoIdx = res.autoIdx;
}

if (resultItem.type == null
Expand Down Expand Up @@ -383,18 +379,16 @@ export function getDimCount(
function genName(
name: DimensionName,
map: HashMap<unknown, DimensionName>,
autoIdx: number,
fromZero: boolean
): { name: DimensionName, autoIdx: number } {
) {
const mapData = map.data;
if (fromZero || mapData.hasOwnProperty(name)) {
let i = autoIdx || 0;
let i = 0;
while (mapData.hasOwnProperty(name + i)) {
i++;
}
name += i;
autoIdx = i + 1;
}
map.set(name, true);
return { name, autoIdx };
return name;
}

0 comments on commit b785031

Please sign in to comment.