Skip to content
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

fixup hoverinfo & hovertemplate initial, delta and final flags for waterfalls #3963

Merged
merged 5 commits into from
Jun 17, 2019

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Jun 14, 2019

A follow up of #3954, #3958 and to address #3960.
The initial, delta and final displayed in the waterfall hover now could be controlled and turned off using hovertemplate and hoverinfo.

Also to note for consistency the initial values and delta from base is also displayed over the total bars.

Codepen before
Codepen after

@plotly/plotly_js
cc: @nicolaskruchten

@archmoj archmoj added bug something broken status: reviewable labels Jun 14, 2019
@archmoj archmoj changed the title implement hoverinfo & hovertemplate initial, delta and final flags for waterfalls fixup hoverinfo & hovertemplate initial, delta and final flags for waterfalls Jun 14, 2019
@nicolaskruchten
Copy link
Contributor

This is cool, but there are some differences between the final text in the on-plot text and the in-hover text:

  • the triangle is missing in the on-plot text
  • the negative amounts are in (accounting-format) in the in-hover text

@etpinard what's the right way forward here?

image

@archmoj
Copy link
Contributor Author

archmoj commented Jun 14, 2019

This is cool, but there are some differences between the final text in the on-plot text and the in-hover text:

  • the triangle is missing in the on-plot text
  • the negative amounts are in (accounting-format) in the in-hover text

@etpinard what's the right way forward here?

image

Good call.
Also to note that currently we only display delta values in accounting style.
Should we change anything there feel free to comment here or open a new issue.

@etpinard
Copy link
Contributor

etpinard commented Jun 14, 2019

This is cool, but there are some differences between the final text in the on-plot text and the in-hover text:

Oh right, we could have done a better job explaining the textinfo behavior to you in #3790 (part of 1.48.0). Our apologies.

That said, (1) nothing guarantees than textinfo flags and hoverinfo flags ended up rendering the same e.g. we should probably always show more precision on-hover than on-graph. (2) Having those Initial: and Final: prefixes on-graph would have made most text items scale down (to fit the bar dimensions) making the number smaller than expected for most users.

Come to think of it, the currently behavior isn't that bad as I doubt that most users will use a textinfo with more than 1 flags. Oh well, texttemplate (ref: #3816) should make everyone happy.

}
if(hasFlag('delta') && point.deltaLabel !== '') {
if(size < 0) {
text.push('(' + point.deltaLabel + ') ' + DIRSYMBOL.decreasing);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this here should be the deltaLabel value so that

hoverinfo: 'delta'

and

hovertemplate: '%{delta}'

render the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for Final: and Initial: prefixes, they should not be part of finalLabel / initalLabel.

See example:

https://codepen.io/etpinard/pen/ewJNVJ


In fact, those prefixes should only be there when there are more than 1 of 'initial', 'delta' and 'final' flags.

Copy link
Contributor

@etpinard etpinard Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In brief, xLabel should have the default-formatted label text for x.

I'd argue that the (v) around negative deltas should be considered formatting, but the DIRSMBOL suffixes should not.

So in brief,

v = formatNumber(Math.abs(point.delta));
point.deltaLabel = size < 0 ? '(' + v + ')' : v;

// ...

    if(size < 0) {
                text.push(point.deltaLabel + DIRSYMBOL.decreasing))
      } else {
                text.push(point.deltaLabel +  DIRSYMBOL.increasing);
      }
``

.then(done);
});

it('should turn on percentages with hoveinfo all', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a <ctrl-c><ctrl-v> gone bad, there are no percentages here 😏

Copy link
Contributor Author

@archmoj archmoj Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye! It was 2/3am.

@@ -1424,7 +1486,7 @@ describe('waterfall hover', function() {
})
.then(function() {
assertHoverLabelContent({
nums: '2.2\n4.4 ▲\nInitial: −2.2',
nums: '2.2\nFinal: 2.2\n4.4 ▲\nInitial: −2.2',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. So wait Final: is new?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a requirement anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. And we could possibly drop that.
But that make it clear what the value is pointing to.

@@ -1460,31 +1522,31 @@ describe('waterfall hover', function() {
.then(function() {
var out = _hover(gd, 0, 1000.5, 'closest');
expect(out.yLabelVal).toEqual(1002.201);
expect(out.extraText).toEqual(undefined);
expect(out.extraText).toEqual('Final: $1,002.201m<br>$2.2m ▲<br>Initial: $1,000.001m');
Copy link
Contributor

@etpinard etpinard Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these expectations change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did not fill any extra text for blue bars (totals). But it is pretty useful to display this info for them for example when there is a base other than zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but what does initial and final refer to for total bars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base and top of the bar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think base/top here represent inital and final values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be displayed in codepen after.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that initial and final don't make sense in 'total' cases

@archmoj
Copy link
Contributor Author

archmoj commented Jun 14, 2019

This is ready for the second review.

if(di.isSum) {
point.final = undefined;
point.initial = undefined;
point.delta = size - di.b;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'm not sure we can call this a "delta" . point.y is probably best for the total bars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In respect to #3963 (comment) displaying delta seems to be useful especially when there is a base; also when hovering using hoverinfo: delta.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it similar to current behaviour, this option is dropped in 8432d8f.

@@ -1424,7 +1486,7 @@ describe('waterfall hover', function() {
})
.then(function() {
assertHoverLabelContent({
nums: '2.2\n4.4 ▲\nInitial: −2.2',
nums: '2.2\n2.2\n4.4 ▲\nInitial: −2.2',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have an extra 2.2 now?

Copy link
Contributor Author

@archmoj archmoj Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In respect to #3963 (comment) displaying delta seems to be useful especially when there is a base; also when hovering using hoverinfo: delta.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra 2.2 here is the final value which is the same as y.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0a58836.

@etpinard
Copy link
Contributor

Very nice implementation 💃

@archmoj archmoj merged commit a0021cd into master Jun 17, 2019
@archmoj archmoj deleted the waterfall-hoverinfo-and-hovertemplate-flags branch June 17, 2019 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants