-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
src/traces/sankey/defaults.js
Outdated
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 '';})); |
There was a problem hiding this comment.
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 asdflt
and it will only be called if needed?
coerce('link.label', function() { return traceOut.link.value.map(function() {return '';}); });
thoughts?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
44e361d
to
878739d
Compare
878739d
to
8715270
Compare
Super - thanks for the quick turnaround! 💃 |
Fixes #2014