logo

G6

  • 文档
  • API
  • 图表示例
  • 社区
  • 所有产品antv logo arrow
  • 5.0.49
  • 简介
  • 开始使用
    • 快速开始
    • 安装
    • 前端框架集成
      • 在 React 中使用
      • 在 Vue 中使用
      • 在 Angular 中使用
    • 详细教程
  • 图 Graph
    • Graph - 图
    • Options 配置项
    • 内置扩展
    • Extension - 扩展
  • 数据 Data
  • 元素 Element
    • 元素总览
    • 元素状态
    • 节点 Node
      • 节点总览
      • 节点通用配置项
      • 圆形节点 Circle
      • 菱形节点 Diamond
      • 甜甜圈节点 Donut
      • 椭圆形节点 Ellipse
      • 六边形节点 Hexagon
      • HTML节点 Html
      • 图片节点 Image
      • 矩形节点 Rect
      • 五角形节点 Star
      • 三角形节点 Triangle
      • 自定义节点
      • 使用 React 定义节点
    • 边 Edge
      • 边总览
      • 边通用配置项
      • 三次贝塞尔曲线边 Cubic
      • 水平三次贝塞尔曲线边 CubicHorizontal
      • 垂直三次贝塞尔曲线边 CubicVertical
      • 直线边 Line
      • 二次贝塞尔曲线边 Quadratic
      • 折线边 Polyline
      • 自定义边
    • 组合 Combo
      • 组合总览
      • 组合通用配置项
      • 圆形组合 Circle
      • 矩形组合 Rect
      • 自定义 Combo
    • 图形 Shape
      • 图形 Shape 与 KeyShape
      • 原子 Shape 以及其属性
      • 复合 Shape 的设计与实现
  • 布局 Layout
    • 布局总览
    • 布局通用配置项
    • AntV Dagre 布局 AntvDagre
    • 环形布局 Circular
    • 复合布局 ComboCombined
    • 紧凑树布局 CompactBox
    • 同心圆布局 Concentric
    • 3D D3力导向布局 D3Force3D
    • D3力导向布局 D3Force
    • Dagre 布局
    • 生态树 Dendrogram
    • 鱼骨布局 Fishbone
    • ForceAtlas2 力导向布局
    • Force 力导向布局
    • Fruchterman 力导向布局
    • 网格布局 Grid
    • 缩进树 Indented
    • 高维数据降维布局 MDS
    • 脑图树 Mindmap
    • 径向布局 Radial
    • 随机布局 Random
    • 蛇形布局 Snake
    • 自定义布局
  • 交互 Behavior
    • 交互总览
    • 缩放画布 ZoomCanvas
    • 标签自适应显示 AutoAdaptLabel
    • 框选 BrushSelect
    • 点击选中 ClickSelect
    • 展开/收起元素 CollapseExpand
    • 创建边 CreateEdge
    • 拖拽画布 DragCanvas
    • 拖拽元素 DragElement
    • 力导向拖拽元素 DragElementForce
    • 缩放画布时固定元素大小 FixElementSize
    • 聚焦元素 FocusElement
    • 悬停激活 HoverActivate
    • 套索选择 LassoSelect
    • 优化视口变换 OptimizeViewportTransform
    • 滚动画布 ScrollCanvas
    • 自定义交互
  • 插件 Plugin
    • 插件总览
    • 背景 Background
    • 气泡集 BubbleSets
    • 上下文菜单 Contextmenu
    • 边绑定 EdgeBundling
    • 边过滤镜 EdgeFilterLens
    • 鱼眼放大镜 Fisheye
    • 全屏展示 Fullscreen
    • 网格线 GridLine
    • 历史记录 History
    • 轮廓包围 Hull
    • 图例 Legend
    • 小地图 Minimap
    • 对齐线 Snapline
    • 时间条 Timebar
    • 工具栏 Toolbar
    • 提示框 Tooltip
    • 水印 Watermark
    • 自定义插件
  • 数据处理 Transform
    • 数据处理总览
    • 动态调整节点大小 MapNodeSize
    • 径向标签 PlaceRadialLabels
    • 平行边 ProcessParallelEdges
    • 自定义数据处理
  • 主题 Theme
    • 主题总览
    • 自定义主题
    • 色板
    • 自定义色板
  • 动画 Animation
    • 动画总览
    • 自定义动画
  • 扩展阅读
    • 事件
    • 渲染器
    • 坐标系
    • 下载图片
    • 使用 iconfont
    • 使用 3D
    • 项目打包
  • 版本特性
    • 新版本特性
    • 升级到 5.0
  • 常见问题
  • 参与贡献

小地图 Minimap

