Skip to content

Refactor and fix chart show value plugin#8916

Open
hokolomopo wants to merge 13 commits into
masterfrom
master-chart-dhow-values-ref-adrm
Open

Refactor and fix chart show value plugin#8916
hokolomopo wants to merge 13 commits into
masterfrom
master-chart-dhow-values-ref-adrm

Conversation

@hokolomopo

Copy link
Copy Markdown
Contributor

Description:

description of this task, what is implemented and why it is implemented that way.

Task: 6123207

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo

robodoo commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Pull request status dashboard

A lot of the behaviour of our ChartJS' show value plugin were not
tested. This commit adds a bunch of tests for it.

Note that some test screenshots show clearly wrong results. These will
be fixed in later commits, this commit only introduce tests to have
a baseline to test against.

Task: 6123207
Our chartJS plugin `chartShowValuesPlugin` is a bit of a mess,
with a bunch of duplicated code, making it very hard to read and
maintain. As a proof the number of bugs to draw the values fixed
in the following commits, and visible in the screenshot tests.

This commit aims to refactor the plugin. The core logic is now in the
`drawValues` helper, which take callbacks for the chart-specific
logic.

The goal of this commit is only to rewrite the code without fixing
or modifying any functional behaviour, these will be fixed in
follow-up commits.

Task: 6123207
This commits splits the chimeric monstrosity
`drawLineOrBarOrRadarChartValues` in separate function for each chart
type.

Task: 6123207
On bar charts, use the actual measured text height to position the
values instead of the font size.

Task: 6123207
The radar charts didn't have a color set for the background of their
points. By default ChartJS use the same color as the dataset background,
which is transparent for filled radar charts.

This commit adds an explicit color for the points, so neither the
points nor the values are half transparent for filled radar charts.

Task: 6123207
With this commit, the values drawn inside a bar/pie chart element
will now be a text colored with he chart background color, with a
halo of the color of the dataset, instead of being chart-dependant.

Task: 6123207
When hovering a legend item, all the other dataset become transparent.
This make the shown values become transparent and a bit ugly. But
if a dataset is made transparent and half-hidden, the shown values
don't make much sense and can be skipped.

Task: 6123207
- The bubble chart show value didn't match the color of the other
types oft charts
- If the bubble didn't have a set size, the show value text would
go over the bubble and hide the point

Task: 6123207
For very small funnel bars, the text wasn't centered. It's because we
re-used the code of horizontal bar charts, which offset the values
too close to the axis origin. Something we don't want for funnel charts.

Task: 6123207
When drawing negative values next to a point element in a chart (line,
scatter, radar and bubble chart), we could draw the value above the
point for positive values, and below for negative values.

The distinction was arbitrary and didn't always make sense, remove it.

Task: 6123207
Calendar charts were doing some try-hard hacky stuff, computing a
false background color of the calendar element by recomputing the
color scale.

This can be simplified by simply fetching the color of the drawn
chart element.

Task: 6123207
The combo chart show value did every computation assuming the dataset
was a bar chart dataset, gicing wrong results for the line datasets.

Task: 6123207
In the chart show value plugin, we use the text positions as key of an
object. This can cause some issues with rounding errors.

Task: 6123207
@hokolomopo hokolomopo force-pushed the master-chart-dhow-values-ref-adrm branch from c1bc801 to 3c146af Compare June 15, 2026 13:57
Comment on lines 64 to +71
switch (options.type) {
case "pie":
drawPieChartValues(chart, options, ctx);
drawPieValues(chart, options);
break;
case "line":
case "scatter":
drawLineValues(chart, options);
break;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's a world where instead of this switch, all the chart specific logic is inside chartjs_show_values.ts and the callbacks are created when creating the runtime rather than here in the chartJs plugin.

It'd be probably a bit better ? I'll wait for another opinion before moving everything.

Comment on lines +18 to +20
interface CallbackArgs {
dataset: any;
chartElement: any;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

typing this probably isn't worth, we keep using "private" properties and having to ts-ignore

@@ -1,10 +1,30 @@
import type { ChartMeta, ChartType, Plugin } from "chart.js";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also some of the fix commits maybe should be backported

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