You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently stratify throws an error if the network input is non-hierarchical. I can see why but I've got a case and could imagine it being a common case where I want to use stratify to try to get a hierarchy out of data and if it can't then it's not an error, it just means I have to do something else. Right now I can try/catch, but I'd prefer there to be a StratifyIfYouCan function that just returns false if it doesn't work.
The text was updated successfully, but these errors were encountered:
My first interpretation is that you want stratify(data) to return false (or perhaps null or undefined?) instead of throwing an error. I don’t agree with this; invalid input is an exceptional case and it’s better to throw an error than return some special value, since that way if you forget to try-catch (or check that the return value is special), you get an error at the moment stratify is called and not some arbitrary point later in your application. And in the common case, I don’t expect callers of stratify to have fallback code to produce a different visualization strategy when the data is not hierarchical. And ultimately, in the rare case where you do have an alternate strategy, the burden is simply a try-catch instead of checking the return value, which is easy to do and even easy to wrap in a helper method if desired.
My second interpretation is that you want a d3.stratifyLoose or equivalent that somehow converts non-hierarchical input into a valid hierarchy. This sounds reasonable, but we’d need to define the logic of how non-hierarchical input is turned into a hierarchy. It should be documented and deterministic (and ideally order-independent). I haven’t thought through what such logic should be, but you’re welcome to submit a PR if this is something you’d like.
Related, I’d like to see a d3.stratify enhancement or equivalent that works with implied parent nodes #33.
Currently stratify throws an error if the network input is non-hierarchical. I can see why but I've got a case and could imagine it being a common case where I want to use stratify to try to get a hierarchy out of data and if it can't then it's not an error, it just means I have to do something else. Right now I can try/catch, but I'd prefer there to be a
StratifyIfYouCan
function that just returns false if it doesn't work.The text was updated successfully, but these errors were encountered: