Merge pull request #547 from antvis/addTest

test: Add test
This commit is contained in:
Yellowthrough 2018-11-30 19:16:09 +08:00 committed by GitHub
commit e2a8e16a9f
10 changed files with 396 additions and 198 deletions

View File

@ -3,19 +3,31 @@
--- ---
#### 2.2.1 #### 2.2.1
`2018-11-25`
* fix: Compatible with MOUSEWHEEL * fix: Compatible with MOUSEWHEEL
* fix: fadeIn aniamtion * fix: fadeIn aniamtion
* fix: fix wheelZoom behaviour by removing the deprecated mousewheel event * fix: fix wheelZoom behaviour by removing the deprecated mousewheel event
#### 2.2.0 #### 2.2.0
`2018-11-22`
* fix: Graph read zIndex * fix: Graph read zIndex
* refactor: Animation * refactor: Animation
#### 2.1.5 #### 2.1.5
`2018-10-26`
* fix: svg pixelRatio bug * fix: svg pixelRatio bug
* feat: add wheel event * feat: add wheel event
#### 2.1.4 #### 2.1.4
`2018-10-06`
* fix: custom math.sign to compatible with ie browser.Closes #516. * fix: custom math.sign to compatible with ie browser.Closes #516.
* fix: legend component from @antv/component * fix: legend component from @antv/component
* feat: update svg minimap && fix svg dom event * feat: update svg minimap && fix svg dom event
@ -48,7 +60,7 @@
* feat: svg render * feat: svg render
* feat: plugin.layout.forceAtlas2 * feat: plugin.layout.forceAtlas2
* feat: plugin.tool.fisheye * feat: plugin.tool.fisheye
* feat: plugin.tool.textDisplay * feat: plugin.tool.textDisplay
* feat: plugin.tool.grid * feat: plugin.tool.grid
* feat: plugin.template.tableSankey * feat: plugin.template.tableSankey
@ -58,7 +70,7 @@
`2018-07-12` `2018-07-12`
improve: add g6 arrow * improve: add g6 arrow
#### 2.0.4 #### 2.0.4
@ -92,7 +104,7 @@ improve: add g6 arrow
* fix(saveImage) saveImage bug * fix(saveImage) saveImage bug
* fix(event): fix dom coord. Closes #305 * fix(event): fix dom coord. Closes #305
## v2.0.1 #### 2.0.1
`2018-06-11` `2018-06-11`
@ -102,299 +114,301 @@ improve: add g6 arrow
* chore: .travis.yml add add Node.js * chore: .travis.yml add add Node.js
* chore: .travis.yml cache node_modules * chore: .travis.yml cache node_modules
## v2.0.0 #### 2.0.0
`2018-06-06` `2018-06-06`
* refactor: 重构架构 && 代码 * refactor: refactor architecture && code
## v1.2.1 #### 1.2.1
`2018-03-15` `2018-03-15`
* feat: 新增 layout 接口 * feat:    layout interface
## v1.2.0 #### 1.2.0
`2018-01-15` `2018-01-15`
* fix: 修复 nodeActivedBoxStyle 拼写错误 * fix: nodeActivedBoxStyle spelling error
* fix: 修复 删除环时报错 * fix: error when deleting a circle
* fix: 修复 右键后再移动鼠标触发 dragstart * fix: trigger dragstart while right clicking and moveing
* feat: 新增 统一布局机制到 Graph * feat: Unify Layout mechanism
* feat: 新增 插件机制 * feat: Plugin mechanism
* feat: 新增 数据过滤机制 * feat: Data filter mechanism
* feat: 新增 激活态接口 * feat: Activated interface
* feat: 新增 行为 wheelZoomAutoLabel * feat: Action wheelZoomAutoLabel
* feat: 新增 graph 配置项 preciseAnchor * feat: configuration of graph -- preciseAnchor
* remove: 移除 Global.preciseAnchor * remove: Global.preciseAnchor
* remove: 移除 Layout.Flow、Layout.Force * remove: Layout.Flow、Layout.Force
* improve: 改进 html 容器策略 * improve: html container strategy
## v1.1.6 #### 1.1.6
`2017-10-15` `2017-10-15`
* fix: 修复 布局算法包中的打包问题 * fix: pack problem in layout algorithm
## v1.1.5 #### 1.1.5
`2017-09-15` `2017-09-15`
* fix: 修复 dragCanvas 在 mousemove 才设置拾取实效,否则会影响点击事件 * fix: dragCanvas is effective while mousemove, prevent it from affecting click events
* fix: 修复 将 node 的 activeRectBox 的拾取设置为false * fix: unactivate pick-up in activeRectBox of node
## v1.1.4 #### 1.1.4
`2017-08-15` `2017-08-15`
* feat: 新增 graph.invertPoint() 转置点 * feat: graph.invertPoint()
* feat: 新增 锚点第三个配置参数 此后锚点支持设置样式、悬浮样式、是否可以连接 * feat: third configuration of anchor to support style setting, float style, connection
* feat: 新增 item.getGroup() * feat: item.getGroup()
* feat: 新增 事件 afteritemrender、itemremove、itemadd * feat: events -- afteritemrender、itemremove、itemadd
* feat: 新增 行为信号量 behaviourSignal * feat: behaviourSignal
* improve: 改进 画布聚焦时 mouseWheel 才生效 * improve: mouseWheel is affective after focusing the canvas
## v1.1.3 #### 1.1.3
`2017-08-8` `2017-08-8`
* feat: 新增 Graph 配置项 useNodeSortGroup用于配置节点组是否使用排序组 * feat: Graph configuration -- useNodeSortGroup
* feat: 新增 Global.nodeDelegationStyle, Global.edgeDelegationStyle 边和节点可独立配置委托图形 * feat: Global.nodeDelegationStyle, Global.edgeDelegationStyle, isolate the delegation of edge and node on graph
* fix: 修复 事件 itemremove 销毁前触发 * fix: itemremove is triggered before destroying a graph
## v1.1.2 #### 1.1.2
`2017-08-01` `2017-08-01`
* feat: 新增 行为 dragBlankX dragBlankY * feat: dragBlankX dragBlankY
#### 1.1.1
## v1.1.1
`2017-07-18` `2017-07-18`
* improve: 改进 添加 dragNode 保护机制 * improve: dragNode protect mechanism
## v1.1.0 #### 1.1.0
`2017-07-05` `2017-07-05`
* feat: 新增 HTML 节点 * feat: HTML node
* feat: 新增 映射支持直接传入 callback * feat: mapper support callback function
* feat: 新增 Graph 接口 updateMatrix、changeSize、showAnchor、hideAnchor、updataNodesPosition * feat: Graph interfaces -- updateMatrix、changeSize、showAnchor、hideAnchor、updataNodesPosition
* feat: 新增 工具方法 Util.isNode()、Util.isEdge() * feat:  tool functions -- Util.isNode()、Util.isEdge()
* feat: 新增 Shape polyLineFlow * feat: Shape polyLineFlow
* feat: 新增 行为 dragEdgeEndHideAnchor、dragNodeEndHideAnchor、hoverAnchorSetActived、hoverNodeShowAnchor * feat:  dragEdgeEndHideAnchor、dragNodeEndHideAnchor、hoverAnchorSetActived、hoverNodeShowAnchor
## v1.0.7 #### 1.0.7
`2017-06-21` `2017-06-21`
* fix: 修复 第一次 draw 时 16ms 内多画一下 * fix: draw one more time in 16ms after first draw
* improve: 改进 edit 模式下怎家滚轮缩放限制 * improve: add zoom by scroll in edit mode
## v1.0.6 #### 1.0.6
`2017-06-15` `2017-06-15`
* fix: 修复 兼容部分 机型 window 下 chrome 首次点击出发 mousemove 导致click事件不正确 * fix: compatible in chrome in windows. triggering mousemove after first click leads to wrong click event.
* feat: 新增 支持尺寸不变图形 * feat: support fix size graphics
* feat: 新增 analysis 分析模式 * feat: analysis mode
* feat: 新增 updateNodesPositon 批量更新节点位置方法 * feat: updateNodesPositon update a set of nodes' position
* improve: 改进 useAnchor 改为 边 edge 的配置项 * improve: change useAnchor to be a configuration of edge
## v1.0.5 #### 1.0.5
`2017-06-01` `2017-06-01`
* feat: 新增 downloadImage 支持传入保存的文件名 * feat: downloadImage support saving with name
* feat: 新增 tooltip 边距自动检测 * feat: automatically detect tooltip padding
* improve: 改进 拖拽移出画布时拖拽行为中止 * improve:  stop the action while mouse dragging out of the canvas
## v1.0.4 #### 1.0.4
`2017-05-20` `2017-05-20`
* fix: 修复 tree changeData Bug * fix: tree changeData Bug
* fix: 修复 getAnchorPoints 返回 auto 时锚点取直线与包围盒的截取点 * fix:  when getAnchorPoints returns auto, anchor is the intersection of edge and the bounding box
* fix: 修复 node label 无法生成的判定条件为 isNull * fix: generate node label according to isNull
* feat: 新增 增加视口参数 tl、tc、tr、rc、br、bc、bl、lc、cc * feat: viewport parameters -- tl、tc、tr、rc、br、bc、bl、lc、cc
* improve: 改进 减小 tolerance 数值,以提高线段截取精准度 * improve: reduce tolerance to improve the accuracy of interception
* improve: 改进 tooltip 事件机制,提升性能 * improve: improve tooltip event mechanisom to enhance performance
## v1.0.3 #### 1.0.3
`2017-05-10` `2017-05-10`
* feat: 新增 graph.guide().link() 添加 link 辅助元素 * feat: graph.guide().link()
## v1.0.2 #### 1.0.2
`2017-05-10` `2017-05-10`
* fix: 修复 Object.values => Util.getObjectValues * fix: Object.values => Util.getObjectValues
* fix: 修复 anchorPoints 为 auto 时edge上就算传了anchorpoint也返回截取点 * fix:  when anchorPoints is auto, there is only anchorpoint on edge, it will also return the intersection
* fix: 修复 tree 更新接口 Bug * fix: tree update interface Bug
* improve: 改进 位置信息用 group.transfrom() 来表示 * improve:  represent positions information by group.transfrom()
## v1.0.1 #### 1.0.1
`2017-04-22` `2017-04-22`
* fix: 修复 复制、粘贴 bug * fix: copy and paste bug
* feat: 新增 控制 16s 内只 draw 一次 * feat: draw once in 16ms
* feat: 新增 事件 itemactived itemunactived itemhover itemupdate itemmouseenter itemmouseleave * feat: itemactived itemunactived itemhover itemupdate itemmouseenter itemmouseleave
* improve: 改进 框选行为激活图形前,应清楚之前图形的激活 * improve: be clear the status of graphics before activating graphics by frame selection
* improve: 改进 dragAddEdge 行为,可链接到锚点 * improve: dragAddEdge, linkable to anchor
* improve: 改进 优化动画性能 * improve: performance of animation
## v1.0.0 #### 1.0.0
`2017-03-31` `2017-03-31`
* feat: 新增 fitView 视口配置项 * feat: fitView configurations
* feat: 新增 graph.zoom() 缩放接口 * feat:  graph.zoom()
* feat: 新增 wheelZoomHideEdges 滚轮缩放边隐藏行为 * feat: wheelZoomHideEdges hide the edges while zooming by wheel
* feat: 新增 dragHideEdges 拖动边隐藏行为 * feat: dragHideEdges hide the edge while dragging edge
* feat: 新增 graph.filterBehaviour() 过滤行为接口 * feat: graph.filterBehaviour()
* feat: 新增 graph.addBehaviour() 增加行为接口 * feat: graph.addBehaviour()
* feat: 新增 graph.changeLayout() 更改布局 * feat:   graph.changeLayout()
* feat: 新增 read 读接口,重定义 save 保存接口 * feat:  read interface, re-define save interface
* feat: 新增 graph.snapshot 快照功能 graph.downloadImage 导出图片功能 * feat:  graph.snapshot, graph.downloadImage
* feat: 新增 graph.autoSize() 自动缩放画布尺寸 * feat:  graph.autoSize()
* feat: 新增 graph.focusPoint() 聚焦某点 * feat:  graph.focusPoint()
* feat: 新增 tree 树图、net 网图 * feat: tree graph、net graph
* feat: 新增 交互机制 事件 => 行为 => 模式 * feat: interaction mechanism -- event => action => mode
* feat: 新增 动画机制 * feat: animation mechanism
* feat: 新增 itemmouseleave、itemmouseenter 事件 * feat: itemmouseleave、itemmouseenter
* remove: 去除 graph.refresh() * remove: graph.refresh()
* remove: 去除 graph.changeNodes() * remove: graph.changeNodes()
* remove: 去除 graph属性 zoomable、dragable、resizeable、selectable * remove: graph attributes -- zoomable、dragable、resizeable、selectable
* improve: 改进 锚点机制,更快、更强 * improve: anchor mechanism
* improve: 改进 不再抛出 G6.GraphUtil 方法,全部统一成 G6.Util * improve: hide G6.GraphUtil functions, unified in G6.Util
* improve: 改进 替换 g-canvas-core => g-canvas 性能提升 * improve: replace g-canvas-core to g-canvas to improve performance
* improve: 改进 移除 Global.nodeBoxStyle 改用 Global.nodeAcitveBoxStyle * improve: Global.nodeAcitveBoxStyle instead of Global.nodeBoxStyle
* improve: 改进 小写事件名 afterAdd => afteradd * improve: afterAdd => afteradd
* improve: 改进 G6.Graph 沉为抽象类 * improve: G6.Graph to be an abstract class
## v0.2.3 #### 0.2.3
`2017-03-2` `2017-03-2`
* fix: 修复 dragable 可用于控制默认模式下是否可拖动画布 * fix: dragable for controlling dragable under default mode
* feat: 新增 graph.converPoint() 反置点方法 * feat: graph.converPoint()
* feat: 新增 graph.autoSize() * feat: graph.autoSize()
* feat: 新增 rightmousedown leftmousedown wheeldown 事件 * feat: rightmousedown leftmousedown wheeldown
* improve: 改进 用tyr catch 防御getPoint由于path长度为零出错 * improve: use try catch to prevent the length of getPoint of path equals zero
## v0.2.2 #### 0.2.2
`2017-02-24` `2017-02-24`
* fix: 修复 tooltip css padding 加px * fix: add px totooltip css padding
* fix: 修复 tooltip 单子段映射错误 * fix: tooltip mapping error
* fix: 修复 精确截取点错误 * fix: accurate intersection
* fix: 修复 双精屏下缩放点错误 * fix: zoom error on double accuracy screen
* fix: 修复 包围盒应该 apply keyShape 父元素 * fix: buonding box extended from keyShape
* feat: 新增 afterAdd 事件 * feat:   afterAdd
* feat: 新增 dblclick 事件 * feat: dblclick
* improve: 改进 width、height 默认null * improve: width、height default null
* improve: 改进 节点不再使用hovershape * improve: remove hovershape on node
* improve: 改进 tooltip 增加防御机制 * improve: tooltip defense mechanism
## v0.2.1 #### 0.2.1
`2017-02-14` `2017-02-14`
* fix: 新增 添加节点时增加rollback * fix: rollback when add node
* fix: 新增 计算包围盒apply父容器变换 * fix: apply tranformation of parent container while calculating bounding box
* feat: 新增 waterPath 水波路径算法 * feat: waterPath
* feat: 新增 tooltip 提示信息 * feat: tooltip tip information
* feat: 新增 mouseover 事件 * feat: mouseover
* feat: 新增 multiSelectable 配置项,默认关闭,关闭时选择模式开启空白处拖动功能 * feat: multiSelectable, default false
* feat: 新增 width 没设置时自动forceFit 为 true * feat:  set forceFit to true while width is undefined
* improve: 改进 zoomable、dragable、resizeable、selectable 默认为 true * improve: zoomable、dragable、resizeable、selectable default true
## v0.2.0 #### 0.2.0
`2017-02-07` `2017-02-07`
* feat: 新增 精确逼近锚点机制 * feat: accurate anchor mechanism
* feat: 新增 GraphUtil.getEllipsePath 点集到椭圆Path * feat: GraphUtil.getEllipsePath
* feat: 新增 GraphUtil.pointsToPolygon 点集到多边形Path * feat:  GraphUtil.pointsToPolygon
* feat: 新增 GraphUtil.pointsToBezier 点集到贝塞尔曲线Path * feat: GraphUtil.pointsToBezier
* feat: 新增 GraphUtil.snapPreciseAnchor 获取精准锚点方法 * feat: GraphUtil.snapPreciseAnchor
* feat: 新增 GraphUtil.arrowTo 箭头旋转方法 * feat: GraphUtil.arrowTo
* feat: 新增 GraphUtil.drawEdge 画边方法 * feat: GraphUtil.drawEdge
* feat: 新增 bezierQuadratic 二阶贝塞尔曲线 * feat: bezierQuadratic
* feat: 新增 node.show 显示节点 * feat: node.show
* feat: 新增 node.hide 隐藏节点 * feat: node.hide
* feat: 新增 node.getLinkNodes 获取相连的节点 * feat: node.getLinkNodes
* feat: 新增 node.getUnLinkNodes 获取不相连的节点 * feat:  node.getUnLinkNodes
* feat: 新增 node.getRelativeItems 获取相关的子项 * feat: node.getRelativeItems
* feat: 新增 node.getUnRelativeItems 获取不相关的子项 * feat: node.getUnRelativeItems
* feat: 新增 edge.show 显示边 * feat: edge.show
* feat: 新增 edge.hide 隐藏边 * feat: edge.hide
* feat: 新增 Shape afterDraw 接口 * feat: Shape afterDraw
* improve: 改进 改进贝塞尔曲线控制点位置 * improve:  the controlling point positions of Bezier Curve改进贝塞尔曲线控制点位置
* improve: 改进 grpah.delete => graph.del * improve: grpah.delete => graph.del
* improve: 改进 添加 id 重复抛出异常 * improve: error when adding id
## v0.1.4 #### 0.1.4
`2017-01-17` `2017-01-17`
* fix: 修复 拖动节点时委托中心应是bbox中心 * fix: delegator of dragging a node is the center of bbox
* fix: 修复 所有排序算法采用基数排序,保持层级稳定 * fix: use cardinality sort for all the sorting algorithm
* fix: 修复 边的id自动生成机制才用随机数 * fix: random id on edges
* feat: 新增 边支持层级排序,边文本会排在最上层 * feat: level sort on edges, edge labels on the top level
* feat: 新增 注册边时,如果不指定继承形,则尝试从注册形获取继承形 * feat:  while extending shape is undefined when register an edge, find the extending shaoe automatically
## v0.1.3 #### 0.1.3
`2017-01-15` `2017-01-15`
* fix: 修复 所有assistGrid在进行操作时判断该对象是否存在 * fix: judge the existance of the object while operating assistGrid
* feat: 新增 rollback 增加判断,默认不开启回退机制 * feat: rollback judgement, default unactivate
* feat: 新增 新增style 映射通道 * feat:  style mapping channel
* feat: 新增 getAnchorPoints 不存在 或者 返回为假时 取线段交点 * feat: return the intersections while getAnchorPoints is null or returns false
* feat: 新增 新增边水平曲线bezierHorizontal、竖直曲线bezierVertical * feat:  bezierHorizontal、bezierVertical
* improve: 改进 默认交互行为结束后触发 'eventEnd' 事件 * improve: 'eventEnd'
## v0.1.2 #### 0.1.2
`2017-01-12` `2017-01-12`
* fix: 修复 更新网格时需要判定配置项grid * fix: judge the configuration before updating grid
* fix: 修复 graphContainer 不设置自己的宽高 由内部canvas撑大 * fix: the size of graphContainer in unsetable, setted by inner canvas
* fix: 修复 添加edges时若无target或source则不添加edge * fix: will not add an edge if the target or source is undefined
* fix: 修复 changeSize() 设置最大限容错 * fix: changeSize() maximum tolerance for error
* feat: 新增 graph.get('el') 获取最上层canvas DOM * feat: graph.get('el')  to get canvas DOM
* feat: 新增 事件抛出当前shape * feat: event exposures shape
## v0.1.1 #### 0.1.1
`2017-01-09` `2017-01-09`
* feat: 新增 graph 的入口为 G6.Graph * feat: entrance of graph is G6.Graph
## v0.1.0 #### 0.1.0
`2017-01-07` `2017-01-07`
* feat: 新增 抛出颜色计算库 * feat: color calculation library
* feat: 新增 添加快捷键操作 * feat: hot key
* feat: 新增 updo、redo * feat: updo, redo
* feat: 新增 复制、粘贴 * feat: copy, paste
* feat: 新增 重置缩放、自动缩放 * feat: reset zoom, auto zoom
* feat: 新增 树图、线性图、桑基图、流图布局 * feat: tree graph, linear graph, sankey graph, flow laout
* feat: 新增 业务流程图封装 * feat: flow chart package
* feat: 新增 时序图封装 * feat: timing diagram package
* feat: 新增 鼠标交互:单选、框选 * feat: single selection, frame selection
* feat: 新增 鼠标交互:节点变形 * feat: node deformation
* feat: 新增 鼠标交互:边变形 * feat:  edge deformation
* feat: 新增 鼠标交互:节点、边拖拽交互 * feat: drag node and edge
* feat: 新增 鼠标交互:边链接到锚点 * feat: link edge and node
* feat: 新增 鼠标交互:画布拖拽 * feat: drag canvas
* feat: 新增 鼠标交互:画布缩放 * feat: zoom
* feat: 新增 添加模式选择 * feat: select mode
* feat: 新增 集成 g-graph * feat: integrate g-graph

