Skip to content

Commit

Permalink
feat(chart): improve chart dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
nanochromatic committed Oct 24, 2024
1 parent 30b5677 commit bcea0a6
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 489 deletions.
2 changes: 2 additions & 0 deletions src/App.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "./styles/highcharts.scss";

.App {
p {
margin: 2vh 4vw;
Expand Down
18 changes: 8 additions & 10 deletions src/components/MusicChart.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/** @jsxImportSource @emotion/react */
import { css, SerializedStyles } from '@emotion/react';
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import { useTheme } from '../context/ThemeContext';
import { themeGlobalDark, themeGlobalLight } from './charts/ChartTheme';

interface IMusicChartProps {
styles?: SerializedStyles;
Expand All @@ -14,15 +13,14 @@ interface IMusicChartProps {

export const MusicChart: React.FC<IMusicChartProps> = (props) => {
const appTheme = useTheme();
const [classTheme, setClassTheme] = useState('');

useEffect(() => {
const themeConfig = appTheme.darkMode ? themeGlobalDark : themeGlobalLight;
const newOptions = {
...props.options,
...themeConfig,
};
props.chartComponent.current?.chart?.update(newOptions);
}, [props.chartComponent, props.options, appTheme]);
const themeClass = appTheme.darkMode
? 'highcharts-dark'
: 'highcharts-light';
setClassTheme(themeClass);
}, [appTheme]);

return (
<div
Expand All @@ -39,7 +37,7 @@ export const MusicChart: React.FC<IMusicChartProps> = (props) => {
>
<HighchartsReact
containerProps={{
className: 'react-highcharts-container',
className: `react-highcharts-container ${classTheme}`,
style: { width: '100%', height: '100%' },
}}
highcharts={Highcharts}
Expand Down
Loading

0 comments on commit bcea0a6

Please sign in to comment.