-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
pie chart label() misdocumented, inconsistent #703
Comments
Thanks for pointing this out. This indeed annoying. The pie chart is inconsistent with the bubble and row charts:
... and even the two examples in the documentation are inconsistent:
To fix this, we'd probably have to break all pie charts that use |
Tempted to make these consistent throughout, even if it breaks code, for 2.0. |
We will break the interface to make these consistent for 2.1 |
@gordonwoodhull Why not break the interface for 2.0? 2.0 is a major semver release, so it actually makes more sense to me if it were to go goes into 2.0 than 2.1 (minor). Besides, I would love to have this fix in for my own purposes. 😄 |
We're already in beta on 2.0, and have been for a year or more, so I want to maintain the consistent interface there. Breaking everyone's apps as they upgrade betas isn't very nice. As for semantic versioning, I'm doing something a little unorthodox because dc.js has so much surface area (and was developed very quickly): the minor versions introduce breaking interface changes. Otherwise the major version would go through the roof, because many improvements break the interface. |
@gordonwoodhull All very good points to which I can't argue. :) I looked briefly at doing a monkey patch, but the |
Well, just in the sense that we try not to expose all the internals; normally what we do is expose functions as we see a need for customization (but try to have decent APIs rather than just lots of hooks, where possible). I guess if you want a workaround for 2.0, what we'd need to do is expose Alternately, you could probably use a pretransition hook to change the labels before they're drawn to the screen. |
Okay, I tried it out and that didn't quite work, so we need a patch for either approach. The application of the label text during the transition is probably wrong, so I'm pulling that out to its own patchable function Now you can have your choice of: chart._applyLabelText = function(labels) {
labels.text(function(d) {
console.log(d);
return d.data.key + ' ' + dc.utils.printSingleValue((d.endAngle - d.startAngle) / (2*Math.PI) * 100) + '%';
});
}; or I somewhat prefer (and I'm adding this to the pie example): chart.on('pretransition', function(chart) {
chart.selectAll('text.pie-slice').text(function(d) {
return d.data.key + ' ' + dc.utils.printSingleValue((d.endAngle - d.startAngle) / (2*Math.PI) * 100) + '%';
})
}); |
(These changes will be available in 2.0 beta 26 this afternoon.) |
YES! Thank you @gordonwoodhull ! |
allowing a workaround for #703
workaround for #703 not enough data is currently available to write a `.label()` function that displays percentages, so this demonstrates using a pretransition hook to correct the labels
two properties need to look at the outer datum which is a well-documented but unsolved design failure of dc.js dc-js/dc.js#872 dc-js/dc.js#755 dc-js/dc.js#703 tl;dr it would be non-intuitive for the user to have to deal with objects they didn't provide to the library. but they often would like to know what the library has done with their data. :-p anyway, this apparently confused me into using .eval nowhere, and then wrapping all values in functors manually. just sooooo wrong.
two properties need to look at the outer datum which is a well-documented but unsolved design failure of dc.js dc-js/dc.js#872 dc-js/dc.js#755 dc-js/dc.js#703 tl;dr it would be non-intuitive for the user to have to deal with objects they didn't provide to the library. but they often would like to know what the library has done with their data. :-p anyway, this apparently confused me into using .eval nowhere, and then wrapping all values in functors manually. just sooooo wrong.
Label function docs state
... but argument (d) passed to the anonymous function is already d.data.
I discovered this while trying to calculate a piechart percentage label using d.startAngle and d.endAngle, which obviously are undefined.
Did I read the docs wrong or what gives?
The text was updated successfully, but these errors were encountered: