Skip to content

Commit 919feea

Browse files
committed
Add zhoverformat to contour plots
1 parent 7a27542 commit 919feea

File tree

5 files changed

+19
-48
lines changed

5 files changed

+19
-48
lines changed

src/components/fx/hover.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,8 @@ function cleanPoint(d, hovermode) {
10951095
d.yVal = d.ya.c2d(d.yLabelVal);
10961096
}
10971097

1098-
if(d.zLabelVal !== undefined && d.zLabel === undefined) { // Traces like heatmaps generate the zLabel in their hoverPoints function
1098+
// Traces like heatmaps generate the zLabel in their hoverPoints function
1099+
if(d.zLabelVal !== undefined && d.zLabel === undefined) {
10991100
d.zLabel = String(d.zLabelVal);
11001101
}
11011102

src/traces/contour/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = extendFlat({
3030
transpose: heatmapAttrs.transpose,
3131
xtype: heatmapAttrs.xtype,
3232
ytype: heatmapAttrs.ytype,
33+
zhoverformat: heatmapAttrs.zhoverformat,
3334

3435
connectgaps: heatmapAttrs.connectgaps,
3536

src/traces/contour/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3434

3535
handleContoursDefaults(traceIn, traceOut, coerce);
3636
handleStyleDefaults(traceIn, traceOut, coerce, layout);
37+
38+
coerce('zhoverformat');
39+
// Needed for formatting of hoverlabel if format is not explicitly specified
40+
traceOut._separators = layout.separators;
3741
};

src/traces/heatmap/hover.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour)
2727
y = cd0.y,
2828
z = cd0.z,
2929
zmask = cd0.zmask,
30-
zmin = trace.zmin,
31-
zmax = trace.zmax,
30+
range = [trace.zmin, trace.zmax],
3231
zhoverformat = trace.zhoverformat,
3332
_separators = trace._separators,
3433
x2 = x,
@@ -105,9 +104,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour)
105104
}
106105

107106
var zLabel;
108-
var dummyAx = { // dummy axis for formatting the z value
107+
// dummy axis for formatting the z value
108+
var dummyAx = {
109109
type: 'linear',
110-
range: [zmin, zmax],
110+
range: range,
111111
hoverformat: zhoverformat,
112112
_separators: _separators
113113
};

test/jasmine/tests/heatmap_test.js

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,10 @@ describe('heatmap hover', function() {
616616
return hoverData;
617617
}
618618

619-
function assertLabels(hoverPoint, xLabelVal, yLabelVal, zLabelVal, zLabel, text) {
620-
expect(hoverPoint.xLabelVal).toEqual(xLabelVal, 'have correct x label value');
621-
expect(hoverPoint.yLabelVal).toEqual(yLabelVal, 'have correct y label value');
622-
expect(hoverPoint.zLabelVal).toEqual(zLabelVal, 'have correct z label value');
623-
expect(hoverPoint.zLabel).toEqual(zLabel, 'have correct z label');
619+
function assertLabels(hoverPoint, xLabel, yLabel, zLabel, text) {
620+
expect(hoverPoint.xLabelVal).toEqual(xLabel, 'have correct x label');
621+
expect(hoverPoint.yLabelVal).toEqual(yLabel, 'have correct y label');
622+
expect(hoverPoint.zLabelVal).toEqual(zLabel, 'have correct z label');
624623
expect(hoverPoint.text).toEqual(text, 'have correct text label');
625624
}
626625

@@ -641,14 +640,14 @@ describe('heatmap hover', function() {
641640
var pt = _hover(gd, 0.5, 0.5)[0];
642641

643642
expect(pt.index).toEqual([1, 0], 'have correct index');
644-
assertLabels(pt, 1, 1, 4, '4');
643+
assertLabels(pt, 1, 1, 4);
645644
});
646645

647646
it('should find closest point (case 2) and should', function() {
648647
var pt = _hover(gd, 1.5, 0.5)[0];
649648

650649
expect(pt.index).toEqual([0, 0], 'have correct index');
651-
assertLabels(pt, 2, 0.2, 6, '6');
650+
assertLabels(pt, 2, 0.2, 6);
652651
});
653652
});
654653

@@ -674,47 +673,13 @@ describe('heatmap hover', function() {
674673
var pt = _hover(gd, 0.5, 0.5)[0];
675674

676675
expect(pt.index).toEqual([0, 0], 'have correct index');
677-
assertLabels(pt, 1, 1, 10, '10', 'a');
676+
assertLabels(pt, 1, 1, 10, 'a');
678677

679678
Plotly.relayout(gd, 'xaxis.range', [1, 2]).then(function() {
680679
var pt2 = _hover(gd, 1.5, 0.5)[0];
681680

682681
expect(pt2.index).toEqual([0, 1], 'have correct index');
683-
assertLabels(pt2, 2, 1, 4, '4', 'b');
684-
})
685-
.then(done);
686-
});
687-
688-
});
689-
690-
describe('for hovering with specific number format', function() {
691-
692-
beforeAll(function(done) {
693-
gd = createGraphDiv();
694-
695-
Plotly.plot(gd, [{
696-
type: 'heatmap',
697-
x: [1, 2, 3],
698-
y: [1, 1, 1],
699-
z: [0.123456789, 2.9999, 4],
700-
zhoverformat: '.2f'
701-
}])
702-
.then(done);
703-
});
704-
705-
afterAll(destroyGraphDiv);
706-
707-
it('should find closest point and should', function(done) {
708-
var pt = _hover(gd, 0.5, 0.5)[0];
709-
710-
expect(pt.index).toEqual([0, 0], 'have correct index');
711-
assertLabels(pt, 1, 1, 0.123456789, '0.12');
712-
713-
Plotly.relayout(gd, 'xaxis.range', [1, 2]).then(function() {
714-
var pt2 = _hover(gd, 1.5, 0.5)[0];
715-
716-
expect(pt2.index).toEqual([0, 1], 'have correct index');
717-
assertLabels(pt2, 2, 1, 2.9999, '3.00');
682+
assertLabels(pt2, 2, 1, 4, 'b');
718683
})
719684
.then(done);
720685
});

0 commit comments

Comments
 (0)