Skip to content

Commit

Permalink
feat: axis 增加width/height
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Dec 28, 2023
1 parent cf9f566 commit c86bc87
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/f2/src/components/axis/withAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export default (View) => {
}

measureLayout(): PositionLayout | PositionLayout[] {
const { props } = this;
const { props, context } = this;
const { px2hd } = context;
const { visible, coord } = props;
if (visible === false) {
return null;
Expand All @@ -225,7 +226,12 @@ export default (View) => {

const { isPolar } = coord;
const dimType = this._getDimType();
const { width, height } = bbox;

const { width, height } = deepMix(
bbox,
px2hd({ width: props?.width, height: props?.height })
);

if (isPolar) {
// 机坐标系的 y 不占位置
if (dimType === 'y') {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions packages/f2/test/components/axis/axis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,57 @@ describe('Axis 轴', () => {
await delay(1000);
expect(context).toMatchImageSnapshot();
});

it('设置width height', async () => {
const context = createContext('文本换行');

const data = [
{
time: 'Jan.',
value: 551990,
},
{
time: 'Feb.',
value: 513513,
},
{
time: 'Mar.',
value: 538780,
},
{
time: 'Apr.',
value: 419562,
},
{
time: 'May.',
value: 332167,
},
{
time: 'Jun.',
value: 297956,
},
{
time: 'Jul.',
value: 311760,
},
{
time: 'Aug.',
value: 330824,
},
];
const { props } = (
<Canvas context={context} pixelRatio={1}>
<Chart data={data}>
<Axis field="time" />
<Axis field="value" width={100} />
<Interval x="time" y="value" color="#2FC25B" />
</Chart>
</Canvas>
);
const canvas = new Canvas(props);
await canvas.render();

await delay(1000);
expect(context).toMatchImageSnapshot();
});
});

0 comments on commit c86bc87

Please sign in to comment.