Skip to content

adding hovertemplates to polar bar and scatter and ternary scatter #3398

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

Merged
merged 4 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/traces/barpolar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

'use strict';

var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
var constants = require('./constants');
var extendFlat = require('../../lib/extend').extendFlat;
var scatterPolarAttrs = require('../scatterpolar/attributes');
var barAttrs = require('../bar/attributes');
Expand Down Expand Up @@ -69,6 +71,9 @@ module.exports = {
marker: barAttrs.marker,

hoverinfo: scatterPolarAttrs.hoverinfo,
hovertemplate: hovertemplateAttrs({}, {
keys: constants.eventDataKeys
}),

selected: barAttrs.selected,
unselected: barAttrs.unselected
Expand Down
14 changes: 14 additions & 0 deletions src/traces/barpolar/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

module.exports = {
eventDataKeys: []
};
1 change: 1 addition & 0 deletions src/traces/barpolar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('width');

coerce('text');
coerce('hovertemplate');
// coerce('hovertext');

// var textPosition = coerce('textposition');
Expand Down
1 change: 1 addition & 0 deletions src/traces/barpolar/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
var _cdi = Lib.extendFlat({}, cdi, {r: cdi.s, theta: cdi.p});
fillHoverText(cdi, trace, pointData);
makeHoverPointText(_cdi, trace, subplot, pointData);
pointData.hovertemplate = trace.hovertemplate;
pointData.color = getTraceColor(trace, cdi);
pointData.xLabelVal = pointData.yLabelVal = undefined;

Expand Down
5 changes: 5 additions & 0 deletions src/traces/scatterpolar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

'use strict';

var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
var constants = require('./constants');
var extendFlat = require('../../lib/extend').extendFlat;
var scatterAttrs = require('../scatter/attributes');
var plotAttrs = require('../../plots/attributes');
Expand Down Expand Up @@ -130,6 +132,9 @@ module.exports = {
flags: ['r', 'theta', 'text', 'name']
}),
hoveron: scatterAttrs.hoveron,
hovertemplate: hovertemplateAttrs({}, {
keys: constants.eventDataKeys
}),

selected: scatterAttrs.selected,
unselected: scatterAttrs.unselected
Expand Down
14 changes: 14 additions & 0 deletions src/traces/scatterpolar/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

module.exports = {
eventDataKeys: []
};
1 change: 1 addition & 0 deletions src/traces/scatterpolar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');
coerce('text');
coerce('hovertext');
coerce('hovertemplate');

if(subTypes.hasLines(traceOut)) {
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
Expand Down
45 changes: 24 additions & 21 deletions src/traces/scatterpolar/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,44 @@ function hoverPoints(pointData, xval, yval, hovermode) {
newPointData.xLabelVal = undefined;
newPointData.yLabelVal = undefined;
makeHoverPointText(cdi, trace, subplot, newPointData);

newPointData.hovertemplate = trace.hovertemplate;
return scatterPointData;
}

function makeHoverPointText(cdi, trace, subplot, pointData) {

var radialAxis = subplot.radialAxis;
var angularAxis = subplot.angularAxis;
var hoverinfo = cdi.hi || trace.hoverinfo;
var parts = hoverinfo.split('+');
var text = [];

radialAxis._hovertitle = 'r';
angularAxis._hovertitle = 'θ';

var hoverinfo = cdi.hi || trace.hoverinfo;
var text = [];
function textPart(ax, val) {
text.push(ax._hovertitle + ': ' + Axes.tickText(ax, val, 'hover').text);
}

if(parts.indexOf('all') !== -1) parts = ['r', 'theta', 'text'];
if(parts.indexOf('r') !== -1) {
textPart(radialAxis, radialAxis.c2l(cdi.r));
}
if(parts.indexOf('theta') !== -1) {
var theta = cdi.theta;
textPart(
angularAxis,
angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(theta) : theta
);
}
if(parts.indexOf('text') !== -1 && pointData.text) {
text.push(pointData.text);
delete pointData.text;
}
if(!trace.hovertemplate) {
var parts = hoverinfo.split('+');

if(parts.indexOf('all') !== -1) parts = ['r', 'theta', 'text'];
if(parts.indexOf('r') !== -1) {
textPart(radialAxis, radialAxis.c2l(cdi.r));
}
if(parts.indexOf('theta') !== -1) {
var theta = cdi.theta;
textPart(
angularAxis,
angularAxis.thetaunit === 'degrees' ? Lib.rad2deg(theta) : theta
);
}
if(parts.indexOf('text') !== -1 && pointData.text) {
text.push(pointData.text);
delete pointData.text;
}

pointData.extraText = text.join('<br>');
pointData.extraText = text.join('<br>');
}
}

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions src/traces/scatterpolargl/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {

text: scatterPolarAttrs.text,
hovertext: scatterPolarAttrs.hovertext,
hovertemplate: scatterPolarAttrs.hovertemplate,

line: scatterGlAttrs.line,
connectgaps: scatterGlAttrs.connectgaps,
Expand Down
1 change: 1 addition & 0 deletions src/traces/scatterpolargl/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');
coerce('text');
coerce('hovertext');
coerce('hovertemplate');

if(subTypes.hasLines(traceOut)) {
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
Expand Down
5 changes: 5 additions & 0 deletions src/traces/scatterternary/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

'use strict';

var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
var constants = require('./constants');
var scatterAttrs = require('../scatter/attributes');
var plotAttrs = require('../../plots/attributes');
var colorAttributes = require('../../components/colorscale/attributes');
Expand Down Expand Up @@ -147,4 +149,7 @@ module.exports = {
flags: ['a', 'b', 'c', 'text', 'name']
}),
hoveron: scatterAttrs.hoveron,
hovertemplate: hovertemplateAttrs({}, {
keys: constants.eventDataKeys
}),
};
14 changes: 14 additions & 0 deletions src/traces/scatterternary/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright 2012-2019, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';

module.exports = {
eventDataKeys: []
};
1 change: 1 addition & 0 deletions src/traces/scatterternary/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';
coerce('mode', defaultMode);
Expand Down
17 changes: 8 additions & 9 deletions src/traces/scatterternary/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
var trace = newPointData.trace;
var ternary = newPointData.subplot;
var hoverinfo = cdi.hi || trace.hoverinfo;
var parts = hoverinfo.split('+');
var text = [];

function textPart(ax, val) {
text.push(ax._hovertitle + ': ' + Axes.tickText(ax, val, 'hover').text);
}

if(parts.indexOf('all') !== -1) parts = ['a', 'b', 'c'];
if(parts.indexOf('a') !== -1) textPart(ternary.aaxis, cdi.a);
if(parts.indexOf('b') !== -1) textPart(ternary.baxis, cdi.b);
if(parts.indexOf('c') !== -1) textPart(ternary.caxis, cdi.c);

if(!trace.hovertemplate) {
var parts = hoverinfo.split('+');
if(parts.indexOf('all') !== -1) parts = ['a', 'b', 'c'];
if(parts.indexOf('a') !== -1) textPart(ternary.aaxis, cdi.a);
if(parts.indexOf('b') !== -1) textPart(ternary.baxis, cdi.b);
if(parts.indexOf('c') !== -1) textPart(ternary.caxis, cdi.c);
}
newPointData.extraText = text.join('<br>');

newPointData.hovertemplate = trace.hovertemplate;
return scatterPointData;
};