Repository navigation
feat(Yagr): add prepared point labels - #968
grachevelloper wants to merge 2 commits into
Conversation
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
🎭 Tests Report is ready. |
|
Preview is ready. |
korvin89
left a comment
There was a problem hiding this comment.
🤖 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 aprocessedhook closure. Yagr's extension point for this is a plugin inconfig.plugins: it receives the instance directly and is bound to the chart lifecycle. - Texts read from uPlot series.
u.series[i].pointLabelsworks only becauseconfigureSeriesspreads 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 adataLabelsAPI 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
placementAPI andallowOverlap: falsecover both. - A Yagr bug fixed inside the labels hook.
chart.canvas = u.ctx.canvasworks aroundYagr.canvasnot being updated infullUpdate(). 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?
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). |
| enabled: true, | ||
| headless: true, | ||
| provider: playwright({}), | ||
| provider: playwright({contextOptions: {locale: 'en-US'}}), |
There was a problem hiding this comment.
There were an error without that
1a74f21 to
f06bcfa
Compare
| /** | ||
| * Draw labels even when they overlap other labels. Defaults to false. | ||
| */ | ||
| allowOverlap?: boolean; |
There was a problem hiding this comment.
@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
Done:
_data[].label: omitted or null labels show the value; empty strings hide the label.