Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add oversized label demo (#5505)
* docs: add oversized label demo * docs: add copy label demo * docs: update label text wordWrap * docs: use clipboard API * test: add test for element label oversized
- Loading branch information
Showing
9 changed files
with
407 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/g6/__tests__/demo/static/element-label-oversized.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Graph } from '@/src'; | ||
import type { StaticTestCase } from '../types'; | ||
|
||
export const elementLabelOversized: StaticTestCase = async (context) => { | ||
const { container, animation, theme } = context; | ||
const data = { | ||
nodes: [ | ||
{ | ||
id: 'node1', | ||
data: { | ||
x: 100, | ||
y: 150, | ||
label: `This label is too long to be displayed`, | ||
size: 100, | ||
}, | ||
}, | ||
{ | ||
id: 'node2', | ||
data: { | ||
x: 400, | ||
y: 150, | ||
label: 'This label is too long to be displayed', | ||
size: 150, | ||
}, | ||
}, | ||
], | ||
edges: [ | ||
{ | ||
id: 'edge1', | ||
source: 'node1', | ||
target: 'node2', | ||
data: { | ||
label: 'This label is too long to be displayed', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const graph = new Graph({ | ||
container: container, | ||
theme, | ||
data, | ||
node: { | ||
style: { | ||
type: 'rect', | ||
x: (d: any) => d.data.x, | ||
y: (d: any) => d.data.y, | ||
size: (d: any) => d.data.size, | ||
labelPosition: 'bottom', | ||
labelText: (d: any) => d.data.label, | ||
labelMaxWidth: '90%', | ||
labelBackgroundFill: '#eee', | ||
labelBackgroundFillOpacity: 0.5, | ||
labelBackgroundRadius: 4, | ||
labelWordWrap: true, | ||
labelMaxLines: 4, | ||
}, | ||
}, | ||
edge: { | ||
style: { | ||
labelOffsetY: -4, | ||
labelTextBaseline: 'bottom', | ||
labelText: (d: any) => d.data.label, | ||
labelMaxWidth: '80%', | ||
labelBackgroundFill: 'red', | ||
labelBackgroundFillOpacity: 0.5, | ||
labelBackgroundRadius: 4, | ||
labelWordWrap: true, | ||
labelMaxLines: 4, | ||
}, | ||
}, | ||
behaviors: ['drag-node'], | ||
animation, | ||
}); | ||
|
||
await graph.render(); | ||
}; |
175 changes: 175 additions & 0 deletions
175
packages/g6/__tests__/integration/snapshots/static/element-label-oversized.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.