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 a0783fc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,14 @@ class Geometry<
* 如果是Category/Identity 则第一个元素走 mapping
*/
_mapping(records) {
const { attrs, props, attrController } = this;
const { attrs, props, attrController, context } = this;
const { coord } = props;

const { linearAttrs, nonlinearAttrs } = attrController.getAttrsByLinear();
const defaultAttrValues = attrController.getDefaultAttrValues();

const mappedRecords = [];

for (let i = 0, len = records.length; i < len; i++) {
const record = records[i];
const { children } = record;
Expand All @@ -488,8 +489,9 @@ class Geometry<
for (let k = 0, len = nonlinearAttrs.length; k < len; k++) {
const attrName = nonlinearAttrs[k];
const attr = attrs[attrName];
const value = attr.mapping(firstChild[attr.field], firstChild.origin);
// 非线性映射只用映射第一项就可以了
attrValues[attrName] = attr.mapping(firstChild[attr.field], firstChild.origin);
attrValues[attrName] = context.px2hd(value);
}

// 线性属性映射
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.
23 changes: 22 additions & 1 deletion packages/f2/test/components/interval/interval.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jsx } from '../../../src';
import { Canvas, Chart, Interval, Axis } from '../../../src';
import { Canvas, Chart, Interval, Axis, Point, Line } from '../../../src';
import { createContext, delay } from '../../util';
const context = createContext();

Expand Down Expand Up @@ -43,6 +43,27 @@ describe('Interval', () => {
expect(context).toMatchImageSnapshot();
});

it('size 支持px', async () => {
const ref = {};
const context = createContext('size 支持px');
const { type, props } = (
<Canvas context={context} pixelRatio={1}>
<Chart data={data}>
<Axis field="genre" />
<Axis field="sold" min={0} />
<Interval x="genre" y="sold" size={'60px'}></Interval>
<Point x="genre" y="sold" size={'30px'}></Point>
<Line x="genre" y="sold" size={'20px'} />
</Chart>
</Canvas>
);

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

await delay(1000);
expect(context).toMatchImageSnapshot();
});
it('startOnZero', async () => {
const { props } = (
<Canvas context={context} pixelRatio={1}>
Expand Down

0 comments on commit a0783fc

Please sign in to comment.