antv/x6的2.x版本在vue3中使用history插件实现撤销恢复

一、引用

import { Graph, Shape } from '@antv/x6'
import { History } from '@antv/x6-plugin-history'
//其他插件....

二、初始化画布和插件

const graphContainer = ref()
let graph = ref()
const canUndo = ref(true)
const canRedo = ref(false)
const history = new History({
    enabled:true
});
graph.value = new Graph({
	container: graphContainer.value,
	grid: true,
	background: false, //背景透明
	snapline: false, //对齐线
	// 鼠标缩放
	mousewheel: {
	    enabled: true,
	    zoomAtMousePosition: true,
	    modifiers: 'ctrl',
	    minScale: 0.5,
	    maxScale: 3,
	},
	// 配置连线规则
	connecting: {
	    router: 'manhattan', // 算法路由 manhattan orth  metro
	    // 边渲染到画布后的样式
	    connector: {
	        name: 'rounded',
	        args: {
	            radius: 8,
	        },
	    },
	    anchor: 'center',
	    connectionPoint: 'anchor',
	    allowBlank: false, //是否允许连接到画布空白位置的点
	    allowMulti: true, //是否允许在相同的起始节点和终止之间创建多条边
	    allowLoop: true, //是否允许创建循环连线,即边的起始节点和终止节点为同一节点
	    highlight: true, //拖动边时,是否高亮显示所有可用的节点
	    snap: true, //自动吸附
	    highlighting: {
	        magnetAdsorbed: {
	            name: "stroke",
	            args: {
	                attrs: {
	                    fill: "#5F95FF",
	                    stroke: "#5F95FF",
	                },
	            },
	        },
	    },
	},
	panning: {
	    enabled: false,
	},
	grid: {
	    type: "dot",
	    size: 10, // 网格大小 10px
	    visible: true, // 渲染网格背景
	    args: {
	        color: "#a0a0a0", // 网格线/点颜色
	        thickness: 2, // 网格线宽度/网格点大小
	    }
	}
})
//使用插件
graph.value.use(history)
	
//监听命令
graph.value.on('history:change', (e) => {
	canUndo.value = history.canUndo()
	canRedo.value = history.canRedo()
})

三、撤销恢复事件方法

//撤销
const Undo = () =>{
    history.undo()
}
//恢复
const Redo = () =>{
    history.redo()
}
<span class="mx-2 cursor-pointer">
    <el-tooltip content="撤销" placement="bottom">
        <component :is="Back" size="24" @click="Undo"></component>
    </el-tooltip>
</span>
<span class="mx-2 cursor-pointer">
    <el-tooltip content="恢复" placement="bottom">
        <component :is="Next" size="24" @click="Redo"></component>
    </el-tooltip>
</span>
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
antv/G2 4.1.46 版本,可以通过添加缩略轴组件来实现缩略轴,同时可以通过设置 handler 的 symbol 属性为 'circle' 来使其呈现圆形。 以下是一个简单的示例代码: ```javascript import { Chart, Axis, Tooltip, Interval, Slider } from '@antv/g2'; const data = [ { year: '1991', value: 3 }, { year: '1992', value: 4 }, { year: '1993', value: 3.5 }, { year: '1994', value: 5 }, { year: '1995', value: 4.9 }, { year: '1996', value: 6 }, { year: '1997', value: 7 }, { year: '1998', value: 9 }, { year: '1999', value: 13 }, ]; const chart = new Chart({ container: 'container', autoFit: true, height: 500, }); chart.data(data); chart.scale({ year: { range: [0, 1], }, value: { nice: true, }, }); chart.tooltip({ showCrosshairs: true, shared: true, }); chart.axis('value', { label: null, title: null, line: null, }); chart.axis('year', { label: null, tickLine: null, line: null, }); chart .interval() .position('year*value') .color('#1890ff'); const slider = new Slider({ container: 'slider', width: 'auto', height: 26, padding: [0, 30, 0, 30], start: 0, end: 1, data, xAxis: 'year', yAxis: 'value', backgroundChart: { type: 'line', }, handlerStyle: { symbol: 'circle', }, }); slider.render(); chart.interaction('element-active'); chart.render(); ``` 在上面的代码,我们通过 `new Slider()` 方法创建了一个 Slider 组件,并将其渲染到页面上。在 Slider 组件的配置,我们设置了 `handlerStyle` 属性的 `symbol` 值为 'circle',从而使 handler 呈现圆形。同时,我们还设置了 `backgroundChart` 属性的 `type` 值为 'line',从而使缩略轴呈现折线图的形式。 你可以在该示例修改数据和样式来满足自己的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值