G2 Legend Expert
Installation
SKILL.md
G2 Legend Expert Skill
Overview
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.
Legend Rendering Flow in G2
The legend rendering flow in G2 follows a multi-stage process that transforms legend configuration into visual components. This flow involves several key stages:
1. Legend Component Inference
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:
- Scale Analysis: The system analyzes all scales in the chart, looking for channels like
shape,size,color, andopacity - Legend Type Detection: Based on the scale types, the system determines whether to create
legendCategory(for discrete scales) orlegendContinuous(for continuous scales) - Position Inference: Default positions and orientations are inferred based on the chart type and coordinate system