Skip to content

Commit 904be02

Browse files
authored
[Uptime] Fix charts dark theme (#69748)
1 parent 94321cc commit 904be02

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

x-pack/plugins/uptime/public/components/common/charts/duration_chart.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { useState } from 'react';
7+
import React, { useContext, useState } from 'react';
88
import { i18n } from '@kbn/i18n';
99
import moment from 'moment';
1010
import { FormattedMessage } from '@kbn/i18n/react';
@@ -26,6 +26,7 @@ import { getTickFormat } from './get_tick_format';
2626
import { ChartEmptyState } from './chart_empty_state';
2727
import { DurationAnomaliesBar } from './duration_line_bar_list';
2828
import { AnomalyRecords } from '../../../state/actions';
29+
import { UptimeThemeContext } from '../../../contexts';
2930

3031
interface DurationChartProps {
3132
/**
@@ -59,6 +60,8 @@ export const DurationChartComponent = ({
5960

6061
const [hiddenLegends, setHiddenLegends] = useState<string[]>([]);
6162

63+
const { chartTheme } = useContext(UptimeThemeContext);
64+
6265
const onBrushEnd: BrushEndListener = ({ x }) => {
6366
if (!x) {
6467
return;
@@ -93,6 +96,7 @@ export const DurationChartComponent = ({
9396
legendPosition={Position.Bottom}
9497
onBrushEnd={onBrushEnd}
9598
onLegendItemClick={legendToggleVisibility}
99+
{...chartTheme}
96100
/>
97101
<Axis
98102
id="bottom"

x-pack/plugins/uptime/public/components/common/charts/monitor_bar_series.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface MonitorBarSeriesProps {
3939
export const MonitorBarSeries = ({ histogramSeries }: MonitorBarSeriesProps) => {
4040
const {
4141
colors: { danger },
42+
chartTheme,
4243
} = useContext(UptimeThemeContext);
4344
const [getUrlParams, updateUrlParams] = useUrlParams();
4445
const { absoluteDateRangeStart, absoluteDateRangeEnd } = getUrlParams();
@@ -62,6 +63,7 @@ export const MonitorBarSeries = ({ histogramSeries }: MonitorBarSeriesProps) =>
6263
<Settings
6364
xDomain={{ min: absoluteDateRangeStart, max: absoluteDateRangeEnd }}
6465
onBrushEnd={onBrushEnd}
66+
{...chartTheme}
6567
/>
6668
<Axis
6769
hide

x-pack/plugins/uptime/public/components/common/charts/ping_histogram.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
6060
}) => {
6161
const {
6262
colors: { danger, gray },
63+
chartTheme,
6364
} = useContext(UptimeThemeContext);
6465

6566
const [, updateUrlParams] = useUrlParams();
@@ -128,6 +129,7 @@ export const PingHistogramComponent: React.FC<PingHistogramComponentProps> = ({
128129
}}
129130
showLegend={false}
130131
onBrushEnd={onBrushEnd}
132+
{...chartTheme}
131133
/>
132134
<Axis
133135
id={i18n.translate('xpack.uptime.snapshotHistogram.xAxisId', {

x-pack/plugins/uptime/public/contexts/uptime_theme_context.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
88
import React, { createContext, useMemo } from 'react';
99
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
10+
import { EUI_CHARTS_THEME_DARK, EUI_CHARTS_THEME_LIGHT } from '@elastic/eui/dist/eui_charts_theme';
11+
import { DARK_THEME, LIGHT_THEME, PartialTheme, Theme } from '@elastic/charts';
1012
import { UptimeAppColors } from '../uptime_app';
1113

1214
export interface UptimeThemeContextValues {
1315
colors: UptimeAppColors;
16+
chartTheme: {
17+
baseTheme?: Theme;
18+
theme?: PartialTheme;
19+
};
1420
}
1521

1622
/**
@@ -26,6 +32,10 @@ const defaultContext: UptimeThemeContextValues = {
2632
warning: euiLightVars.euiColorWarning,
2733
gray: euiLightVars.euiColorLightShade,
2834
},
35+
chartTheme: {
36+
baseTheme: LIGHT_THEME,
37+
theme: EUI_CHARTS_THEME_LIGHT.theme,
38+
},
2939
};
3040

3141
export const UptimeThemeContext = createContext(defaultContext);
@@ -58,8 +68,12 @@ export const UptimeThemeContextProvider: React.FC<ThemeContextProps> = ({ darkMo
5868
const value = useMemo(() => {
5969
return {
6070
colors,
71+
chartTheme: {
72+
baseTheme: darkMode ? DARK_THEME : LIGHT_THEME,
73+
theme: darkMode ? EUI_CHARTS_THEME_DARK.theme : EUI_CHARTS_THEME_LIGHT.theme,
74+
},
6175
};
62-
}, [colors]);
76+
}, [colors, darkMode]);
6377

6478
return <UptimeThemeContext.Provider value={value} children={children} />;
6579
};

0 commit comments

Comments
 (0)