上一篇
图例 Legend
下一篇
对齐线 Snapline

资源

Ant Design
Galacea Effects
Umi-React 应用开发框架
Dumi-组件/文档研发工具
ahooks-React Hooks 库

社区

体验科技专栏
seeconfSEE Conf-蚂蚁体验科技大会

帮助

GitHub
StackOverflow

more products更多产品

Ant DesignAnt Design-企业级 UI 设计语言
yuque语雀-知识创作与分享工具
EggEgg-企业级 Node 开发框架
kitchenKitchen-Sketch 工具集
GalaceanGalacean-互动图形解决方案
xtech蚂蚁体验科技
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

概述

Minimap(小地图)的主要作用是为用户提供以缩略图形式展示当前图内容的整体布局,可以快速定位图操作位置。

⚠️ 需要注意,Minimap 插件当前不兼容 React Node 渲染机制,在需要使用 Minimap 功能的场景中,建议通过 内置节点 或者自定义节点 实现节点渲染。

使用场景

Minimap(小地图)插件主要适用于以下场景:

  • 提供全局视野,快速定位区域
  • 导航与交互辅助,通过操作小地图可以快速定位到目标位置

基本用法

以下是一个简单的 Minimap 插件初始化示例:

const graph = new Graph({
plugins: [
{
key: 'minimap',
type: 'minimap',
size: [240, 160],
},
],
});

在线体验

minimap.md

createGraph(
{
data: {
nodes: Array.from({ length: 50 }).map((_, i) => ({
id: `node-${i}`,
x: Math.random() * 500,
y: Math.random() * 300,
})),
edges: Array.from({ length: 100 }).map((_, i) => ({
id: `edge-${i}`,
source: `node-${Math.floor(Math.random() * 50)}`,
target: `node-${Math.floor(Math.random() * 50)}`,
})),
},
node: { style: { fill: '#7e3feb' } },
edge: { style: { stroke: '#8b9baf' } },
layout: { type: 'force' },
behaviors: ['drag-canvas'],
plugins: [{ type: 'minimap', key: 'minimap', size: [240, 160], position: 'right-bottom' }],
},
{ width: 600, height: 300 },
(gui, graph) => {
const options = {
type: 'minimap',
width: 240,
height: 160,
shape: 'key',
padding: 10,
position: 'right-bottom',
maskStyleBorder: '1px solid #ddd',
maskStyleBackground: 'rgba(0, 0, 0, 0.1)',
containerStyleBorder: '1px solid #ddd',
containerStyleBackground: '#fff',
delay: 128,
};
const optionFolder = gui.addFolder('Minimap Options');
optionFolder.add(options, 'type').disable(true);
optionFolder
.add(options, 'width', 100, 500, 1)
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
size: [value, options.height],
});
graph.render();
});
optionFolder
.add(options, 'height', 100, 500, 1)
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
size: [options.width, value],
});
graph.render();
});
optionFolder
.add(options, 'shape', ['key'])
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
shape: value,
});
graph.render();
});
optionFolder
.add(options, 'padding', 0, 50, 1)
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
padding: value,
});
graph.render();
});
optionFolder
.add(options, 'position', ['right-bottom', 'left-bottom', 'right-top', 'left-top'])
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
position: value,
});
graph.render();
});
optionFolder
.addColor(options, 'maskStyleBorder')
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
maskStyle: { ...options.maskStyle, border: value },
});
graph.render();
});
optionFolder
.addColor(options, 'maskStyleBackground')
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
maskStyle: { ...options.maskStyle, background: value },
});
graph.render();
});
optionFolder
.addColor(options, 'containerStyleBorder')
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
containerStyle: { ...options.containerStyle, border: value },
});
graph.render();
});
optionFolder
.addColor(options, 'containerStyleBackground')
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
containerStyle: { ...options.containerStyle, background: value },
});
graph.render();
});
optionFolder
.add(options, 'delay', 0, 500, 1)
.listen()
.onChange((value) => {
graph.updatePlugin({
key: 'minimap',
delay: value,
});
graph.render();
});
// Update the maskStyle and containerStyle in the options object
Object.defineProperty(options, 'maskStyle', {
get: () => ({
border: options.maskStyleBorder,
background: options.maskStyleBackground,
}),
set: (value) => {
options.maskStyleBorder = value.border;
options.maskStyleBackground = value.background;
},
});
Object.defineProperty(options, 'containerStyle', {
get: () => ({
border: options.containerStyleBorder,
background: options.containerStyleBackground,
}),
set: (value) => {
options.containerStyleBorder = value.border;
options.containerStyleBackground = value.background;
},
});
},
);

