g6/plugins/template.maxSpanningForest/index.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-06-05 23:58:10 +08:00
/**
* @fileOverview 图分析模版
* @author huangtonger@aliyun.com
* 保留字段:
* node.vx, node.vy, node.x, node.y
* node.to, node.from
* node.visited, node.edges, node.links
* edge.isTreeEdgeedge.lineWidth
* 可配置字段:
* node.rank 分层权重
* node.label 节点标签
*/
2018-06-14 11:50:35 +08:00
const G6 = require('@antv/g6');
2018-06-05 23:58:10 +08:00
const maxSpanningForest = require('./maxSpanningForest');
const Layout = require('../layout.forceAtlas2/layout');
2018-06-05 23:58:10 +08:00
const Util = G6.Util;
class Plugin {
constructor(options) {
Util.mix(this, {
layout: new Layout({
kr: 50,
2018-07-13 16:27:12 +08:00
kg: 8.0,
mode: 'common',
prev_overlapping: true,
dissuade_hubs: false,
2018-07-13 16:27:12 +08:00
max_iteration: 1000,
barnes_hut: true,
ks: 0.1,
ksmax: 10,
tao: 0.1
2018-07-13 16:27:12 +08:00
}, options),
2018-06-05 23:58:10 +08:00
...options
});
}
init() {
const graph = this.graph;
graph.on('beforeinit', () => {
const layout = graph.get('layout');
if (!layout) {
graph.set('layout', this.layout);
}
});
graph.on('beforerender', () => {
const data = graph.getSource();
2018-07-10 11:08:57 +08:00
const {
nodes,
edges
} = data;
2018-06-05 23:58:10 +08:00
const forest = maxSpanningForest(nodes, edges);
forest.edges.forEach(edge => {
edge.isTreeEdge = true;
});
graph.addFilter(item => {
return !item.isEdge || item.getModel().isTreeEdge;
});
});
}
}
G6.Plugins['template.maxSpanningForest'] = Plugin;
module.exports = Plugin;