Skip to content

Sankey default link label #2016

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 1 commit into from
Sep 19, 2017
Merged

Sankey default link label #2016

merged 1 commit into from
Sep 19, 2017

Conversation

monfera
Copy link
Contributor

@monfera monfera commented Sep 19, 2017

Fixes #2014

@monfera monfera added bug something broken status: reviewable labels Sep 19, 2017
@monfera
Copy link
Contributor Author

monfera commented Sep 19, 2017

Changes
image

to

image

@monfera monfera self-assigned this Sep 19, 2017
coerce('link.source');
coerce('link.target');
coerce('link.value');
coerce('link.line.color');
coerce('link.line.width');

coerce('link.label', traceOut.link.value.map(function() {return '';}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

🐎 (also for link.color) we're always doing this map even if we don't need the default. Would it be worth either:

  • running that after the coerce call, ie:
var linkLabel = coerce('link.label');
if(!linkLabel) traceOut.link.label = traceOut.link.value.map(function() {return '';});
  • building into coerce that you can pass a function as dflt and it will only be called if needed?
coerce('link.label', function() { return traceOut.link.value.map(function() {return '';}); });

thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also typically when we rely on a previously coerced value to modify later behavior, usually we just save it from its coercion: var linkValue = coerce('link.value')

Which brings up the question: some of these inputs are strictly necessary in order to have meaningful output. What's the minimal set here, without which we should automatically hide the trace? If there's no link.value this map will throw an error, which we definitely don't want.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I guess you default to [] so it won't error... but it still doesn't seem meaningful right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, definitely worth avoiding useless work. Whenever adding some array attributes, I felt it'd be good to be able to specify a default value for the array elements (in attributes.js) rather than just the whole array. But your suggestion is more flexible because it allows a function (default element values depending on other values) so I'll

Copy link
Contributor

Choose a reason for hiding this comment

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

@monfera why don't you move this piece of logic to the calc step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard I think of array values as conceptually default-able (though there's no elementDefault in attributes.js), and saw usages elsewhere that were also in defaults.js. But I can do it in calc or even in the tooltip caller code linkLabel || '' - after all, only the tooltip has a problem with undefined, which is external to sankey. As @alexcjohnson had an alternative suggestion, I wonder which direction would be best in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, if you can handle it entirely at the point of hover - so no fallback processing needs to happen at all during plotting - that seems like the best of all, performance-wise, and we do have other examples of arrays that may or may not exist and we leave it until the value is needed to test this rather than trying to fill it in at supplyDefaults or even calc.

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 fix got pivoted to this consensus, the assertLabel test function now also checks whether the value no longer breaches the tooltip bounding box for a new test case (and other tests that use it already). The test properly breaks when I comment out the fix.

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 commit is in, that's all there is to it, plus the tests 😄

@monfera monfera force-pushed the sankey-default-link-label branch from 44e361d to 878739d Compare September 19, 2017 16:24
@monfera monfera force-pushed the sankey-default-link-label branch from 878739d to 8715270 Compare September 19, 2017 19:02
@alexcjohnson
Copy link
Collaborator

Super - thanks for the quick turnaround! 💃

@monfera monfera merged commit cb5a465 into master Sep 19, 2017
@monfera monfera deleted the sankey-default-link-label branch September 19, 2017 19:52
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