配置项

属性描述类型默认值必选
type插件类型stringminimap✓
key插件唯一标识符,用于后续更新string-
className缩略图画布类名,传入外置容器时不生效string
container缩略图挂载的容器,无则挂载到 Graph 所在容器HTMLElement | string
containerStyle缩略图的容器样式,传入外置容器时不生效Partial<CSSStyleDeclaration>
delay延迟更新时间(毫秒),用于性能优化number128
filter过滤器,用于过滤不必显示的元素(id: string, elementType: node | edge | combo) => boolean
maskStyle遮罩的样式Partial<CSSStyleDeclaration>
padding内边距number | number[]10
position缩略图相对于画布的位置[number, number] | left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | centerright-bottom
renderer渲染器,默认使用 Canvas 渲染器IRenderer
shape元素缩略图形的生成方法key | ((id: string, elementType: node | edge | combo) => DisplayObject)key
size宽度和高度[number, number][240, 160]

containerStyle

设置缩略图的容器样式,传入外置容器时不生效。继承了所有 CSS 样式属性(CSSStyleDeclaration),你可以使用任何合法的 CSS 属性来配置缩略图容器的样式。

以下是一些常用配置:

属性描述类型默认值必选
border容器边框样式string1px solid #ddd✓
background容器背景颜色string#fff✓
borderRadius容器圆角大小string-
boxShadow容器阴影效果string-
padding容器内边距string-
margin容器外边距string-
opacity透明度string-

maskStyle

指定遮罩的样式。继承了所有 CSS 样式属性(CSSStyleDeclaration),你可以使用任何合法的 CSS 属性来配置缩略图容器的样式。

以下是一些常用配置:

属性描述类型默认值必选
border容器边框样式string1px solid #ddd✓
background容器背景颜色stringrgba(0, 0, 0, 0.1)✓
borderRadius容器圆角大小string--
boxShadow容器阴影效果string--
padding容器内边距string--
margin容器外边距string--
opacity透明度string--

position

缩略图相对于画布的位置,缩略图位置配置支持数组形式和预设值形式。

  • 数组形式 [number, number] 表示相对位置,取值范围为 0~1。举例:[0, 0] 代表画布左上角,[1, 1] 代表画布右下角。
  • 预设值形式用于设定缩略图所在画布固定方位,可选值有:left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | center
const graph = new Graph({
plugins:[
{
... // 其他配置
key: 'minimap',
type: 'minimap',
position: 'right-bottom' // 这里进行修改minimap所在位置
}
]
})

效果如下:

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
width: 600,
height: 300,
data: {
nodes: Array.from({ length: 50 }).map((_, i) => ({
id: `node-${i}`,
x: Math.random() * 500,
y: Math.random() * 300,
})),
edges: Array.from({ length: 100 }).map((_, i) => ({
id: `edge-${i}`,
source: `node-${Math.floor(Math.random() * 50)}`,
target: `node-${Math.floor(Math.random() * 50)}`,
})),
},
node: { style: { fill: '#7e3feb' } },
edge: { style: { stroke: '#8b9baf' } },
layout: { type: 'force' },
behaviors: ['drag-canvas'],
plugins: [{ type: 'minimap', key: 'minimap', size: [240, 160], position: 'right-bottom' }],
});
graph.render();

size

设置小地图的宽度和高度,默认值为 [240, 160]

const graph = new Graph({
plugins:[
{
... // 其他配置
key: 'minimap',
type: 'minimap',
size: [200, 120] // minimap的宽度和高度的设置
}
]
})

效果如下:

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
width: 600,
height: 300,
data: {
nodes: Array.from({ length: 50 }).map((_, i) => ({
id: `node-${i}`,
x: Math.random() * 500,
y: Math.random() * 300,
})),
edges: Array.from({ length: 100 }).map((_, i) => ({
id: `edge-${i}`,
source: `node-${Math.floor(Math.random() * 50)}`,
target: `node-${Math.floor(Math.random() * 50)}`,
})),
},
node: { style: { fill: '#7e3feb' } },
edge: { style: { stroke: '#8b9baf' } },
layout: { type: 'force' },
behaviors: ['drag-canvas'],
plugins: [{ type: 'minimap', key: 'minimap', size: [200, 120], position: 'right-bottom' }],
});
graph.render();

实际案例

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
data: { nodes: Array.from({ length: 20 }).map((_, i) => ({ id: `node${i}` })) },
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element'],
plugins: [
{
type: 'minimap',
size: [240, 160],
},
],
node: {
palette: 'spectral',
},
layout: {
type: 'circular',
},
autoFit: 'view',
});
graph.render();