Skip to content

Commit 05b53e2

Browse files
authored
feat: magnifier组件增加offsetX和offsetY属性 (#2088)
1 parent e8c2ee7 commit 05b53e2

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

packages/f2/src/components/magnifier/withMagnifier.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ export default (View) => {
3232
return class Magnifier extends Component<MagnifierProps> {
3333
static defaultProps = {
3434
radius: '50px',
35+
offsetX: 0,
36+
offsetY: 0,
3537
};
3638

3739
getPositionAndRadius() {
3840
const { coord } = this.props;
3941
const { right, top } = coord;
40-
const { radius, position: propsPosition } = this.context.px2hd(this.props);
42+
const { radius, position: propsPosition, offsetX, offsetY } = this.context.px2hd(this.props);
4143

4244
// 计算默认 position
4345
const calculatedPosition = [right - radius, top + radius];
44-
const position = propsPosition || calculatedPosition;
46+
let position = propsPosition || calculatedPosition;
47+
48+
position = [position[0] + offsetX, position[1] + offsetY];
4549

4650
return { position, radius };
4751
}
10.9 KB
Loading

packages/f2/test/components/magnifier/magnifier.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,38 @@ describe('Magnifier', () => {
477477

478478
expect(context).toMatchImageSnapshot();
479479
});
480+
481+
it('offsetX and offsetY', async () => {
482+
const context = createContext('Magnifier offsetX/offsetY', {
483+
width: '500px',
484+
height: '200px',
485+
});
486+
const magnifierRef = { current: null };
487+
const { props } = (
488+
<Canvas context={context}>
489+
<Chart
490+
data={data}
491+
style={{
492+
padding: ['50px', '50px', '50px', '50px'],
493+
}}
494+
>
495+
<Line x="date" y="value" color="rgb(208,178,136)" />
496+
<Magnifier
497+
ref={magnifierRef}
498+
focusRange={[data.length - 8, data.length - 1]}
499+
offsetX={'-100px'}
500+
offsetY={'20px'}
501+
frameStyle={{
502+
background: '#fff',
503+
boxShadow: '0 2px 8px rgba(24,144,255,0.15)',
504+
}}
505+
></Magnifier>
506+
</Chart>
507+
</Canvas>
508+
);
509+
const canvas = new Canvas(props);
510+
await canvas.render();
511+
await delay(500);
512+
expect(context).toMatchImageSnapshot();
513+
});
480514
});

0 commit comments

Comments
 (0)