Skip to content

Commit db3563f

Browse files
committed
[Lens] fix empty state for pie
1 parent 15c0644 commit db3563f

File tree

5 files changed

+63
-37
lines changed

5 files changed

+63
-37
lines changed

x-pack/plugins/lens/public/pie_visualization/register_expression.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import React from 'react';
88
import ReactDOM from 'react-dom';
99
import { i18n } from '@kbn/i18n';
10+
import { I18nProvider } from '@kbn/i18n/react';
1011
import { PartialTheme } from '@elastic/charts';
1112
import {
1213
IInterpreterRenderHandlers,
@@ -111,13 +112,15 @@ export const getPieRenderer = (dependencies: {
111112
const executeTriggerActions = getExecuteTriggerActions();
112113
const formatFactory = await dependencies.formatFactory;
113114
ReactDOM.render(
114-
<MemoizedChart
115-
{...config}
116-
{...dependencies}
117-
formatFactory={formatFactory}
118-
executeTriggerActions={executeTriggerActions}
119-
isDarkMode={dependencies.isDarkMode}
120-
/>,
115+
<I18nProvider>
116+
<MemoizedChart
117+
{...config}
118+
{...dependencies}
119+
formatFactory={formatFactory}
120+
executeTriggerActions={executeTriggerActions}
121+
isDarkMode={dependencies.isDarkMode}
122+
/>
123+
</I18nProvider>,
121124
domNode,
122125
() => {
123126
handlers.done();

x-pack/plugins/lens/public/pie_visualization/render_function.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { CHART_NAMES, DEFAULT_PERCENT_DECIMALS } from './constants';
3131
import { ColumnGroups, PieExpressionProps } from './types';
3232
import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
3333
import { getSliceValueWithFallback, getFilterContext } from './render_helpers';
34+
import { EmptyPlaceholder } from '../shared_components';
3435
import './visualization.scss';
3536

3637
const EMPTY_SLICE = Symbol('empty_slice');
@@ -201,27 +202,29 @@ export function PieComponent(
201202
const value = row[metricColumn.id];
202203
return typeof value === 'number' && value < 0;
203204
});
204-
if (firstTable.rows.length === 0 || hasNegative) {
205+
const isEmpty =
206+
firstTable.rows.length === 0 ||
207+
firstTable.rows.every(row =>
208+
groups.every(colId => !row[colId] || typeof row[colId] === 'undefined')
209+
);
210+
211+
if (isEmpty) {
212+
return <EmptyPlaceholder icon="visPie" />;
213+
}
214+
215+
if (hasNegative) {
205216
return (
206217
<EuiText className="lnsChart__empty" textAlign="center" color="subdued" size="xs">
207-
{hasNegative ? (
208-
<FormattedMessage
209-
id="xpack.lens.pie.pieWithNegativeWarningLabel"
210-
defaultMessage="{chartType} charts can't render with negative values. Try a different chart type."
211-
values={{
212-
chartType: CHART_NAMES[shape].label,
213-
}}
214-
/>
215-
) : (
216-
<FormattedMessage
217-
id="xpack.lens.xyVisualization.noDataLabel"
218-
defaultMessage="No results found"
219-
/>
220-
)}
218+
<FormattedMessage
219+
id="xpack.lens.pie.pieWithNegativeWarningLabel"
220+
defaultMessage="{chartType} charts can't render with negative values. Try a different chart type."
221+
values={{
222+
chartType: CHART_NAMES[shape].label,
223+
}}
224+
/>
221225
</EuiText>
222226
);
223227
}
224-
225228
return (
226229
<VisualizationContainer className="lnsPieExpression__container" isReady={state.isReady}>
227230
<Chart>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { EuiIcon, EuiText, IconType, EuiSpacer } from '@elastic/eui';
9+
import { FormattedMessage } from '@kbn/i18n/react';
10+
11+
export const EmptyPlaceholder = (props: { icon: IconType }) => (
12+
<>
13+
<EuiText className="lnsChart__empty" textAlign="center" color="subdued" size="xs">
14+
<EuiIcon type={props.icon} color="subdued" size="l" />
15+
<EuiSpacer size="s" />
16+
<p>
17+
<FormattedMessage
18+
id="xpack.lens.xyVisualization.noDataLabel"
19+
defaultMessage="No results found"
20+
/>
21+
</p>
22+
</EuiText>
23+
</>
24+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export * from './empty_placeholder';

x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import {
2626
ExpressionFunctionDefinition,
2727
ExpressionValueSearchContext,
2828
} from 'src/plugins/expressions/public';
29-
import { EuiIcon, EuiText, IconType, EuiSpacer } from '@elastic/eui';
30-
import { FormattedMessage } from '@kbn/i18n/react';
29+
import { IconType } from '@elastic/eui';
3130
import { i18n } from '@kbn/i18n';
3231
import {
3332
ValueClickTriggerContext,
@@ -41,6 +40,7 @@ import { isHorizontalChart } from './state_helpers';
4140
import { getExecuteTriggerActions } from '../services';
4241
import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
4342
import { parseInterval } from '../../../../../src/plugins/data/common';
43+
import { EmptyPlaceholder } from '../shared_components';
4444

4545
type InferPropType<T> = T extends React.FunctionComponent<infer P> ? P : T;
4646
type SeriesSpec = InferPropType<typeof LineSeries> &
@@ -193,18 +193,7 @@ export function XYChart({
193193

194194
if (filteredLayers.length === 0) {
195195
const icon: IconType = layers.length > 0 ? getIconForSeriesType(layers[0].seriesType) : 'bar';
196-
return (
197-
<EuiText className="lnsChart__empty" textAlign="center" color="subdued" size="xs">
198-
<EuiIcon type={icon} color="subdued" size="l" />
199-
<EuiSpacer size="s" />
200-
<p>
201-
<FormattedMessage
202-
id="xpack.lens.xyVisualization.noDataLabel"
203-
defaultMessage="No results found"
204-
/>
205-
</p>
206-
</EuiText>
207-
);
196+
return <EmptyPlaceholder icon={icon} />;
208197
}
209198

210199
// use formatting hint of first x axis column to format ticks

0 commit comments

Comments
 (0)