Skip to content

Commit

Permalink
Use margin to specify the spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed committed Mar 2, 2023
1 parent 9650d26 commit 80caca5
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions packages/chart/src/ChartUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ describe('updating layout axes', () => {
describe('handles subplots and columns/rows correctly', () => {
const width = ChartUtils.AXIS_SIZE_PX * 5;
const height = ChartUtils.AXIS_SIZE_PX * 10;
const halfXMargin = ChartUtils.AXIS_SIZE_PX / width / 2;
const halfYMargin = ChartUtils.AXIS_SIZE_PX / height / 2;

it('handles row location correctly', () => {
const axes = ChartTestUtils.makeDefaultAxes();
Expand All @@ -328,10 +330,10 @@ describe('handles subplots and columns/rows correctly', () => {
const figure = ChartTestUtils.makeFigure({ charts, rows: 2 });
expect(
ChartUtils.getChartBounds(figure, charts[0], width, height)
).toEqual({ bottom: 0.55, top: 1, left: 0, right: 1 });
).toEqual({ bottom: 0.5 + halfYMargin, top: 1, left: 0, right: 1 });
expect(
ChartUtils.getChartBounds(figure, charts[1], width, height)
).toEqual({ bottom: 0, top: 0.45, left: 0, right: 1 });
).toEqual({ bottom: 0, top: 0.5 - halfYMargin, left: 0, right: 1 });
});

it('handles column location correctly', () => {
Expand All @@ -343,10 +345,10 @@ describe('handles subplots and columns/rows correctly', () => {
const figure = ChartTestUtils.makeFigure({ charts, cols: 2 });
expect(
ChartUtils.getChartBounds(figure, charts[0], width, height)
).toEqual({ bottom: 0, top: 1, left: 0, right: 0.4 });
).toEqual({ bottom: 0, top: 1, left: 0, right: 0.5 - halfXMargin });
expect(
ChartUtils.getChartBounds(figure, charts[1], width, height)
).toEqual({ bottom: 0, top: 1, left: 0.6, right: 1 });
).toEqual({ bottom: 0, top: 1, left: 0.5 + halfXMargin, right: 1 });
});

it('handles colspan', () => {
Expand All @@ -357,15 +359,25 @@ describe('handles subplots and columns/rows correctly', () => {
ChartTestUtils.makeChart({ axes, row: 1, colspan: 2 }),
];
const figure = ChartTestUtils.makeFigure({ charts, cols: 2, rows: 2 });
expect(
ChartUtils.getChartBounds(figure, charts[0], width, height)
).toEqual({ bottom: 0.55, top: 1, left: 0, right: 0.4 });
expect(
ChartUtils.getChartBounds(figure, charts[1], width, height)
).toEqual({ bottom: 0.55, top: 1, left: 0.6, right: 1 });
expect(ChartUtils.getChartBounds(figure, charts[0], width, height)).toEqual(
{
bottom: 0.5 + halfYMargin,
top: 1,
left: 0,
right: 0.5 - halfXMargin,
}
);
expect(ChartUtils.getChartBounds(figure, charts[1], width, height)).toEqual(
{
bottom: 0.5 + halfYMargin,
top: 1,
left: 0.5 + halfXMargin,
right: 1,
}
);
expect(
ChartUtils.getChartBounds(figure, charts[2], width, height)
).toEqual({ bottom: 0, top: 0.45, left: 0, right: 1 });
).toEqual({ bottom: 0, top: 0.5 - halfYMargin, left: 0, right: 1 });
});

it('handles rowspan', () => {
Expand All @@ -376,15 +388,25 @@ describe('handles subplots and columns/rows correctly', () => {
ChartTestUtils.makeChart({ axes, column: 1, rowspan: 2 }),
];
const figure = ChartTestUtils.makeFigure({ charts, cols: 2, rows: 2 });
expect(
ChartUtils.getChartBounds(figure, charts[0], width, height)
).toEqual({ bottom: 0.55, top: 1, left: 0, right: 0.4 });
expect(
ChartUtils.getChartBounds(figure, charts[1], width, height)
).toEqual({ bottom: 0, top: 0.45, left: 0, right: 0.4 });
expect(ChartUtils.getChartBounds(figure, charts[0], width, height)).toEqual(
{
bottom: 0.5 + halfYMargin,
top: 1,
left: 0,
right: 0.5 - halfXMargin,
}
);
expect(ChartUtils.getChartBounds(figure, charts[1], width, height)).toEqual(
{
bottom: 0,
top: 0.5 - halfYMargin,
left: 0,
right: 0.5 - halfXMargin,
}
);
expect(
ChartUtils.getChartBounds(figure, charts[2], width, height)
).toEqual({ bottom: 0, top: 1, left: 0.6, right: 1 });
).toEqual({ bottom: 0, top: 1, left: 0.5 + halfXMargin, right: 1 });
});
});

Expand Down

0 comments on commit 80caca5

Please sign in to comment.