Skip to content

Commit

Permalink
[8.9] [Infra UI] Fix theme passed in to charts (#162114) (#162301)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.9`:
- [[Infra UI] Fix theme passed in to charts
(#162114)](#162114)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Carlos
Crespo","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-07-19T17:09:05Z","message":"[Infra
UI] Fix theme passed in to charts (#162114)\n\ncloses
[#110217](https://github.com/elastic/kibana/issues/110217)\r\n##
Summary\r\n\r\nThis PR addresses an issue with how the infra sets the
theme in charts.\r\nIt replaces the previous implementation with the use
of\r\n`useChartsBaseTheme` and `useChartsTheme` provided by the
charts\r\nservice, ensuring consistent behavior for both light and dark
modes.\r\nFrom a UI perspective, this change doesn't introduce any
alterations,\r\nbut it solves the problem related to dark
mode.\r\n\r\n### Screenshots\r\n\r\n#### Node Details\r\n<img
width=\"899\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/7ec8b9e9-c440-44d1-86ac-45dbab76a8a9\">\r\n\r\n<img
width=\"899\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/c6aac4a6-8982-47cc-b08e-ee5d8af0391f\">\r\n\r\n\r\n####
Infra\r\n##### Timeline\r\n<img width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/cd4a1a3c-b5a4-47d5-bbde-5bf54dfac262\">\r\n\r\n<img
width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/839ccaf0-02a5-401e-957a-137d0ef25605\">\r\n\r\n\r\n#####
Metrics\r\n<img width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/69138a89-21ff-4f17-bcbd-64ac609dd9e7\">\r\n\r\n<img
width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/63b02a7a-397e-451e-b4d7-7b37fdc4f6a9\">\r\n\r\n\r\n#####
Processes\r\n<img width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/01e7d050-0103-4de6-8215-e93b9f80751b\">\r\n\r\n<img
width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/bd1ce95a-1944-411f-abc4-8f2a998f7643\">\r\n\r\n\r\n###
Metrics Explorer\r\n<img width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/60d2857a-3b97-4fd6-8cc7-8b7ab757b3d5\">\r\n\r\n<img
width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/98bba0ea-27db-48a2-ae20-ff4162212c6e\">\r\n\r\n\r\n###
Alert\r\n#### Inventory rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/8b787e53-cb47-4254-ab69-69ab22ff0388\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a952bf6b-e22f-4753-8db6-f2deb213b22a\">\r\n\r\n\r\n####
Metric Threshold rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/db3d1448-5faa-4e20-bda8-7351d9b52144\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a11bc2de-f042-4d4f-9adc-d376205bc23f\">\r\n\r\n\r\n####
Logs rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/b703e972-2d47-485e-a2f5-4cfca0c982cd\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a98d3827-d930-4ef2-90f9-f336583f15da\">\r\n\r\n\r\n\r\n\r\n###
How to tests\r\n- Set up a local Kibana instance.\r\n- Navigate to the
pages mentioned above.\r\n - Change the user settings to both dark and
light mode.\r\n- In light mode, ensure that there are no differences in
the charts when\r\ncompared to the edge cluster.\r\n- In dark mode,
confirm that the issue described in the ticket is\r\nresolved (no
horizontal line in white).\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"c2249aa0b7d6ca6cf4e826c768b6912b62db9a51","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Metrics
UI","Team:Infra Monitoring
UI","release_note:skip","backport:prev-minor","v8.9.0","v8.10.0"],"number":162114,"url":"https://github.com/elastic/kibana/pull/162114","mergeCommit":{"message":"[Infra
UI] Fix theme passed in to charts (#162114)\n\ncloses
[#110217](https://github.com/elastic/kibana/issues/110217)\r\n##
Summary\r\n\r\nThis PR addresses an issue with how the infra sets the
theme in charts.\r\nIt replaces the previous implementation with the use
of\r\n`useChartsBaseTheme` and `useChartsTheme` provided by the
charts\r\nservice, ensuring consistent behavior for both light and dark
modes.\r\nFrom a UI perspective, this change doesn't introduce any
alterations,\r\nbut it solves the problem related to dark
mode.\r\n\r\n### Screenshots\r\n\r\n#### Node Details\r\n<img
width=\"899\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/7ec8b9e9-c440-44d1-86ac-45dbab76a8a9\">\r\n\r\n<img
width=\"899\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/c6aac4a6-8982-47cc-b08e-ee5d8af0391f\">\r\n\r\n\r\n####
Infra\r\n##### Timeline\r\n<img width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/cd4a1a3c-b5a4-47d5-bbde-5bf54dfac262\">\r\n\r\n<img
width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/839ccaf0-02a5-401e-957a-137d0ef25605\">\r\n\r\n\r\n#####
Metrics\r\n<img width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/69138a89-21ff-4f17-bcbd-64ac609dd9e7\">\r\n\r\n<img
width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/63b02a7a-397e-451e-b4d7-7b37fdc4f6a9\">\r\n\r\n\r\n#####
Processes\r\n<img width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/01e7d050-0103-4de6-8215-e93b9f80751b\">\r\n\r\n<img
width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/bd1ce95a-1944-411f-abc4-8f2a998f7643\">\r\n\r\n\r\n###
Metrics Explorer\r\n<img width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/60d2857a-3b97-4fd6-8cc7-8b7ab757b3d5\">\r\n\r\n<img
width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/98bba0ea-27db-48a2-ae20-ff4162212c6e\">\r\n\r\n\r\n###
Alert\r\n#### Inventory rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/8b787e53-cb47-4254-ab69-69ab22ff0388\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a952bf6b-e22f-4753-8db6-f2deb213b22a\">\r\n\r\n\r\n####
Metric Threshold rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/db3d1448-5faa-4e20-bda8-7351d9b52144\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a11bc2de-f042-4d4f-9adc-d376205bc23f\">\r\n\r\n\r\n####
Logs rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/b703e972-2d47-485e-a2f5-4cfca0c982cd\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a98d3827-d930-4ef2-90f9-f336583f15da\">\r\n\r\n\r\n\r\n\r\n###
How to tests\r\n- Set up a local Kibana instance.\r\n- Navigate to the
pages mentioned above.\r\n - Change the user settings to both dark and
light mode.\r\n- In light mode, ensure that there are no differences in
the charts when\r\ncompared to the edge cluster.\r\n- In dark mode,
confirm that the issue described in the ticket is\r\nresolved (no
horizontal line in white).\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"c2249aa0b7d6ca6cf4e826c768b6912b62db9a51"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/162114","number":162114,"mergeCommit":{"message":"[Infra
UI] Fix theme passed in to charts (#162114)\n\ncloses
[#110217](https://github.com/elastic/kibana/issues/110217)\r\n##
Summary\r\n\r\nThis PR addresses an issue with how the infra sets the
theme in charts.\r\nIt replaces the previous implementation with the use
of\r\n`useChartsBaseTheme` and `useChartsTheme` provided by the
charts\r\nservice, ensuring consistent behavior for both light and dark
modes.\r\nFrom a UI perspective, this change doesn't introduce any
alterations,\r\nbut it solves the problem related to dark
mode.\r\n\r\n### Screenshots\r\n\r\n#### Node Details\r\n<img
width=\"899\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/7ec8b9e9-c440-44d1-86ac-45dbab76a8a9\">\r\n\r\n<img
width=\"899\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/c6aac4a6-8982-47cc-b08e-ee5d8af0391f\">\r\n\r\n\r\n####
Infra\r\n##### Timeline\r\n<img width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/cd4a1a3c-b5a4-47d5-bbde-5bf54dfac262\">\r\n\r\n<img
width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/839ccaf0-02a5-401e-957a-137d0ef25605\">\r\n\r\n\r\n#####
Metrics\r\n<img width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/69138a89-21ff-4f17-bcbd-64ac609dd9e7\">\r\n\r\n<img
width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/63b02a7a-397e-451e-b4d7-7b37fdc4f6a9\">\r\n\r\n\r\n#####
Processes\r\n<img width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/01e7d050-0103-4de6-8215-e93b9f80751b\">\r\n\r\n<img
width=\"541\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/bd1ce95a-1944-411f-abc4-8f2a998f7643\">\r\n\r\n\r\n###
Metrics Explorer\r\n<img width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/60d2857a-3b97-4fd6-8cc7-8b7ab757b3d5\">\r\n\r\n<img
width=\"720\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/98bba0ea-27db-48a2-ae20-ff4162212c6e\">\r\n\r\n\r\n###
Alert\r\n#### Inventory rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/8b787e53-cb47-4254-ab69-69ab22ff0388\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a952bf6b-e22f-4753-8db6-f2deb213b22a\">\r\n\r\n\r\n####
Metric Threshold rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/db3d1448-5faa-4e20-bda8-7351d9b52144\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a11bc2de-f042-4d4f-9adc-d376205bc23f\">\r\n\r\n\r\n####
Logs rule\r\n<img width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/b703e972-2d47-485e-a2f5-4cfca0c982cd\">\r\n\r\n<img
width=\"450\"
alt=\"image\"\r\nsrc=\"https://github.com/elastic/kibana/assets/2767137/a98d3827-d930-4ef2-90f9-f336583f15da\">\r\n\r\n\r\n\r\n\r\n###
How to tests\r\n- Set up a local Kibana instance.\r\n- Navigate to the
pages mentioned above.\r\n - Change the user settings to both dark and
light mode.\r\n- In light mode, ensure that there are no differences in
the charts when\r\ncompared to the edge cluster.\r\n- In dark mode,
confirm that the issue described in the ticket is\r\nresolved (no
horizontal line in white).\r\n\r\n---------\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"c2249aa0b7d6ca6cf4e826c768b6912b62db9a51"}}]}]
BACKPORT-->
  • Loading branch information
crespocarlos authored Jul 20, 2023
1 parent a5860bf commit 2af0d49
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { first, last } from 'lodash';
import moment from 'moment';
import React, { useCallback, useMemo } from 'react';
import { getChartTheme } from '../../../utils/get_chart_theme';
import { useIsDarkMode } from '../../../hooks/use_is_dark_mode';
import { useTimelineChartTheme } from '../../../utils/use_timeline_chart_theme';
import { InventoryMetricConditions } from '../../../../common/alerting/metrics';
import { Color } from '../../../../common/color_palette';
import { MetricsExplorerAggregation, MetricsExplorerRow } from '../../../../common/http_api';
Expand Down Expand Up @@ -45,6 +44,7 @@ export const ExpressionChart: React.FC<Props> = ({
nodeType,
sourceId,
}) => {
const chartTheme = useTimelineChartTheme();
const timerange = useMemo(
() => ({
interval: `${expression.timeSize || 1}${expression.timeUnit}`,
Expand Down Expand Up @@ -77,7 +77,6 @@ export const ExpressionChart: React.FC<Props> = ({
region: options.region,
timerange,
});
const isDarkMode = useIsDarkMode();

const metric = {
field: expression.metric,
Expand Down Expand Up @@ -192,7 +191,7 @@ export const ExpressionChart: React.FC<Props> = ({
tickFormat={dateFormatter}
/>
<Axis id={'values'} position={Position.Left} tickFormat={yAxisFormater} domain={domain} />
<Settings theme={getChartTheme(isDarkMode)} />
<Settings baseTheme={chartTheme.baseTheme} />
<Tooltip {...tooltipProps} />
</Chart>
</ChartContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import {
} from '@elastic/charts';
import { EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { getChartTheme } from '../../../../utils/get_chart_theme';
import { useIsDarkMode } from '../../../../hooks/use_is_dark_mode';
import { PersistedLogViewReference } from '../../../../../common/log_views';
import { useTimelineChartTheme } from '../../../../utils/use_timeline_chart_theme';
import { ExecutionTimeRange } from '../../../../types';
import {
ChartContainer,
Expand Down Expand Up @@ -143,7 +142,7 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
annotations,
filterSeriesByGroupName,
}) => {
const isDarkMode = useIsDarkMode();
const chartTheme = useTimelineChartTheme();
const timezone = useKibanaTimeZoneSetting();

const {
Expand Down Expand Up @@ -331,7 +330,7 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
tickFormat={yAxisFormatter}
domain={chartDomain}
/>
<Settings theme={getChartTheme(isDarkMode)} />
<Settings baseTheme={chartTheme.baseTheme} />
<Tooltip {...tooltipProps} />
</Chart>
</ChartContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jest.mock('../../../hooks/use_kibana', () => ({
...mockStartServices,
charts: {
activeCursor: jest.fn(),
theme: {
useChartsBaseTheme: jest.fn(() => ({})),
useChartsTheme: jest.fn(() => ({})),
},
},
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { useActiveCursor } from '@kbn/charts-plugin/public';
import { DataViewBase } from '@kbn/es-query';
import { first, last } from 'lodash';

import { getChartTheme } from '../../../utils/get_chart_theme';
import { useIsDarkMode } from '../../../hooks/use_is_dark_mode';
import { useTimelineChartTheme } from '../../../utils/use_timeline_chart_theme';
import { MetricsSourceConfiguration } from '../../../../common/metrics_sources';
import { Color } from '../../../../common/color_palette';
import { MetricsExplorerRow, MetricsExplorerAggregation } from '../../../../common/http_api';
Expand Down Expand Up @@ -72,7 +71,7 @@ export const ExpressionChart: React.FC<Props> = ({
timeRange,
}) => {
const { charts } = useKibanaContextForPlugin().services;
const isDarkMode = useIsDarkMode();
const chartTheme = useTimelineChartTheme();

const { isLoading, data } = useMetricsExplorerChartData(
expression,
Expand Down Expand Up @@ -200,7 +199,7 @@ export const ExpressionChart: React.FC<Props> = ({
externalPointerEvents={{
tooltip: { visible: true },
}}
theme={getChartTheme(isDarkMode)}
baseTheme={chartTheme.baseTheme}
/>
</Chart>
</ChartContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import {
MetricsExplorerChartType,
type MetricsExplorerOptionsMetric,
} from '../../../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options';
import { useIsDarkMode } from '../../../../hooks/use_is_dark_mode';
import { MetricExplorerSeriesChart } from '../../../../pages/metrics/metrics_explorer/components/series_chart';
import type { MetricsExplorerSeries } from '../../../../../common/http_api';
import { getTimelineChartThemes } from '../../../../utils/get_chart_theme';
import { useTimelineChartTheme } from '../../../../utils/use_timeline_chart_theme';

import { ChartHeader } from './chart_header';

Expand Down Expand Up @@ -58,7 +57,7 @@ export const ChartSection = ({
domain,
stack = false,
}: Props) => {
const isDarkMode = useIsDarkMode();
const chartTheme = useTimelineChartTheme();
const metrics = series.map((chartSeries) => chartSeries.metric);

return (
Expand Down Expand Up @@ -92,7 +91,11 @@ export const ChartSection = ({
}}
/>
<Tooltip headerFormatter={({ value }) => moment(value).format('Y-MM-DD HH:mm:ss.SSS')} />
<Settings {...getTimelineChartThemes(isDarkMode)} onPointerUpdate={onPointerUpdate} />
<Settings
onPointerUpdate={onPointerUpdate}
baseTheme={chartTheme.baseTheme}
theme={chartTheme.theme}
/>
</Chart>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import {
} from '@elastic/charts';
import moment from 'moment';
import React from 'react';
import { useIsDarkMode } from '../../../../../../../hooks/use_is_dark_mode';
import { useTimelineChartTheme } from '../../../../../../../utils/use_timeline_chart_theme';
import { MetricsExplorerSeries } from '../../../../../../../../common/http_api';
import { getTimelineChartThemes } from '../../../../../../../utils/get_chart_theme';
import { MetricExplorerSeriesChart } from '../../../../../metrics_explorer/components/series_chart';
import {
MetricsExplorerChartType,
Expand Down Expand Up @@ -58,7 +57,7 @@ export const ChartSection = ({
domain,
stack = false,
}: Props) => {
const isDarkMode = useIsDarkMode();
const chartTheme = useTimelineChartTheme();
const metrics = series.map((chartSeries) => chartSeries.metric);
const tooltipProps: TooltipProps = {
headerFormatter: ({ value }) => moment(value).format('Y-MM-DD HH:mm:ss.SSS'),
Expand Down Expand Up @@ -93,7 +92,11 @@ export const ChartSection = ({
gridLine={{ visible: true }}
/>
<Tooltip {...tooltipProps} />
<Settings onPointerUpdate={onPointerUpdate} {...getTimelineChartThemes(isDarkMode)} />
<Settings
onPointerUpdate={onPointerUpdate}
baseTheme={chartTheme.baseTheme}
theme={chartTheme.theme}
/>
</Chart>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { first, last } from 'lodash';
import moment from 'moment';
import React, { useMemo } from 'react';
import { useIsDarkMode } from '../../../../../../../hooks/use_is_dark_mode';
import { useTimelineChartTheme } from '../../../../../../../utils/use_timeline_chart_theme';
import { Color } from '../../../../../../../../common/color_palette';
import { createFormatter } from '../../../../../../../../common/formatters';
import { MetricsExplorerAggregation } from '../../../../../../../../common/http_api';
import { getChartTheme } from '../../../../../../../utils/get_chart_theme';
import { calculateDomain } from '../../../../../metrics_explorer/components/helpers/calculate_domain';
import { MetricExplorerSeriesChart } from '../../../../../metrics_explorer/components/series_chart';
import { MetricsExplorerChartType } from '../../../../../metrics_explorer/hooks/use_metrics_explorer_options';
Expand Down Expand Up @@ -74,12 +73,12 @@ interface ProcessChartProps {
label: string;
}
const ProcessChart = ({ timeseries, color, label }: ProcessChartProps) => {
const chartTheme = useTimelineChartTheme();
const chartMetric = {
color,
aggregation: 'avg' as MetricsExplorerAggregation,
label,
};
const isDarkMode = useIsDarkMode();

const dateFormatter = useMemo(() => {
if (!timeseries) return () => '';
Expand Down Expand Up @@ -128,7 +127,7 @@ const ProcessChart = ({ timeseries, color, label }: ProcessChartProps) => {
gridLine={{ visible: true }}
/>
<Tooltip headerFormatter={({ value }) => moment(value).format('Y-MM-DD HH:mm:ss.SSS')} />
<Settings theme={getChartTheme(isDarkMode)} />
<Settings baseTheme={chartTheme.baseTheme} theme={chartTheme.theme} />
</Chart>
</ChartContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { EuiFlexItem } from '@elastic/eui';
import { EuiFlexGroup } from '@elastic/eui';
import { EuiIcon } from '@elastic/eui';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { useTimelineChartTheme } from '../../../../../utils/use_timeline_chart_theme';
import { toMetricOpt } from '../../../../../../common/snapshot_metric_i18n';
import { MetricsExplorerAggregation } from '../../../../../../common/http_api';
import { colorTransformer, Color } from '../../../../../../common/color_palette';
Expand All @@ -38,12 +39,10 @@ import { useWaffleTimeContext } from '../../hooks/use_waffle_time';
import { useWaffleFiltersContext } from '../../hooks/use_waffle_filters';
import { MetricExplorerSeriesChart } from '../../../metrics_explorer/components/series_chart';
import { MetricsExplorerChartType } from '../../../metrics_explorer/hooks/use_metrics_explorer_options';
import { getTimelineChartThemes } from '../../../../../utils/get_chart_theme';
import { calculateDomain } from '../../../metrics_explorer/components/helpers/calculate_domain';
import { InfraFormatter } from '../../../../../lib/lib';
import { useMetricsHostsAnomaliesResults } from '../../hooks/use_metrics_hosts_anomalies';
import { useMetricsK8sAnomaliesResults } from '../../hooks/use_metrics_k8s_anomalies';
import { useIsDarkMode } from '../../../../../hooks/use_is_dark_mode';

interface Props {
interval: string;
Expand All @@ -57,6 +56,8 @@ export const Timeline: React.FC<Props> = ({ interval, yAxisFormatter, isVisible
const { currentTime, jumpToTime, stopAutoReload } = useWaffleTimeContext();
const { filterQueryAsJson } = useWaffleFiltersContext();

const chartTheme = useTimelineChartTheme();

const { loading, error, startTime, endTime, timeseries, reload } = useTimeline(
filterQueryAsJson,
[metric],
Expand Down Expand Up @@ -123,7 +124,6 @@ export const Timeline: React.FC<Props> = ({ interval, yAxisFormatter, isVisible
return niceTimeFormatter([firstTimestamp, lastTimestamp]);
}, [timeseries]);

const isDarkMode = useIsDarkMode();
const tooltipProps: TooltipProps = {
headerFormatter: ({ value }) => moment(value).format('Y-MM-DD HH:mm:ss.SSS'),
};
Expand Down Expand Up @@ -295,7 +295,11 @@ export const Timeline: React.FC<Props> = ({ interval, yAxisFormatter, isVisible
gridLine={{ visible: true }}
/>
<Tooltip {...tooltipProps} />
<Settings onElementClick={onClickPoint} {...getTimelineChartThemes(isDarkMode)} />
<Settings
onElementClick={onClickPoint}
baseTheme={chartTheme.baseTheme}
theme={chartTheme.theme}
/>
</Chart>
</TimelineChartContainer>
</TimelineContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
Tooltip,
} from '@elastic/charts';
import { EuiPageContentBody_Deprecated as EuiPageContentBody } from '@elastic/eui';
import { useIsDarkMode } from '../../../../hooks/use_is_dark_mode';
import { useTimelineChartTheme } from '../../../../utils/use_timeline_chart_theme';

import { SeriesChart } from './series_chart';
import {
getFormatter,
Expand All @@ -30,7 +31,6 @@ import {
seriesHasLessThen2DataPoints,
} from './helpers';
import { ErrorMessage } from './error_message';
import { getChartTheme } from '../../../../utils/get_chart_theme';
import { useKibanaUiSetting } from '../../../../utils/use_kibana_ui_setting';
import { VisSectionProps } from '../types';

Expand All @@ -46,7 +46,8 @@ export const ChartSectionVis = ({
seriesOverrides,
type,
}: VisSectionProps) => {
const isDarkMode = useIsDarkMode();
const chartTheme = useTimelineChartTheme();

const [dateFormat] = useKibanaUiSetting('dateFormat');
/* eslint-disable-next-line react-hooks/exhaustive-deps */
const valueFormatter = useCallback(getFormatter(formatter, formatterTemplate), [
Expand Down Expand Up @@ -135,7 +136,7 @@ export const ChartSectionVis = ({
<Tooltip {...tooltipProps} />
<Settings
onBrushEnd={handleTimeChange}
theme={getChartTheme(isDarkMode)}
baseTheme={chartTheme.baseTheme}
showLegend
showLegendExtra
legendPosition="right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ import {
} from '@elastic/charts';
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiToolTip } from '@elastic/eui';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { first, last } from 'lodash';
import moment from 'moment';
import React, { useCallback, useMemo } from 'react';
import { useIsDarkMode } from '../../../../hooks/use_is_dark_mode';
import { useTimelineChartTheme } from '../../../../utils/use_timeline_chart_theme';
import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana';
import { MetricsExplorerSeries } from '../../../../../common/http_api/metrics_explorer';
import { MetricsSourceConfigurationProperties } from '../../../../../common/metrics_sources';
import { getChartTheme } from '../../../../utils/get_chart_theme';
import { useKibanaUiSetting } from '../../../../utils/use_kibana_ui_setting';
import {
MetricsExplorerChartOptions,
Expand Down Expand Up @@ -65,8 +64,13 @@ export const MetricsExplorerChart = ({
timeRange,
onTimeChange,
}: Props) => {
const uiCapabilities = useKibana().services.application?.capabilities;
const isDarkMode = useIsDarkMode();
const {
services: {
application: { capabilities: uiCapabilities },
},
} = useKibanaContextForPlugin();

const chartTheme = useTimelineChartTheme();
const { metrics } = options;
const [dateFormat] = useKibanaUiSetting('dateFormat');
const handleTimeChange: BrushEndListener = ({ x }) => {
Expand Down Expand Up @@ -160,7 +164,7 @@ export const MetricsExplorerChart = ({
domain={domain}
/>
<Tooltip {...tooltipProps} />
<Settings onBrushEnd={handleTimeChange} theme={getChartTheme(isDarkMode)} />
<Settings onBrushEnd={handleTimeChange} baseTheme={chartTheme.baseTheme} />
</Chart>
) : options.metrics.length > 0 ? (
<MetricsExplorerEmptyChart />
Expand Down
40 changes: 0 additions & 40 deletions x-pack/plugins/infra/public/utils/get_chart_theme.ts

This file was deleted.

Loading

0 comments on commit 2af0d49

Please sign in to comment.