Skip to content

feat(Yagr): add prepared point labels - #968

Open
grachevelloper wants to merge 2 commits into
mainfrom
feat/CHARTS-11212-draw-yagr-labes
Open

grachevelloper wants to merge 2 commits into
mainfrom
feat/CHARTS-11212-draw-yagr-labes

Conversation

@grachevelloper

@grachevelloper grachevelloper commented Nov 11, 2026 •

Copy link
Copy Markdown

Done:

  • Add canvas data labels for Yagr line charts, disabled by default, with configurable padding and overlap control.
  • Support custom text through _data[].label: omitted or null labels show the value; empty strings hide the label.
  • Keep labels aligned after updates, resizing and scale changes, including PNG export.
  • Assign unique automatic series IDs for duplicate names while preserving explicit IDs.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 31.62% 575 / 1818
🔵 Statements 31.69% 595 / 1877
🔵 Functions 24.93% 98 / 393
🔵 Branches 27.32% 397 / 1453
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/plugins/yagr/types.ts 100% 100% 100% 100%
src/plugins/yagr/plugins/YagrDataLabelsPlugin/index.ts 96.77% 94% 100% 96.61% 50, 55
src/plugins/yagr/renderer/utils.ts 44.26% 35.1% 47.61% 45.68% 32-79, 84-99, 111-127, 135-143, 230-247, 263-266, 291-298
Generated in workflow #409 for commit f06bcfa by the Vitest Coverage Report Action

@gravity-ui-bot

Copy link
Copy Markdown
Contributor

🎭 Tests Report is ready.
🎭 Coverage Report is ready.

@gravity-ui-bot

Copy link
Copy Markdown
Contributor

Preview is ready.

@grachevelloper
grachevelloper marked this pull request as ready for review November 11, 2026 09:55

@korvin89 korvin89 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI generated

I think the approach of this PR should change, and propose a different design in #970.

Why not the current approach

  • Hooks instead of a Yagr plugin. Labels are wired through libraryConfig.hooks, and the Yagr instance is captured in a processed hook closure. Yagr's extension point for this is a plugin in config.plugins: it receives the instance directly and is bound to the chart lifecycle.
  • Texts read from uPlot series. u.series[i].pointLabels works only because configureSeries spreads unknown fields into uPlot series. In-place updates (yagr.setSeries) copy a fixed list of fields to them, so labels go stale.
  • A contract with no room to grow. pointLabels: (string | null)[] has no place for options, so overlap handling, placement and style would each need a new field next to it. gravity-charts already has a dataLabels API for this; the contract should follow it instead of introducing a new one.
  • Placement and overlap. Negative columns are labelled on the zero side, so their labels disappear when 0 is outside the scale, and overlapping labels are not handled. The gravity-charts placement API and allowOverlap: false cover both.
  • A Yagr bug fixed inside the labels hook. chart.canvas = u.ctx.canvas works around Yagr.canvas not being updated in fullUpdate(). That bug breaks PNG export for every chart after a data update, so the fix belongs in Yagr.

Proposal: #970

A stateless Yagr plugin owned by ChartKit, with a serializable contract (graphs[i].dataLabels and graphs[i].labels) that mirrors gravity-charts dataLabels, delivered in phases. This PR could become phase 1.

@kuzmadom, what do you think about this direction?

@kuzmadom

Copy link
Copy Markdown
Contributor

@kuzmadom, what do you think about this direction?

Yes, I agree. But regarding “mirrors gravity-charts dataLabels” — I suggest not making a full mirror here, but supporting only the required properties. For now, just “enabled” will be enough (the rest without a config, with a clear default).

Comment thread vitest.config.ts
enabled: true,
headless: true,
provider: playwright({}),
provider: playwright({contextOptions: {locale: 'en-US'}}),

@grachevelloper grachevelloper Nov 13, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were an error without that

@grachevelloper
grachevelloper force-pushed the feat/CHARTS-11212-draw-yagr-labes branch from 1a74f21 to f06bcfa Compare November 13, 2026 14:24
Comment thread src/plugins/yagr/types.ts
/**
* Draw labels even when they overlap other labels. Defaults to false.
*/
allowOverlap?: boolean;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuzmadom I looked deeper into it and reviewed our discuss about this param
I think it's not a big problem to add it into API, it's appearing in only 1 if in function that draw the labes.
So it's not complicate code base at all

This branch has not been deployed

No deployments
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.

4 participants