Skip to content

Commit

Permalink
Fix typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Dec 2, 2020
1 parent 8003607 commit dbbebbe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useMemo, useState, useCallback } from 'react';
import React, { useMemo, useState } from 'react';
import { debounce } from 'lodash';
import { i18n } from '@kbn/i18n';
import { EuiSearchBar, EuiSpacer, EuiEmptyPrompt, EuiButton } from '@elastic/eui';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, useMemo } from 'react';
import moment from 'moment';
import { first, last } from 'lodash';
import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiTableRow,
Expand All @@ -22,16 +20,7 @@ import {
EuiButton,
EuiSpacer,
} from '@elastic/eui';
import { Axis, Chart, Settings, Position, TooltipValue, niceTimeFormatter } from '@elastic/charts';
import { AutoSizer } from '../../../../../../../components/auto_sizer';
import { createFormatter } from '../../../../../../../../common/formatters';
import { useUiSetting } from '../../../../../../../../../../../src/plugins/kibana_react/public';
import { getChartTheme } from '../../../../../metrics_explorer/components/helpers/get_chart_theme';
import { calculateDomain } from '../../../../../metrics_explorer/components/helpers/calculate_domain';
import { MetricsExplorerChartType } from '../../../../../metrics_explorer/hooks/use_metrics_explorer_options';
import { MetricExplorerSeriesChart } from '../../../../../metrics_explorer/components/series_chart';
import { MetricsExplorerAggregation } from '../../../../../../../../common/http_api';
import { Color } from '../../../../../../../../common/color_palette';
import { euiStyled } from '../../../../../../../../../observability/public';
import { Process } from './types';
import { ProcessRowCharts } from './process_row_charts';
Expand Down Expand Up @@ -131,76 +120,6 @@ export const ProcessRow = ({ cells, item }: Props) => {
);
};

interface ProcessChartProps {
timeseries: Process['timeseries']['x'];
color: Color;
label: string;
}
const ProcessChart = ({ timeseries, color, label }: ProcessChartProps) => {
const chartMetric = {
color,
aggregation: 'avg' as MetricsExplorerAggregation,
label,
};
const isDarkMode = useUiSetting<boolean>('theme:darkMode');

const dateFormatter = useMemo(() => {
if (!timeseries) return () => '';
const firstTimestamp = first(timeseries.rows)?.timestamp;
const lastTimestamp = last(timeseries.rows)?.timestamp;

if (firstTimestamp == null || lastTimestamp == null) {
return (value: number) => `${value}`;
}

return niceTimeFormatter([firstTimestamp, lastTimestamp]);
}, [timeseries]);

const yAxisFormatter = createFormatter('percent');

const tooltipProps = {
headerFormatter: (tooltipValue: TooltipValue) =>
moment(tooltipValue.value).format('Y-MM-DD HH:mm:ss.SSS'),
};

const dataDomain = calculateDomain(timeseries, [chartMetric], false);
const domain = dataDomain
? {
max: dataDomain.max * 1.1, // add 10% headroom.
min: dataDomain.min,
}
: { max: 0, min: 0 };

return (
<ChartContainer>
<Chart>
<MetricExplorerSeriesChart
type={MetricsExplorerChartType.area}
metric={chartMetric}
id="0"
series={timeseries}
stack={false}
/>
<Axis
id={'timestamp'}
position={Position.Bottom}
showOverlappingTicks={true}
tickFormat={dateFormatter}
/>
<Axis
id={'values'}
position={Position.Left}
tickFormat={yAxisFormatter}
domain={domain}
ticks={6}
showGridLines
/>
<Settings tooltip={tooltipProps} theme={getChartTheme(isDarkMode)} />
</Chart>
</ChartContainer>
);
};

export const CodeLine = euiStyled(EuiCode).attrs({
transparentBackground: true,
})`
Expand Down Expand Up @@ -228,22 +147,3 @@ const ExpandedRowCell = euiStyled(EuiTableRowCell).attrs({
padding: 0 ${(props) => props.theme.eui.paddingSizes.m};
background-color: ${(props) => props.theme.eui.euiColorLightestShade};
`;

const ChartContainer = euiStyled.div`
width: 300px;
height: 140px;
`;

const cpuMetricLabel = i18n.translate(
'xpack.infra.metrics.nodeDetails.processes.expandedRowLabelCPU',
{
defaultMessage: 'CPU',
}
);

const memoryMetricLabel = i18n.translate(
'xpack.infra.metrics.nodeDetails.processes.expandedRowLabelMemory',
{
defaultMessage: 'Memory',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ProcessListAPIChartRequest,
ProcessListAPIChartQueryAggregation,
ProcessListAPIRow,
ProcessListAPIChartResponse,
} from '../../../common/http_api';
import { ESSearchClient } from '../metrics/types';
import { CMDLINE_FIELD } from './common';
Expand Down Expand Up @@ -119,7 +120,7 @@ export const getProcessListChart = async (
)
)
);
return timeseries;
return timeseries as ProcessListAPIChartResponse;
} catch (e) {
throw e;
}
Expand Down

0 comments on commit dbbebbe

Please sign in to comment.