V5 fix label shape error (#4645)

* update: update demo for bug reproduce

* fix: fix the bug
This commit is contained in:
MaLaiXiGua 2023-06-15 11:08:21 +08:00 committed by GitHub
parent f2b9c6be18
commit eea0536007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 14 deletions

View File

@ -378,7 +378,7 @@ export abstract class BaseEdge {
shapeStyle.height = h;
}
if (labelShapeProps) {
if (labelShape) {
const referShape = labelBackgroundShape || labelShape;
const referBounds =
this.boundsCache.labelBackgroundShapeGeometry ||

View File

@ -1,9 +1,6 @@
import G6 from '../../../src/index';
import { container, height, width } from '../../datasets/const';
// 1. Now, G6v5 already supports users to use different types of id
// 2. At the same time, it also supports users to pass in mixed type ids.
// 3. like: id:1, id:'2', id:'node1', etc.
export default () => {
const data = {
nodes: [
@ -12,31 +9,76 @@ export default () => {
data: {
x: 100,
y: 100,
badgeShapes: {
tag: 'badgeShape',
position: 'topRight', // Support topRight,topLeft and some other positions that contain uppercase Right or Left.
text: 'label'
}
}
type: 'circle-node',
},
},
{
id: '2',
id: 2,
data: {
x: 200,
y: 100,
}
type: 'circle-node',
},
},
],
edges: [
{
id: 'edge1',
source: 1,
target: 2,
data: {
type: 'line-edge'
}
}
]
};
const edge: ((data: any) => any) = (edgeInnerModel: any) => {
const { id, data } = edgeInnerModel
return {
id,
data: {
...data,
// labelShape: {
// text: 'label',
// position: 'bottom',
// },
iconShape: {
// img: 'https://gw.alipayobjects.com/zos/basement_prod/012bcf4f-423b-4922-8c24-32a89f8c41ce.svg',
text: 'label',
},
labelBackgroundShape: {
fill: 'red'
},
}
}
}
const graph = new G6.Graph({
container,
width,
height,
data,
type: 'graph',
modes: {
default: ['click-select', 'drag-canvas', 'zoom-canvas', 'drag-node'],
},
node: (nodeInnerModel: any) => {
const { id, data } = nodeInnerModel;
return {
id,
data: {
...data,
keyShape: {
r: 16
},
}
}
},
edge,
});
return graph
return graph;
}