Skip to content

Commit

Permalink
auto-calculate width/height only once
Browse files Browse the repository at this point in the history
fixes #980, fixes #1070
auto-calculating the width/height of a chart based on the parent div is
a bit of a misfeature because there are many things (like the controls)
that will cause the parent div to always be larger than the SVG it
contains

these bugs were mostly hidden in the past because we only set the SVG
width/height once (on render) - now that we are resizing the SVG on
redraw it causes obvious issues

so restrict the auto-calculate to only fire once - although better if we
could trigger calculate on each render only
  • Loading branch information
gordonwoodhull committed Dec 21, 2015
1 parent 556cb46 commit 1a32bc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 2.0 Series
## 2.0.0 beta 24
* Only auto-calculate width/height once - sizes were getting calculated wrong ([#1070](https://github.com/dc-js/dc.js/issues/1070)) and charts were changing size on redraw if they didn't have a fixed size in the chart spec or in the div style ([#980](https://github.com/dc-js/dc.js/issues/980))

## 2.0.0 beta 23
* Domain was getting set for composite charts even when `elasticY` disabled. ([#1056](https://github.com/dc-js/dc.js/issues/1056)

Expand Down
12 changes: 10 additions & 2 deletions src/base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ dc.baseMixin = function (_chart) {
*/
_chart.height = function (height) {
if (!arguments.length) {
return _height(_root.node());
if (!dc.utils.isNumber(_height)) {
// only calculate once
_height = _height(_root.node());
}
return _height;
}
_height = d3.functor(height || _defaultHeight);
return _chart;
Expand All @@ -155,7 +159,11 @@ dc.baseMixin = function (_chart) {
*/
_chart.width = function (width) {
if (!arguments.length) {
return _width(_root.node());
if (!dc.utils.isNumber(_width)) {
// only calculate once
_width = _width(_root.node());
}
return _width;
}
_width = d3.functor(width || _defaultWidth);
return _chart;
Expand Down

0 comments on commit 1a32bc5

Please sign in to comment.