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

fix(heatmap): render empty state #1532

Merged
merged 2 commits into from
Dec 24, 2021
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
5 changes: 3 additions & 2 deletions packages/charts/src/chart_types/heatmap/state/chart_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getTooltipAnchorSelector } from './selectors/get_tooltip_anchor';
import { getSpecOrNull } from './selectors/heatmap_spec';
import { isBrushAvailableSelector } from './selectors/is_brush_available';
import { isBrushingSelector } from './selectors/is_brushing';
import { isEmptySelector } from './selectors/is_empty';
import { isTooltipVisibleSelector } from './selectors/is_tooltip_visible';
import { createOnBrushEndCaller } from './selectors/on_brush_end_caller';
import { createOnElementClickCaller } from './selectors/on_element_click_caller';
Expand Down Expand Up @@ -60,8 +61,8 @@ export class HeatmapState implements InternalChartState {
return isBrushingSelector(globalState);
}

isChartEmpty() {
return false;
isChartEmpty(globalState: GlobalChartState) {
return isEmptySelector(globalState);
}

getLegendItems(globalState: GlobalChartState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getDeselectedSeriesSelector } from '../../../../state/selectors/get_deselected_data_series';
import { getColorScale } from './get_color_scale';
import { getSpecOrNull } from './heatmap_spec';
import { isEmptySelector } from './is_empty';

const EMPTY_LEGEND: LegendItem[] = [];
/** @internal */
export const computeLegendSelector = createCustomCachedSelector(
[getSpecOrNull, getColorScale, getDeselectedSeriesSelector],
(spec, { bands }, deselectedDataSeries): LegendItem[] => {
if (spec === null) {
[getSpecOrNull, getColorScale, getDeselectedSeriesSelector, isEmptySelector],
(spec, { bands }, deselectedDataSeries, empty): LegendItem[] => {
if (spec === null || empty) {
return EMPTY_LEGEND;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { computeChartElementSizesSelector } from './compute_chart_dimensions';
import { getColorScale } from './get_color_scale';
import { getHeatmapSpecSelector } from './get_heatmap_spec';
import { getHeatmapTableSelector } from './get_heatmap_table';
import { isEmptySelector } from './is_empty';

const getDeselectedSeriesSelector = (state: GlobalChartState) => state.interactions.deselectedDataSeries;

Expand All @@ -27,8 +28,9 @@ export const getHeatmapGeometries = createCustomCachedSelector(
getColorScale,
getDeselectedSeriesSelector,
getChartThemeSelector,
isEmptySelector,
],
(heatmapSpec, dims, heatmapTable, { bands, scale: colorScale }, deselectedSeries, theme): ShapeViewModel => {
(heatmapSpec, dims, heatmapTable, { bands, scale: colorScale }, deselectedSeries, theme, empty): ShapeViewModel => {
// instead of using the specId, each legend item is associated with an unique band label
const disabledBandLabels = new Set(
deselectedSeries.map(({ specId }) => {
Expand All @@ -42,6 +44,8 @@ export const getHeatmapGeometries = createCustomCachedSelector(
})
.map(({ start, end }) => [start, end]);

return heatmapSpec ? render(heatmapSpec, dims, heatmapTable, colorScale, bandsToHide, theme) : nullShapeViewModel();
return heatmapSpec && !empty
? render(heatmapSpec, dims, heatmapTable, colorScale, bandsToHide, theme)
: nullShapeViewModel();
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getHeatmapTableSelector } from './get_heatmap_table';

/** @internal */
export const isEmptySelector = createCustomCachedSelector([getHeatmapTableSelector], (heatmap): boolean => {
return heatmap.table.length === 0;
});