2018-07-13 16:27:12 +08:00
|
|
|
/**
|
|
|
|
* @fileOverview fisheye zoom
|
|
|
|
* @author shiwu.wyy@antfin.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
const G6 = require('@antv/g6');
|
|
|
|
const Util = G6.Util;
|
|
|
|
|
2018-09-11 16:56:16 +08:00
|
|
|
function getMaskRect(graph) {
|
|
|
|
const width = graph.getWidth();
|
|
|
|
const height = graph.getHeight();
|
|
|
|
const tl = graph.getPointByDom({
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
});
|
|
|
|
const br = graph.getPointByDom({
|
|
|
|
x: width,
|
|
|
|
y: height
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
x: tl.x,
|
|
|
|
y: tl.y,
|
|
|
|
width: br.x - tl.x,
|
|
|
|
height: br.y - tl.y
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-07-13 16:27:12 +08:00
|
|
|
G6.registerGuide('mask', {
|
|
|
|
draw(item) {
|
|
|
|
const group = item.getGraphicGroup();
|
|
|
|
const graph = item.getGraph();
|
2018-09-11 16:56:16 +08:00
|
|
|
const maskRect = getMaskRect(graph);
|
2018-09-17 22:22:42 +08:00
|
|
|
const model = item.getModel();
|
|
|
|
const { style } = model;
|
2018-07-13 16:27:12 +08:00
|
|
|
return group.addShape('rect', {
|
|
|
|
attrs: {
|
2018-09-11 16:56:16 +08:00
|
|
|
...maskRect,
|
2018-09-17 22:22:42 +08:00
|
|
|
...style
|
2018-07-13 16:27:12 +08:00
|
|
|
},
|
|
|
|
capture: false
|
|
|
|
});
|
2018-09-11 16:56:16 +08:00
|
|
|
},
|
|
|
|
bboxCalculation: false
|
2018-07-13 16:27:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class Plugin {
|
|
|
|
constructor(options) {
|
2018-09-17 22:22:42 +08:00
|
|
|
Util.mix(this, {
|
|
|
|
maskStyle: {
|
|
|
|
fill: 'rgb(255, 255, 255)',
|
|
|
|
fillOpacity: 0.8
|
|
|
|
}
|
|
|
|
}, options);
|
2018-07-13 16:27:12 +08:00
|
|
|
}
|
|
|
|
init() {
|
2018-08-31 20:58:48 +08:00
|
|
|
const graph = this.graph;
|
|
|
|
graph.on('afterinit', () => {
|
2018-07-13 16:27:12 +08:00
|
|
|
this.graph.highlightSubgraph = this.highlightSubgraph;
|
2018-08-08 10:08:34 +08:00
|
|
|
this.graph.unhighlightGraph = this.unhighlightGraph;
|
2018-09-11 16:56:16 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
graph.on('afterchange', () => {
|
|
|
|
let mask = graph.find('mask');
|
|
|
|
if (!mask) {
|
|
|
|
mask = graph.add('guide', {
|
|
|
|
shape: 'mask',
|
2018-09-17 22:22:42 +08:00
|
|
|
id: 'mask',
|
|
|
|
style: this.maskStyle
|
2018-09-11 16:56:16 +08:00
|
|
|
});
|
|
|
|
mask.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
graph.on('afterviewportchange', () => {
|
|
|
|
const mask = graph.find('mask');
|
|
|
|
if (mask) {
|
|
|
|
mask.forceUpdate();
|
|
|
|
}
|
2018-07-13 16:27:12 +08:00
|
|
|
});
|
|
|
|
}
|
2018-08-31 20:58:48 +08:00
|
|
|
highlightSubgraph(items) {
|
2018-08-08 10:08:34 +08:00
|
|
|
this.unhighlightGraph();
|
2018-09-11 16:56:16 +08:00
|
|
|
const mask = this.find('mask');
|
|
|
|
mask.toFront();
|
|
|
|
mask.show();
|
2018-09-03 17:40:47 +08:00
|
|
|
items.forEach(item => {
|
2018-09-11 16:56:16 +08:00
|
|
|
const group = item.getGraphicGroup();
|
|
|
|
group.toFront();
|
2018-07-13 16:27:12 +08:00
|
|
|
});
|
2018-09-11 16:56:16 +08:00
|
|
|
this.draw();
|
2018-07-13 16:27:12 +08:00
|
|
|
}
|
2018-08-08 10:08:34 +08:00
|
|
|
unhighlightGraph() {
|
2018-07-13 16:27:12 +08:00
|
|
|
// hide the mask
|
2018-09-11 16:56:16 +08:00
|
|
|
this.find('mask').hide();
|
|
|
|
this.draw();
|
2018-07-13 16:27:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
G6.Plugins['tool.highlightSubgraph'] = Plugin;
|
|
|
|
module.exports = Plugin;
|