AgentSkillsCN

yfiles-interactivity

为 yFiles 应用程序添加用户交互功能,包括工具提示、上下文菜单、点击处理器、图谱搜索、概览组件、悬停效果以及选中事件。通过这些功能,您可以为用户提供丰富而互动性强的图表体验。当您需要实现工具提示、上下文菜单、搜索功能、概览导航、点击事件、悬停效果,或当用户提到“工具提示”“上下文菜单”“搜索”“概览”“点击处理器”“选中状态变化”“悬停”“交互式功能”时,此技能将助您轻松实现。

SKILL.md
--- frontmatter
name: yfiles-interactivity
description: Adds user interactivity to yFiles applications including tooltips, context menus, click handlers, graph search, overview component, hover effects, and selection events. Enables rich interactive diagram experiences. Use when implementing tooltips, context menus, search functionality, overview navigation, click events, hover effects, or when user mentions "tooltip", "context menu", "search", "overview", "click handler", "selection changed", "hover", or "interactive features".

User Interactivity

Add interactive features like tooltips, context menus, search, and navigation to yFiles applications.

Quick Start

typescript
// Tooltips
inputMode.addEventListener('query-item-tool-tip', (evt) => {
  evt.toolTip = createTooltipContent(evt.item)
  evt.handled = true
})

// Context menu
inputMode.addEventListener('populate-item-context-menu', (evt) => {
  evt.contextMenu = [
    { label: 'Delete', action: () => inputMode.deleteSelection() }
  ]
})

// Overview
const overview = new GraphOverviewComponent('overviewDiv', graphComponent)

// Search with highlighting
graphComponent.highlights.clear()
graph.nodes.forEach(node => {
  if (matches(node, searchText)) {
    graphComponent.highlights.add(node)
  }
})

Before Implementing

Always query yFiles MCP for current API:

code
yfiles:yfiles_get_symbol_details(name="GraphEditorInputMode")
yfiles:yfiles_list_members(name="GraphEditorInputMode", includeInherited=true)
yfiles:yfiles_get_symbol_details(name="GraphOverviewComponent")
yfiles:yfiles_search_documentation(query="tooltips context menu")

Core Concepts

  • Tooltips: query-item-tool-tip event, ToolTipInputMode configuration
  • Context Menus: populate-item-context-menu event, contextMenu array
  • Click Events: item-clicked, item-double-clicked, item-right-clicked
  • Graph Search: Highlights manager, custom matching logic
  • Overview: GraphOverviewComponent for navigation
  • Selection Events: selection.item-added, selection.item-removed, current-item-changed

Note: Always use addEventListener (yFiles 3.0) instead of addListener (yFiles 2.6). The @yfiles/eslint-plugin rule @yfiles/replace-legacy-event-listeners enforces this and auto-fixes legacy patterns.

When to Implement

  • Tooltips: Show additional information on hover
  • Context Menus: Provide contextual actions via right-click
  • Click Events: React to user clicks on graph items
  • Graph Search: Enable finding and highlighting nodes/edges
  • Overview: Navigate large graphs with minimap
  • Selection Events: React to selection changes for details panels

Code Examples

See examples.md for:

  • Tooltip setup with HTML content
  • Context menu with conditional items
  • Graph search with highlighting
  • Overview component integration
  • Click event handlers
  • Selection change listeners

Reference

See reference.md for:

  • Event parameters and signatures
  • ToolTipInputMode configuration options
  • Context menu item format
  • GraphOverviewComponent API
  • Highlight manager usage
  • Selection API

Related Skills

  • /yfiles-init - Initial setup
  • /yfiles-graphbuilder - Build graphs from data
  • /yfiles-nodestyle-basic - Custom visuals for highlighting

MCP Tools

  • yfiles:yfiles_get_symbol_details(name="GraphEditorInputMode") - Input mode API
  • yfiles:yfiles_get_symbol_details(name="GraphOverviewComponent") - Overview component
  • yfiles:yfiles_search_documentation(query="tooltips") - Documentation
  • yfiles:yfiles_search_by_description(query="search highlight") - Find related APIs