From 7c9e281a053359c2871c19d2d2cb27795bdc0b10 Mon Sep 17 00:00:00 2001 From: Barbara Schiavinato Date: Mon, 1 Oct 2018 11:58:04 +0100 Subject: [PATCH 1/2] Fix bar width --- modules/bar-chart/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/bar-chart/index.js b/modules/bar-chart/index.js index 0c392bd..93b4843 100644 --- a/modules/bar-chart/index.js +++ b/modules/bar-chart/index.js @@ -77,7 +77,6 @@ export default class BarChart extends PureComponent { lineData: [], width: 400, height: 200, - barWidth: 10, axes: false, xType: 'text', yType: 'linear', @@ -339,7 +338,7 @@ export default class BarChart extends PureComponent { clickHandler, colorBars, xType, - barWidth + barWidth = 10 } = this.props; const calculateDate = (v) => this.parseDate(v); @@ -352,8 +351,8 @@ export default class BarChart extends PureComponent { const calculateY = (d) => y(d.y); const calculateW = () => ( (xType === 'text') - ? x.bandwidth() - : barWidth); + ? Math.max(x.bandwidth(), barWidth) : barWidth); + const calculateH = (d) => h - y(d.y); const mouseover = (d) => mouseOverHandler(d, lastEvent); @@ -463,16 +462,20 @@ export default class BarChart extends PureComponent { yDomainRange, margin, width, - height + height, + barWidth } = this.props; const hasLineData = this.hasLineData(); const m = calculateMargin(axes, margin, yAxisOrientRight, hasLineData); - const w = reduce(width, m.left, m.right); + const calcWidth = (barWidth && data.length > 0) ? + Math.max((((barWidth + 1) * data.length) + m.left + m.right), width) + : width; + const w = reduce(calcWidth, m.left, m.right); + const h = reduce(height, m.top, m.bottom); const x = this.createDomainRangeGenerator('x', xDomainRange, data, xType, w); const y = this.createDomainRangeGenerator('y', yDomainRange, data, yType, h); - const node = this.createSvgNode({ m, w, h }); const root = this.createSvgRoot({ node, m }); From e2d1c9873efbf7717657676e9eb0b7a8fa549b9a Mon Sep 17 00:00:00 2001 From: Barbara Schiavinato Date: Mon, 1 Oct 2018 14:45:08 +0100 Subject: [PATCH 2/2] Remove barWith from required --- tests/bar-chart/bar-chart.test.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/bar-chart/bar-chart.test.js b/tests/bar-chart/bar-chart.test.js index f7629ae..ae2308c 100644 --- a/tests/bar-chart/bar-chart.test.js +++ b/tests/bar-chart/bar-chart.test.js @@ -155,14 +155,6 @@ describe('BarChart component', () => { expect(chart.props).to.have.property('height', 200); }); - it('has a width for the bar on the chart', () => { - /** - * Bar Charts must have a non-zero width for the bars - * on the graph. We default to 10 - */ - expect(chart.props).to.have.property('barWidth', 10); - }); - it('has a pattern for formatting dates on the chart', () => { /** * We provide a pattern for formatting dates