Loading...
The Fullscreen plugin allows users to expand the graph visualization content to the entire screen, providing a broader view and a better immersive experience.
The Fullscreen plugin is mainly suitable for the following scenarios:
Below is a simple example of initializing the Fullscreen plugin:
const graph = new Graph({plugins: [{type: 'fullscreen',autoFit: true,trigger: {request: 'F', // Use shortcut key F to enter fullscreenexit: 'Esc', // Use shortcut key Esc to exit fullscreen},onEnter: () => {console.log('Entered fullscreen mode');},onExit: () => {console.log('Exited fullscreen mode');},},],});
Property | Description | Type | Default Value | Required |
---|---|---|---|---|
type | Plugin type | string | fullscreen | ✓ |
key | Unique identifier for the plugin, can be used to get the plugin instance or update plugin options | string | - | |
autoFit | Whether to auto-fit the canvas size, the canvas size will automatically adapt to the screen size when fullscreen | boolean | true | |
trigger | Method to trigger fullscreen, example | { request?: string; exit?: string; } | - | |
onEnter | Callback after entering fullscreen | () => void | - | |
onExit | Callback after exiting fullscreen | () => void | - |
The trigger property is used to control the method of triggering fullscreen. It supports two configuration methods:
Use keyboard shortcuts to trigger fullscreen and exit fullscreen.
const graph = new Graph({plugins: [{type: 'fullscreen',trigger: {request: 'F', // Use shortcut key F to enter fullscreenexit: 'Esc', // Use shortcut key Esc to exit fullscreen},},],});
Control fullscreen by calling the request and exit methods.
const graph = new Graph({plugins: [{type: 'fullscreen',key: 'my-fullscreen',},],});// Enter fullscreengraph.getPluginInstance('my-fullscreen').request();// Exit fullscreengraph.getPluginInstance('my-fullscreen').exit();
Whether to auto-fit the canvas size, the canvas size will automatically adapt to the screen size when fullscreen.
const graph = new Graph({plugins: [{type: 'fullscreen',autoFit: true,},],});
This method is used to enter fullscreen mode programmatically. It can be called on the plugin instance to expand the graph visualization to the entire screen.
const graph = new Graph({plugins: [{type: 'fullscreen',key: 'my-fullscreen',},],});// Enter fullscreengraph.getPluginInstance('my-fullscreen').request();
This method is used to exit fullscreen mode programmatically. It can be called on the plugin instance to revert the graph visualization back to its original size.
const graph = new Graph({plugins: [{type: 'fullscreen',key: 'my-fullscreen',},],});// Exit fullscreengraph.getPluginInstance('my-fullscreen').exit();
import { Graph } from '@antv/g6';const graph = new Graph({data: { nodes: Array.from({ length: 20 }).map((_, i) => ({ id: `node${i}` })) },autoFit: 'center',background: '#fff',plugins: [{type: 'fullscreen',key: 'fullscreen',},function () {const graph = this;return {type: 'toolbar',key: 'toolbar',position: 'top-left',onClick: (item) => {const fullscreenPlugin = graph.getPluginInstance('fullscreen');if (item === 'request-fullscreen') {fullscreenPlugin.request();}if (item === 'exit-fullscreen') {fullscreenPlugin.exit();}},getItems: () => {return [{ id: 'request-fullscreen', value: 'request-fullscreen' },{ id: 'exit-fullscreen', value: 'exit-fullscreen' },];},};},],});graph.render();