Replies: 1 comment
-
import { Graph, Markup } from '@antv/x6'
const graph = new Graph({
container: document.getElementById('container'),
grid: true,
resizing: true
})
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="109" height="109">
<g class="layer" transform="translate(-293.5 -96.5)">
<g fill="none" stroke="#000" stroke-width="5">
<circle cx="348" cy="151" r="52"/>
<circle cx="348" cy="152" r="16"/>
</g>
<g fill="none" stroke="#000" stroke-width="5">
<path d="M353 101l-3 36M348 167l-2 38M363 152l38 1M332 148l-36 1M359 139l28-22M334 163l-27 20M340 141l-22-33M357 165l23 28"/>
</g>
</g>
</svg>
`
const width = 109
const height = 109
const { markup, attrs } = Markup.xml2json(svg)
const node = graph.addNode({
shape: 'empty',
x: 100,
y: 100,
width,
height,
markup,
attrs,
})
fix(node); // important!
function fix(node) {
const anchor = '> svg'
const { width, height } = node.getAttrByPath(anchor)
node.setAttrByPath('> svg', {
refWidth: '100%',
refHeight: '100%',
viewBox: `0 0 ${width} ${height}`
})
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
如何保证可缩放?
当前版本官方不支持 SVG 缩放。如果你遇到这个问题,可以试试这个方法:
创建一个自定义组件,该自定义组件继承 Shape.Empty,然后实现上面的两点
以下示例基于 自定义开关节点 改造
代码示例:
可以将上面的代码粘贴到 自定义开关节点 代码编辑器中查看效果。
最终效果演示:
5.mp4
Beta Was this translation helpful? Give feedback.
All reactions