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

[Lens] fix empty state for pie #66206

Merged
merged 3 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -7,6 +7,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { i18n } from '@kbn/i18n';
import { I18nProvider } from '@kbn/i18n/react';
import { PartialTheme } from '@elastic/charts';
import {
IInterpreterRenderHandlers,
Expand Down Expand Up @@ -111,13 +112,15 @@ export const getPieRenderer = (dependencies: {
const executeTriggerActions = getExecuteTriggerActions();
const formatFactory = await dependencies.formatFactory;
ReactDOM.render(
<MemoizedChart
{...config}
{...dependencies}
formatFactory={formatFactory}
executeTriggerActions={executeTriggerActions}
isDarkMode={dependencies.isDarkMode}
/>,
<I18nProvider>
<MemoizedChart
{...config}
{...dependencies}
formatFactory={formatFactory}
executeTriggerActions={executeTriggerActions}
isDarkMode={dependencies.isDarkMode}
/>
</I18nProvider>,
domNode,
() => {
handlers.done();
Expand Down
35 changes: 19 additions & 16 deletions x-pack/plugins/lens/public/pie_visualization/render_function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { CHART_NAMES, DEFAULT_PERCENT_DECIMALS } from './constants';
import { ColumnGroups, PieExpressionProps } from './types';
import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
import { getSliceValueWithFallback, getFilterContext } from './render_helpers';
import { EmptyPlaceholder } from '../shared_components';
import './visualization.scss';

const EMPTY_SLICE = Symbol('empty_slice');
Expand Down Expand Up @@ -201,27 +202,29 @@ export function PieComponent(
const value = row[metricColumn.id];
return typeof value === 'number' && value < 0;
});
if (firstTable.rows.length === 0 || hasNegative) {
const isEmpty =
firstTable.rows.length === 0 ||
firstTable.rows.every(row =>
groups.every(colId => !row[colId] || typeof row[colId] === 'undefined')
);

if (isEmpty) {
return <EmptyPlaceholder icon="visPie" />;
}

if (hasNegative) {
return (
<EuiText className="lnsChart__empty" textAlign="center" color="subdued" size="xs">
{hasNegative ? (
<FormattedMessage
id="xpack.lens.pie.pieWithNegativeWarningLabel"
defaultMessage="{chartType} charts can't render with negative values. Try a different chart type."
values={{
chartType: CHART_NAMES[shape].label,
}}
/>
) : (
<FormattedMessage
id="xpack.lens.xyVisualization.noDataLabel"
defaultMessage="No results found"
/>
)}
<FormattedMessage
id="xpack.lens.pie.pieWithNegativeWarningLabel"
defaultMessage="{chartType} charts can't render with negative values. Try a different chart type."
values={{
chartType: CHART_NAMES[shape].label,
}}
/>
</EuiText>
);
}

return (
<VisualizationContainer className="lnsPieExpression__container" isReady={state.isReady}>
<Chart>
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/lens/public/shared_components/empty_placeholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiIcon, EuiText, IconType, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

export const EmptyPlaceholder = (props: { icon: IconType }) => (
<>
<EuiText className="lnsChart__empty" textAlign="center" color="subdued" size="xs">
<EuiIcon type={props.icon} color="subdued" size="l" />
<EuiSpacer size="s" />
<p>
<FormattedMessage
id="xpack.lens.xyVisualization.noDataLabel"
defaultMessage="No results found"
/>
</p>
</EuiText>
</>
);
7 changes: 7 additions & 0 deletions x-pack/plugins/lens/public/shared_components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from './empty_placeholder';
17 changes: 3 additions & 14 deletions x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
ExpressionFunctionDefinition,
ExpressionValueSearchContext,
} from 'src/plugins/expressions/public';
import { EuiIcon, EuiText, IconType, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { IconType } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import {
ValueClickTriggerContext,
Expand All @@ -41,6 +40,7 @@ import { isHorizontalChart } from './state_helpers';
import { getExecuteTriggerActions } from '../services';
import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
import { parseInterval } from '../../../../../src/plugins/data/common';
import { EmptyPlaceholder } from '../shared_components';

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

if (filteredLayers.length === 0) {
const icon: IconType = layers.length > 0 ? getIconForSeriesType(layers[0].seriesType) : 'bar';
return (
<EuiText className="lnsChart__empty" textAlign="center" color="subdued" size="xs">
<EuiIcon type={icon} color="subdued" size="l" />
<EuiSpacer size="s" />
<p>
<FormattedMessage
id="xpack.lens.xyVisualization.noDataLabel"
defaultMessage="No results found"
/>
</p>
</EuiText>
);
return <EmptyPlaceholder icon={icon} />;
}

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