Skip to content

Commit

Permalink
[data usage] add line series for totals (elastic#201038)
Browse files Browse the repository at this point in the history
## Summary

add line series for totals

<img width="2294" alt="Screenshot 2024-11-20 at 3 04 11 PM"
src="https://github.com/user-attachments/assets/275214b9-a1c5-45a9-ae1e-d42c4ef31cb9">


### 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)
- [ ] ...
  • Loading branch information
neptunian authored and TattdCodeMonkey committed Nov 21, 2024
1 parent a63c6ba commit 4c36fb5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions x-pack/plugins/data_usage/public/app/components/chart_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
niceTimeFormatter,
DARK_THEME,
LIGHT_THEME,
LineSeries,
} from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import { LegendAction } from './legend_action';
Expand Down Expand Up @@ -59,6 +60,18 @@ export const ChartPanel: React.FC<ChartPanelProps> = ({
[minTimestamp, maxTimestamp]
);

// Calculate the total for each time bucket
const totalSeries = useMemo(() => {
const totalsMap = new Map<number, number>();

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 (
Expand Down Expand Up @@ -87,6 +100,19 @@ export const ChartPanel: React.FC<ChartPanelProps> = ({
xDomain={{ min: minTimestamp, max: maxTimestamp }}
legendAction={renderLegendAction}
/>
<LineSeries
id="Total"
name="Total"
data={totalSeries}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor="x"
yAccessors={['y']}
lineSeriesStyle={{
line: { strokeWidth: 2 },
point: { visible: 'always', radius: 5 },
}}
/>
{series.map((stream, streamIdx) => (
<BarSeries
key={streamIdx}
Expand Down

0 comments on commit 4c36fb5

Please sign in to comment.