-
Notifications
You must be signed in to change notification settings - Fork 0
Add hoverlabel.zformat attribute #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
acce9bf
b918176
7a27542
919feea
5e20a48
a24be4f
11f5edc
86277f2
1760d66
f991039
48509f3
5c0b2f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
var Fx = require('../../components/fx'); | ||
var Lib = require('../../lib'); | ||
var Axes = require('../../plots/cartesian/axes'); | ||
|
||
var MAXDIST = Fx.constants.MAXDIST; | ||
|
||
|
@@ -26,6 +27,10 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour) | |
y = cd0.y, | ||
z = cd0.z, | ||
zmask = cd0.zmask, | ||
zmin = trace.zmin, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't scope variables if you're only going to use them once. The block below could be rewritten as: var dummyAx = {
type: 'linear',
range: [trace.zmin, trace.zmax],
hoverformat: trace.zhoverformat,
_separators: trace._separators
};
var zLabel = Axes.tickText(dummyAx, zVal, 'hover').text; |
||
zmax = trace.zmax, | ||
zhoverformat = trace.zhoverformat, | ||
_separators = trace._separators, | ||
x2 = x, | ||
y2 = y, | ||
xl, | ||
|
@@ -99,6 +104,16 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour) | |
text = cd0.text[ny][nx]; | ||
} | ||
|
||
var zLabel; | ||
var dummyAx = { // dummy axis for formatting the z value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicely done. Creating the dummy axis here isn't optimal, but shouldn't make much of a difference. 👍 |
||
type: 'linear', | ||
range: [zmin, zmax], | ||
hoverformat: zhoverformat, | ||
_separators: _separators | ||
}; | ||
var zLabelObj = Axes.tickText(dummyAx, zVal, 'hover'); | ||
zLabel = zLabelObj.text; | ||
|
||
return [Lib.extendFlat(pointData, { | ||
index: [ny, nx], | ||
// never let a 2D override 1D type as closest point | ||
|
@@ -110,6 +125,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour) | |
xLabelVal: xl, | ||
yLabelVal: yl, | ||
zLabelVal: zVal, | ||
zLabel: zLabel, | ||
text: text | ||
})]; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,6 +499,43 @@ describe('hover info', function() { | |
.catch(fail) | ||
.then(done); | ||
}); | ||
|
||
it('should display correct label content with specified format', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the two test cases you added are pretty much equivalent. Pick your favorite and 🔪 the other. |
||
var gd = createGraphDiv(); | ||
|
||
Plotly.plot(gd, [{ | ||
type: 'heatmap', | ||
y: [0, 1], | ||
z: [[1.11111, 2.2222, 3.33333], [4.44444, 5.55555, 6.66666]], | ||
name: 'one', | ||
zhoverformat: '.2f' | ||
}, { | ||
type: 'heatmap', | ||
y: [2, 3], | ||
z: [[1, 2, 3], [2, 2, 1]], | ||
name: 'two' | ||
}], { | ||
width: 500, | ||
height: 400, | ||
margin: {l: 0, t: 0, r: 0, b: 0} | ||
}) | ||
.then(function() { | ||
_hover(gd, 250, 100); | ||
assertHoverLabelContent({ | ||
nums: 'x: 1\ny: 3\nz: 2', | ||
name: 'two' | ||
}); | ||
}) | ||
.then(function() { | ||
_hover(gd, 250, 300); | ||
assertHoverLabelContent({ | ||
nums: 'x: 1\ny: 1\nz: 5.56', | ||
name: 'one' | ||
}); | ||
}) | ||
.catch(fail) | ||
.then(done); | ||
}); | ||
}); | ||
|
||
describe('hoverformat', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Too bad we need this. Good catch ⚾
cleanPoint
could use a little bit of a refactor.Would you mind putting that
//
comment about theif()
statement?