Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Explain Log Rate Spikes: fix chart showing as empty when filter matches field/value pair in hovered row #142693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,17 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = ({
// TODO Let user choose between ZOOM and BRUSH mode.
const [viewMode] = useState<VIEW_MODE>(VIEW_MODE.BRUSH);

const hasNoData = useMemo(
() =>
(chartPoints === undefined || chartPoints.length < 1) &&
(chartPointsSplit === undefined ||
(Array.isArray(chartPointsSplit) && chartPointsSplit.length < 1)),
[chartPoints, chartPointsSplit]
);

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

// If chart has only one bucket
// it won't show up correctly unless we add an extra data point
Expand All @@ -145,12 +153,11 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = ({

const adjustedChartPointsSplit = useMemo(() => {
// Display empty chart when no data in range
if (!Array.isArray(chartPointsSplit) || chartPointsSplit.length < 1)
return [{ time: timeRangeEarliest, value: 0 }];
if (hasNoData) 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 (chartPointsSplit.length === 1) {
if (Array.isArray(chartPointsSplit) && chartPointsSplit.length === 1) {
return [
...chartPointsSplit,
{
Expand Down Expand Up @@ -349,18 +356,20 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = ({
timeAxisLayerCount={useLegacyTimeAxis ? 0 : 2}
style={useLegacyTimeAxis ? {} : MULTILAYER_TIME_AXIS_STYLE}
/>
<HistogramBarSeries
id={SPEC_ID}
name={chartPointsSplit ? overallSeriesNameWithSplit : overallSeriesName}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor="time"
yAccessors={['value']}
data={adjustedChartPoints}
timeZone={timeZone}
yNice
/>
{chartPointsSplit && (
{adjustedChartPoints?.length && (
<HistogramBarSeries
id={SPEC_ID}
name={chartPointsSplit ? overallSeriesNameWithSplit : overallSeriesName}
xScaleType={ScaleType.Time}
yScaleType={ScaleType.Linear}
xAccessor="time"
yAccessors={['value']}
data={adjustedChartPoints}
timeZone={timeZone}
yNice
/>
)}
{adjustedChartPointsSplit?.length && (
<HistogramBarSeries
id={`${SPEC_ID}_split`}
name={chartPointsSplitLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ export const DocumentCountContent: FC<DocumentCountContentProps> = ({
}, [windowParameters]);

const bucketTimestamps = Object.keys(documentCountStats?.buckets ?? {}).map((time) => +time);
const timeRangeEarliest = Math.min(...bucketTimestamps);
const timeRangeLatest = Math.max(...bucketTimestamps);
const splitBucketTimestamps = Object.keys(documentCountStatsSplit?.buckets ?? {}).map(
(time) => +time
);
const timeRangeEarliest = Math.min(...[...bucketTimestamps, ...splitBucketTimestamps]);
const timeRangeLatest = Math.max(...[...bucketTimestamps, ...splitBucketTimestamps]);

if (
documentCountStats === undefined ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ export const ExplainLogRateSpikesPage: FC<ExplainLogRateSpikesPageProps> = ({
brushSelectionUpdateHandler={setWindowParameters}
clearSelectionHandler={clearSelection}
documentCountStats={documentCountStats}
documentCountStatsSplit={
currentSelectedChangePoint || currentSelectedGroup
? documentCountStatsCompare
: undefined
}
documentCountStatsSplit={documentCountStatsCompare}
documentCountStatsSplitLabel={getDocumentCountStatsSplitLabel(
currentSelectedChangePoint,
currentSelectedGroup
Expand Down