Skip to content

Commit e8941d6

Browse files
authored
Refactor the changes
1 parent b47c7af commit e8941d6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/plots/cartesian/set_convert.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,30 @@ module.exports = function setConvert(ax, fullLayout) {
126126
*/
127127
function setCategoryIndex(v) {
128128
if(v !== null && v !== undefined) {
129+
if (ax._categoriesMap === undefined)
130+
ax._categoriesMap = {};
129131

130-
if(ax._categoriesMap[v] === undefined) {
132+
if (ax._categoriesMap[v] !== undefined) {
133+
return ax._categoriesMap[v];
134+
} else {
131135
ax._categories.push(v);
132136

133137
var curLength = ax._categories.length - 1;
134138
ax._categoriesMap[v] = curLength;
135139

136140
return curLength;
137141
}
138-
return ax._categoriesMap[v];
139142
}
140143
return BADNUM;
141144
}
142145

143146
function getCategoryIndex(v) {
144147
// d2l/d2c variant that that won't add categories but will also
145148
// allow numbers to be mapped to the linearized axis positions
146-
var index = ax._categories.indexOf(v);
147-
if(index !== -1) return index;
149+
if(ax._categoriesMap)
150+
var index = ax._categoriesMap[v]?ax._categoriesMap:undefined;
151+
152+
if(index !== undefined) return index;
148153
if(typeof v === 'number') return v;
149154
}
150155

0 commit comments

Comments
 (0)