antv/x6 导出图片方法exportPNG
antv/x6 导出图片方法exportPNG
antv/x6 版本如下:
"@antv/x6": "2.14.1","@antv/x6-plugin-export": "2.1.6",
在文件中导入
import { Graph, Shape, StringExt } from '@antv/x6'
import { Export } from '@antv/x6-plugin-export'this.graph.use(new Export())
exportPNG方法
this.graph.exportPNG('导出图片名称', {quality: 0.8,backgroundColor: 'black'
})
API
width number - 导出图片的宽度
height number - 导出图片的高度
backgroundColor string - 导出图片的背景色
padding NumberExt.SideOptions - 图片的 padding
quality number - 图片质量,可以从 0 到 1 的区间内选择图片的质量。如果超出取值范围,将会使用默认值 0.92
preserveDimensions boolean | Size - preserveDimensions 用来控制导出 svg 的尺寸, 如果不设置,width 和 height 默认为 100%;如果设置为 true, width 和 height 会自动计算为图形区域的实际大小
viewBox Rectangle.RectangleLike - 设置导出 svg 的 viewBox
copyStyles boolean true 是否复制外部样式表中的样式,默认是 true。开启 copyStyles 后,在导出过程中因为需要禁用所有样式表,所以页面可能会出现短暂的样式丢失现象。如果效果特别差,可以将 copyStyles 设置为 false
stylesheet string - 自定义样式表
serializeImages boolean true 是否将 image 元素的 xlink:href 链接转化为 dataUri 格式
beforeSerialize (this: Graph, svg: SVGSVGElement) => any - 可以在导出 svg 字符串之前调用 beforeSerialize 来修改它