Skip to content

Commit b5da4fb

Browse files
committed
try to reinvent what r means for type: 'category' axes
1 parent a0f8333 commit b5da4fb

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

src/plots/cartesian/axes.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) {
114114

115115
if(ax.type === 'category') {
116116
// if position is given as a category name, convert it to a number
117-
if(typeof pos === 'string' && (ax._categories || []).length) {
118-
newPos = ax._categories.indexOf(pos);
119-
containerOut[attr] = (newPos === -1) ? dflt : newPos;
117+
if(typeof pos === 'string' && pos !== '') {
118+
containerOut[attr] = pos;
120119
return;
121120
}
122121
}

src/plots/cartesian/set_convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ module.exports = function setConvert(ax, fullLayout) {
238238

239239
ax.d2p = function(v) { return ax.l2p(getCategoryIndex(v)); };
240240
ax.p2d = function(px) { return getCategoryName(p2l(px)); };
241-
ax.r2p = ax.l2p;
241+
ax.r2p = ax.d2p;
242242
ax.p2r = p2l;
243243
}
244244

src/plots/plots.js

+3-21
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ plots.doCalcdata = function(gd, traces) {
20322032
}
20332033
}
20342034

2035-
var hasCategoryAxis = initCategories(axList);
2035+
initCategories(axList);
20362036

20372037
var hasCalcTransform = false;
20382038

@@ -2101,25 +2101,11 @@ plots.doCalcdata = function(gd, traces) {
21012101
}
21022102

21032103
Registry.getComponentMethod('fx', 'calc')(gd);
2104-
2105-
// To handle the case of components using category names as coordinates, we
2106-
// need to re-supply defaults for these objects now, after calc has
2107-
// finished populating the category mappings
2108-
// Any component that uses `Axes.coercePosition` falls into this category
2109-
if(hasCategoryAxis) {
2110-
var dataReferencedComponents = ['annotations', 'shapes', 'images'];
2111-
for(i = 0; i < dataReferencedComponents.length; i++) {
2112-
Registry.getComponentMethod(dataReferencedComponents[i], 'supplyLayoutDefaults')(
2113-
gd.layout, fullLayout, fullData);
2114-
}
2115-
}
21162104
};
21172105

2106+
// initialize the category list, if there is one, so we start over
2107+
// to be filled in later by ax.d2c
21182108
function initCategories(axList) {
2119-
var hasCategoryAxis = false;
2120-
2121-
// initialize the category list, if there is one, so we start over
2122-
// to be filled in later by ax.d2c
21232109
for(var i = 0; i < axList.length; i++) {
21242110
axList[i]._categories = axList[i]._initialCategories.slice();
21252111

@@ -2128,11 +2114,7 @@ function initCategories(axList) {
21282114
for(var j = 0; j < axList[i]._categories.length; j++) {
21292115
axList[i]._categoriesMap[axList[i]._categories[j]] = j;
21302116
}
2131-
2132-
if(axList[i].type === 'category') hasCategoryAxis = true;
21332117
}
2134-
2135-
return hasCategoryAxis;
21362118
}
21372119

21382120
plots.rehover = function(gd) {

0 commit comments

Comments
 (0)