Skip to content

Commit

Permalink
Merge pull request #20703 from highcharts/bugfix/15921-fillcolor-hcm
Browse files Browse the repository at this point in the history
bugfix/15921-fillcolor-hcm
  • Loading branch information
TorsteinHonsi committed Mar 1, 2024
2 parents 023c395 + 2b30840 commit 3059b3e
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 19 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: Highcharts - high contrast mode
authors:
- Gøran Slettemark
js_wrap: b
...
11 changes: 11 additions & 0 deletions samples/highcharts/accessibility/high-contrast-mode/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
<div id="container"></div>

<p class="highcharts-description">
Area chart with high contrast mode enabled and custom colors defined.
</p>
</figure>

29 changes: 29 additions & 0 deletions samples/highcharts/accessibility/high-contrast-mode/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Highcharts.chart('container', {
chart: {
type: 'area'
},
title: {
text: 'High contrast mode with custom colors'
},
accessibility: {
highContrastMode: true, // force high contrast mode,
highContrastTheme: {
colors: [
'#FFFFFF',
'#f9455a',
'#041867'
]
}
},
series: [
{
data: [5, 5, 5, 5, 5, 5]
},
{
data: [0, 1, 2, 3, 4, 5]
},
{
data: [5, 4, 3, 2, 1, 0]
}
]
});
16 changes: 16 additions & 0 deletions samples/unit-tests/accessibility/accessibility-options/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ QUnit.test('Keyboard navigation', function (assert) {
!chart.container.parentNode.querySelector('.highcharts-exit-anchor'),
'The exit anchor element shouldn\'t be rendered (#19374).'
);

chart.update({
accessibility: {
highContrastMode: true,
highContrastTheme: {
colors: ['#ff0000', '#00ff00', '#0000ff']
}
}
});

assert.strictEqual(
chart.options.colors.length,
3,
'The colors array should be updated with high contrast colors.'
);

});

QUnit.test('No data', function (assert) {
Expand Down
8 changes: 6 additions & 2 deletions ts/Accessibility/Accessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,13 @@ class Accessibility {
this.keyboardNavigation.update(kbdNavOrder);

// Handle high contrast mode
// Should only be applied once, and not if explicitly disabled
if (
!chart.highContrastModeActive && // Only do this once
whcm.isHighContrastModeActive()
!chart.highContrastModeActive &&
a11yOptions.highContrastMode !== false && (
whcm.isHighContrastModeActive() ||
a11yOptions.highContrastMode === true
)
) {
whcm.setHighContrastTheme(chart);
}
Expand Down
43 changes: 29 additions & 14 deletions ts/Accessibility/HighContrastMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import type Accessibility from './Accessibility';
import type ColorType from '../Core/Color/ColorType';
import type SeriesOptions from '../Core/Series/SeriesOptions';

import H from '../Core/Globals.js';
const {
Expand Down Expand Up @@ -110,26 +111,40 @@ function setHighContrastTheme(
const theme: AnyRecord = (
chart.options.accessibility.highContrastTheme
);

chart.update(theme, false);

const hasCustomColors = theme.colors?.length > 1;

// Force series colors (plotOptions is not enough)
chart.series.forEach(function (s): void {
const plotOpts = theme.plotOptions[s.type] || {};
s.update({

const fillColor = hasCustomColors && s.colorIndex !== void 0 ?
theme.colors[s.colorIndex] :
plotOpts.color || 'window';

const seriesOptions: Partial<SeriesOptions> = {
color: plotOpts.color || 'windowText',
colors: [plotOpts.color || 'windowText'],
borderColor: plotOpts.borderColor || 'window'
});

// Force point colors if existing
s.points.forEach(function (p): void {
if (p.options && p.options.color) {
p.update({
color: plotOpts.color || 'windowText',
borderColor: plotOpts.borderColor || 'window'
}, false);
}
});
colors: hasCustomColors ?
theme.colors : [plotOpts.color || 'windowText'],
borderColor: plotOpts.borderColor || 'window',
fillColor
};

s.update(seriesOptions, false);

if (s.points) {
// Force point colors if existing
s.points.forEach(function (p): void {
if (p.options && p.options.color) {
p.update({
color: plotOpts.color || 'windowText',
borderColor: plotOpts.borderColor || 'window'
}, false);
}
});
}
});

// The redraw for each series and after is required for 3D pie
Expand Down
9 changes: 6 additions & 3 deletions ts/Accessibility/HighContrastTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ declare module '../Core/Series/DataLabelOptions' {
*
* */

const theme: DeepPartial<Options> = {
export type HighContrastThemeOptions = DeepPartial<Options>;

const theme: HighContrastThemeOptions = {
chart: {
backgroundColor: 'window'
},
Expand All @@ -56,7 +58,8 @@ const theme: DeepPartial<Options> = {
colorAxis: {
minColor: 'windowText',
maxColor: 'windowText',
stops: []
stops: [],
dataClasses: []
},
colors: ['windowText'],
xAxis: {
Expand Down Expand Up @@ -117,7 +120,7 @@ const theme: DeepPartial<Options> = {
lineColor: 'windowText',
fillColor: 'windowText'
}
} as any,
},
pie: {
color: 'window',
colors: ['window'],
Expand Down
11 changes: 11 additions & 0 deletions ts/Accessibility/Options/A11yDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,17 @@ const Options: DeepPartial<A11yOptions> = {
* @apioption accessibility.highContrastTheme
*/

/**
* Controls how [highContrastTheme](#accessibility.highContrastTheme)
* is applied.
*
* The default option is `auto`, which applies the high contrast theme
* the user's system has a high contrast theme active.
*
* @since next
*/
highContrastMode: 'auto',

/**
* A text description of the chart.
*
Expand Down
1 change: 1 addition & 0 deletions ts/Accessibility/Options/A11yOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface AccessibilityOptions {
customComponents?: AnyRecord;
description?: string;
enabled: boolean;
highContrastMode: boolean | 'auto';
highContrastTheme: AnyRecord;
keyboardNavigation: AccessibilityKeyboardNavigationOptions;
landmarkVerbosity: string;
Expand Down

0 comments on commit 3059b3e

Please sign in to comment.