From d39d0d67a516abd5f4be63577f58c833962f27e6 Mon Sep 17 00:00:00 2001 From: Sandra G Date: Wed, 20 Nov 2024 19:03:59 -0500 Subject: [PATCH] [data usage] add line series for totals (#201038) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary add line series for totals Screenshot 2024-11-20 at 3 04 11 PM ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --- .../public/app/components/chart_panel.tsx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx b/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx index 7554716c59492..31ae68244e982 100644 --- a/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx +++ b/x-pack/plugins/data_usage/public/app/components/chart_panel.tsx @@ -16,6 +16,7 @@ import { niceTimeFormatter, DARK_THEME, LIGHT_THEME, + LineSeries, } from '@elastic/charts'; import { i18n } from '@kbn/i18n'; import { LegendAction } from './legend_action'; @@ -59,6 +60,18 @@ export const ChartPanel: React.FC = ({ [minTimestamp, maxTimestamp] ); + // Calculate the total for each time bucket + const totalSeries = useMemo(() => { + const totalsMap = new Map(); + + series.forEach((stream) => { + stream.data.forEach((point) => { + totalsMap.set(point.x, (totalsMap.get(point.x) || 0) + point.y); + }); + }); + + return Array.from(totalsMap.entries()).map(([x, y]) => ({ x, y })); + }, [series]); const renderLegendAction = useCallback( ({ label }: { label: string }) => { return ( @@ -87,6 +100,19 @@ export const ChartPanel: React.FC = ({ xDomain={{ min: minTimestamp, max: maxTimestamp }} legendAction={renderLegendAction} /> + {series.map((stream, streamIdx) => (