Skip to content

Commit c3de434

Browse files
author
xuying.xu
committed
feat: rect gudie 增加offsetXoffsetY
1 parent df8b666 commit c3de434

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

packages/f2/src/components/guide/views/Rect.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ export interface RectGuideProps extends GuideProps {
88
theme?: any;
99
}
1010

11-
export default (props: RectGuideProps) => {
11+
export default (props: RectGuideProps, context) => {
1212
const { theme = {} } = props;
13-
const { points, style, animation } = deepMix({ ...theme.rect }, props);
14-
const checkNaN = points.some((d)=> isNaN(d.x) || isNaN(d.y));
15-
if(checkNaN) return null;
16-
13+
const { points, style, animation, offsetX, offsetY } = deepMix({ ...theme.rect }, props);
14+
const checkNaN = points.some((d) => isNaN(d.x) || isNaN(d.y));
15+
if (checkNaN) return null;
16+
1717
const start = points[0] || {};
1818
const end = points[1] || {};
1919

20+
const offsetXNum = context.px2hd(offsetX);
21+
const offsetYNum = context.px2hd(offsetY);
22+
const posX = Math.min(start.x, end.x) + (offsetXNum || 0);
23+
const posY = Math.min(start.y, end.y) + (offsetYNum || 0);
24+
2025
return (
2126
<group>
2227
<rect
2328
style={{
24-
x: Math.min(start.x, end.x),
25-
y: Math.min(start.y, end.y),
29+
x: posX,
30+
y: posY,
2631
width: Math.abs(end.x - start.x),
2732
height: Math.abs(start.y - end.y),
2833
...style,

packages/f2/test/components/guide/guide.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
LineGuide,
66
PointGuide,
77
TextGuide,
8+
RectGuide,
89
withGuide,
910
LottieGuide,
1011
withLegend,
@@ -239,6 +240,26 @@ describe('Guide ', () => {
239240
});
240241
it('tag', () => {});
241242

243+
it('rect guide', async () => {
244+
const context = createContext();
245+
const { props } = (
246+
<Canvas context={context} pixelRatio={1} animate={false}>
247+
<Chart data={data}>
248+
<Line x="genre" y="sold" color="type" />
249+
<RectGuide
250+
records={[data[0], data[1]]}
251+
style={{ fill: 'yellow', fillOpacity: 0.5 }}
252+
offsetX="-24px"
253+
offsetY="24px"
254+
/>
255+
</Chart>
256+
</Canvas>
257+
);
258+
const chart = new Canvas(props);
259+
chart.render();
260+
await delay(50);
261+
expect(context).toMatchImageSnapshot();
262+
});
242263
it('guide 超出范围', async () => {
243264
const context = createContext();
244265
const { props } = (

0 commit comments

Comments
 (0)