Background
Previous
Plugin Overview
Next
BubbleSets
Loading...
Support setting a background image for the graph canvas to enhance its layering and narrative.
This plugin is mainly used for:
const graph = new Graph({plugins: [{type: 'background',key: 'my-background', // Specify an identifier for the plugin for dynamic updatesbackgroundColor: '#f0f2f5', // Set background colorbackgroundImage: 'url(https://example.com/bg.png)', // Set background image},],});
The configuration options for the Background plugin inherit all CSS style properties (CSSStyleDeclaration), so you can use any valid CSS property to configure the background. Here are some common configurations:
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
type | Plugin type | string | background | ✓ |
key | Unique identifier for the plugin for subsequent updates | string | - | |
width | Background width | string | 100% | |
height | Background height | string | 100% | |
backgroundColor | Background color | string | - | |
backgroundImage | Background image | string | - | |
backgroundSize | Background size | string | cover | |
backgroundPosition | Background position | string | - | |
backgroundRepeat | Background repeat method | string | - | |
opacity | Background opacity | string | - | |
transition | Transition animation | string | background 0.5s | |
zIndex | Stacking order | string | -1 |
Note: The default
zIndex
is -1 to prevent the background from covering other plugin DOM elements, such as grid lines.
const graph = new Graph({// Other configurations...plugins: [{type: 'background',backgroundColor: '#f0f2f5',},],});
const graph = new Graph({// Other configurations...plugins: [{type: 'background',backgroundImage: 'url(https://example.com/bg.png)',backgroundSize: 'cover',backgroundPosition: 'center',},],});
const graph = new Graph({// Other configurations...plugins: [{type: 'background',background: 'linear-gradient(45deg, #1890ff, #722ed1)',opacity: '0.8',},],});
// Configuration during initializationconst graph = new Graph({// Other configurations...plugins: [{type: 'background',key: 'my-background',backgroundColor: '#f0f2f5',},],});// Subsequent updatesgraph.updatePlugin({key: 'my-background',backgroundColor: '#e6f7ff',transition: 'background 1s ease',});
By default, the zIndex
of the background plugin is set to -1
to ensure it is below other elements. If there is still a conflict, you can adjust the zIndex
value:
const graph = new Graph({plugins: [{type: 'background',zIndex: '-2', // Lower the z-index to avoid conflict},],});