Skip to content

Commit

Permalink
fix: size支持px
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed May 29, 2024
1 parent 736701d commit 5c0e6ab
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Geometry<
this.attrController = new AttrController(chart.scale, attrsRange);
const { attrController, justifyContent } = this;

if (props?.size) {
props.size = context.px2hd(props.size);
}

const attrOptions = attrController.getAttrOptions(props, !coord.isCyclic() || justifyContent);
attrController.create(attrOptions);
}
Expand Down Expand Up @@ -473,6 +477,7 @@ class Geometry<
const defaultAttrValues = attrController.getDefaultAttrValues();

const mappedRecords = [];

for (let i = 0, len = records.length; i < len; i++) {
const record = records[i];
const { children } = record;
Expand Down
1 change: 0 additions & 1 deletion packages/f2/src/components/interval/withInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default (Views) => {

mapping() {
const records = super.mapping();

const { props } = this;
const { coord, sizeZoom } = props;
const y0 = this.getY0Value();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions packages/f2/test/components/geometry/attr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,27 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[1].children[0].size).toBe(16);
});

it('size 支持 px', async () => {
const ref = {};
const context = createContext('size 支持px');
const { type, props } = (
<Canvas context={context} pixelRatio={1}>
<Chart data={data}>
<Axis field="year" />
<Axis field="sales" />
<Interval x="year" y="sales" size={'10px'}></Interval>
<Line x="year" y="sales" size={'5px'} />
</Chart>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();

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

it('size = {field} 用size大小来做分类', async () => {
const context = createContext('size = {field} 用size大小来做分类', { width: '380px' });
const geometryRef = { current: null };
Expand All @@ -477,6 +498,33 @@ describe('Geometry - Attr', () => {
expect(geometryRef.current.records[1].children[0].size).toBe(3);
});

it('size = {{ field, range }} 支持px', async () => {
const ref = {};
const context = createContext('size = {{ field, range }} 支持px');
const { type, props } = (
<Canvas context={context} pixelRatio={1}>
<Chart data={data}>
<Axis field="year" />
<Axis field="sales" />
<Point
x="year"
y="sales"
size={{
field: 'sales',
range: ['5px', '30px'],
}}
/>
</Chart>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();

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

it('size = {{ field, range }} 用size大小来做分类', async () => {
const context = createContext('size = {{ field, range }} 用size大小来做分类', {
width: '380px',
Expand Down

0 comments on commit 5c0e6ab

Please sign in to comment.