diff --git a/packages/fund-components/src/guide/guideView.tsx b/packages/fund-components/src/guide/guideView.tsx index 20df5030b..2a65a81fd 100644 --- a/packages/fund-components/src/guide/guideView.tsx +++ b/packages/fund-components/src/guide/guideView.tsx @@ -1,7 +1,7 @@ // @ts-nocheck export default (props: any) => { - const { points, height } = props; + const { points, height, triggerRef } = props; if (!points || !points.length) { return null; } @@ -37,6 +37,7 @@ export default (props: any) => { }} /> = x && minY <= y && maxY >= y; +} + export default View => { return class Guide extends Component { mount() { - const { chart } = this; + const { chart, props } = this; + const { onClick } = props; const canvas = chart.get('canvas'); canvas.on('click', ev => { + const { points } = ev; + const shape = this.triggerRef.current; + const bbox = shape.getBBox(); + if (isInBBox(bbox, points[0])) { + ev.shape = shape; + onClick && onClick(ev); + } }); } parsePoint(record) { @@ -28,7 +42,10 @@ export default View => { const width = canvas.get('width'); const height = canvas.get('height'); const points = records.map(record => this.parsePoint(record)); - return + + const triggerRef = {}; + this.triggerRef = triggerRef; + return } } } diff --git a/packages/jsx/jsx-runtime.js b/packages/jsx/jsx-runtime.js index 6769b687b..b9552e7b1 100644 --- a/packages/jsx/jsx-runtime.js +++ b/packages/jsx/jsx-runtime.js @@ -1,2 +1,2 @@ "use strict"; -module.exports = require('./lib/index.js'); +module.exports = require('./src/index.ts'); diff --git a/packages/jsx/src/render.ts b/packages/jsx/src/render.ts index 9dff4d6b9..4b00a0d4c 100644 --- a/packages/jsx/src/render.ts +++ b/packages/jsx/src/render.ts @@ -58,7 +58,7 @@ function createElement(node: any, container: any, parentLayout: any) { } return element; } - return container.addShape(type, { + const element = container.addShape(type, { ...props, attrs: { x: left, @@ -68,6 +68,10 @@ function createElement(node: any, container: any, parentLayout: any) { ...attrs, }, }); + if (props.ref) { + props.ref.current = element; + } + return element; } export default (node: any, container: any) => { diff --git a/packages/react/package.json b/packages/react/package.json index 84ce8ca23..cbbb8123e 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -9,6 +9,7 @@ "@antv/f2": "^3.8.1" }, "devDependencies": { + "enzyme": "^3.11.0", "react": "^17.0.1", "react-dom": "^17.0.1" }, diff --git a/packages/react/src/model.ts b/packages/react/src/model.ts index 0a1963c0b..24cd3bf65 100644 --- a/packages/react/src/model.ts +++ b/packages/react/src/model.ts @@ -2,7 +2,7 @@ import { useEffect, Children } from 'react'; import Chart from '@ali/f2-components'; export default ({ canvasRef, pixelRatio, data, children }: any) => { - + useEffect(() => { // 构造component的json描述 const components: any = []; diff --git a/packages/react/test/chart.test.tsx b/packages/react/test/chart.test.tsx index c91c4d0ac..4d2daf099 100644 --- a/packages/react/test/chart.test.tsx +++ b/packages/react/test/chart.test.tsx @@ -1,7 +1,7 @@ /** @jsxImportSource react */ // @ts-nocheck -import { useRef } from 'react'; +import { useRef, useState, Component } from 'react'; import ReactDOM from 'react-dom'; import Chart from '../src'; @@ -36,32 +36,74 @@ const eventData = event.map(eventRecord => { return records; }); - -const App = () => { - return ( - - - - - { - eventData.map((records, index) => { - return - }) - } - - ); +class App extends Component { + state = { + activeIndex: 0, + } + guideClick = (index) => { + this.setState({ + activeIndex: index, + }); + } + render() { + const { activeIndex } = this.state; + return ( + + + + + { + eventData.map((records, index) => { + return this.guideClick(index) } + /> + }) + } + + ); + } } -describe('test', () => { - it('test', () => { - expect(true).toBe(true); - }); -}); + +// const App = () => { +// const [activeIndex, setActiveIndex] = useState(0); + +// const guideClick = (index) => { +// setActiveIndex(index) +// } + +// return ( +// +// +// +// +// { +// eventData.map((records, index) => { +// return guideClick(index) } +// /> +// }) +// } +// +// ); +// } + +// describe('test', () => { +// it('test', () => { +// expect(true).toBe(true); +// }); +// }); ReactDOM.render(, root);