Skip to content

fix(echarts): pin categorical legend with right instead of design-canvas left - #99

Merged
Chenglong Wang (Chenglong-MS) merged 2 commits into
microsoft:devfrom
zhnd:feat/echarts-legend-right-anchor
Aug 15, 2026
Merged

fix(echarts): pin categorical legend with right instead of design-canvas left#99
Chenglong Wang (Chenglong-MS) merged 2 commits into
microsoft:devfrom
zhnd:feat/echarts-legend-right-anchor

Conversation

@zhnd

@zhnd zhnd (zhnd) commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #98.

What

Categorical ECharts legends (and the matching title graphic) used left: designW - gutter. That is correct only when the host inits at _width. After chart.resize() the plot stretches (grid.right is an inset) but the legend stays at the design-canvas x, so it overlaps the series or clips off the right edge.

This PR pins them with right: 16 (CANVAS_BUFFER). ECharts right is the inset to the legend box’s right edge — not designW - left (that value is the gutter to the legend’s left edge and would grow into the plot).

Same change in streamgraph post-process and faceted legend repositioning.

Unchanged at _width

At the designed canvas the reserved gutter is the same. Gallery / MCP that still render at _width × _height should look as they do today. The site EChartsView still paints at the designed size because visualMap / rose / some radii remain design-px.

534px (_width) 800px + resize()
Before 534 before 800 before
After 534 after 800 after

534 before/after should match (legend in the gutter). 800 before overlaps the series; 800 after keeps the gutter.

Out of scope

Sunburst/pie radius: 'NNpx' is still design-absolute. Happy to follow up separately.

Test

  • npm run test:js -- tests/slope.test.ts (33, including the new legend.right assertion)
  • npm run typecheck:js

…vas left

legend.left was `_width - gutter`, so chart.resize() overlapped the plot
or clipped the legend. Anchor the legend and its title graphic with
right: 16. At `_width` the gutter is unchanged; only fluid hosts change.

Fixes microsoft#98.
Show that at `_width` the right-anchored legend matches the old left
pixel layout; only the resized canvas changes.
@zhnd

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@Chenglong-MS

Copy link
Copy Markdown
Contributor

Awesome! Thanks! I haven't maintain ECharts very actively, glad to have you spot this.

@Chenglong-MS
Chenglong Wang (Chenglong-MS) merged commit 8680ab3 into microsoft:dev Aug 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants