使用指南交互

提示框 Tooltip

悬停或点击节点和边时,显示它们的详细信息。

悬停或点击节点和边时,显示它们的详细信息。

配置方式

触发方式通过 trigger 设置,内容通过 getContent 返回。点击触发时,再次点击同一元素或点击空白处可关闭提示框。

behaviors: [{ type: 'tooltip', trigger: 'hover', delay: 120 }],

示例

正在加载示例…
悬停 API、DB 或边显示,等待 120ms;移开隐藏,Cache 节点不显示
const tooltip: BuiltInBehaviorOptionsMap['tooltip'] = {
  type: 'tooltip', trigger: 'hover', delay: 120, className: 'docs-hover-tooltip',
  enable: (ctx) => ctx.nodeId !== 'Cache',
  getContent: (ctx) => {
    const card = document.createElement('div');
    card.style.cssText = 'padding:10px 14px;border-radius:8px;background:#163B65;color:white;font:12px system-ui;box-shadow:0 4px 16px #163b6533;';
    const title = document.createElement('strong');
    title.textContent = String(ctx.data?.label ?? ctx.nodeId ?? ctx.edgeId ?? '');
    const detail = document.createElement('div');
    detail.textContent = ctx.itemType === 'node'
      ? `Requests: ${Number(ctx.data?.requests ?? 0)}`
      : `${ctx.source} → ${ctx.target}`;
    card.append(title, detail);
    return card;
  },
};

运行示例与完整代码 · 参数与默认值 · 查看点击触发与样式配置