Skip to content

Commit 9217db4

Browse files
committed
handle end edge case
1 parent df6353d commit 9217db4

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/traces/scatter/hover.js

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
112112
hovertemplate: trace.hovertemplate
113113
});
114114

115+
if(trace.xperiodalignment === 'end') pointData.xPeriod = di.x;
116+
if(trace.yperiodalignment === 'end') pointData.yPeriod = di.y;
117+
115118
fillText(di, trace, pointData);
116119
Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);
117120

src/traces/scattergl/hover.js

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ function calcHover(pointData, x, y, trace) {
202202
hovertemplate: di.ht
203203
});
204204

205+
if(trace.xperiodalignment === 'end') pointData2.xPeriod = di.x;
206+
if(trace.yperiodalignment === 'end') pointData2.yPeriod = di.y;
207+
205208
if(di.htx) pointData2.text = di.htx;
206209
else if(di.tx) pointData2.text = di.tx;
207210
else if(trace.text) pointData2.text = trace.text;

test/jasmine/tests/hover_label_test.js

+58
Original file line numberDiff line numberDiff line change
@@ -5393,6 +5393,64 @@ describe('hovermode: (x|y)unified', function() {
53935393
});
53945394
});
53955395

5396+
['scatter', 'scattergl'].forEach(function(scatterType) {
5397+
it(scatterType + ' period points alignments (all end edge case)', function(done) {
5398+
Plotly.newPlot(gd, {
5399+
data: [
5400+
{
5401+
name: 'bar',
5402+
type: 'bar',
5403+
x: ['2000-01', '2000-02'],
5404+
y: [1, 2],
5405+
xhoverformat: '%b',
5406+
xperiod: 'M1',
5407+
xperiodalignment: 'end'
5408+
},
5409+
{
5410+
name: 'start',
5411+
type: scatterType,
5412+
x: ['2000-01', '2000-02'],
5413+
y: [1, 2],
5414+
xhoverformat: '%b',
5415+
xperiod: 'M1',
5416+
xperiodalignment: 'end'
5417+
},
5418+
{
5419+
name: 'end',
5420+
type: scatterType,
5421+
x: ['2000-01', '2000-02'],
5422+
y: [1, 2],
5423+
xhoverformat: '%b',
5424+
xperiod: 'M1',
5425+
xperiodalignment: 'end'
5426+
},
5427+
],
5428+
layout: {
5429+
showlegend: false,
5430+
width: 600,
5431+
height: 400,
5432+
hovermode: 'x unified'
5433+
}
5434+
})
5435+
.then(function(gd) {
5436+
_hover(gd, { xpx: 50, ypx: 200 });
5437+
assertLabel({title: 'Jan', items: [
5438+
'bar : 1',
5439+
'start : 1',
5440+
'end : 1',
5441+
]});
5442+
5443+
_hover(gd, { xpx: 350, ypx: 200 });
5444+
assertLabel({title: 'Feb', items: [
5445+
'bar : 2',
5446+
'start : 2',
5447+
'end : 2',
5448+
]});
5449+
})
5450+
.then(done, done.fail);
5451+
});
5452+
});
5453+
53965454
[{
53975455
type: 'scatter',
53985456
alignment: 'start',

0 commit comments

Comments
 (0)