Skip to content

Commit

Permalink
fix(heatmap): render empty state (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 authored Dec 24, 2021
1 parent 676a403 commit 59002df
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
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;
});

0 comments on commit 59002df

Please sign in to comment.