Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add oversized label demo #5505

Merged
merged 5 commits into from Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/g6/__tests__/demo/static/common.ts
Expand Up @@ -29,6 +29,7 @@ export * from './edge-loop';
export * from './edge-polyline';
export * from './edge-port';
export * from './edge-quadratic';
export * from './element-label-oversized';
export * from './graph-element';
export * from './layered-canvas';
export * from './node-circle';
Expand Down
77 changes: 77 additions & 0 deletions packages/g6/__tests__/demo/static/element-label-oversized.ts
@@ -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();
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.