노드를 클릭하면 모든 비 인접 노드를 투명하게 만드는 기능을 만들었습니다. 이제는 동일한 노드를 마우스 이벤트에 응답하지 않고 표시 노드를 응답 성있게 유지하려고합니다. 투명 노드에 CSS 속성 pointer-events:none
을 할당하는 옵션이 있습니다. 시그마로 할 수 있을까요?sigma.js (캔버스 렌더러)에서 선택된 노드에 CSS 속성을 추가하는 방법
* 이렇게하려면 불투명도 0의 rgba 색상을 지정합니다. 따라서 WebGL은 투명도를 지원하지 않으므로 캔버스 렌더러를 사용해야합니다.
내 코드 :
function highlight() {
var s = sigma.instances()[0];
var nodes = s.graph.nodes();
var edges = s.graph.edges();
var maxCollab = d3.max(edges, function(d) { return d.collaborations; });
// We first need to save the original colors of our
// nodes and edges, like this:
nodes.forEach(function(n) {
n.originalColor = n.color;
});
edges.forEach(function(e) {
e.originalColor = e.color;
});
// When a node is clicked, we check for each node
// if it is a neighbor of the clicked one. If not,
// we set its color as grey, and else, it takes its
// original color.
// We do the same for the edges, and we only keep
// edges that have both extremities colored.
s.bind('clickNode', function(e) {
var nodeId = e.data.node.id,
toKeep = s.graph.neighbors(nodeId);
toKeep[nodeId] = e.data.node;
nodes.forEach(function(n) {
if (toKeep[n.id])
n.color = n.originalColor;
else
n.color = 'rgba(0,0,0,0)';
});
edges.forEach(function(e) {
if (toKeep[e.source] && toKeep[e.target]) {
e.color = e.originalColor;
}
else
e.color = 'rgba(0,0,0,0)';
});
// Since the data has been modified, we need to
// call the refresh method to make the colors
// update effective.
s.refresh();
});
// When the stage is clicked, we just color each
// node and edge with its original color.
s.bind('clickStage', function(e) {
nodes.forEach(function(n) {
n.color = n.originalColor;
});
edges.forEach(function(e) {
e.color = e.originalColor;
});
s.refresh();
});
}
예'node.hidden = true'가 내 케이스에서 실제로 작동했습니다! 그러나, 나는 여전히 ti'd가 이벤트를 통해 CSS 속성을 변경할 수 있다고 생각합니다. – Fede9390
여기서 문제는 canvas 또는 webgl 렌더러에 의해 렌더링되는 sigma.js 요소에 CSS 클래스를 할당 할 수 없다는 것입니다. 단순히 CSML 클래스가 DOM의 일부가 아니기 때문입니다. 나는 이것을 위해 svg 렌더러를 사용해야 할 것이라고 생각한다. –