Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
add tests for layout.showarrow
  • Loading branch information
emilykl committed Jul 22, 2025
commit 60f57188630312bfd0d2e2db66da2174a8b181c0
97 changes: 97 additions & 0 deletions test/jasmine/tests/hover_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7038,3 +7038,100 @@ describe('hover on traces with (x|y)hoverformat', function() {
.then(done, done.fail);
});
});

describe('hoverlabel.showarrow', function() {
'use strict';

var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

function _hover(x, y) {
mouseEvent('mousemove', x, y);
Lib.clearThrottle();
}

function getHoverPath() {
var hoverLabels = d3SelectAll('g.hovertext');
if (hoverLabels.size() === 0) return null;
return hoverLabels.select('path').attr('d');
}

it('should show hover arrow by default', function(done) {
Plotly.newPlot(gd, [{
x: [1, 2, 3],
y: [1, 2, 1],
type: 'scatter',
mode: 'markers'
}], {
width: 400,
height: 400,
margin: {l: 50, t: 50, r: 50, b: 50}
})
.then(function() {
_hover(200, 200); // Hover over middle point
})
.then(delay(HOVERMINTIME * 1.1))
.then(function() {
var pathD = getHoverPath();
expect(pathD).not.toBeNull('hover path should exist');
// Arrow paths contain 'L' commands for the triangular pointer
expect(pathD).toMatch(/M0,0L/, 'path should contain arrow (L command from origin)');
})
.then(done, done.fail);
});

it('should hide hover arrow when showarrow is false', function(done) {
Plotly.newPlot(gd, [{
x: [1, 2, 3],
y: [1, 2, 1],
type: 'scatter',
mode: 'markers'
}], {
width: 400,
height: 400,
margin: {l: 50, t: 50, r: 50, b: 50},
hoverlabel: { showarrow: false }
})
.then(function() {
_hover(200, 200); // Hover over middle point
})
.then(delay(HOVERMINTIME * 1.1))
.then(function() {
var pathD = getHoverPath();
expect(pathD).not.toBeNull('hover path should exist');
// No-arrow paths should be simple rectangles (no 'L' commands from origin)
expect(pathD).not.toMatch(/M0,0L/, 'path should not contain arrow');
expect(pathD).toMatch(/^M-/, 'path should start with rectangle (M- for left edge)');
})
.then(done, done.fail);
});

it('should work at trace level', function(done) {
Plotly.newPlot(gd, [{
x: [1, 2, 3],
y: [1, 2, 1],
type: 'scatter',
mode: 'markers',
hoverlabel: { showarrow: false }
}], {
width: 400,
height: 400,
margin: {l: 50, t: 50, r: 50, b: 50}
})
.then(function() {
_hover(200, 200); // Hover over middle point
})
.then(delay(HOVERMINTIME * 1.1))
.then(function() {
var pathD = getHoverPath();
expect(pathD).not.toBeNull('hover path should exist');
expect(pathD).not.toMatch(/M0,0L/, 'trace-level showarrow:false should hide arrow');
})
.then(done, done.fail);
});
});