Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] charts: revamp chart management #1373

Closed

Conversation

pro-odoo
Copy link
Collaborator

@pro-odoo pro-odoo commented May 20, 2022

Description:

Since the addition of scorecard and gauge chart, it becomes a mess to
manage different types of charts. There is a duplication of many concepts,
like getters (getBasicChartDefinition, getGaugeChartDefinition, ...),
local state (charts, scorecard, gauge), ...
In addition, it was not possible to add a new type of chart from outside
o-spreadsheet (for example add Odoo charts).

This commit introduce something similar to cellFactory => a chart Factory.
Based on the type of the chart in the definition of a chart, an instance of
a Chart is created and stored in the local state of chart core plugin.
A Chart is an instance of a class (which inherits from AbstractChart),
which implements some functions that will be called by the plugin.

For each Chart class, a Chart Runtime class should be created to
compute the runtime data needed by the components.
A Side panel should also be created (a config panel and a design panel).

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 (_lt("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented May 20, 2022

@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from 54f78c0 to 1633074 Compare May 25, 2022 08:04
@pro-odoo pro-odoo changed the base branch from master to master-chart-add-gauge-chart-laa May 25, 2022 08:15
@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch 3 times, most recently from 9de8fa1 to d49c165 Compare May 31, 2022 10:33
@pro-odoo pro-odoo changed the title [POC] Charts [REF] charts: revamp chart management May 31, 2022
@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from d49c165 to e2bb14e Compare May 31, 2022 11:35
@pro-odoo
Copy link
Collaborator Author

Some work to do in Odoo:

  • Update the code to add an Odoo link to a chart side panel
  • Migrations of commands which are update_chart

@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from e2bb14e to 1c6f829 Compare May 31, 2022 11:48
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

Coucou first review :)
Really nice split

src/helpers/charts/abstract_chart.ts Show resolved Hide resolved
src/helpers/charts/abstract_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/abstract_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/chart_factory.ts Outdated Show resolved Hide resolved
src/helpers/charts/abstract_chart.ts Outdated Show resolved Hide resolved
src/types/chart/gauge_chart.ts Show resolved Hide resolved
src/types/chart/chart.ts Outdated Show resolved Hide resolved
tests/collaborative/clipboard.test.ts Outdated Show resolved Hide resolved
tests/components/charts.test.ts Outdated Show resolved Hide resolved
src/plugins/core/chart.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@hokolomopo hokolomopo left a comment

Choose a reason for hiding this comment

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

Fast-ish review, I didn't really check the tests

demo/data.js Show resolved Hide resolved
src/helpers/charts/abstract_chart.ts Outdated Show resolved Hide resolved
src/components/figures/chart/chartJs/chartjs.ts Outdated Show resolved Hide resolved
src/components/figures/chart/chartJs/chartjs.ts Outdated Show resolved Hide resolved
src/helpers/charts/pie_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/pie_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/pie_chart.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/types/chart/common_chart.ts Show resolved Hide resolved
@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from eed9c64 to 0a58519 Compare June 3, 2022 06:01
@pro-odoo pro-odoo force-pushed the master-chart-add-gauge-chart-laa branch from 38bef89 to 895f021 Compare June 3, 2022 06:02
@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from 0a58519 to e159fd7 Compare June 3, 2022 06:03
@pro-odoo pro-odoo force-pushed the master-chart-add-gauge-chart-laa branch from 895f021 to b544dfe Compare June 3, 2022 07:13
@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from e159fd7 to 4dffb5d Compare June 3, 2022 07:21
@rrahir
Copy link
Collaborator

rrahir commented Jun 7, 2022

Add task id

Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

going to miam miam 🍔

src/helpers/charts/bar_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/bar_chart.ts Show resolved Hide resolved
src/helpers/charts/chart_ui_common.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/helpers/charts/scorecard_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/abstract_chart.ts Outdated Show resolved Hide resolved
src/helpers/range.ts Outdated Show resolved Hide resolved
src/helpers/charts/bar_chart.ts Outdated Show resolved Hide resolved
The CSS to transform text overflow in menus to ellipsis wasn't working.

The sub-menu arrow was also not displayed if the name of the menu was too long

Odoo task 2877337

closes #1403

Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Copy link
Collaborator

@rrahir rrahir left a comment

Choose a reason for hiding this comment

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

My current remaining comments - lul pointed out some of them. Don't want him to negate my review completely :p

src/helpers/charts/chart_factory.ts Outdated Show resolved Hide resolved
get chartRuntime(): ChartJSRuntime {
const runtime = this.env.model.getters.getChartRuntime(this.props.figureId);
if (!("type" in runtime)) {
throw new Error("Unsupported chart runtime");
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't have a suggetion but I don't like that we rely on the presence of a key to decide that, specifically this key. This means taht type exists on all ChartDefinition and all ChartConfiguration but the one of gauge (and potentially the ones from Odoo but I think they'll be chartJs as well)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not have a better solution, actually this chart is instantiate based on a matching so...

src/components/figures/chart/chartJs/chartjs.ts Outdated Show resolved Hide resolved
}

const GraphColors = [
// the same colors as those used in odoo reporting
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated but I am again surprised that a graph color does not match its range in the seletction input).

Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

some useless key checks and useless if statements

src/helpers/charts/gauge_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/gauge_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/scorecard_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/scorecard_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/scorecard_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/chart_common.ts Outdated Show resolved Hide resolved
src/helpers/charts/chart_common.ts Outdated Show resolved Hide resolved
src/helpers/charts/chart_common.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

good opportunity to add readonly everywhere for new/moved types

Comment on lines 13 to 14
rangeMin: string;
rangeMax: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

could they be parsed to numbers earlier to avoid casting to number basically everywhere they are used ?

src/helpers/charts/gauge_chart.ts Outdated Show resolved Hide resolved
src/helpers/charts/gauge_chart.ts Outdated Show resolved Hide resolved
No need to pass the array of ranges and the index, just give the range.
Also, sheetId is useless since it's already in the range

closes #1402

Signed-off-by: Pierre Rousseau (pro) <[email protected]>
@LucasLefevre LucasLefevre force-pushed the master-poc-chart-pro branch 2 times, most recently from 29c01a4 to edfcee6 Compare June 8, 2022 10:26
Add scorecard chart
-------------------

Add "Scorecard" chart type. Create new getters in chart.ts and
evaluation_chart.ts specific for this type of chart.

The chart itself is not a ChartJS chart, but is a standard Component
with hand-written logic for scaling the font sizes.

Some work should be done at a latter date in the chart plugins to better
handle all types of chart and avoid the repeated if/else.

Add gauge chart
---------------

Gauge chart based on "chartjs-gauge" library

Revamp chart management
-----------------------

Since the addition of scorecard and gauge chart, it becomes a mess to
manage different types of charts. There is a duplication of many concepts,
like getters (getBasicChartDefinition, getGaugeChartDefinition, ...),
local state (charts, scorecard, gauge), ...
In addition, it was not possible to add a new type of chart from outside
o-spreadsheet (for example add Odoo charts).

This commit introduce something similar to cellFactory => a chart Factory.
Based on the type of the chart in the definition of a chart, an instance of
a Chart is created and stored in the local state of chart core plugin.
A Chart is an instance of a class (which inherits from AbstractChart),
which implements some functions that will be called from the plugin.

For each Chart class, a Chart Runtime class should be created to
compute the runtime data needed by the components.
A Side panel should also be created (a config panel and a design panel).

Odoo task 2796685

Co-authored-by: Adrien Minne <[email protected]>
Co-authored-by: Alexis Lacroix <[email protected]>
@pro-odoo pro-odoo force-pushed the master-poc-chart-pro branch from edfcee6 to 503c0a9 Compare June 8, 2022 10:36
@pro-odoo
Copy link
Collaborator Author

pro-odoo commented Jun 8, 2022

Will be done here: #1393

@pro-odoo pro-odoo closed this Jun 8, 2022
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.

5 participants