From 8230a85282ac84a7046f2925243f40f115b3bae6 Mon Sep 17 00:00:00 2001 From: Michael Kurz Date: Wed, 13 Apr 2022 21:43:47 +0200 Subject: [PATCH] #38: small code improvements --- .../components/BubbleChart/BubbleChart.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/src/visualizations/team-awareness/components/BubbleChart/BubbleChart.js b/ui/src/visualizations/team-awareness/components/BubbleChart/BubbleChart.js index 547cf86e..9d4ff1e4 100644 --- a/ui/src/visualizations/team-awareness/components/BubbleChart/BubbleChart.js +++ b/ui/src/visualizations/team-awareness/components/BubbleChart/BubbleChart.js @@ -8,12 +8,14 @@ export default class BubbleChart extends React.Component { constructor(props) { super(props); this.styles = _.assign({}, chartStyle); + const { width, height } = this.props; + this.state = { componentMounted: false, content: this.props.content, colors: this.createColorSchema(_.map(this.props.content, 'id')), - width: this.props.width || 0, - height: this.props.height || 0 + width: width || 0, + height: height || 0 }; window.addEventListener('resize', () => this.visualizeChart()); } @@ -87,12 +89,14 @@ export default class BubbleChart extends React.Component { return; } - const bubbleArea = d3.select(this.bubbleAreaRef); + const { hierarchy, pack, select } = d3; + + const bubbleArea = select(this.bubbleAreaRef); bubbleArea.selectAll('a').remove(); const { clientWidth, clientHeight } = this.svgRef; - const layout = d3.pack().size([clientWidth, clientHeight]); - const root = d3.hierarchy({ children: this.state.content }).sum(d => d.activity); + const layout = pack().size([clientWidth, clientHeight]); + const root = hierarchy({ children: this.state.content }).sum(d => d.activity); layout(root); const leaf = bubbleArea.selectAll('a').data(root.leaves()).join('a').attr('transform', d => `translate(${d.x},${d.y})`);