From d14cdab2b239d635492c92700a43862cacf8888e Mon Sep 17 00:00:00 2001 From: etienne Date: Fri, 2 Feb 2018 16:02:55 -0500 Subject: [PATCH 1/5] add support for (hover) 'text' in mesh3d traces --- src/traces/mesh3d/attributes.js | 13 +++++++ src/traces/mesh3d/convert.js | 7 ++++ src/traces/mesh3d/defaults.js | 2 ++ test/jasmine/tests/gl3d_plot_interact_test.js | 36 +++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/src/traces/mesh3d/attributes.js b/src/traces/mesh3d/attributes.js index 86125b522b7..a0e37a38477 100644 --- a/src/traces/mesh3d/attributes.js +++ b/src/traces/mesh3d/attributes.js @@ -78,6 +78,19 @@ module.exports = extendFlat(colorAttrs('', 'calc', false), { }, + text: { + valType: 'string', + role: 'info', + dflt: '', + arrayOk: true, + editType: 'calc', + description: [ + 'Sets the text elements associated with the vertices.', + 'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,', + 'these elements will be seen in the hover labels.' + ].join(' ') + }, + delaunayaxis: { valType: 'enumerated', role: 'info', diff --git a/src/traces/mesh3d/convert.js b/src/traces/mesh3d/convert.js index 31ebf3c30c3..b32910e3f49 100644 --- a/src/traces/mesh3d/convert.js +++ b/src/traces/mesh3d/convert.js @@ -40,6 +40,13 @@ proto.handlePick = function(selection) { this.data.z[selectIndex] ]; + var text = this.data.text; + if(Array.isArray(text) && text[selectIndex] !== undefined) { + selection.textLabel = text[selectIndex]; + } else if(text) { + selection.textLabel = text; + } + return true; } }; diff --git a/src/traces/mesh3d/defaults.js b/src/traces/mesh3d/defaults.js index 2e9df0d3b1c..4049e5f8b5f 100644 --- a/src/traces/mesh3d/defaults.js +++ b/src/traces/mesh3d/defaults.js @@ -84,4 +84,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout else if('vertexcolor' in traceIn) coerce('vertexcolor'); else coerce('color', defaultColor); } + + coerce('text'); }; diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index d6fc3a2e145..fbcd6245346 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -302,6 +302,42 @@ describe('Test gl3d plots', function() { .then(done); }); + it('should display correct hover labels (mesh3d case)', function(done) { + var x = [1, 1, 2, 3, 4, 2]; + var y = [2, 1, 3, 4, 5, 3]; + var z = [3, 7, 4, 5, 3.5, 2]; + var text = x.map(function(_, i) { + return [ + 'ts: ' + x[i], + 'hz: ' + y[i], + 'ftt:' + z[i] + ].join('
'); + }); + + function _hover() { + mouseEvent('mouseover', 250, 250); + return delay(20)(); + } + + Plotly.newPlot(gd, [{ + type: 'mesh3d', + x: x, + y: y, + z: z, + text: text + }], { + width: 500, + height: 500 + }) + .then(delay(20)) + .then(_hover) + .then(function() { + assertHoverText('x: 3', 'y: 4', 'z: 5', 'ts: 3\nhz: 4\nftt:5'); + }) + .catch(fail) + .then(done); + }); + it('should be able to reversibly change trace type', function(done) { var _mock = Lib.extendDeep({}, mock2); var sceneLayout = { aspectratio: { x: 1, y: 1, z: 1 } }; From 8ae2d0e0acc669f8e097cc4e9353e85e3e34ed1c Mon Sep 17 00:00:00 2001 From: etienne Date: Mon, 5 Feb 2018 15:23:01 -0500 Subject: [PATCH 2/5] fix and lock hoverinfo restyle for gl3d traces --- src/traces/mesh3d/attributes.js | 6 ++- src/traces/scatter3d/attributes.js | 3 ++ src/traces/surface/attributes.js | 5 ++- test/jasmine/tests/gl3d_plot_interact_test.js | 45 ++++++++++++++++++- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/traces/mesh3d/attributes.js b/src/traces/mesh3d/attributes.js index a0e37a38477..2c6db0d1450 100644 --- a/src/traces/mesh3d/attributes.js +++ b/src/traces/mesh3d/attributes.js @@ -12,10 +12,10 @@ var colorAttrs = require('../../components/colorscale/color_attributes'); var colorscaleAttrs = require('../../components/colorscale/attributes'); var colorbarAttrs = require('../../components/colorbar/attributes'); var surfaceAtts = require('../surface/attributes'); +var baseAttrs = require('../../plots/attributes'); var extendFlat = require('../../lib/extend').extendFlat; - module.exports = extendFlat(colorAttrs('', 'calc', false), { x: { valType: 'data_array', @@ -222,5 +222,7 @@ module.exports = extendFlat(colorAttrs('', 'calc', false), { description: 'Epsilon for face normals calculation avoids math issues arising from degenerate geometry.' }, editType: 'calc' - }, surfaceAtts.lighting) + }, surfaceAtts.lighting), + + hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'}) }); diff --git a/src/traces/scatter3d/attributes.js b/src/traces/scatter3d/attributes.js index 229f51e1c5f..4fdd7adb7d6 100644 --- a/src/traces/scatter3d/attributes.js +++ b/src/traces/scatter3d/attributes.js @@ -11,6 +11,7 @@ var scatterAttrs = require('../scatter/attributes'); var colorAttributes = require('../../components/colorscale/color_attributes'); var errorBarAttrs = require('../../components/errorbars/attributes'); +var baseAttrs = require('../../plots/attributes'); var DASHES = require('../../constants/gl3d_dashes'); var MARKER_SYMBOLS = require('../../constants/gl3d_markers'); @@ -171,6 +172,8 @@ var attrs = module.exports = overrideAll({ error_x: errorBarAttrs, error_y: errorBarAttrs, error_z: errorBarAttrs, + + hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'}) }, 'calc', 'nested'); attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes'; diff --git a/src/traces/surface/attributes.js b/src/traces/surface/attributes.js index 896988070b4..952dcef2d2b 100644 --- a/src/traces/surface/attributes.js +++ b/src/traces/surface/attributes.js @@ -11,6 +11,7 @@ var Color = require('../../components/color'); var colorscaleAttrs = require('../../components/colorscale/attributes'); var colorbarAttrs = require('../../components/colorbar/attributes'); +var baseAttrs = require('../../plots/attributes'); var extendFlat = require('../../lib/extend').extendFlat; var overrideAll = require('../../plot_api/edit_types').overrideAll; @@ -242,7 +243,9 @@ var attrs = module.exports = overrideAll({ zmax: extendFlat({}, colorscaleAttrs.zmax, { description: 'Obsolete. Use `cmax` instead.' }) - } + }, + + hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'}) }, 'calc', 'nested'); attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes'; diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index fbcd6245346..30efc92f36d 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -36,7 +36,10 @@ describe('Test gl3d plots', function() { var mock3 = require('@mocks/gl3d_autocolorscale'); function assertHoverText(xLabel, yLabel, zLabel, textLabel) { - var content = [xLabel, yLabel, zLabel]; + var content = []; + if(xLabel) content.push(xLabel); + if(yLabel) content.push(yLabel); + if(zLabel) content.push(zLabel); if(textLabel) content.push(textLabel); assertHoverLabelContent({nums: content.join('\n')}); } @@ -193,6 +196,16 @@ describe('Test gl3d plots', function() { .then(_hover) .then(function() { assertHoverText('x: 二 6, 2017', 'y: c', 'z: 100k', 'Clementine'); + + return Plotly.restyle(gd, 'hoverinfo', 'text'); + }) + .then(function() { + assertHoverText(null, null, null, 'Clementine'); + + return Plotly.restyle(gd, 'hoverinfo', 'z'); + }) + .then(function() { + assertHoverText(null, null, '100k'); }) .catch(fail) .then(done); @@ -273,6 +286,18 @@ describe('Test gl3d plots', function() { 'colorbar.tickvals': undefined, 'colorbar.ticktext': undefined }); + + return Plotly.restyle(gd, 'hoverinfo', 'z'); + }) + .then(_hover) + .then(function() { + assertHoverText(null, null, '43'); + + return Plotly.restyle(gd, 'hoverinfo', 'text'); + }) + .then(_hover) + .then(function() { + assertHoverText(null, null, null, 'one two'); }) .then(done); }); @@ -334,6 +359,24 @@ describe('Test gl3d plots', function() { .then(function() { assertHoverText('x: 3', 'y: 4', 'z: 5', 'ts: 3\nhz: 4\nftt:5'); }) + .then(function() { + return Plotly.restyle(gd, 'hoverinfo', 'x+y'); + }) + .then(function() { + assertHoverText('(3, 4)'); + }) + .then(function() { + return Plotly.restyle(gd, 'hoverinfo', 'text'); + }) + .then(function() { + assertHoverText('ts: 3\nhz: 4\nftt:5'); + }) + .then(function() { + return Plotly.restyle(gd, 'text', 'yo!'); + }) + .then(function() { + assertHoverText(null, null, null, 'yo!'); + }) .catch(fail) .then(done); }); From d20bdc1aae4e7ec42e27678c78951c429687b9ca Mon Sep 17 00:00:00 2001 From: etienne Date: Mon, 5 Feb 2018 15:32:22 -0500 Subject: [PATCH 3/5] add support for scalar hover 'text' in surface traces --- src/traces/surface/attributes.js | 13 +++++++++++-- src/traces/surface/convert.js | 7 +++++-- test/jasmine/tests/gl3d_plot_interact_test.js | 5 +++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/traces/surface/attributes.js b/src/traces/surface/attributes.js index 952dcef2d2b..ac7c6d9792e 100644 --- a/src/traces/surface/attributes.js +++ b/src/traces/surface/attributes.js @@ -113,9 +113,18 @@ var attrs = module.exports = overrideAll({ }, text: { - valType: 'data_array', - description: 'Sets the text elements associated with each z value.' + valType: 'string', + role: 'info', + dflt: '', + arrayOk: true, + editType: 'calc', + description: [ + 'Sets the text elements associated with each z value.', + 'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,', + 'these elements will be seen in the hover labels.' + ].join(' ') }, + surfacecolor: { valType: 'data_array', description: [ diff --git a/src/traces/surface/convert.js b/src/traces/surface/convert.js index 029369206bd..1881235686e 100644 --- a/src/traces/surface/convert.js +++ b/src/traces/surface/convert.js @@ -67,10 +67,13 @@ proto.handlePick = function(selection) { ]; var text = this.data.text; - if(text && text[selectIndex[1]] && text[selectIndex[1]][selectIndex[0]] !== undefined) { + if(Array.isArray(text) && text[selectIndex[1]] && text[selectIndex[1]][selectIndex[0]] !== undefined) { selection.textLabel = text[selectIndex[1]][selectIndex[0]]; + } else if(text) { + selection.textLabel = text; + } else { + selection.textLabel = ''; } - else selection.textLabel = ''; selection.data.dataCoordinate = selection.dataCoordinate.slice(); diff --git a/test/jasmine/tests/gl3d_plot_interact_test.js b/test/jasmine/tests/gl3d_plot_interact_test.js index 30efc92f36d..d1df6a2709a 100644 --- a/test/jasmine/tests/gl3d_plot_interact_test.js +++ b/test/jasmine/tests/gl3d_plot_interact_test.js @@ -298,6 +298,11 @@ describe('Test gl3d plots', function() { .then(_hover) .then(function() { assertHoverText(null, null, null, 'one two'); + + return Plotly.restyle(gd, 'text', 'yo!'); + }) + .then(function() { + assertHoverText(null, null, null, 'yo!'); }) .then(done); }); From a20aa937d9b090fc70ef59947dd165cbe3e1357c Mon Sep 17 00:00:00 2001 From: etienne Date: Tue, 6 Feb 2018 09:33:06 -0500 Subject: [PATCH 4/5] :hocho: editType patches already covered by overrideAll --- src/traces/scatter3d/attributes.js | 2 +- src/traces/surface/attributes.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/traces/scatter3d/attributes.js b/src/traces/scatter3d/attributes.js index 4fdd7adb7d6..1f814195485 100644 --- a/src/traces/scatter3d/attributes.js +++ b/src/traces/scatter3d/attributes.js @@ -173,7 +173,7 @@ var attrs = module.exports = overrideAll({ error_y: errorBarAttrs, error_z: errorBarAttrs, - hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'}) + hoverinfo: extendFlat({}, baseAttrs.hoverinfo) }, 'calc', 'nested'); attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes'; diff --git a/src/traces/surface/attributes.js b/src/traces/surface/attributes.js index ac7c6d9792e..9f2f1ac03f8 100644 --- a/src/traces/surface/attributes.js +++ b/src/traces/surface/attributes.js @@ -254,7 +254,7 @@ var attrs = module.exports = overrideAll({ }) }, - hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'}) + hoverinfo: extendFlat({}, baseAttrs.hoverinfo) }, 'calc', 'nested'); attrs.x.editType = attrs.y.editType = attrs.z.editType = 'calc+clearAxisTypes'; From 13a3ecf0f2564c851af453dcf08b03584ffc964a Mon Sep 17 00:00:00 2001 From: etienne Date: Tue, 6 Feb 2018 14:25:31 -0500 Subject: [PATCH 5/5] one more editType :hocho: --- src/traces/surface/attributes.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/traces/surface/attributes.js b/src/traces/surface/attributes.js index 9f2f1ac03f8..2ae56bad8db 100644 --- a/src/traces/surface/attributes.js +++ b/src/traces/surface/attributes.js @@ -117,7 +117,6 @@ var attrs = module.exports = overrideAll({ role: 'info', dflt: '', arrayOk: true, - editType: 'calc', description: [ 'Sets the text elements associated with each z value.', 'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',