Skip to content

Commit 3aa03f7

Browse files
committed
tests of histogram hover label range format, and log-negative format
1 parent 51ad8c2 commit 3aa03f7

File tree

1 file changed

+127
-5
lines changed

1 file changed

+127
-5
lines changed

test/jasmine/tests/hover_label_test.js

+127-5
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ describe('hover info', function() {
458458
});
459459
});
460460

461-
describe('\'hover info for x/y/z traces', function() {
462-
function _hover(gd, xpx, ypx) {
463-
Fx.hover(gd, { xpx: xpx, ypx: ypx }, 'xy');
464-
Lib.clearThrottle();
465-
}
461+
function _hover(gd, xpx, ypx) {
462+
Fx.hover(gd, { xpx: xpx, ypx: ypx }, 'xy');
463+
Lib.clearThrottle();
464+
}
466465

466+
describe('\'hover info for x/y/z traces', function() {
467467
it('should display correct label content', function(done) {
468468
var gd = createGraphDiv();
469469

@@ -501,6 +501,128 @@ describe('hover info', function() {
501501
});
502502
});
503503

504+
describe('hover info for negative data on a log axis', function() {
505+
it('shows negative data even though it is infinitely off-screen', function(done) {
506+
var gd = createGraphDiv();
507+
508+
Plotly.plot(gd, [{x: [1, 2, 3], y: [1, -5, 10]}], {
509+
yaxis: {type: 'log'},
510+
width: 500,
511+
height: 400,
512+
margin: {l: 0, t: 0, r: 0, b: 0}
513+
})
514+
.then(function() {
515+
_hover(gd, 250, 200);
516+
assertHoverLabelContent({
517+
nums: '\u22125', // unicode minus
518+
axis: '2'
519+
});
520+
})
521+
.catch(fail)
522+
.then(done);
523+
});
524+
});
525+
526+
describe('histogram hover info', function() {
527+
it('shows the data range when bins have multiple values', function(done) {
528+
var gd = createGraphDiv();
529+
530+
Plotly.plot(gd, [{
531+
x: [0, 2, 3, 4, 5, 6, 7],
532+
xbins: {start: -0.5, end: 8.5, size: 3},
533+
type: 'histogram'
534+
}], {
535+
width: 500,
536+
height: 400,
537+
margin: {l: 0, t: 0, r: 0, b: 0}
538+
})
539+
.then(function() {
540+
_hover(gd, 250, 200);
541+
assertHoverLabelContent({
542+
nums: '3',
543+
axis: '3 - 5'
544+
});
545+
})
546+
.catch(fail)
547+
.then(done);
548+
});
549+
550+
it('shows the exact data when bins have single values', function(done) {
551+
var gd = createGraphDiv();
552+
553+
Plotly.plot(gd, [{
554+
// even though the data aren't regularly spaced, each bin only has
555+
// one data value in it so we see exactly that value
556+
x: [0, 0, 3.3, 3.3, 3.3, 7, 7],
557+
xbins: {start: -0.5, end: 8.5, size: 3},
558+
type: 'histogram'
559+
}], {
560+
width: 500,
561+
height: 400,
562+
margin: {l: 0, t: 0, r: 0, b: 0}
563+
})
564+
.then(function() {
565+
_hover(gd, 250, 200);
566+
assertHoverLabelContent({
567+
nums: '3',
568+
axis: '3.3'
569+
});
570+
})
571+
.catch(fail)
572+
.then(done);
573+
});
574+
});
575+
576+
describe('histogram2d hover info', function() {
577+
it('shows the data range when bins have multiple values', function(done) {
578+
var gd = createGraphDiv();
579+
580+
Plotly.plot(gd, [{
581+
x: [0, 2, 3, 4, 5, 6, 7],
582+
y: [1, 3, 4, 5, 6, 7, 8],
583+
xbins: {start: -0.5, end: 8.5, size: 3},
584+
ybins: {start: 0.5, end: 9.5, size: 3},
585+
type: 'histogram2d'
586+
}], {
587+
width: 500,
588+
height: 400,
589+
margin: {l: 0, t: 0, r: 0, b: 0}
590+
})
591+
.then(function() {
592+
_hover(gd, 250, 200);
593+
assertHoverLabelContent({
594+
nums: 'x: 3 - 5\ny: 4 - 6\nz: 3'
595+
});
596+
})
597+
.catch(fail)
598+
.then(done);
599+
});
600+
601+
it('shows the exact data when bins have single values', function(done) {
602+
var gd = createGraphDiv();
603+
604+
Plotly.plot(gd, [{
605+
x: [0, 0, 3.3, 3.3, 3.3, 7, 7],
606+
y: [2, 2, 4.2, 4.2, 4.2, 8.8, 8.8],
607+
xbins: {start: -0.5, end: 8.5, size: 3},
608+
ybins: {start: 0.5, end: 9.5, size: 3},
609+
type: 'histogram2d'
610+
}], {
611+
width: 500,
612+
height: 400,
613+
margin: {l: 0, t: 0, r: 0, b: 0}
614+
})
615+
.then(function() {
616+
_hover(gd, 250, 200);
617+
assertHoverLabelContent({
618+
nums: 'x: 3.3\ny: 4.2\nz: 3'
619+
});
620+
})
621+
.catch(fail)
622+
.then(done);
623+
});
624+
});
625+
504626
describe('hoverformat', function() {
505627
var data = [{
506628
x: [1, 2, 3],

0 commit comments

Comments
 (0)