Skip to content

feat(Chart): add meger option logic#1056

Merged
ArgoZhang merged 1 commit into
masterfrom
dev-chart-meger
Jul 11, 2026
Merged

feat(Chart): add meger option logic#1056
ArgoZhang merged 1 commit into
masterfrom
dev-chart-meger

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jul 11, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1055

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Improve chart option handling by merging new configuration into existing chart instances instead of replacing them.

New Features:

  • Support merging new chart options into an already initialized chart element and its underlying chart configuration.

Bug Fixes:

  • Ensure updates to chart options correctly apply to existing chart instances by merging configurations and triggering a chart update.

@bb-auto bb-auto Bot added the enhancement New feature or request label Jul 11, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Jul 11, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds deep merge behavior when initializing or re-initializing chart instances so that existing chart configurations and instances can be updated in place instead of replaced.

Sequence diagram for chart initialization with deep merge

sequenceDiagram
    participant ChartInit as Chart.init
    participant ElementMap as elementMap
    participant DataStore as Data
    participant ChartObj as chart

    ChartInit->>ElementMap: has(element)
    alt element not in map
        ChartInit->>ElementMap: set(element, instance)
    else element already in map
        ChartInit->>ElementMap: get(element)
        ChartInit->>ElementMap: deepMerge(existingInstance, instance)
    end

    ChartInit->>DataStore: Data.get(element)
    alt data.chart exists
        ChartInit->>ChartObj: deepMerge(chart.config._config, instance)
        ChartInit->>ChartObj: update()
    end
Loading

File-Level Changes

Change Details Files
Introduce deep merge logic to update existing chart instances and configurations when getInstance is called multiple times for the same element.
  • When an existing instance is found in the internal element map, deeply merge the new instance into the existing one instead of overwriting it.
  • Retrieve existing chart data for the element and, if present, deeply merge the new instance into the chart configuration object.
  • Trigger a chart update after merging configuration so visual state reflects the merged options.
src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#1055 Implement merge option logic for Chart component options so that new instances/options are merged into existing chart configuration instead of replaced.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@ArgoZhang ArgoZhang merged commit 913e36d into master Jul 11, 2026
3 checks passed
@ArgoZhang ArgoZhang deleted the dev-chart-meger branch July 11, 2026 05:30

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • When merging into an existing elementMap entry, you're calling deepMerge(elementMap.get(element), instance) but not resetting the map value; if deepMerge returns a new object rather than mutating in place this will leave elementMap pointing at the old config, so consider assigning the merged result back.
  • The merge into data.chart.config._config relies on a private _config property of Chart.js; consider whether there is a more stable public API for updating options to avoid potential breakage with library upgrades.
  • Repeated deep merges and chart updates on every setOptions call may become expensive; if this code path can be hit frequently, consider guarding the merge/update with a shallow comparison or more targeted updates to avoid unnecessary work.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When merging into an existing `elementMap` entry, you're calling `deepMerge(elementMap.get(element), instance)` but not resetting the map value; if `deepMerge` returns a new object rather than mutating in place this will leave `elementMap` pointing at the old config, so consider assigning the merged result back.
- The merge into `data.chart.config._config` relies on a private `_config` property of Chart.js; consider whether there is a more stable public API for updating options to avoid potential breakage with library upgrades.
- Repeated deep merges and chart updates on every `setOptions` call may become expensive; if this code path can be hit frequently, consider guarding the merge/update with a shallow comparison or more targeted updates to avoid unnecessary work.

## Individual Comments

### Comment 1
<location path="src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js" line_range="24-26" />
<code_context>
+                deepMerge(elementMap.get(element), instance)
+            }
+
+            const data = Data.get(element);
+            if (data && data.chart) {
+                deepMerge(data.chart.config._config, instance);
+                data.chart.update();
+            }
</code_context>
<issue_to_address>
**issue (bug_risk):** Merging directly into `data.chart.config._config` may rely on internal/unstable Chart.js APIs and could break if `_config` changes.

`data.chart.config._config` appears to be an internal Chart.js structure rather than a stable public API. If Chart.js changes this field, the merge will start failing silently. Prefer merging into a documented config object (e.g. `data.chart.config` or `data.chart.options`) or using the library’s official update API instead.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +24 to +26
const data = Data.get(element);
if (data && data.chart) {
deepMerge(data.chart.config._config, instance);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Merging directly into data.chart.config._config may rely on internal/unstable Chart.js APIs and could break if _config changes.

data.chart.config._config appears to be an internal Chart.js structure rather than a stable public API. If Chart.js changes this field, the merge will start failing silently. Prefer merging into a documented config object (e.g. data.chart.config or data.chart.options) or using the library’s official update API instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Chart): add meger option logic

1 participant