Skip to content

Commit 6533ba8

Browse files
tycuporigami-zjoshwoodinggithub-actions[bot]renovate[bot]
committed
Highcharts Theme | LineChart (#5246)
Co-authored-by: origami-z <[email protected]> Co-authored-by: Josh Wooding <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Liberty Curtis <[email protected]> Co-authored-by: mark-tate <[email protected]>
1 parent 575ac8e commit 6533ba8

28 files changed

+3178
-2
lines changed

.changeset/tidy-radios-watch.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
"@salt-ds/highcharts-theme": minor
3+
---
4+
5+
### Summary
6+
7+
Salt Highcharts theme is a package that supplies the Salt theme for Highcharts. It includes a CSS file for all CSS-based styles, and an options object for styles that are not CSS configurable. Together, they provide a complete theming solution for Highcharts version 10 to version 12.
8+
9+
_Please note, this package is a WIP. Highcharts CSS files and Options object are not finalised._
10+
11+
### Rationale
12+
13+
A theme-only package for Highcharts offers a lightweight solution focused solely on styling, making it easier to maintain and update visual consistency across charts. Unlike a full React wrapper, it doesn't impose additional abstraction layers, allowing developers to leverage Highcharts' native capabilities directly. This approach minimizes overhead and complexity, providing flexibility to integrate with various frameworks or environments without being tied to a specific implementation.
14+
15+
### Supported charts
16+
17+
This package is a work in progress and represents a snapshot release focusing specifically on the LineChart.
18+
19+
Our intent is to gather feedback on the provided solution, allowing us to refine and expand the theme to support additional chart types in future, incremental releases.
20+
21+
### Usage
22+
23+
Please see the package [README.md](https://github.com/jpmorganchase/salt-ds/blob/main/packages/highcharts-theme/README.md) for guidance on usage.
24+
25+
### License
26+
27+
A license is required to use Highcharts.
28+
29+
### Migration
30+
31+
The Salt Highcharts theme replaces previous approaches that bundled a chart wrapper with styling. Because this package contains **only** theme assets (CSS + Highcharts options), you can keep using any Highcharts integration you prefer and simply apply the theme.
32+
33+
**Steps to migrate**
34+
35+
1. **Install the package** (snapshot build, requires Highcharts 10 – 12):
36+
37+
```bash
38+
# npm
39+
npm install @salt-ds/highcharts-theme
40+
41+
# yarn
42+
yarn add @salt-ds/highcharts-theme
43+
```
44+
45+
2. **Import the theme resources** at your application entry point:
46+
47+
```ts
48+
import "@salt-ds/highcharts-theme/index.css";
49+
50+
// Salt CSS overrides
51+
import Highcharts from "highcharts";
52+
import { highchartsOptionsSalt } from "@salt-ds/highcharts-theme";
53+
54+
// apply global theme options
55+
Highcharts.setOptions(highchartsOptionsSalt);
56+
```
57+
58+
3. **Continue using your existing chart code.** For React you might use `highcharts-react-official` (or any other wrapper):
59+
60+
```jsx
61+
<div className="highcharts-theme-salt">
62+
<HighchartsReact highcharts={Highcharts} options={chartOptions} />
63+
</div>
64+
```
65+
66+
4. **Merge additional options as required.** Highcharts deep-merges subsequent calls to `Highcharts.setOptions`; you can also combine objects per-chart with `Highcharts.merge()`.
67+
68+
**Things to watch for:**
69+
70+
- This snapshot styles **LineChart** only; other chart types will fall back to default Highcharts styles until future releases.
71+
- Ensure the Salt CSS is loaded **after** the default Highcharts CSS to guarantee correct specificity.
72+
- If a previous wrapper injected theme styles automatically, you must now call `Highcharts.setOptions` yourself and add the `highcharts-theme-salt` class to chart containers.

.stylelintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@
5757
}
5858
]
5959
}
60+
},
61+
{
62+
"files": ["**/highcharts-theme/css/**/*.css"],
63+
"rules": {
64+
"salt/correct-theme-token-usage": [
65+
false,
66+
{
67+
"severity": "warning"
68+
}
69+
]
70+
}
6071
}
6172
]
6273
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"start": "yarn storybook",
1616
"build": "yarn workspaces foreach --exclude @salt-ds/site -Apt run build && yarn bundle:css",
1717
"build:ag-grid-theme": "yarn workspace @salt-ds/ag-grid-theme build",
18+
"build:hc-theme": "yarn workspace @salt-ds/highcharts-theme build",
1819
"bundle:css": "yarn bundle:core:css && yarn bundle:lab:css && yarn bundle:embla-carousel:css && yarn copy:icon:css && yarn copy:countries:css",
1920
"bundle:core:css": "yarn workspace @salt-ds/core bundle:css",
2021
"bundle:lab:css": "yarn workspace @salt-ds/lab bundle:css",
@@ -29,12 +30,13 @@
2930
"lint": "biome check",
3031
"lint:fix": "biome check --fix",
3132
"lint:check:error": "biome check --diagnostic-level=error",
32-
"lint:style": "yarn lint:style:core && yarn lint:style:icon && yarn lint:style:lab && yarn lint:style:ag-theme",
33+
"lint:style": "yarn lint:style:core && yarn lint:style:icon && yarn lint:style:lab && yarn lint:style:ag-theme && yarn lint:style:hc-theme",
3334
"lint:style:core": "yarn stylelint -f verbose \"packages/core/src/**/*.css\"",
3435
"lint:style:icon": "yarn stylelint -f verbose \"packages/icons/src/**/*.css\"",
3536
"lint:style:lab": "yarn stylelint -f verbose \"packages/lab/src/**/*.css\"",
3637
"lint:style:embla-carousel": "yarn stylelint -f verbose \"packages/embla-carousel/src/**/*.css\"",
3738
"lint:style:ag-theme": "yarn stylelint -f verbose \"packages/ag-grid-theme/css/**/*.css\"",
39+
"lint:style:hc-theme": "yarn stylelint -f verbose \"packages/highcharts-theme/css/**/*.css\"",
3840
"lint:style:theme": "yarn stylelint -f verbose \"packages/theme/css/**/*.css\"",
3941
"storybook": "storybook dev -p 6006",
4042
"build-storybook": "yarn build:ag-grid-theme && yarn bundle:css && storybook build --stats-json",
@@ -78,6 +80,8 @@
7880
"cypress-real-events": "^1.13.0",
7981
"deepmerge": "^4.2.2",
8082
"dom-accessibility-api": "^0.7.0",
83+
"highcharts": "^10.2.0",
84+
"highcharts-react-official": "^3.2.2",
8185
"mockdate": "^3.0.5",
8286
"msw": "^2.7.0",
8387
"msw-storybook-addon": "^2.0.4",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Salt Highcharts Theme
2+
3+
Salt Highcharts Theme is a package that adds Salt theme styles to Highcharts. The package contains a CSS file and a Highcharts global options object necessary for positional property application.
4+
5+
_Please note, this package is a WIP. Highcharts CSS files and Options object are not finalised._
6+
7+
## Supported Highchart versions
8+
9+
This package is compatible with version 10 to 12 of Highcharts.
10+
11+
Within the package CSS folder, the default theme is considered to be v10.
12+
13+
CSS changes from other major versions are isolated into their own file but feature in prior versions too.
14+
15+
### License
16+
17+
A license is required to use Highcharts.
18+
19+
## Installation
20+
21+
To install the Salt Highcharts theme package, ensure you have a supported version of Highcharts installed and add `@salt-ds/highcharts-theme` via your package manager
22+
23+
```bash
24+
npm install @salt-ds/highcharts-theme
25+
# or
26+
yarn add @salt-ds/highcharts-theme
27+
```
28+
29+
### Import Highcharts CSS
30+
31+
The Salt Highcharts theme overrides the default Highcharts CSS. To ensure the theme is applied correctly, import the Highcharts CSS before the Salt Highcharts theme CSS.
32+
33+
> You can download the [Highcharts CSS
34+
> here](https://code.highcharts.com/10.2.0/css/highcharts.css), specifying the
35+
> required version via the URL.
36+
37+
### Import Salt Highcharts theme
38+
39+
To import the Salt Highcharts theme, use:
40+
41+
```js
42+
import "@salt-ds/highcharts-theme/index.css";
43+
```
44+
45+
Then wrap your Highcharts with `highcharts-theme-salt` class name as shown below:
46+
47+
```jsx
48+
<div className="highcharts-theme-salt">
49+
<HighchartsReact highcharts={Highcharts} options={yourChartSpecificOptions} />
50+
</div>
51+
```
52+
53+
### Set Highcharts Global options
54+
55+
Many Highchart stylistic properties cannot be configured via CSS alone. To adhere to the Salt design system, import and set the [Highcharts global options](https://www.highcharts.com/docs/getting-started/how-to-set-options) at your entry point.
56+
57+
```js
58+
import Highcharts from "highcharts";
59+
60+
Highcharts.setOptions(highchartsOptionsSalt);
61+
```
62+
63+
### Compatibility with existing Highcharts options
64+
65+
If you already have a [Highcharts global options object](https://www.highcharts.com/docs/getting-started/how-to-set-options), you can call `Highcharts.setOptions` again with the `highchartsOptionsSalt` after your initial call. Any fields set by `highchartsOptionsSalt` will take precedence over any previously set fields.
66+
67+
For granular control, you can also use the `Highcharts.merge()` utility function to deep merge the `highchartsOptionsSalt` with your existing options object, including at the chart level.
68+
69+
To see which Options properties the Salt Highchart Theme package provides, see `src/highcharts-options-salt.ts`.
70+
71+
### Patterns and Fills
72+
73+
The Salt Highcharts theme also provides Salt patterns and fills that can be applied to create visible contrast between series. For example, the `salt-line-patterns` class applies
74+
a line pattern to each series in a Line Chart.
75+
76+
Guidance on Fills TBA.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
.highcharts-theme-salt .highcharts-color-0 {
2+
fill: var(--salt-category-1-bold-background);
3+
stroke: var(--salt-category-1-subtle-borderColor);
4+
}
5+
6+
.highcharts-theme-salt .highcharts-color-1 {
7+
fill: var(--salt-category-2-bold-background);
8+
stroke: var(--salt-category-2-subtle-borderColor);
9+
}
10+
11+
.highcharts-theme-salt .highcharts-color-2 {
12+
fill: var(--salt-category-3-bold-background);
13+
stroke: var(--salt-category-3-subtle-borderColor);
14+
}
15+
16+
.highcharts-theme-salt .highcharts-color-3 {
17+
fill: var(--salt-category-4-bold-background);
18+
stroke: var(--salt-category-4-subtle-borderColor);
19+
}
20+
21+
.highcharts-theme-salt .highcharts-color-4 {
22+
fill: var(--salt-category-5-bold-background);
23+
stroke: var(--salt-category-5-subtle-borderColor);
24+
}
25+
26+
.highcharts-theme-salt .highcharts-color-5 {
27+
fill: var(--salt-category-6-bold-background);
28+
stroke: var(--salt-category-6-subtle-borderColor);
29+
}
30+
31+
.highcharts-theme-salt .highcharts-color-6 {
32+
fill: var(--salt-category-7-bold-background);
33+
stroke: var(--salt-category-7-subtle-borderColor);
34+
}
35+
36+
.highcharts-theme-salt .highcharts-color-7 {
37+
fill: var(--salt-category-8-bold-background);
38+
stroke: var(--salt-category-8-subtle-borderColor);
39+
}
40+
41+
.highcharts-theme-salt .highcharts-color-8 {
42+
fill: var(--salt-category-9-bold-background);
43+
stroke: var(--salt-category-9-subtle-borderColor);
44+
}
45+
46+
.highcharts-theme-salt .highcharts-color-9 {
47+
fill: var(--salt-category-10-bold-background);
48+
stroke: var(--salt-category-10-subtle-borderColor);
49+
}
50+
51+
.highcharts-theme-salt .highcharts-grid-line {
52+
stroke: var(--salt-separable-tertiary-borderColor);
53+
}
54+
55+
.highcharts-theme-salt .highcharts-title {
56+
fill: var(--salt-content-primary-foreground);
57+
font-size: var(--salt-text-h4-fontSize);
58+
font-weight: var(--salt-text-h4-fontWeight);
59+
line-height: var(--salt-text-h4-lineHeight);
60+
font-family: var(--salt-text-h4-fontFamily);
61+
}
62+
.highcharts-theme-salt .highcharts-subtitle,
63+
.highcharts-theme-salt .highcharts-axis-title,
64+
.highcharts-theme-salt .highcharts-axis-labels {
65+
fill: var(--salt-content-secondary-foreground);
66+
font-size: var(--salt-text-label-fontSize);
67+
line-height: var(--salt-text-label-lineHeight);
68+
font-family: var(--salt-text-label-fontFamily);
69+
}
70+
71+
/* Deselected legend state, requires !important to override default styles, which also use !important */
72+
.highcharts-theme-salt .highcharts-legend-item-hidden * {
73+
stroke: revert !important;
74+
fill: revert !important;
75+
opacity: 0.2;
76+
}
77+
78+
.highcharts-theme-salt .highcharts-legend-item > text,
79+
.highcharts-theme-salt .highcharts-legend-item span {
80+
fill: var(--salt-content-secondary-foreground);
81+
font-size: var(--salt-text-label-fontSize);
82+
font-weight: var(--salt-text-label-fontWeight);
83+
line-height: var(--salt-text-label-lineHeight);
84+
font-family: var(--salt-text-label-fontFamily);
85+
}
86+
.highcharts-theme-salt .highcharts-axis-line {
87+
stroke: var(--salt-separable-primary-borderColor);
88+
}
89+
90+
.highcharts-theme-salt .highcharts-data-label text,
91+
.highcharts-theme-salt text.highcharts-data-label {
92+
fill: var(--salt-content-primary-foreground);
93+
font-weight: var(--salt-text-label-fontWeight);
94+
font-size: var(--salt-text-label-fontSize);
95+
line-height: var(--salt-text-label-lineHeight);
96+
font-family: var(--salt-text-label-fontFamily);
97+
}
98+
99+
.highcharts-theme-salt .highcharts-tooltip-box {
100+
fill: var(--salt-container-primary-background);
101+
}
102+
103+
.highcharts-theme-salt .highcharts-tooltip text,
104+
.highcharts-theme-salt .highcharts-tooltip foreignObject span {
105+
fill: var(--salt-content-primary-foreground);
106+
}
107+
108+
.highcharts-theme-salt .highcharts-background {
109+
fill: var(--salt-container-primary-background);
110+
}
111+
112+
.highcharts-theme-salt path.highcharts-legend-nav-active {
113+
fill: var(--salt-content-secondary-foreground);
114+
}
115+
116+
.highcharts-theme-salt path.highcharts-legend-nav-inactive {
117+
fill: var(--salt-content-secondary-foreground-disabled);
118+
}
119+
120+
.highcharts-theme-salt text.highcharts-legend-navigation {
121+
fill: var(--salt-content-secondary-foreground);
122+
font-weight: var(--salt-text-label-fontWeight);
123+
font-size: var(--salt-text-label-fontSize);
124+
line-height: var(--salt-text-label-lineHeight);
125+
font-family: var(--salt-text-label-fontFamily);
126+
}
127+
128+
.highcharts-theme-salt .highcharts-point {
129+
stroke: var(--salt-color-white);
130+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.highcharts-theme-salt .highcharts-legend-item:hover text {
2+
fill: var(--salt-content-secondary-foreground);
3+
}

0 commit comments

Comments
 (0)