Skip to content

feat(Chart): add Total/Tooltip/CategoryLabel format parameter - #1082

Merged
ArgoZhang merged 4 commits into
masterfrom
dev-dv
Jul 23, 2026
Merged

feat(Chart): add Total/Tooltip/CategoryLabel format parameter#1082
ArgoZhang merged 4 commits into
masterfrom
dev-dv

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jul 23, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1081

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

Add configurable text formatting options for chart labels and tooltips and expose a new dock layout switching helper.

New Features:

  • Allow configuring stacked total data labels with customizable format, color, background, border radius, padding, and font weight.
  • Allow formatting X-axis category labels via a format string with placeholders for label and value.
  • Allow formatting tooltip titles and labels via format strings with placeholders for label, value, dataset label, and indices.
  • Provide a DockView JavaScript API to switch layouts by delegating to the underlying dockview instance.

Enhancements:

  • Refactor chart total data label logic to reuse a shared stacked total calculation and text formatting helper.

@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 self-assigned this Jul 23, 2026
@ArgoZhang ArgoZhang added the enhancement New feature or request label Jul 23, 2026
@ArgoZhang ArgoZhang added this to the v10.0.0 milestone Jul 23, 2026
@ArgoZhang
ArgoZhang merged commit 07ed88c into master Jul 23, 2026
2 checks passed
@ArgoZhang
ArgoZhang deleted the dev-dv branch July 23, 2026 09:03
@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds configurable formatting options for chart stacked total data labels, category axis labels, and tooltips, plus a DockView layout switch helper, by wiring new ChartOptions properties into the JavaScript chart configuration and exposing a new dock layout API.

Sequence diagram for chart tooltip/title/category label formatting

sequenceDiagram
    participant ChartComponent
    participant ChartOptions
    participant getChartOption
    participant formatChartText

    ChartComponent->>getChartOption: getChartOption(option)
    getChartOption->>ChartOptions: read CategoryLabelFormatter
    getChartOption->>formatChartText: formatChartText(CategoryLabelFormatter, { value, label })
    getChartOption->>ChartOptions: read TooltipTitleFormatter
    getChartOption->>formatChartText: formatChartText(TooltipTitleFormatter, { label, value, datasetLabel, dataIndex, datasetIndex })
    getChartOption->>ChartOptions: read TooltipLabelFormatter
    getChartOption->>formatChartText: formatChartText(TooltipLabelFormatter, { label, value, datasetLabel, dataIndex, datasetIndex })
    getChartOption-->>ChartComponent: configured chart options with formatted labels
Loading

Sequence diagram for stacked total data label formatting

sequenceDiagram
    participant ChartComponent
    participant ChartOptions
    participant getChartOption
    participant getStackedTotal
    participant formatChartText

    ChartComponent->>getChartOption: getChartOption(option)
    getChartOption->>ChartOptions: read ShowTotalDataLabel
    getChartOption->>getStackedTotal: getStackedTotal(context)
    getStackedTotal-->>getChartOption: total
    getChartOption->>ChartOptions: read TotalDataLabelFormatter
    getChartOption->>formatChartText: formatChartText(TotalDataLabelFormatter, { total, value: total })
    formatChartText-->>getChartOption: formattedTotalText
    getChartOption-->>ChartComponent: datalabels.labels.total with totalLabel
Loading

Sequence diagram for DockView layout switching

sequenceDiagram
    participant DockClient
    participant switchLayout
    participant Data
    participant dockview

    DockClient->>switchLayout: switchLayout(id, options)
    switchLayout->>Data: Data.get(id)
    Data-->>switchLayout: dock
    switchLayout->>dockview: dockview.switchLayout(options)
    dockview-->>DockClient: layout updated
Loading

File-Level Changes

Change Details Files
Introduce a reusable text formatting helper and use it to support configurable formatting for stacked total data labels and X-axis category labels in charts.
  • Add a generic formatChartText helper that replaces placeholders in a format string with runtime values.
  • Refactor stacked total label computation into a dedicated getStackedTotal function for reuse.
  • Build a configurable totalLabel object for stacked charts, applying new color, background, radius, padding, and font weight options when present.
  • Apply a categoryLabelFormatter option to x-axis tick callbacks, allowing label/value placeholder replacement.
src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js
Add formatter and styling configuration properties to ChartOptions to control stacked total labels, category labels, and tooltip content.
  • Add TotalDataLabelFormatter and related color/background/border/padding/font weight properties for stacked total data label customization.
  • Add CategoryLabelFormatter to control X-axis category label text using {label} and {value} placeholders.
  • Add TooltipTitleFormatter and TooltipLabelFormatter to customize tooltip title and label text using various placeholders (label, value, datasetLabel, dataIndex, datasetIndex).
src/components/BootstrapBlazor.Chart/Components/Chart/ChartOptions.cs
Wire new tooltip formatting options into the chart configuration, enabling custom title and label text via callbacks when format strings are provided.
  • Create a tooltip configuration object and conditionally add callbacks based on TooltipTitleFormatter and TooltipLabelFormatter options.
  • Populate tooltip callback contexts with label, formatted value, dataset label, and indices, and pass them through formatChartText.
  • Attach the tooltip configuration to the chart options only when callbacks are defined.
src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js
Expose a DockView layout switching API on the client-side to allow changing layouts programmatically.
  • Add a switchLayout(id, options) export that retrieves the dock instance and calls dockview.switchLayout(options).
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#1081 Add a configurable formatter parameter for stacked total data labels in Chart (including using placeholders like {total}).
#1081 Add configurable formatter parameters for Chart tooltips (title and label), supporting placeholders such as {label}, {value}, {datasetLabel}, {dataIndex}, {datasetIndex}.
#1081 Add a configurable formatter parameter for Chart category (X-axis) labels, supporting placeholders like {label} and {value}.

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

@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 left some high level feedback:

  • The new formatChartText helper relies on String.prototype.replaceAll, which may not be available in all target browsers/environments; consider using a more broadly supported implementation (e.g. replace with a global regex) or a polyfill.
  • In Chart.razor.js the checks if (option.options.totalDataLabelBorderRadius !== null) and if (option.options.totalDataLabelPadding !== null) will also be true when the values are undefined, causing borderRadius/padding to be set to undefined; consider changing these to != null or explicitly checking for typeof ... === 'number' to avoid passing undefined into the Chart.js config.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `formatChartText` helper relies on `String.prototype.replaceAll`, which may not be available in all target browsers/environments; consider using a more broadly supported implementation (e.g. `replace` with a global regex) or a polyfill.
- In `Chart.razor.js` the checks `if (option.options.totalDataLabelBorderRadius !== null)` and `if (option.options.totalDataLabelPadding !== null)` will also be true when the values are `undefined`, causing `borderRadius`/`padding` to be set to `undefined`; consider changing these to `!= null` or explicitly checking for `typeof ... === 'number'` to avoid passing undefined into the Chart.js config.

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.

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 Total/Tooltip/CategoryLabel format parameter

1 participant