Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: axis 增加width/height #1907

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions packages/f2/src/components/axis/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export interface AxisProps<
mask?: string;
min?: number;
max?: number;
width?: number | string;
height?: number | string;
nice?: boolean;
ticks?: Array;
/**
Expand Down
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();
});
});
Loading