Skip to content

Commit 9b14795

Browse files
committed
Cartesian dropline support
Draw droplines to the x and y axes on hover if the option is enabled and we're not on 'compare' hovermode.
1 parent 2b24f9d commit 9b14795

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/components/dragelement/unhover.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ unhover.raw = function unhoverRaw(gd, evt) {
4141
}
4242

4343
fullLayout._hoverlayer.selectAll('g').remove();
44+
fullLayout._hoverlayer.selectAll('line').remove();
4445
gd._hoverdata = undefined;
4546

4647
if(evt.target && oldhoverdata) {

src/plot_api/plot_config.js

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ module.exports = {
4848
// new users see some hints about interactivity
4949
showTips: true,
5050

51+
// display droplines on cartesian graphs
52+
showDroplines: false,
53+
5154
// enable axis pan/zoom drag handles
5255
showAxisDragHandles: true,
5356

src/plots/cartesian/graph_interact.js

+43
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,16 @@ function hover(gd, evt, subplot) {
577577
container: fullLayout._hoverlayer,
578578
outerContainer: fullLayout._paperdiv
579579
};
580+
581+
if(gd._context.showDroplines) {
582+
var droplineOpts = {
583+
hovermode: hovermode,
584+
container: fullLayout._hoverlayer,
585+
outerContainer: fullLayout._paperdiv
586+
};
587+
createDroplines(hoverData, droplineOpts);
588+
}
589+
580590
var hoverLabels = createHoverText(hoverData, labelOpts);
581591

582592
hoverAvoidOverlaps(hoverData, rotateLabels ? 'xa' : 'ya');
@@ -818,8 +828,41 @@ fx.loneUnhover = function(containerOrSelection) {
818828
d3.select(containerOrSelection);
819829

820830
selection.selectAll('g.hovertext').remove();
831+
selection.selectAll('line.dropline').remove();
821832
};
822833

834+
function createDroplines(hoverData, opts) {
835+
var hovermode = opts.hovermode,
836+
container = opts.container;
837+
838+
if(hovermode !== 'closest') return;
839+
var c0 = hoverData[0];
840+
var x = (c0.x0 + c0.x1) / 2;
841+
var y = (c0.y0 + c0.y1) / 2;
842+
var xOffset = c0.xa._offset;
843+
var yOffset = c0.ya._offset;
844+
container.selectAll('line.dropline').remove();
845+
container.append('line')
846+
.attr('x1', xOffset + (c0.ya.side === 'right' ? c0.xa._length : 0))
847+
.attr('x2', xOffset + x)
848+
.attr('y1', yOffset + y)
849+
.attr('y2', yOffset + y)
850+
.attr('stroke-width', 3)
851+
.attr('stroke', c0.color)
852+
.attr('stroke-dasharray', '5,5')
853+
.attr('class', 'dropline');
854+
855+
container.append('line')
856+
.attr('x1', xOffset + x)
857+
.attr('x2', xOffset + x)
858+
.attr('y1', yOffset + y)
859+
.attr('y2', yOffset + c0.ya._length)
860+
.attr('stroke-width', 3)
861+
.attr('stroke', c0.color)
862+
.attr('stroke-dasharray', '5,5')
863+
.attr('class', 'dropline');
864+
}
865+
823866
function createHoverText(hoverData, opts) {
824867
var hovermode = opts.hovermode,
825868
rotateLabels = opts.rotateLabels,

0 commit comments

Comments
 (0)