Skip to content

Commit

Permalink
fix(tiles-chart): update tile size when rerendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Inanda Menezes committed Jul 20, 2017
1 parent 2ac21a1 commit 352aa0e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ws-tiles-chart/ws-tiles-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,29 @@ export class WSTilesChart extends Component {
}

/**
* Calculate the tiles size
* Called before the component mounts to calculate the tiles size
* @returns {void}
*/
componentWillMount() {
this.setState({tileSize: this.getTileSize()});
this.setState({tileSize: this.getTileSize(this.props)});
}

/**
* Called when the props updates to calculate the tiles size
* @param {Object} nextProps next props received
* @returns {void}
*/
componentWillReceiveProps(nextProps) {
this.setState({tileSize: this.getTileSize(nextProps)});
}

/**
* Returns the size to be used for the tile
* @param {Object} props props of the component
* @returns {number}
*/
getTileSize() {
const {height, width, maxTileSize, minTileSize, data} = this.props;
getTileSize(props) {
const {height, width, maxTileSize, minTileSize, data} = props;
const groups = data.groups || {};

if (maxTileSize === minTileSize || Object.keys(groups).length === 0) {
Expand Down

0 comments on commit 352aa0e

Please sign in to comment.