Skip to content

Conversation

Aarebecca
Copy link
Contributor

Apr-17-2024 15-12-55

HTML Node

image

G Node

Apr-17-2024 15-16-22

React Node

  • 添加 HTML 节点元素 / Add HTML node element
const graph = new Graph({
  node: {
    style: {
      type: 'html', // 👈🏻 Node shape type.
      size: [240, 80],
      innerHTML: (d) => `
<div style="width: 100%; height: 100%; background: ${d.style.color}; display: flex; justify-content: center; align-items: center;">
  <span style="color: #fff; font-size: 20px;">
    ${d.data.content}
  </span>
</div>`,
    },
  },
});
  • 添加 JSX 写法的 G Node / Add GNode element can be written in JSX
const graph = new Graph({
  node: {
    style: {
      type: 'g',
      component: () => (
        <Rect width={100} height={100}>
          <Circle radius={10} />
        </Rect>
      ),
    },
  },
});
  • 添加 ReactNode 元素 / Add ReactNode element
const graph = new Graph({
  node: {
    style: {
      type: 'react',
      component: () => (
        <div>
          <span>Title</span>
        </div>
      ),
    },
  },
});
  • Graph 未传入尺寸时使用容器尺寸 / Graph Uses container dimensions when no size is passed in
  • 完善 Graph 销毁后调用 render/draw 的场景校验 / Perfect the scene verification by calling render/draw after Graph destruction

@dosubot dosubot bot added size:XL example g6 example contribution labels Apr 17, 2024
@Aarebecca Aarebecca force-pushed the feat/react-node branch 2 times, most recently from 8221295 to 21e8d7c Compare April 17, 2024 08:00
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 17, 2024
import { createRoot } from 'react-dom/client';

export interface ReactNodeStyleProps extends HTMLStyleProps {
component: FC;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

innerHTML 要 omit 掉

import { HTML } from '@antv/g6';
import type { FC, ReactNode as IReactNode } from 'react';
import type { Root } from 'react-dom/client';
import { createRoot } from 'react-dom/client';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是直接从 react-dom import 吗?这个区别是啥

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createRoot 是从 react-dom/client 导出的,react-dom 并没有导出

@@ -0,0 +1 @@
export { ReactNodeEvent } from './events';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个好像不需要用到?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是之前的逻辑,忘删了

@Aarebecca Aarebecca merged commit 79c18aa into v5 Apr 18, 2024
@Aarebecca Aarebecca deleted the feat/react-node branch April 18, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example g6 example contribution lgtm This PR has been approved by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants