Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

@antv/react-g

Package Overview
Dependencies
5
Maintainers
64
Versions
128
Issues
File Explorer

Advanced tools

@antv/react-g

react render for @antv/g

    1.8.58latest
    GitHub

Version published
Maintainers
64
Weekly downloads
481
decreased by-41.34%

Weekly downloads

Readme

Source

react-g

react render for @antv/g

Install

npm i @antv/react-g

Usage

react-g provide host-component:

  • Container: Canvas and Group.
  • Shape: Text, Circle, Ellipse, Image, Line, Marker, Path, Polygon and Polyline.

Basic usage

import React, { useState } from 'react'; import { Canvas, Circle } from '@antv/react-g'; import { Renderer as CanvasRenderer } from '@antv/g-canvas'; const renderer = new CanvasRenderer(); const App = () => { const [size, setSize] = useState(50); return ( <Canvas width={600} height={400} renderer={renderer}> <Circle x={100} y={200} r={size} fill="#1890FF" stroke="#F04864" lineWidth={4} onClick={() => { setSize(100); }} /> </Canvas> ); }; export default App;

Use ref to access shape instance

Like react-dom, you can use ref to access the shape instance.

import React, { useState, useRef } from 'react'; import { Canvas, Circle } from '@antv/react-g'; import { Renderer as CanvasRenderer } from '@antv/g-canvas'; const renderer = new CanvasRenderer(); const App = () => { const circleRef = useRef(); const [size, setSize] = useState(50); return ( <Canvas width={600} height={400} renderer={renderer}> <Circle ref={circleRef} x={100} y={200} r={size} fill="#1890FF" stroke="#F04864" lineWidth={4} onClick={() => { setSize(100); }} /> </Canvas> ); }; export default App;

render react-g component to target g element

  • 将 react-g 组件渲染到任意的 g 实例(Canvas/Group/Shape)中
  • 意味着可以将 react-g 组件渲染到 g2,g6 等其他库中
import React, { useState } from 'react'; import { Canvas as GCanvas } from '@antv/g'; import { Circle, render } from '@antv/react-g'; import { Renderer as CanvasRenderer } from '@antv/g-canvas'; const renderer = new CanvasRenderer(); const CircleComponent = () => { const [size, setSize] = useState(50); return ( <Circle x={100} y={200} r={size} fill="#1890FF" stroke="#F04864" lineWidth={4} onMouseenter={() => { setSize(100); }} onMouseleave={() => { setSize(50); }} /> ); }; const canvas = new GCanvas({ container: 'container', // DOM 节点id width: 600, height: 500, renderer, }); // canvas can also be group/shape render(<CircleComponent />, canvas);

Keywords

FAQs

Last updated on 23 Mar 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc