Skip to content

Commit f180c79

Browse files
committed
categorical 2dmap: do not use indexOf to find trace-level category mapping
1 parent 4d4b0b7 commit f180c79

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/traces/heatmap/clean_2d_array.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,20 @@ module.exports = function clean2dArray(zOld, trace, xa, ya) {
3333
}
3434

3535
var padOld2new = function(zOld, i, j) {
36-
if(i === undefined || j === undefined) return undefined;
36+
if(i === BADNUM || j === BADNUM) return BADNUM;
3737
return old2new(zOld, i, j);
3838
};
3939

4040
function axisMapping(ax) {
4141
if(trace && trace.type !== 'carpet' && trace.type !== 'contourcarpet' &&
4242
ax && ax.type === 'category' && trace['_' + ax._id.charAt(0)].length) {
4343
var axLetter = ax._id.charAt(0);
44-
var axMapping = [];
45-
for(i = 0; i < ax._categories.length; i++) {
46-
axMapping.push((trace['_' + axLetter + 'Map'] || trace[axLetter]).indexOf(ax._categories[i]));
44+
var axMapping = {};
45+
var traceCategories = trace['_' + axLetter + 'CategoryMap'] || trace[axLetter];
46+
for(i = 0; i < traceCategories.length; i++) {
47+
axMapping[traceCategories[i]] = i;
4748
}
48-
return function(i) {return axMapping[i] === -1 ? BADNUM : axMapping[i];};
49+
return function(i) {return axMapping.hasOwnProperty(ax._categories[i]) ? axMapping[ax._categories[i]] : BADNUM;};
4950
} else {
5051
return Lib.identity;
5152
}

src/traces/heatmap/convert_column_xyz.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
6767
if(hasColumnHoverText) trace._hovertext = hovertext;
6868

6969
if(ax1 && ax1.type === 'category') {
70-
trace['_' + var1Name + 'Map'] = col1vals.map(function(v) { return ax1._categories[v];});
70+
trace['_' + var1Name + 'CategoryMap'] = col1vals.map(function(v) { return ax1._categories[v];});
7171
}
7272

7373
if(ax2 && ax2.type === 'category') {
74-
trace['_' + var2Name + 'Map'] = col2vals.map(function(v) { return ax2._categories[v];});
74+
trace['_' + var2Name + 'CategoryMap'] = col2vals.map(function(v) { return ax2._categories[v];});
7575
}
7676
};

0 commit comments

Comments
 (0)