EF1874 commented on issue #20870: URL: https://github.com/apache/echarts/issues/20870#issuecomment-2760085488
> did you try [highlight](https://echarts.apache.org/en/api.html#action.highlight) action? I tried, but emphasis config will triggerOn hover always; I need to use custom highlight set like this ``` chart.on('click', params => { if (params.dataType === 'node') { const targetId = params.data.id; const related = new Set([targetId]); const relatedLinks = new Set(); // 标记关联元素 links.forEach(link => { if (link.source === targetId || link.target === targetId) { related.add(link.source); related.add(link.target); relatedLinks.add(`${link.source}-${link.target}`); } }); // 更新节点透明度 const newNodes = nodes.map(n => ({ ...n, itemStyle: { opacity: related.has(n.id) ? 1 : 0.1 } })); // 更新连线透明度 const newLinks = links.map(link => ({ ...link, lineStyle: { opacity: relatedLinks.has(`${link.source}-${link.target}`) || relatedLinks.has(`${link.target}-${link.source}`) ? 1 : 0.1 } })); // 应用更新并保留布局 chart.setOption({ series: [{ data: newNodes, links: newLinks, // 保持力导向图的当前布局 force: { initLayout: null // 保留现有位置 } }] }, { notMerge: false }); } }); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
