Skip to content

Commit 9cf7b5c

Browse files
authored
Merge pull request #1732 from keithbro/bugfix/histogram-bins
Omit first and last bins when specifying d3-array thresholds.
2 parents 831a5f2 + 3664370 commit 9cf7b5c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/victory-histogram/src/helper-methods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const getBinningFunc = ({ data, x, bins, dataOrBinsContainsDates }) => {
4343

4444
if (Array.isArray(bins)) {
4545
bin.domain([bins[0], bins[bins.length - 1]]);
46-
bin.thresholds(bins);
46+
bin.thresholds(bins.slice(1, bins.length - 1));
4747

4848
return bin;
4949
}

test/client/spec/victory-histogram/victory-histogram.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ describe("components/victory-histogram", () => {
6161
expect(bars.length).to.be.greaterThan(0);
6262
});
6363

64+
it("renders 2 bars of equal height", () => {
65+
const data = [{ x: 2 }, { x: 3 }];
66+
const wrapper = mount(<VictoryHistogram data={data} bins={[2, 2.5, 3]} />);
67+
const bars = wrapper.find("Bar");
68+
const heights = bars.map(SvgTestHelper.getBarHeight).map((n) => parseInt(n));
69+
70+
expect(bars.length).to.equal(2);
71+
expect(heights[0]).to.equal(heights[1]);
72+
expect(heights[0]).to.be.greaterThan(0);
73+
});
74+
6475
it("renders bars values with null accessor", () => {
6576
const data = range(30);
6677
const wrapper = shallow(<VictoryHistogram data={data} x={null} y={null} />);

0 commit comments

Comments
 (0)