Skip to content

Commit ffd56c7

Browse files
committed
fix and test hoveron=fills for scatterternary
1 parent 5552c77 commit ffd56c7

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/traces/scatterternary/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ module.exports = {
117117
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
118118
flags: ['a', 'b', 'c', 'text', 'name']
119119
}),
120+
hoveron: scatterAttrs.hoveron,
120121
_nestedModules: {
121122
'marker.colorbar': 'Colorbar'
122123
}

src/traces/scatterternary/defaults.js

+8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8181
handleTextDefaults(traceIn, traceOut, layout, coerce);
8282
}
8383

84+
var dfltHoverOn = '';
85+
8486
if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {
8587
coerce('marker.maxdisplayed');
88+
dfltHoverOn = 'points';
8689
}
8790

8891
coerce('fill');
@@ -92,4 +95,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
9295
}
9396

9497
coerce('hoverinfo', (layout._dataLength === 1) ? 'a+b+c+text' : undefined);
98+
99+
if(!dfltHoverOn && (traceOut.fill === 'tonext' || traceOut.fill === 'toself')) {
100+
dfltHoverOn = 'fills';
101+
}
102+
coerce('hoveron', dfltHoverOn || 'points');
95103
};

src/traces/scatterternary/hover.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
1717
var scatterPointData = scatterHover(pointData, xval, yval, hovermode);
1818
if(!scatterPointData || scatterPointData[0].index === false) return;
1919

20+
// if hoveron='fills', we don't show any point data so the label is
21+
// unchanged from what scatter gives us.
22+
if(scatterPointData[0].index === undefined) return scatterPointData;
23+
2024
var newPointData = scatterPointData[0],
2125
cdi = newPointData.cd[newPointData.index];
2226

test/jasmine/tests/hover_label_test.js

+13
Original file line numberDiff line numberDiff line change
@@ -690,4 +690,17 @@ describe('hover on fill', function() {
690690
return assertLabelsCorrect([155, 260], [160.325, 248.1], 'trace 0');
691691
}).then(done);
692692
});
693+
694+
it('should work for scatterternary too', function(done) {
695+
var mock = require('@mocks/ternary_fill.json');
696+
mock.data.forEach(function(trace) { trace.hoveron = 'fills'; });
697+
698+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(function() {
699+
return assertLabelsCorrect([245, 171], [249.7, 166], 'trace 2');
700+
}).then(function() {
701+
return assertLabelsCorrect([245, 226], [268.75, 265], 'trace 1');
702+
}).then(function() {
703+
return assertLabelsCorrect([245, 259], [249.7, 254], 'trace 0');
704+
}).then(done);
705+
});
693706
});

0 commit comments

Comments
 (0)