skills/g2-legend-expert/g2-legend-expert/SKILL.md
Expert skill for G2 legend development - provides comprehensive knowledge about legend rendering implementation, component architecture, layout algorithms, and interaction handling. Use when implementing, customizing, or debugging legend functionality in G2 visualizations.
npx skillsauth add aiagentskills/skills G2 Legend ExpertInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides comprehensive knowledge about legend rendering in G2, covering the complete legend rendering flow from component creation to layout calculation and interaction handling.
The legend rendering flow in G2 follows a multi-stage process that transforms legend configuration into visual components. This flow involves several key stages:
Legend components are inferred from the chart's scales and configuration during the initial setup phase. The inference process is handled by the inferComponent function in src/runtime/component.ts:
shape, size, color, and opacitylegendCategory (for discrete scales) or legendContinuous (for continuous scales)Two main legend component types are implemented:
Located in src/component/legendCategory.ts, this component handles categorical legends:
LegendCategoryLayout to handle layout positioningrender optionLocated in src/component/legendContinuous.ts, this handles continuous legends:
The layout process is managed in src/runtime/layout.ts and involves several critical steps:
The computeComponentSize function handles sizing based on component type:
The core layout logic is in the computePadding function:
const autoSizeOf = (d) => {
if (d.size) return;
if (value !== 'auto') sizeOf(d);
else {
// Compute component size dynamically
computeComponentSize(
d,
crossSize,
crossPadding,
position,
theme,
library,
);
defaultSizeOf(d);
}
};
computeComponentSize to measure actual content dimensionsdefaultSize directly, bypassing content measurementThe renderComponent function in src/runtime/component.ts handles the actual rendering:
After size calculation, the placeComponents function assigns bounding boxes:
Categorical legends (LegendCategory) are used for discrete scales and support:
render optionContinuous legends (LegendContinuous) handle continuous scales:
The legend filtering interaction is implemented in src/interaction/legendFilter.ts:
Legends support multiple visual states:
Legend components integrate with G2's theming system:
When paddingTop is manually set (e.g., paddingTop: 72), the height of legendCategory changes unexpectedly (e.g., from 60px to 40px). This occurs because:
defaultSize instead of measuring actual contentLegendCategory, the default size is 40 (defined in src/component/legendCategory.ts)size property in the legend configuration to override the defaultFor more detailed information on legend layout mechanisms and related topics, see the knowledge directory:
./knowledge/legendLayout.md - Detailed analysis of padding behavior and layout calculations
computePadding functiondocumentation
Guides using bun.sys for system calls and file I/O in Zig. Use when implementing file operations instead of std.fs or std.posix.
development
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
development
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
development
Guides writing HMR/Dev Server tests in test/bake/. Use when creating or modifying dev server, hot reloading, or bundling tests.