Skip to content

Add per-option options to chart menu, with backgroundColor for PNG export - #301

Merged
cwbuecheler merged 2 commits into
mainfrom
png-export-options
Oct 8, 2026
Merged

cwbuecheler merged 2 commits into
mainfrom
png-export-options

Conversation

@cwbuecheler

@cwbuecheler cwbuecheler commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Add optional options to PNG export - first one: background color. Default remains transparent

Summary

Chart menu options can now carry an optional options object. It is passed to the option's onClick as options. The first use is PNG export, which gains a backgroundColor setting. Until now PNG exports always had a transparent background.

Changes

  • ChartCardMenuOption and ChartCardMenuOptionOnClickProps gain an optional options field.
  • ChartCardMenuPro forwards option.options to onClick on all three paths: instant actions, onCustomDownload, and the default path.
  • exportPNG reads options.backgroundColor and passes it to dom-to-image-more as bgcolor. The exported PngExportOptions type describes it.
  • Tests cover the default (no bgcolor), backgroundColor reaching toPng, and option forwarding, including through onCustomDownload.
  • A changeset is included (minor).

Backwards compatibility

Both new fields are optional. With no options set, exports behave as before, and existing themes and custom onClick functions need no changes.

Usage

chartMenuOptions: defaultChartMenuProOptions.map((o) =>
  o.value === 'png' ? { ...o, options: { backgroundColor: '#ffffff' } } : o,
)

Notes for review

  • The shared options prop is typed Record<string, unknown>, and exportPNG casts it to PngExportOptions. A narrower parameter type on exportPNG wouldn't type-check when assigned to onClick.

Summary by CodeRabbit

  • New Features
    • Chart menu options can now pass custom settings to click callbacks, including when custom downloads provide additional data.
    • PNG exports can use a specified background color; when none is provided, the background remains transparent.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 019af96f-9bef-49e8-acdc-2f4703346e34

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00f2bcbe-adb6-45d3-b32a-39494ff60d4d
📥 Commits

Reviewing files that changed from the base of the PR and between 26acdc5 and e5ed705.

📒 Files selected for processing (6)
  • .changeset/png-export-options.md
  • src/components/charts/shared/ChartCard/ChartCardMenuPro/ChartCardMenuPro.test.tsx
  • src/components/charts/shared/ChartCard/ChartCardMenuPro/ChartCardMenuPro.tsx
  • src/theme/defaults/defaults.ChartCardMenu.constants.ts
  • src/theme/utils/export.utils.test.ts
  • src/theme/utils/export.utils.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

Chart menu options now reach click callbacks. PNG export accepts an optional background color and passes it to the renderer when configured.

Changes

Chart export options

Layer / File(s) Summary
Forward per-option settings
src/theme/defaults/defaults.ChartCardMenu.constants.ts, src/components/charts/shared/ChartCard/ChartCardMenuPro/ChartCardMenuPro.tsx, src/components/charts/shared/ChartCard/ChartCardMenuPro/ChartCardMenuPro.test.tsx
Menu options and callback props include an optional settings record. The menu adds the option settings to callback arguments, including custom-download arguments. Tests cover both callback paths.
Apply PNG background options
src/theme/utils/export.utils.ts, src/theme/utils/export.utils.test.ts, .changeset/png-export-options.md
exportPNG accepts PngExportOptions and passes a truthy backgroundColor to domtoimage.toPng as bgcolor. Tests cover the default and configured cases. The changeset documents the options.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ChartCardMenuPro
  participant OptionOnClick as option.onClick
  participant exportPNG
  participant domtoimage.toPng
  ChartCardMenuPro->>OptionOnClick: callback arguments with option.options
  OptionOnClick->>exportPNG: options.backgroundColor
  exportPNG->>domtoimage.toPng: bgcolor when backgroundColor is truthy
Loading

Merge Risk: ⚪ Minimal · up to e5ed7

No merge-blocking issue is established by the reviewed changes; normal project checks remain appropriate.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: per-option settings for chart menu actions and a PNG background color option.
Description check ✅ Passed The description explains the change, its purpose, backwards compatibility, usage, and test coverage. It does not use the template headings or give test run results, but it provides the key information…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@cwbuecheler cwbuecheler changed the title [DRAFT] Add per-option options to chart menu, with backgroundColor for PNG export Add per-option options to chart menu, with backgroundColor for PNG export Oct 6, 2026
@cwbuecheler

Copy link
Copy Markdown
Contributor Author

@mad-raccoon - No issues from coderabbit or sonarqube. Claude didn't spam a bunch of comments in, either 😁 ... could you take a look when you have a couple minutes?

@mad-raccoon mad-raccoon 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.

approved with a comment.

Comment thread src/theme/utils/export.utils.ts Outdated
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@cwbuecheler
cwbuecheler merged commit dae6656 into main Oct 8, 2026
4 checks passed
@cwbuecheler
cwbuecheler deleted the png-export-options branch October 8, 2026 14:54
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