图标来源
每个节点都以不同的方式绘制其字形 - 一张图、五种机制、没有链接、固定位置,因此读起来就像一个图例:
iconClass— 基于类的图标字体。该卡附带了生成的假FontAwesome网络字体(fa-solid fa-star); ivotick 从计算的::before中读取字形 ** 和 ** 其字体,因此任何图标字体都可以在零配置下使用。html+ CSS mask — “仅类”版本中的错误图标,其中字形是 SVG 数据 URI,应用于background-color: currentColor上的mask。没有网络字体 - 只需将misp-icon类放入自定义 HTML 节点即可。svgIcon— 原始内联<svg>;fill="currentColor"选取节点的strokeColor。imagePath— 任何图像 URL,直接绘制到节点中(默认情况下很小;请参阅图像适合模式以使其填充形状)。iconUnicode— 一个文字字符(这里是表情符号),对于一次性字形很方便。
自由混合和匹配:FontAwesome和misp-iconify节点愉快地共存于同一个图中,没有每个消费者的粘合剂。
js
const options = {
// Static demo: no forces; fx/fy pin every node so the row never drifts.
simulation: { enabled: false },
render: {
defaultNodeStyle: {
size: 26,
strokeColor: '#ffffff',
strokeWidth: 2,
// Caption sits below each node (shift ≥ 1 ⇒ themed, readable pill).
text: (node) => node.getData()?.name,
textVerticalShift: -1.9
}
}
}js
// A raw inline SVG (fill="currentColor" resolves to the node's strokeColor).
const shieldSvg =
'<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l8 3v6c0 5-3.4 8.5-8 11-4.6-2.5-8-6-8-11V5l8-3z"/></svg>'
// A misp-iconify icon delivered "class only" via CSS mask (see misp-mask.css):
// a <span> whose background is masked by the icon's SVG — coloured by `color`.
// `html` must return an HTMLElement, so build the node rather than a string.
const mispMask = () => {
const wrap = document.createElement('div')
wrap.style.cssText = 'display:flex;align-items:center;justify-content:center;width:100%;height:100%;color:#fff;font-size:34px'
const icon = document.createElement('span')
icon.className = 'misp-icon misp-icon-event misp-hexagone'
wrap.append(icon)
return wrap
}
// One node per icon-delivery mechanism, pinned in a row (x/y) so nothing drifts.
const data = {
nodes: [
{ id: 'fa', fx: -320, fy: 0, data: { name: 'iconClass' }, style: { color: '#f59e0b', textColor: '#ffffff', iconClass: 'fa-solid fa-star' } },
{ id: 'misp', fx: -160, fy: 0, data: { name: 'html + mask' }, style: { color: '#2563eb', html: mispMask } },
{ id: 'svg', fx: 0, fy: 0, data: { name: 'svgIcon' }, style: { color: '#16a34a', strokeColor: '#ffffff', svgIcon: shieldSvg } },
{ id: 'img', fx: 160, fy: 0, data: { name: 'imagePath' }, style: { color: '#f1f5f9', imagePath: import.meta.env.BASE_URL + 'pivotick.svg' } },
{ id: 'emoji', fx: 320, fy: 0, data: { name: 'iconUnicode' }, style: { color: '#7c3aed', iconUnicode: '🚀' } }
],
edges: []
}