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

Bar charts: Allow xUnits to depend on width/height / override on render #970

Closed
amergin opened this issue Aug 5, 2015 · 7 comments
Closed
Labels
Milestone

Comments

@amergin
Copy link

amergin commented Aug 5, 2015

Use-case: composite chart that consists of multiple bar charts. The extent of values for these figures can differ significantly as they are drawn dynamically. That is also why I've had problems in determining the correct xUnits as in one case an integer precision is the correct, while in another it could be fractions of a thousand.

To overcome this problem, I use a value 45 for xUnits. This works reasonably well if the figure width/height are adequate.

The problem now: Once the chart is initially drawn to some width/height, the xUnits is locked and cannot be overridden by setting it again and calling render().

The first figure is the initial draw (xUnits=45). The second figure is larger but still uses the same xUnits value: as you can see, the bars are too narrow. If I could reset xUnits to have it depend on the new width/height and then call render, the bar width could be more appropriate.

I really wish dc.js will address the resize support in the coming versions. For the time being, are there any workarounds for my problem? One solution that comes to mind is to completely erase the figure and then create it from scratch, but that seems excessive.

too_thin_resized_1
too_thin_resized_2

@gordonwoodhull
Copy link
Contributor

I really hate .xUnits - it's very unintuitive and trips people up all the time. But I think you can get the bar widths corrected by calling .rescale(), right?

@amergin
Copy link
Author

amergin commented Aug 5, 2015

I think the problem is more that the chart cannot determine a sane default width for the bars (hence the xUnits). Here's what the chart looks like when there's no xUnits (bulky, too wide):

image

With xUnits & rescale on width/height change, I see no difference. Changing the width/height without having to render() is another problem, that I asked here.

@gordonwoodhull
Copy link
Contributor

Right, I wish there were a good way to determine bar widths without .xUnits... but let's leave perfect design aside for the moment.

I just double-checked, and calling rescale definitely causes xUnits to be reread and the bar width to be recalculated. You can set breakpoints in calculateBarWidth to verify this. The new example web/resizing/resizing-bar.html verifies this.

I've solved the svg resize-on-redraw problem in 2.0 beta 15. Let me go ahead and push that now - please let me know if it helps.

@gordonwoodhull gordonwoodhull added this to the v2.0 milestone Aug 5, 2015
@amergin
Copy link
Author

amergin commented Aug 5, 2015

Yep, now changing the width/height works as expected using redraw() and xUnits as well.

@gordonwoodhull
Copy link
Contributor

[moved some unrelated comments to #544 and #972]

Is _this_ issue fixed by using rescale+redraw or not?

@amergin
Copy link
Author

amergin commented Aug 5, 2015

Yep, this issue is fixed, closing.

@amergin amergin closed this as completed Aug 5, 2015
@gordonwoodhull
Copy link
Contributor

Great, thanks for the cogent and precise reports as always!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants