bundled/skills/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 foryourhealth111-pixel/vco-skills-codex 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 functiondevelopment
Chunked N-D arrays for cloud storage. Compressed arrays, parallel I/O, S3/GCS integration, NumPy/Dask/Xarray compatible, for large-scale scientific computing pipelines.
tools
Use only when the user explicitly asks to stage, commit, push, and open a GitHub pull request in one flow using the GitHub CLI (`gh`).
tools
Spreadsheet toolkit (.xlsx/.csv). Create/edit with formulas/formatting, analyze data, visualization, recalculate formulas, for spreadsheet processing and analysis.
tools
High-performance CSV processing with xan CLI for large tabular datasets, streaming transformations, and low-memory pipelines.