[Lens] Enable overrides for Chart component (enables title and description) (#160962)

## Summary

Fixes #160737 

This PR adds support for title and description within the Embeddable
overrides realm.
While there also enables the support for overrides for the new TagCloud
visualization.

The playground example has been extended to test it for any type of
chart:
<img width="572" alt="Screenshot 2023-06-30 at 10 17 04"
src="8b069c2f-dd31-4aaa-9ded-0e33f34b4860">



### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marco Liberati 2023-06-30 13:54:44 +02:00 committed by GitHub
parent 37b909c8c7
commit fd81b12e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 76 additions and 25 deletions

View file

@ -10,7 +10,7 @@ import type { PaletteRegistry } from '@kbn/coloring';
import type { PersistedState } from '@kbn/visualizations-plugin/public';
import type { ChartsPluginSetup } from '@kbn/charts-plugin/public';
import type { IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import type { AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import type { AllowedSettingsOverrides, AllowedChartOverrides } from '@kbn/charts-plugin/common';
import type { AllowedGaugeOverrides, GaugeExpressionProps } from './expression_functions';
export type FormatFactory = (mapping?: SerializedFieldFormat) => IFieldFormat;
@ -21,5 +21,5 @@ export type GaugeRenderProps = GaugeExpressionProps & {
paletteService: PaletteRegistry;
renderComplete: () => void;
uiState: PersistedState;
overrides?: AllowedGaugeOverrides & AllowedSettingsOverrides;
overrides?: AllowedGaugeOverrides & AllowedSettingsOverrides & AllowedChartOverrides;
};

View file

@ -361,7 +361,7 @@ export const GaugeComponent: FC<GaugeRenderProps> = memo(
return (
<div className="gauge__wrapper">
<Chart>
<Chart {...getOverridesFor(overrides, 'chart')}>
<Settings
noResults={<EmptyPlaceholder icon={icon} renderComplete={onRenderChange} />}
debugState={window._echDebugStateFlag ?? false}

View file

@ -14,7 +14,11 @@ import {
} from '@kbn/expressions-plugin/common';
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common';
import { AllowedSettingsOverrides, CustomPaletteState } from '@kbn/charts-plugin/common';
import {
AllowedChartOverrides,
AllowedSettingsOverrides,
CustomPaletteState,
} from '@kbn/charts-plugin/common';
import type { LegendSize } from '@kbn/visualizations-plugin/public';
import {
EXPRESSION_HEATMAP_NAME,
@ -95,7 +99,7 @@ export interface HeatmapExpressionProps {
syncTooltips: boolean;
syncCursor: boolean;
canNavigateToLens?: boolean;
overrides?: AllowedSettingsOverrides;
overrides?: AllowedSettingsOverrides & AllowedChartOverrides;
}
export interface HeatmapRender {

View file

@ -611,7 +611,7 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
legendPosition: args.legend.position,
}}
>
<Chart ref={chartRef}>
<Chart ref={chartRef} {...getOverridesFor(overrides, 'chart')}>
<ChartSplit
splitColumnAccessor={splitChartColumnAccessor}
splitRowAccessor={splitChartRowAccessor}

View file

@ -15,7 +15,11 @@ import {
ExpressionValueRender,
} from '@kbn/expressions-plugin/common';
import { ExpressionValueVisDimension, prepareLogTable } from '@kbn/visualizations-plugin/common';
import type { AllowedSettingsOverrides, CustomPaletteState } from '@kbn/charts-plugin/common';
import type {
AllowedChartOverrides,
AllowedSettingsOverrides,
CustomPaletteState,
} from '@kbn/charts-plugin/common';
import { VisParams, visType } from './expression_renderers';
import {
EXPRESSION_METRIC_NAME,
@ -48,7 +52,7 @@ export interface MetricVisRenderConfig {
visType: typeof visType;
visData: Datatable;
visConfig: Pick<VisParams, 'metric' | 'dimensions'>;
overrides?: AllowedSettingsOverrides;
overrides?: AllowedSettingsOverrides & AllowedChartOverrides;
}
export type MetricVisExpressionFunctionDefinition = ExpressionFunctionDefinition<

View file

@ -38,7 +38,7 @@ import { CUSTOM_PALETTE } from '@kbn/coloring';
import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';
import { useResizeObserver, useEuiScrollBar, EuiIcon } from '@elastic/eui';
import { AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import { AllowedChartOverrides, AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import { getOverridesFor } from '@kbn/chart-expressions-common';
import { DEFAULT_TRENDLINE_NAME } from '../../common/constants';
import { VisParams } from '../../common';
@ -118,7 +118,7 @@ export interface MetricVisComponentProps {
fireEvent: IInterpreterRenderHandlers['event'];
renderMode: RenderMode;
filterable: boolean;
overrides?: AllowedSettingsOverrides;
overrides?: AllowedSettingsOverrides & AllowedChartOverrides;
}
export const MetricVis = ({
@ -301,7 +301,7 @@ export const MetricVis = ({
height: ${scrollChildHeight};
`}
>
<Chart>
<Chart {...getOverridesFor(overrides, 'chart')}>
<Settings
theme={[
{

View file

@ -7,7 +7,7 @@
*/
import { Position } from '@elastic/charts';
import type { AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import type { AllowedChartOverrides, AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import type { PaletteOutput } from '@kbn/coloring';
import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common';
import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
@ -118,7 +118,7 @@ export interface PartitionChartProps {
visConfig: PartitionVisParams;
syncColors: boolean;
canNavigateToLens?: boolean;
overrides?: AllowedPartitionOverrides & AllowedSettingsOverrides;
overrides?: AllowedPartitionOverrides & AllowedSettingsOverrides & AllowedChartOverrides;
}
export enum LabelPositions {

View file

@ -493,7 +493,7 @@ const PartitionVisComponent = (props: PartitionVisComponentProps) => {
legendPosition={legendPosition}
/>
)}
<Chart size="100%">
<Chart size="100%" {...getOverridesFor(overrides, 'chart')}>
<ChartSplit
splitColumnAccessor={splitChartColumnAccessor}
splitRowAccessor={splitChartRowAccessor}

View file

@ -14,6 +14,7 @@ import {
ExpressionValueRender,
} from '@kbn/expressions-plugin/common';
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common';
import type { AllowedSettingsOverrides, AllowedChartOverrides } from '@kbn/charts-plugin/common';
import { EXPRESSION_NAME, ScaleOptions, Orientation } from '../constants';
interface TagCloudCommonParams {
@ -41,6 +42,7 @@ export interface TagcloudRendererConfig {
visData: Datatable;
visParams: TagCloudRendererParams;
syncColors: boolean;
overrides?: AllowedSettingsOverrides & AllowedChartOverrides;
}
export type ExpressionTagcloudFunctionDefinition = ExpressionFunctionDefinition<

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import React from 'react';
import { Wordcloud, Settings, WordcloudSpec } from '@elastic/charts';
import { Wordcloud, Settings, WordcloudSpec, Chart } from '@elastic/charts';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import type { Datatable } from '@kbn/expressions-plugin/public';
import { mount } from 'enzyme';
@ -195,4 +195,15 @@ describe('TagCloudChart', function () {
]);
expect(wrapperPropsWithIndexes.fireEvent).toHaveBeenCalled();
});
test('should apply overrides at the right level', async () => {
const component = mount(
<TagCloudChart
{...wrapperPropsWithIndexes}
overrides={{ settings: { rotation: -90 }, chart: { title: 'Hello' } }}
/>
);
expect(component.find(Chart).props().title).toBe('Hello');
expect(component.find(Settings).props().rotation).toBe(-90);
});
});

View file

@ -15,6 +15,8 @@ import { Chart, Settings, Wordcloud, RenderChangeListener } from '@elastic/chart
import { EmptyPlaceholder } from '@kbn/charts-plugin/public';
import type { PaletteRegistry, PaletteOutput } from '@kbn/coloring';
import { IInterpreterRenderHandlers } from '@kbn/expressions-plugin/public';
import { getOverridesFor } from '@kbn/chart-expressions-common';
import type { AllowedSettingsOverrides, AllowedChartOverrides } from '@kbn/charts-plugin/common';
import { getColumnByAccessor, getFormatByAccessor } from '@kbn/visualizations-plugin/common/utils';
import { getFormatService } from '../format_service';
import { TagcloudRendererConfig } from '../../common/types';
@ -28,6 +30,7 @@ export type TagCloudChartProps = TagcloudRendererConfig & {
fireEvent: IInterpreterRenderHandlers['event'];
renderComplete: IInterpreterRenderHandlers['done'];
palettesRegistry: PaletteRegistry;
overrides?: AllowedSettingsOverrides & AllowedChartOverrides;
};
const calculateWeight = (value: number, x1: number, y1: number, x2: number, y2: number) =>
@ -80,6 +83,7 @@ export const TagCloudChart = ({
fireEvent,
renderComplete,
syncColors,
overrides,
}: TagCloudChartProps) => {
const [warning, setWarning] = useState(false);
const { bucket, metric, scale, palette, showLabel, orientation } = visParams;
@ -203,12 +207,13 @@ export const TagCloudChart = ({
<EuiResizeObserver onResize={updateChart}>
{(resizeRef) => (
<div className="tgcChart__wrapper" ref={resizeRef} data-test-subj="tagCloudVisualization">
<Chart size="100%">
<Chart size="100%" {...getOverridesFor(overrides, 'chart')}>
<Settings
onElementClick={handleWordClick}
onRenderChange={onRenderChange}
ariaLabel={visParams.ariaLabel}
ariaUseDefaultSummary={!visParams.ariaLabel}
{...getOverridesFor(overrides, 'settings')}
/>
<Wordcloud
id="tagCloud"

View file

@ -86,6 +86,7 @@ export const tagcloudRenderer: (
renderComplete={renderComplete}
fireEvent={handlers.event}
syncColors={config.syncColors}
overrides={config.overrides}
/>
</VisualizationContainer>
)}

View file

@ -7,7 +7,7 @@
*/
import { CustomAnnotationTooltip } from '@elastic/charts';
import { AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import type { AllowedChartOverrides, AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
import {
AvailableAnnotationIcon,
ManualPointEventAnnotationArgs,
@ -21,7 +21,7 @@ export interface XYChartProps {
syncCursor: boolean;
syncColors: boolean;
canNavigateToLens?: boolean;
overrides?: AllowedXYOverrides & AllowedSettingsOverrides;
overrides?: AllowedXYOverrides & AllowedSettingsOverrides & AllowedChartOverrides;
}
export interface XYRender {

View file

@ -827,7 +827,7 @@ export function XYChart({
singleTable,
}}
>
<Chart ref={chartRef}>
<Chart ref={chartRef} {...getOverridesFor(overrides, 'chart')}>
<Tooltip<Record<string, string | number>, XYChartSeriesIdentifier>
boundary={document.getElementById('app-fixed-viewport') ?? undefined}
headerFormatter={

View file

@ -18,7 +18,13 @@ export type {
export { palette, systemPalette } from './expressions/palette';
export { paletteIds, defaultCustomColors } from './constants';
export type { AllowedSettingsOverrides, ColorSchema, RawColorSchema, ColorMap } from './static';
export type {
AllowedChartOverrides,
AllowedSettingsOverrides,
ColorSchema,
RawColorSchema,
ColorMap,
} from './static';
export {
ColorSchemas,
vislibColorMaps,

View file

@ -11,4 +11,4 @@ export { ColorSchemas, vislibColorMaps, colorSchemas, getHeatmapColors } from '.
export { ColorMode, LabelRotation, defaultCountLabel } from './components';
export * from './styles';
export type { AllowedSettingsOverrides } from './overrides';
export type { AllowedSettingsOverrides, AllowedChartOverrides } from './overrides';

View file

@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { SettingsProps } from '@elastic/charts';
import type { ChartProps, SettingsProps } from '@elastic/charts';
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
@ -26,6 +26,10 @@ export type MakeOverridesSerializable<T> = {
: NonNullable<T[KeyType]>;
};
export type AllowedChartOverrides = Partial<
Record<'chart', Simplify<MakeOverridesSerializable<Pick<ChartProps, 'title' | 'description'>>>>
>;
export type AllowedSettingsOverrides = Partial<
Record<
'settings',

View file

@ -328,8 +328,11 @@ type SettingsOverride = Record<
};
}
>;
type ChartOverride = Record<'chart', { title: string; description: string }>;
export type AllOverrides = Partial<XYOverride & PieOverride & SettingsOverride & GaugeOverride>;
export type AllOverrides = Partial<
XYOverride & PieOverride & SettingsOverride & GaugeOverride & ChartOverride
>;
export function OverridesMenu({
currentAttributes,
@ -350,7 +353,6 @@ export function OverridesMenu({
onClick={() => setOverridesPopoverOpen(!overridesPopoverOpen)}
iconType="arrowDown"
iconSide="right"
isDisabled={!isSupportedChart(currentAttributes)}
>
Overrides{' '}
<EuiNotificationBadge color={hasOverridesEnabled ? 'accent' : 'subdued'}>
@ -463,6 +465,16 @@ export function OverridesMenu({
controlLabel="Enable border color"
/>
) : null}
<OverrideSwitch
override={{
chart: { title: 'Custom title', description: 'Custom description here' },
}}
value={overrides}
setOverrideValue={setOverrides}
rowLabel="Custom title"
controlLabel="Enable custom title"
helpText={`This override enables custom titles at the visualization level`}
/>
</div>
</EuiPopover>
);

View file

@ -17,7 +17,7 @@ import { CollapseFunction } from './expressions';
export type { OriginalColumn } from './expressions/map_to_columns';
export type { AllowedPartitionOverrides } from '@kbn/expression-partition-vis-plugin/common';
export type { AllowedSettingsOverrides } from '@kbn/charts-plugin/common';
export type { AllowedSettingsOverrides, AllowedChartOverrides } from '@kbn/charts-plugin/common';
export type { AllowedGaugeOverrides } from '@kbn/expression-gauge-plugin/common';
export type { AllowedXYOverrides } from '@kbn/expression-xy-plugin/common';
export type { FormatFactory } from '@kbn/visualization-ui-components/public';

View file

@ -102,6 +102,7 @@ import {
} from '../types';
import type {
AllowedChartOverrides,
AllowedPartitionOverrides,
AllowedSettingsOverrides,
AllowedGaugeOverrides,
@ -176,6 +177,7 @@ export type LensByValueInput = {
* the current behaviour by passing the "ignore" string to the override prop (i.e. onBrushEnd: "ignore" to stop brushing)
*/
overrides?:
| AllowedChartOverrides
| AllowedSettingsOverrides
| AllowedXYOverrides
| AllowedPartitionOverrides