File diff suppressed because one or more lines are too long

View File

@ -99,7 +99,7 @@
"screenshot": "node ./bin/screenshot.js", "screenshot": "node ./bin/screenshot.js",
"start": "npm run dev", "start": "npm run dev",
"test": "torch --compile --renderer --recursive ./test/unit", "test": "torch --compile --renderer --recursive ./test/unit",
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/plugins/template.tableSankey-spec", "test-live": "torch --compile --interactive --watch --recursive ./test/unit/helper/graph2canvas-spec",
"watch": "webpack --config webpack-dev.config.js", "watch": "webpack --config webpack-dev.config.js",
"win-dev": "node ./bin/win-dev.js" "win-dev": "node ./bin/win-dev.js"
}, },

View File

@ -7,7 +7,7 @@ const G6 = require('@antv/g6');
const Util = G6.Util; const Util = G6.Util;
const dataCleaner = { const dataCleaner = {
clearData(data) { cleanData(data) {
const nodeMap = {}; const nodeMap = {};
const invalidEdges = []; const invalidEdges = [];
data.nodes.forEach(node => { data.nodes.forEach(node => {

View File

@ -13,7 +13,6 @@
*/ */
const Global = require('../global'); const Global = require('../global');
// const Util = require('../util/');
/** /**
* scale in animate * scale in animate

View File

@ -54,8 +54,11 @@ class Graph2Canvas {
}); });
if (domShapes.length > 0) { if (domShapes.length > 0) {
domShapes.forEach(domShape => { domShapes.forEach(domShape => {
domShape.domImageOnload = false;
const el = domShape.get('el'); const el = domShape.get('el');
if (!el) {
return;
}
domShape.domImageOnload = false;
const width = domShape.attr('width'); const width = domShape.attr('width');
const height = domShape.attr('height'); const height = domShape.attr('height');
domToImage.toPng(el, { domToImage.toPng(el, {

View File

@ -0,0 +1,39 @@
const G6 = require('../../../src/index');
// const chai = require('chai');
// const expect = chai.expect;
const Util = G6.Util;
const Animation = require('../../../src/animation/');
const div = document.createElement('div');
document.body.appendChild(div);
describe('animation test', () => {
const data = {
nodes: [{
id: 'node1',
x: 100,
y: 200
}, {
id: 'node2',
x: 300,
y: 200
}],
edges: [{
target: 'node2',
source: 'node1'
}]
};
const graph = new G6.Graph({
container: div,
width: 500,
height: 500
});
graph.read(data);
const item = graph.find('node1');
const group = item.getGraphicGroup();
it('all', () => {
Util.each(Animation, animation => {
animation({ item, element: group, done: () => {} });
});
graph.destroy();
});
});

View File

@ -0,0 +1,64 @@
const G6 = require('../../../src/index');
// const chai = require('chai');
// const expect = chai.expect;
const Graph2canvas = require('../../../src/helper/graph2canvas');
const div = document.createElement('div');
document.body.appendChild(div);
describe('helper graph2canvas test', () => {
it('graph2canvas', () => {
const data = {
nodes: [{
id: 'node1',
x: 100,
y: 200,
html: '<div>ssss</div>',
shape: 'html'
}, {
id: 'node2',
x: 300,
y: 200,
shape: 'customNode'
}, {
id: 'node3',
x: 300,
y: 300,
shape: 'common'
}],
edges: [{
target: 'node2',
source: 'node1'
}]
};
G6.registerNode('customNode', {
draw(item) {
const group = item.getGraphicGroup();
const html = G6.Util.createDOM('<div>这里是 HTML 节点</div>');
return group.addShape('dom', {
attrs: {
x: 0,
y: 0,
width: 100,
height: 100,
html
}
});
}
});
const graph = new G6.Graph({
container: div, // 容器ID
renderer: 'svg',
height: window.innerHeight
});
graph.read(data);
setTimeout(() => {
const graph2canvas = new Graph2canvas({
graph,
width: 400,
height: 500
});
graph2canvas.toCanvas();
graph.destroy();
}, 300);
});
});

View File

@ -0,0 +1,52 @@
const G6 = require('../../../src/index');
const chai = require('chai');
const expect = chai.expect;
const Util = G6.Util;
document.body.appendChild(Util.createDOM(`
<div id='mountNode'></div>
`));
require('../../../plugins/util.randomData/');
require('../../../plugins/tool.grid/');
describe('tool grid', () => {
it('init default', () => {
const Plugin = G6.Plugins['tool.grid'];
const plugin = new Plugin();
const graph = new G6.Graph({
container: 'mountNode',
fitView: 'cc',
width: 500,
height: 500,
plugins: [ plugin ]
});
graph.node({
size: 16
});
graph.read({});
plugin.hide();
plugin.show();
expect(plugin.gridEl).not.eql(undefined);
graph.destroy();
expect(plugin.gridEl.get('destroyed')).eql(true);
});
it('init default', () => {
const Plugin = G6.Plugins['tool.grid'];
const plugin = new Plugin({
type: 'line'
});
const graph = new G6.Graph({
container: 'mountNode',
fitView: 'cc',
width: 500,
height: 500,
plugins: [ plugin ]
});
graph.node({
size: 16
});
graph.read({});
expect(plugin.gridEl).not.eql(undefined);
graph.destroy();
expect(plugin.gridEl.get('destroyed')).eql(true);
});
});

View File

@ -0,0 +1,27 @@
const G6 = require('../../../src/index');
const expect = require('chai').expect;
const Util = G6.Util;
require('../../../plugins/util.dataCleaner/');
describe('plugin data cleaner test', () => {
it('cleanData', () => {
const data = {
nodes: [{
id: 1
}, {
id: 2
}],
edges: [{
source: 1,
target: 3
}, {
source: 3,
target: 1
}, {
source: 1,
target: 2
}]
};
Util.cleanData(data);
expect(data.edges.length).eql(1);
});
});