我是缩放图表(网络图表)的新手,我有几个问题:
- 我希望能够拖动一个节点并在用户放下它时处理事件。有没有办法做到这一点?我正在查看 onPositionChange 事件,但该事件在拖动过程中会触发多次。无法知道用户何时真正删除了节点。至少我没有找到一种方法来确定这一点。也许我错过了一些东西。
- 我有一个项目列表,我希望能够将它们拖到图表中并将它们转换为节点。这工作正常,除了当我使用(外部项目的)dragend 事件时,我无法正确设置新创建的节点的 x 和 y 位置。我尝试使用 ClientX 和 ClientY、LayerX 和 LayerY 以及 DragEnd 事件参数提供的其他坐标,但它们都没有将节点定位到释放光标的位置。实现这一目标的最佳方法是什么?
这是我的图表定义:
this.chart = new ZoomCharts.NetChart({
container: chartContainer,
area: {
height: null,
style: { fillColor: "rgba(14,33,40,0.9)" }
},
data: {
preloaded: {
"nodes": this.nodes,
"links": this.links
}
},
events: {
onRightClick: function (event: any, args: any) {
//set up the customer context menu
event.preventDefault();
},
onHoverChange: function (event: any, args: any) {
var content = "";
if (args.hoverNode) {
content = args.hoverNode.data.description;
}
infoElementVisible = !!content;
infoElement.innerHTML = content;
//delay the showing
if (infoElementVisible) {
setTimeout(() => {
infoElement.style.display = infoElementVisible ? "block" : "none";
}, 1000);
} else {
infoElement.style.display = infoElementVisible ? "block" : "none";
}
}
},
style: {
nodeStyleFunction: function (node: any) {
if (node.selected) {
node.lineColor = "yellow";
node.lineWidth = 3;
node.radius = node.radius * 1.5;
} else {
node.lineColor = null;
node.lineWidth = 0;
}
node.userLock = true;
node.label = node.data.name;
if (node.data.auras == "Selection GNQ") {
node.fillColor = "darkorange";
} else {
node.fillColor = "cyan";
}
},
linkStyleFunction: function (link: any) {
link.fromDecoration = "circle";
link.toDecoration = "arrow";
link.radius = 5;
},
node: {
radius: 50,
imageCropping: true,
shadowBlur: 15,
shadowColor: "#262626",
fillColor: "rgba(44,233,233,0.8)"
},
nodeHovered: {
shadowColor: "white",
shadowBlur: 15,
},
nodeLabelScaleBase: 25,
nodeSelected: {
lineColor: null
},
selection: {
fillColor: null,
lineColor: null
},
nodeFocused: {
shadowColor: "yellow",
shadowBlur: 15
},
nodeLabel: {
textStyle: { font: '24px Arial' }
}
},
theme: ZoomCharts.NetChart.themes.dark,
layout: {
mode: 'static',
nodeSpacing: 100
}
});
谢谢你。