Skip to content

Commit

Permalink
[ML] Fix Data Visualizer event rate chart empty for some indices when…
Browse files Browse the repository at this point in the history
… using long time range (#97655)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
qn895 and kibanamachine authored Apr 22, 2021
1 parent 158fff3 commit fecdd45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const DocumentCountContent: FC<Props> = ({ config, totalCount }) => {
chartPoints={chartPoints}
timeRangeEarliest={timeRangeEarliest}
timeRangeLatest={timeRangeLatest}
interval={documentCounts.interval}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { FC } from 'react';
import React, { FC, useMemo } from 'react';

import { i18n } from '@kbn/i18n';

Expand All @@ -29,6 +29,7 @@ interface Props {
chartPoints: DocumentCountChartPoint[];
timeRangeEarliest: number;
timeRangeLatest: number;
interval?: number;
}

const SPEC_ID = 'document_count';
Expand All @@ -38,6 +39,7 @@ export const DocumentCountChart: FC<Props> = ({
chartPoints,
timeRangeEarliest,
timeRangeLatest,
interval,
}) => {
const seriesName = i18n.translate('xpack.ml.fieldDataCard.documentCountChart.seriesLabel', {
defaultMessage: 'document count',
Expand All @@ -50,6 +52,21 @@ export const DocumentCountChart: FC<Props> = ({

const dateFormatter = niceTimeFormatter([timeRangeEarliest, timeRangeLatest]);

const adjustedChartPoints = useMemo(() => {
// Display empty chart when no data in range
if (chartPoints.length < 1) return [{ time: timeRangeEarliest, value: 0 }];

// If chart has only one bucket
// it won't show up correctly unless we add an extra data point
if (chartPoints.length === 1) {
return [
...chartPoints,
{ time: interval ? Number(chartPoints[0].time) + interval : timeRangeEarliest, value: 0 },
];
}
return chartPoints;
}, [chartPoints, timeRangeEarliest, timeRangeLatest, interval]);

return (
<div style={{ width: width ?? '100%' }} data-test-subj="mlFieldDataDocumentCountChart">
<Chart
Expand All @@ -73,8 +90,7 @@ export const DocumentCountChart: FC<Props> = ({
yScaleType={ScaleType.Linear}
xAccessor="time"
yAccessors={['value']}
// Display empty chart when no data in range
data={chartPoints.length > 0 ? chartPoints : [{ time: timeRangeEarliest, value: 0 }]}
data={adjustedChartPoints}
/>
</Chart>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface FieldVisStats {
latest?: number;
documentCounts?: {
buckets?: DocumentCountBuckets;
interval?: number;
};
avg?: number;
distribution?: {
Expand Down

0 comments on commit fecdd45

Please sign in to comment.