Skip to content

Feat/ Add auto-contrast toggle to Data labels#244

Open
ansaganie wants to merge 11 commits into
microsoft:mainfrom
ansaganie:features/add-auto-contrast-for-data-labels
Open

Feat/ Add auto-contrast toggle to Data labels#244
ansaganie wants to merge 11 commits into
microsoft:mainfrom
ansaganie:features/add-auto-contrast-for-data-labels

Conversation

@ansaganie

Copy link
Copy Markdown
Contributor

Adds an Auto-contrast toggle to the Format pane → Data labels group. When enabled (default: on), each label's lightness is automatically clamped so the text remains legible against its cell background colour, while preserving the hue and saturation the user chose.

Copilot AI review requested due to automatic review settings June 12, 2026 13:19

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an auto-contrast option for heatmap data labels so label colors remain legible against varying cell background colors, while preserving the user-selected hue/saturation.

Changes:

  • Introduces getAdaptiveLabelColor() (d3-color based) and applies it to data label fill styling when auto-contrast is enabled.
  • Adds a new formatting capability/setting (labels.autoContrast) with an en-US resource label.
  • Adds visual tests validating utility behavior and end-to-end label rendering with auto-contrast toggling.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/visualTest.ts Adds unit/E2E-style tests for adaptive label color and the auto-contrast toggle behavior.
stringResources/en-US/resources.resjson Adds a localized label for the new Auto-contrast toggle in the Format pane.
src/visual.ts Applies adaptive label fill color at render time based on cell background and toggle state.
src/settings.ts Introduces DataLabelsCardSettings with an autoContrast toggle; wires it into SettingsModel.labels.
src/heatmapUtils.ts Adds getAdaptiveLabelColor() to clamp label lightness using d3-color parsing and Lab lightness.
package.json Adds d3-color and its typings dependency.
capabilities.json Adds the labels.autoContrast property to the visual capabilities schema.
CHANGELOG.md Documents the new Auto-contrast feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/settings.ts Outdated
Comment thread src/heatmapUtils.ts Outdated
Comment thread test/visualTest.ts
Comment thread src/visual.ts
@ansaganie ansaganie marked this pull request as ready for review June 12, 2026 13:21
Copilot AI review requested due to automatic review settings June 15, 2026 05:51

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Comment thread src/visual.ts
Comment thread test/visualTest.ts
Comment thread test/visualTest.ts Outdated
Copilot AI review requested due to automatic review settings June 16, 2026 04:33
@ansaganie ansaganie changed the title Feat/ add Auto-contrast toggle to Data labels Feat/ Add auto-contrast toggle to Data labels Jun 16, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 6 comments.

Comment thread src/heatmapUtils.ts
Comment thread src/settings.ts
Comment thread src/heatmapUtils.ts
Comment thread src/visual.ts
Comment thread src/heatmapUtils.ts
Comment thread test/visualTest.ts

@Demonkratiy Demonkratiy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the feature! A few changes requested before merge — see inline comments (default value, lockfile churn, and shipping this as a proper accessibility option).

Comment thread src/settings.ts Outdated
Comment thread package.json
Comment thread src/heatmapUtils.ts
Copilot AI review requested due to automatic review settings June 19, 2026 10:56

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/heatmapUtils.ts Outdated
Comment thread src/visual.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 19, 2026 11:43

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Comment thread src/heatmapUtils.ts
Comment thread src/heatmapUtils.ts Outdated
Comment thread src/visual.ts
const adaptiveLabelColorCache = new Map<string, string>();
// .value → ILocalizedItemMember (selected option); .value.value → the raw EnumMemberValue string.
// Fall back to Soft (the configured default) if the value is absent.
const autoContrastMode = (labelSettings.autoContrast.value?.value as AutoContrastMode | undefined) ?? AUTO_CONTRAST_MODE_SOFT;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed and valid. In high-contrast mode parseSettings forces labels.fill to the theme foreground, but renderLabels still applies auto-contrast (default Soft) and mutates that color — which breaks the strict high-contrast color contract and can reduce contrast. We should force auto-contrast Off when this.colorHelper.isHighContrast. Keeping this thread open until that's addressed.

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.

3 participants