Skip to content

Commit b2fa5d5

Browse files
committed
attempt making test pass
- category d2r shouldn't add new categories
1 parent c135e09 commit b2fa5d5

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

src/components/annotations/click.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,22 @@ function getToggleSets(gd, hoverData) {
8383
explicitOffSet = [],
8484
hoverLen = (hoverData || []).length;
8585

86-
var i, j, anni, showMode, pointj, toggleType;
86+
var i, j, anni, showMode, pointj, xa, ya, toggleType;
8787

8888
for(i = 0; i < annotations.length; i++) {
8989
anni = annotations[i];
9090
showMode = anni.clicktoshow;
91+
9192
if(showMode) {
9293
for(j = 0; j < hoverLen; j++) {
9394
pointj = hoverData[j];
94-
if(pointj.xaxis._id === anni.xref &&
95-
pointj.yaxis._id === anni.yref &&
96-
pointj.xaxis.d2r(pointj.x) === anni._xclick &&
97-
pointj.yaxis.d2r(pointj.y) === anni._yclick
95+
xa = pointj.xaxis;
96+
ya = pointj.yaxis;
97+
98+
if(xa._id === anni.xref &&
99+
ya._id === anni.yref &&
100+
xa.d2r(pointj.x) === clickData2r(anni._xclick, xa) &&
101+
ya.d2r(pointj.y) === clickData2r(anni._yclick, ya)
98102
) {
99103
// match! toggle this annotation
100104
// regardless of its clicktoshow mode
@@ -121,3 +125,8 @@ function getToggleSets(gd, hoverData) {
121125

122126
return {on: onSet, off: offSet, explicitOff: explicitOffSet};
123127
}
128+
129+
// to handle log axes until v2
130+
function clickData2r(d, ax) {
131+
return ax.type === 'log' ? ax.l2r(d) : ax.d2r(d);
132+
}

src/plots/cartesian/axes.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
100100
* - for other types: coerce them to numbers
101101
*/
102102
axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) {
103-
var pos,
104-
newPos;
103+
var pos;
105104

106105
if(axRef === 'paper' || axRef === 'pixel') {
107106
pos = coerce(attr, dflt);

src/plots/cartesian/set_convert.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ module.exports = function setConvert(ax, fullLayout) {
152152
if(index !== undefined) return index;
153153
}
154154

155-
if(typeof v === 'number') { return v; }
155+
if(isNumeric(v)) return +v;
156156
}
157157

158158
function l2p(v) {
@@ -224,17 +224,17 @@ module.exports = function setConvert(ax, fullLayout) {
224224
ax.p2d = ax.p2r = function(px, r, calendar) { return ms2dt(p2l(px), r, calendar); };
225225
}
226226
else if(ax.type === 'category') {
227-
// d is categories; r, c, and l are indices
228-
// TODO: should r accept category names too?
229-
// ie r2c and r2l would be getCategoryIndex (and r2p would change)
227+
// d is categories (string)
228+
// c and l are indices (numbers)
229+
// r is categories or numbers
230230

231-
ax.d2r = ax.d2c = ax.d2l = setCategoryIndex;
231+
ax.d2c = ax.d2l = setCategoryIndex;
232232
ax.r2d = ax.c2d = ax.l2d = getCategoryName;
233233

234-
// special d2l variant that won't add categories
235-
ax.d2l_noadd = getCategoryIndex;
234+
ax.d2r = ax.d2l_noadd = getCategoryIndex;
236235

237-
ax.r2l = ax.l2r = ax.r2c = ax.c2r = num;
236+
ax.l2r = ax.r2c = ax.c2r = num;
237+
ax.r2l = getCategoryIndex;
238238

239239
ax.d2p = function(v) { return ax.l2p(getCategoryIndex(v)); };
240240
ax.p2d = function(px) { return getCategoryName(p2l(px)); };

src/traces/heatmap/calc.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ module.exports = function calc(gd, trace) {
5757
z = binned.z;
5858
}
5959
else {
60-
if(hasColumns(trace)) convertColumnData(trace, xa, ya, 'x', 'y', ['z']);
60+
if(hasColumns(trace)) {
61+
convertColumnData(trace, xa, ya, 'x', 'y', ['z']);
62+
x = trace.x;
63+
y = trace.y;
64+
} else {
65+
x = trace.x ? xa.makeCalcdata(trace, 'x') : [];
66+
y = trace.y ? ya.makeCalcdata(trace, 'y') : [];
67+
}
6168

62-
x = trace.x ? xa.makeCalcdata(trace, 'x') : [];
63-
y = trace.y ? ya.makeCalcdata(trace, 'y') : [];
6469
x0 = trace.x0 || 0;
6570
dx = trace.dx || 1;
6671
y0 = trace.y0 || 0;

0 commit comments

Comments
 (0)