Skip to content

Commit 78c7249

Browse files
committed
add (u|v|w|x|y|z)hoverformat to gl3d traces
1 parent d546fd6 commit 78c7249

File tree

16 files changed

+243
-14
lines changed

16 files changed

+243
-14
lines changed

src/plots/gl3d/scene.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,14 @@ proto.render = function() {
322322
if(trace.setContourLevels) trace.setContourLevels();
323323
}
324324

325-
function formatter(axisName, val) {
326-
var axis = scene.fullSceneLayout[axisName];
325+
function formatter(axLetter, val, hoverformat) {
326+
var ax = scene.fullSceneLayout[axLetter + 'axis'];
327327

328-
return Axes.tickText(axis, axis.d2l(val), 'hover').text;
328+
if(ax.type !== 'log') {
329+
val = ax.d2l(val);
330+
}
331+
332+
return Axes.hoverLabelText(ax, val, hoverformat);
329333
}
330334

331335
var oldEventData;
@@ -337,9 +341,9 @@ proto.render = function() {
337341
var ptNumber = selection.index;
338342

339343
var labels = {
340-
xLabel: formatter('xaxis', selection.traceCoordinate[0]),
341-
yLabel: formatter('yaxis', selection.traceCoordinate[1]),
342-
zLabel: formatter('zaxis', selection.traceCoordinate[2])
344+
xLabel: formatter('x', selection.traceCoordinate[0], trace.xhoverformat),
345+
yLabel: formatter('y', selection.traceCoordinate[1], trace.yhoverformat),
346+
zLabel: formatter('z', selection.traceCoordinate[2], trace.zhoverformat)
343347
};
344348

345349
var hoverinfo = Fx.castHoverinfo(traceNow, scene.fullLayout, ptNumber);
@@ -358,17 +362,17 @@ proto.render = function() {
358362
var vectorTx = [];
359363

360364
if(trace.type === 'cone' || trace.type === 'streamtube') {
361-
labels.uLabel = formatter('xaxis', selection.traceCoordinate[3]);
365+
labels.uLabel = formatter('x', selection.traceCoordinate[3], trace.uhoverformat);
362366
if(isHoverinfoAll || hoverinfoParts.indexOf('u') !== -1) {
363367
vectorTx.push('u: ' + labels.uLabel);
364368
}
365369

366-
labels.vLabel = formatter('yaxis', selection.traceCoordinate[4]);
370+
labels.vLabel = formatter('y', selection.traceCoordinate[4], trace.vhoverformat);
367371
if(isHoverinfoAll || hoverinfoParts.indexOf('v') !== -1) {
368372
vectorTx.push('v: ' + labels.vLabel);
369373
}
370374

371-
labels.wLabel = formatter('zaxis', selection.traceCoordinate[5]);
375+
labels.wLabel = formatter('z', selection.traceCoordinate[5], trace.whoverformat);
372376
if(isHoverinfoAll || hoverinfoParts.indexOf('w') !== -1) {
373377
vectorTx.push('w: ' + labels.wLabel);
374378
}

src/plots/hoverformat_attributes.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
var FORMAT_LINK = require('../constants/docs').FORMAT_LINK;
44

5-
function axisHoverFormat(axis) {
5+
function axisHoverFormat(str) {
66
return {
77
valType: 'string',
88
dflt: '',
99
editType: 'none',
1010
description: [
11-
'Sets the hover text formatting rule on the ' + axis + ' axis using d3 formatting mini-languages',
11+
'Sets the hover text formatting rule for the ' + str + ' using d3 formatting mini-languages',
1212
'which are very similar to those in Python. See:',
1313
FORMAT_LINK
1414
].join(' ')
1515
};
1616
}
1717

1818
module.exports = {
19-
xhoverformat: axisHoverFormat('x'),
20-
yhoverformat: axisHoverFormat('y'),
21-
zhoverformat: axisHoverFormat('z')
19+
uhoverformat: axisHoverFormat('u component'),
20+
vhoverformat: axisHoverFormat('v component'),
21+
whoverformat: axisHoverFormat('w component'),
22+
23+
xhoverformat: axisHoverFormat('x axis'),
24+
yhoverformat: axisHoverFormat('y aixs'),
25+
zhoverformat: axisHoverFormat('z axis')
2226
};

src/traces/cone/attributes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4+
var hoverformatAttrs = require('../../plots/hoverformat_attributes');
45
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
56
var mesh3dAttrs = require('../mesh3d/attributes');
67
var baseAttrs = require('../../plots/attributes');
@@ -152,6 +153,13 @@ var attrs = {
152153
},
153154

154155
hovertemplate: hovertemplateAttrs({editType: 'calc'}, {keys: ['norm']}),
156+
uhoverformat: hoverformatAttrs.uhoverformat,
157+
vhoverformat: hoverformatAttrs.vhoverformat,
158+
whoverformat: hoverformatAttrs.whoverformat,
159+
xhoverformat: hoverformatAttrs.xhoverformat,
160+
yhoverformat: hoverformatAttrs.yhoverformat,
161+
zhoverformat: hoverformatAttrs.zhoverformat,
162+
155163
showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false})
156164
};
157165

src/traces/cone/defaults.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4545
coerce('text');
4646
coerce('hovertext');
4747
coerce('hovertemplate');
48+
coerce('uhoverformat');
49+
coerce('vhoverformat');
50+
coerce('whoverformat');
51+
coerce('xhoverformat');
52+
coerce('yhoverformat');
53+
coerce('zhoverformat');
4854

4955
// disable 1D transforms (for now)
5056
traceOut._length = null;

src/traces/isosurface/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4+
var hoverformatAttrs = require('../../plots/hoverformat_attributes');
45
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
56
var meshAttrs = require('../mesh3d/attributes');
67
var baseAttrs = require('../../plots/attributes');
@@ -206,6 +207,10 @@ var attrs = module.exports = overrideAll(extendFlat({
206207
description: 'Same as `text`.'
207208
},
208209
hovertemplate: hovertemplateAttrs(),
210+
xhoverformat: hoverformatAttrs.xhoverformat,
211+
yhoverformat: hoverformatAttrs.yhoverformat,
212+
zhoverformat: hoverformatAttrs.zhoverformat,
213+
209214
showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false})
210215
},
211216

src/traces/isosurface/defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
4444
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
4545

4646
['x', 'y', 'z'].forEach(function(dim) {
47+
coerce(dim + 'hoverformat');
48+
4749
var capDim = 'caps.' + dim;
4850
var showCap = coerce(capDim + '.show');
4951
if(showCap) {

src/traces/mesh3d/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4+
var hoverformatAttrs = require('../../plots/hoverformat_attributes');
45
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
56
var surfaceAttrs = require('../surface/attributes');
67
var baseAttrs = require('../../plots/attributes');
@@ -89,6 +90,10 @@ module.exports = extendFlat({
8990
},
9091
hovertemplate: hovertemplateAttrs({editType: 'calc'}),
9192

93+
xhoverformat: hoverformatAttrs.xhoverformat,
94+
yhoverformat: hoverformatAttrs.yhoverformat,
95+
zhoverformat: hoverformatAttrs.zhoverformat,
96+
9297
delaunayaxis: {
9398
valType: 'enumerated',
9499
values: [ 'x', 'y', 'z' ],

src/traces/mesh3d/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8383
coerce('text');
8484
coerce('hovertext');
8585
coerce('hovertemplate');
86+
coerce('xhoverformat');
87+
coerce('yhoverformat');
88+
coerce('zhoverformat');
8689

8790
// disable 1D transforms
8891
// x/y/z should match lengths, and i/j/k should match as well, but

src/traces/scatter3d/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var scatterAttrs = require('../scatter/attributes');
44
var colorAttributes = require('../../components/colorscale/attributes');
5+
var hoverformatAttrs = require('../../plots/hoverformat_attributes');
56
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
67
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
78
var baseAttrs = require('../../plots/attributes');
@@ -89,6 +90,10 @@ var attrs = module.exports = overrideAll({
8990
}),
9091
hovertemplate: hovertemplateAttrs(),
9192

93+
xhoverformat: hoverformatAttrs.xhoverformat,
94+
yhoverformat: hoverformatAttrs.yhoverformat,
95+
zhoverformat: hoverformatAttrs.zhoverformat,
96+
9297
mode: extendFlat({}, scatterAttrs.mode, // shouldn't this be on-par with 2D?
9398
{dflt: 'lines+markers'}),
9499
surfaceaxis: {

src/traces/scatter3d/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2424
coerce('text');
2525
coerce('hovertext');
2626
coerce('hovertemplate');
27+
coerce('xhoverformat');
28+
coerce('yhoverformat');
29+
coerce('zhoverformat');
30+
2731
coerce('mode');
2832

2933
if(subTypes.hasLines(traceOut)) {

src/traces/streamtube/attributes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4+
var hoverformatAttrs = require('../../plots/hoverformat_attributes');
45
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
56
var mesh3dAttrs = require('../mesh3d/attributes');
67
var baseAttrs = require('../../plots/attributes');
@@ -129,6 +130,13 @@ var attrs = {
129130
'norm', 'divergence'
130131
]
131132
}),
133+
uhoverformat: hoverformatAttrs.uhoverformat,
134+
vhoverformat: hoverformatAttrs.vhoverformat,
135+
whoverformat: hoverformatAttrs.whoverformat,
136+
xhoverformat: hoverformatAttrs.xhoverformat,
137+
yhoverformat: hoverformatAttrs.yhoverformat,
138+
zhoverformat: hoverformatAttrs.zhoverformat,
139+
132140
showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false})
133141
};
134142

src/traces/streamtube/defaults.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4747
coerce('text');
4848
coerce('hovertext');
4949
coerce('hovertemplate');
50+
coerce('uhoverformat');
51+
coerce('vhoverformat');
52+
coerce('whoverformat');
53+
coerce('xhoverformat');
54+
coerce('yhoverformat');
55+
coerce('zhoverformat');
5056

5157
// disable 1D transforms (for now)
5258
// x/y/z and u/v/w have matching lengths,

src/traces/surface/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var Color = require('../../components/color');
44
var colorScaleAttrs = require('../../components/colorscale/attributes');
5+
var hoverformatAttrs = require('../../plots/hoverformat_attributes');
56
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
67
var baseAttrs = require('../../plots/attributes');
78

@@ -145,6 +146,10 @@ var attrs = module.exports = overrideAll(extendFlat({
145146
},
146147
hovertemplate: hovertemplateAttrs(),
147148

149+
xhoverformat: hoverformatAttrs.xhoverformat,
150+
yhoverformat: hoverformatAttrs.yhoverformat,
151+
zhoverformat: hoverformatAttrs.zhoverformat,
152+
148153
connectgaps: {
149154
valType: 'boolean',
150155
dflt: false,

src/traces/surface/defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
7272
coerce('text');
7373
coerce('hovertext');
7474
coerce('hovertemplate');
75+
coerce('xhoverformat');
76+
coerce('yhoverformat');
77+
coerce('zhoverformat');
7578

7679
// Coerce remaining properties
7780
[

src/traces/volume/attributes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var attrs = module.exports = overrideAll(extendFlat({
4343
caps: isosurfaceAttrs.caps,
4444
text: isosurfaceAttrs.text,
4545
hovertext: isosurfaceAttrs.hovertext,
46+
xhoverformat: isosurfaceAttrs.xhoverformat,
47+
yhoverformat: isosurfaceAttrs.yhoverformat,
48+
zhoverformat: isosurfaceAttrs.zhoverformat,
4649
hovertemplate: isosurfaceAttrs.hovertemplate
4750
},
4851

0 commit comments

Comments
 (0)