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 skills add https://github.com/foryourhealth111-pixel/Vibe-Skills --skill G2 Legend Expert
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 calculationscomputePadding functionStatistical visualization with pandas integration. Use for quick exploration of distributions, relationships, and categorical comparisons with attractive defaults. Best for box plots, violin plots, pair plots, heatmaps. Built on matplotlib. For interactive plots use plotly; for publication styling use scientific-visualization.
Populates investment banking pitch deck templates with data from source files. Use when: user provides a PowerPoint template to fill in, user has source data (Excel/CSV) to populate into slides, user mentions populating or filling a pitch deck template, or user needs to transfer data into existing slide layouts. Not for creating presentations from scratch.
Statistical visualization with pandas integration. Use for quick exploration of distributions, relationships, and categorical comparisons with attractive defaults. Best for box plots, violin plots, pair plots, heatmaps. Built on matplotlib. For interactive plots use plotly; for publication styling use scientific-visualization.
Meta-skill for publication-ready figures. Use when creating journal submission figures requiring multi-panel layouts, significance annotations, error bars, colorblind-safe palettes, and specific journal formatting (Nature, Science, Cell). Orchestrates matplotlib/seaborn/plotly with publication styles. For quick exploration use seaborn or plotly directly.
Statistical visualization with pandas integration. Use for quick exploration of distributions, relationships, and categorical comparisons with attractive defaults. Best for box plots, violin plots, pair plots, heatmaps. Built on matplotlib. For interactive plots use plotly; for publication styling use scientific-visualization.
Transform text-heavy slides into visual storytelling. Suggest layout improvements, icon usage, and data visualization.
Aggregate and rank signals from multiple edge-finding skills (edge-candidate-agent, theme-detector, sector-analyst, institutional-flow-tracker) into a prioritized conviction dashboard with weighted scoring, deduplication, and contradiction detection.
Optimize Core Web Vitals (LCP, INP, CLS) for better page experience and search ranking. Use when asked to "improve Core Web Vitals", "fix LCP", "reduce CLS", "optimize INP", "page experience optimization", or "fix layout shifts". Focuses specifically on the three Core Web Vitals metrics. Do NOT use for general web performance (use perf-web-optimization), Lighthouse audits (use perf-lighthouse), or Astro-specific optimization (use perf-astro).
Take foryourhealth111-pixel/g2 legend expert from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.