Html HTML
阅读时间约 2 分钟
HTML 节点是一个自定义的矩形区域,用于显示 HTML 内容。
适用场景:
用于表示复杂的自定义节点,如表格、图表或富文本。
适合表示自定义的可视化元素或交互组件。
常用于自定义图表、UI 设计等。
createGraph({data: {nodes: [{id: 'node1',style: {x: 300,y: 110,size: [120, 40],innerHTML: `<div style="width: 100%; height: 100%; background: #7e3feb; display: flex; justify-content: center; align-items: center;"><span style="color: #fff; font-size: 12px;">HTML Node</span></div>`,},},],},node: { type: 'html' },plugins: [{ type: 'grid-line', size: 30 }],},{ width: 600, height: 220 },(gui, graph) => {gui.add({ type: 'html' }, 'type').disable();const options = {size: 50,innerHTML: `<div style="width: 100%; height: 100%; background: #7863FF; display: flex; justify-content: center; align-items: center;"><span style="color: #fff; font-size: 20px;">'HTML Node'</span></div>`,};const optionFolder = gui.addFolder('html.style');optionFolder.add(options, 'size', 0, 100, 1);optionFolder.add(options, 'innerHTML');optionFolder.onChange(({ property, value }) => {graph.updateNodeData([{ id: 'node1', style: { [property]: value } }]);graph.render();});},);
设置 node.type
为 html
以使用 HTML 节点。
如果元素有其特定的属性,我们将在下面列出。对于所有的通用样式属性,见BaseNode
属性 | 描述 | 类型 | 默认值 | 必选 |
---|---|---|---|---|
dx | 横行偏移量。HTML 容器默认以左上角为原点,通过 dx 来进行横向偏移 | number | 0 | |
dy | 纵向偏移量。HTML 容器默认以左上角为原点,通过 dy 来进行横向偏移 | number | 0 | |
innerHTML | HTML 内容,可以为字符串或者 HTMLElement | string | HTMLElement | 0 | ✓ |