8000 More hovertemplates! by etpinard · Pull Request #3530 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

More hovertemplates! #3530

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 7 commits into from
Feb 15, 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
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add hovertemplate to scattercarpet traces
  • Loading branch information
etpinard committed Feb 11, 2019
commit eac9b3bad79eb3c656d9ed2808aac2a574c2a511
2 changes: 1 addition & 1 deletion src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ function createHoverText(hoverData, opts, gd) {
text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || '';
}
else if(d.xLabel === undefined) {
if(d.yLabel !== undefined) text = d.yLabel;
if(d.yLabel !== undefined && d.trace.type !== 'scattercarpet') text = d.yLabel;
}
else if(d.yLabel === undefined) text = d.xLabel;
else text = '(' + d.xLabel + ', ' + d.yLabel + ')';
Expand Down
4 changes: 3 additions & 1 deletion src/traces/scattercarpet/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {
dfltHoverOn.push('fills');
}
coerce('hoveron', dfltHoverOn.join('+') || 'points');

var hoverOn = coerce('hoveron', dfltHoverOn.join('+') || 'points');
if(hoverOn !== 'fills') coerce('hovertemplate');

Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
};
1 change: 1 addition & 0 deletions src/traces/scattercarpet/event_data.js
10000
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function eventData(out, pt, trace, cd, pointNumber) {

out.a = cdi.a;
out.b = cdi.b;
out.y = cdi.y;

return out;
};
31 changes: 18 additions & 13 deletions src/traces/scattercarpet/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {

var trace = newPointData.trace;
var carpet = trace._carpet;
var hoverinfo = cdi.hi || trace.hoverinfo;
var parts = hoverinfo.split('+');

var ij = carpet.ab2ij([cdi.a, cdi.b]);
var i0 = Math.floor(ij[0]);
var ti = ij[0] - i0;
var j0 = Math.floor(ij[1]);
var tj = ij[1] - j0;
var xy = carpet.evalxy([], i0, j0, ti, tj);
newPointData.yLabel = xy[1].toFixed(3);

var text = [];

function textPart(ax, val) {
Expand All @@ -64,21 +71,19 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
text.push(prefix + ': ' + val.toFixed(3) + ax.labelsuffix);
}

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

var ij = carpet.ab2ij([cdi.a, cdi.b]);
var i0 = Math.floor(ij[0]);
var ti = ij[0] - i0;
if(!trace.hovertemplate) {
var hoverinfo = cdi.hi || trace.hoverinfo;
var parts = hoverinfo.split('+');

var j0 = Math.floor(ij[1]);
var tj = ij[1] - j0;
if(parts.indexOf('all') !== -1) parts = ['a', 'b'];
if(parts.indexOf('a') !== -1) textPart(carpet.aaxis, cdi.a);
if(parts.indexOf('b') !== -1) textPart(carpet.baxis, cdi.b);

var xy = carpet.evalxy([], i0, j0, ti, tj);
text.push('y: ' + xy[1].toFixed(3));
text.push('y: ' + newPointData.yLabel);

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

return scatterPointData;
};
22 changes: 22 additions & 0 deletions test/jasmine/tests/carpet_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,28 @@ describe('scattercarpet hover labels', function() {
)
.then(done);
});

it('should generate hover label with *hovertemplate*', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/scattercarpet.json'));
fig.data[5].hovertemplate = 'f(%{a}, %{b}) = %{y}<extra>scattercarpet #%{curveNumber}</extra>';

run(
[200, 200], fig,
[['f(0.2, 3.5) = 2.900'], 'scattercarpet #5']
)
.then(done);
});

it('should generate hover label with arrayOk *hovertemplate*', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/scattercarpet.json'));
fig.data[5].hovertemplate = ['', '', '', 'f(%{a}, %{b}) = %{y:.1f}<extra>pt #%{pointNumber}</extra>'];

run(
[200, 200], fig,
[['f(0.2, 3.5) = 3.0'], 'pt #3']
)
.then(done);
});
});

describe('contourcarpet plotting & editing', function() {
Expand Down
0