Skip to content

Commit 1701325

Browse files
committed
revise funnel hovertemplate and hoverinfo based on comments
1 parent fbc03a3 commit 1701325

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

src/components/fx/hover.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ function _hover(gd, evt, subplot, noHoverEvent) {
432432
xLabelVal: undefined,
433433
yLabelVal: undefined,
434434
zLabelVal: undefined,
435-
percentInitial: undefined,
436-
percentPrevious: undefined,
437-
percentTotal: undefined,
438435
text: undefined
439436
};
440437

@@ -911,16 +908,6 @@ function createHoverText(hoverData, opts, gd) {
911908
text += (text ? '<br>' : '') + d.text;
912909
}
913910

914-
if(d.percentInitial !== undefined) {
915-
text += (text ? '<br>' : '') + d.percentInitial + ' of initial';
916-
}
917-
if(d.percentPrevious !== undefined) {
918-
text += (text ? '<br>' : '') + d.percentPrevious + ' of previous';
919-
}
920-
if(d.percentTotal !== undefined) {
921-
text += (text ? '<br>' : '') + d.percentTotal + ' of total';
922-
}
923-
924911
// used by other modules (initially just ternary) that
925912
// manage their own hoverinfo independent of cleanPoint
926913
// the rest of this will still apply, so such modules
@@ -1396,9 +1383,6 @@ function cleanPoint(d, hovermode) {
13961383
if(infomode.indexOf('z') === -1) d.zLabel = undefined;
13971384
if(infomode.indexOf('text') === -1) d.text = undefined;
13981385
if(infomode.indexOf('name') === -1) d.name = undefined;
1399-
if(infomode.indexOf('percentInitial') === -1) d.percentInitial = undefined;
1400-
if(infomode.indexOf('percentPrevious') === -1) d.percentPrevious = undefined;
1401-
if(infomode.indexOf('percentTotal') === -1) d.percentTotal = undefined;
14021386
}
14031387

14041388
return d;

src/traces/funnel/attributes.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
var barAttrs = require('../bar/attributes');
1212
var lineAttrs = require('../scatter/attributes').line;
1313
var plotAttrs = require('../../plots/attributes');
14+
var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
15+
var constants = require('./constants');
1416
var extendFlat = require('../../lib/extend').extendFlat;
1517
var Color = require('../../components/color');
1618

@@ -23,9 +25,12 @@ module.exports = {
2325
dy: barAttrs.dy,
2426

2527
hovertext: barAttrs.hovertext,
26-
hovertemplate: barAttrs.hovertemplate,
28+
hovertemplate: hovertemplateAttrs({}, {
29+
keys: constants.eventDataKeys
30+
}),
31+
2732
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
28-
flags: ['percentInitial', 'percentPrevious', 'percentTotal'].concat(plotAttrs.hoverinfo.flags)
33+
flags: ['name', 'x', 'y', 'text', 'percent initial', 'percent previous', 'percent total']
2934
}),
3035

3136
textinfo: {

src/traces/funnel/constants.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = {
12+
eventDataKeys: [
13+
'percentInitial',
14+
'percentPrevious',
15+
'percentTotal'
16+
]
17+
};

src/traces/funnel/hover.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,34 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
2727
var sizeLetter = isHorizontal ? 'x' : 'y';
2828
point[sizeLetter + 'LabelVal'] = di.s;
2929

30-
var hoverinfo = trace.hoverinfo;
31-
if(hoverinfo !== 'none' && hoverinfo !== 'skip') {
32-
var parts = (hoverinfo || '').split('+');
33-
var isAll = (hoverinfo === 'all') || (hoverinfo === undefined);
30+
point.percentInitial = di.begR;
31+
point.percentInitialLabel = formatPercent(di.begR, 1);
32+
33+
point.percentPrevious = di.difR;
34+
point.percentPreviousLabel = formatPercent(di.difR, 1);
35+
36+
point.percentTotal = di.sumR;
37+
point.percentTotalLabel = formatPercent(di.sumR, 1);
38+
39+
var hoverinfo = di.hi || trace.hoverinfo;
40+
var text = [];
41+
if(hoverinfo && hoverinfo !== 'none' && hoverinfo !== 'skip') {
42+
var isAll = (hoverinfo === 'all');
43+
var parts = hoverinfo.split('+');
44+
3445
var hasFlag = function(flag) { return isAll || parts.indexOf(flag) !== -1; };
3546

36-
if(hasFlag('percentInitial')) point.percentInitial = formatPercent(di.begR, 1);
37-
if(hasFlag('percentPrevious')) point.percentPrevious = formatPercent(di.difR, 1);
38-
if(hasFlag('percentTotal')) point.percentTotal = formatPercent(di.sumR, 1);
47+
if(hasFlag('percent initial')) {
48+
text.push(point.percentInitialLabel + ' of initial');
49+
}
50+
if(hasFlag('percent previous')) {
51+
text.push(point.percentPreviousLabel + ' of previous');
52+
}
53+
if(hasFlag('percent total')) {
54+
text.push(point.percentTotalLabel + ' of total');
55+
}
3956
}
57+
point.extraText = text.join('<br>');
4058

4159
point.color = getTraceColor(trace, di);
4260

0 commit comments

Comments
 (0)