Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix histogram bar overlap on numeric x-axis",
"packageName": "@fluentui/react-charts",
"email": "24109638d@connect.polyu.hk",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ const simpleDatePoints = [

const secondaryYScalePoints = [{ yMaxValue: 50000, yMinValue: 10000 }];

const histogramBinCenterPoints: VerticalBarChartDataPoint[] = [
{ x: 1550, y: 5, legend: 'Frequency', xAxisCalloutData: '1500-1599' },
{ x: 1650, y: 19, legend: 'Frequency', xAxisCalloutData: '1600-1699' },
{ x: 1750, y: 6, legend: 'Frequency', xAxisCalloutData: '1700-1799' },
{ x: 1850, y: 3, legend: 'Frequency', xAxisCalloutData: '1800-1899' },
];

describe('Vertical bar chart rendering', () => {
beforeEach(sharedBeforeEach);
afterEach(sharedAfterEach);
Expand Down Expand Up @@ -1077,3 +1084,32 @@ describe('Render empty chart calling with respective to props', () => {
expect(htmlAfter).not.toBe(htmlBefore);
});
});

describe('VerticalBarChart - histogram mode', () => {
beforeEach(sharedBeforeEach);
afterEach(sharedAfterEach);

testWithWait(
'Should not overlap numeric histogram bars',
VerticalBarChart,
{
data: histogramBinCenterPoints,
mode: 'histogram',
barWidth: 'auto',
hideLegend: true,
hideLabels: true,
},
container => {
const bars = getById(container, /_VBC_bar/i);
expect(bars).toHaveLength(histogramBinCenterPoints.length);

for (let index = 1; index < bars.length; index++) {
const previousX = Number.parseFloat(bars[index - 1].getAttribute('x') || '0');
const previousWidth = Number.parseFloat(bars[index - 1].getAttribute('width') || '0');
const currentX = Number.parseFloat(bars[index].getAttribute('x') || '0');

expect(previousX + previousWidth).toBeLessThanOrEqual(currentX);
}
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,9 @@ export const VerticalBarChart: React.FunctionComponent<VerticalBarChartProps> =
props.mode,
);
_domainMargin += _barWidth / 2;
_domainMargin += _barWidth / 2;
if (props.mode !== 'histogram') {
_domainMargin += _barWidth / 2;
}
}

return {
Expand Down