Skip to content

Commit

Permalink
feat: 用户编辑过程中动态生成的连线也可以被渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
小耀 authored and bubkoo committed Apr 10, 2020
1 parent 321e0ce commit c09fdbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion examples/x6-example-features/src/pages/tojson-demo.tsx
Expand Up @@ -217,6 +217,13 @@ export default class Example extends Component {
},
})

// 这段字符串是下面代码生成的内容stringify得到的
const string =
'{"nodes":[{"id":"node1","data":{"x":1,"y":2},"shape":"react","visible":true,"x":48,"y":48,"width":180,"height":40,"relative":false,"translateControlPoints":true,"bounds":{"x":48,"y":48,"width":180,"height":40}},{"id":"node2","data":{"xx":11,"yy":22},"shape":"react","label":false,"visible":true,"x":100,"y":200,"width":180,"height":40,"relative":false,"translateControlPoints":true,"bounds":{"x":100,"y":200,"width":180,"height":40}}],"edges":[{"id":"edge1","data":{"edge":"1111"},"curved":true,"rounded":true,"visible":true,"x":0,"y":0,"width":0,"height":0,"relative":true,"translateControlPoints":true,"bounds":{"x":0,"y":0,"width":0,"height":0},"source":"node1","target":"node2"},{"id":"cell-2","data":null,"align":"center","verticalAlign":"middle","fontColor":"rgba(0, 0, 0, 1)","shape":"connector","endArrow":"classic","stroke":"#888","sourceAnchorX":"1","sourceAnchorY":"0.5","targetAnchorX":"1","targetAnchorY":"0.5","sourceAnchorDx":"0","targetAnchorDx":"0","targetAnchorDy":"0","visible":true,"x":0,"y":0,"width":0,"height":0,"relative":true,"translateControlPoints":true,"bounds":{"x":0,"y":0,"width":0,"height":0},"source":"node1","target":"node2"}]}'
graph.render(JSON.parse(string))

return

const node1 = graph.addNode({
id: 'node1',
x: 48,
Expand Down Expand Up @@ -309,7 +316,7 @@ export default class Example extends Component {
console.log('看看画布JSON转换为string:', resultToString)

graph.render(JSON.parse(resultToString))
}, 10000)
}, 8000)
}

// 有群组的情况
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/core/cell.ts
Expand Up @@ -37,7 +37,7 @@ export class Cell<T = any> extends Disposable {
toJSON(cell: Cell) {
const { id, data, style, visible, collapsed, geometry, parent } = cell

const { source, target, ...styleRest } = style
const { source, target, parent: p, ...styleRest } = style
const bounds = geometry && geometry.bounds
// node、edge通用部分数据
const cellData: any = {
Expand Down

0 comments on commit c09fdbd

Please sign in to comment.