Skip to content

Commit eae3f7e

Browse files
committed
Add hovel label color tests
1 parent 2a1e017 commit eae3f7e

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

test/jasmine/tests/gl2d_click_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,53 @@ describe('Test hover and click interactions', function() {
292292
.then(done, done.fail);
293293
});
294294

295+
it('@gl should use the per-point marker color for the hover label', async () => {
296+
await Plotly.newPlot(
297+
gd,
298+
[
299+
{
300+
type: 'scattergl',
301+
mode: 'markers',
302+
x: [1, 2, 3],
303+
y: [1, 2, 3],
304+
marker: {
305+
color: ['#1767C2', '#FF4136', '#2ECC40'],
306+
size: 20
307+
}
308+
}
309+
],
310+
{
311+
hovermode: 'closest',
312+
width: 400,
313+
height: 400,
314+
xaxis: { showspikes: true },
315+
yaxis: { showspikes: true }
316+
}
317+
);
318+
319+
Plotly.Fx.hover(gd, { xval: 2, yval: 2 }, 'xy');
320+
Lib.clearThrottle();
321+
322+
const withArray = d3Select('g.hovertext path').node();
323+
expect(window.getComputedStyle(withArray).fill).toBe('rgb(255, 65, 54)', 'color array');
324+
325+
const spikeStrokes = Array.from(document.querySelectorAll('line.spikeline')).map(
326+
(line) => window.getComputedStyle(line).stroke
327+
);
328+
expect(spikeStrokes.filter((stroke) => stroke === 'rgb(255, 65, 54)').length).toBe(2, 'spikelines');
329+
330+
await Plotly.restyle(gd, {
331+
'marker.color': [[0, 5, 10]],
332+
'marker.colorscale': 'Viridis'
333+
});
334+
335+
Plotly.Fx.hover(gd, { xval: 2, yval: 2 }, 'xy');
336+
Lib.clearThrottle();
337+
338+
const withColorscale = d3Select('g.hovertext path').node();
339+
expect(window.getComputedStyle(withColorscale).fill).toBe('rgb(33, 145, 140)', 'colorscale');
340+
});
341+
295342
it('@gl should show correct label for scattergl when hovertext is set', function(done) {
296343
var _mock = Lib.extendDeep({}, mock1);
297344
_mock.data[0].hovertext = 'text';

test/jasmine/tests/quiver_test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,41 @@ describe('Test quiver interactions', function() {
270270
.then(done, done.fail);
271271
});
272272

273+
it('should use the per-point arrow color for the hover label', async () => {
274+
const fig = {
275+
data: [
276+
{
277+
type: 'quiver',
278+
x: [1, 2, 3],
279+
y: [1, 2, 3],
280+
u: [1, 0, -1],
281+
v: [0, 1, 0],
282+
marker: {
283+
color: [0, 5, 10],
284+
colorscale: 'Viridis',
285+
showscale: false
286+
}
287+
}
288+
],
289+
layout: {
290+
margin: { l: 0, t: 0, r: 0, b: 0 },
291+
width: 400,
292+
height: 400
293+
}
294+
};
295+
296+
await Plotly.newPlot(gd, fig);
297+
298+
mouseEvent('mousemove', 200, 200);
299+
await delay(20)();
300+
301+
const label = document.querySelector('g.hovertext path');
302+
const arrow = gd.querySelectorAll('g.trace.quiver path.js-line')[1];
303+
304+
expect(window.getComputedStyle(label).fill).toBe('rgb(33, 145, 140)', 'hover label');
305+
expect(window.getComputedStyle(arrow).stroke).toBe('rgb(33, 145, 140)', 'arrow');
306+
});
307+
273308
it('should render multiple quiver traces', function(done) {
274309
Plotly.newPlot(gd, [{
275310
type: 'quiver',
@@ -344,4 +379,3 @@ describe('Test quiver interactions', function() {
344379
.then(done, done.fail);
345380
});
346381
});
347-

0 commit comments

Comments
 (0)