Skip to content

Commit 3709de6

Browse files
authored
[Lens] Legend config (#70619)
1 parent 78ea171 commit 3709de6

File tree

19 files changed

+498
-244
lines changed

19 files changed

+498
-244
lines changed

x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel_wrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function WorkspacePanelWrapper({
6363
clearStagedPreview: false,
6464
});
6565
},
66-
[dispatch]
66+
[dispatch, activeVisualization]
6767
);
6868
return (
6969
<>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { toExpression, toPreviewExpression } from './to_expression';
1313
import { LayerState, PieVisualizationState } from './types';
1414
import { suggestions } from './suggestions';
1515
import { CHART_NAMES, MAX_PIE_BUCKETS, MAX_TREEMAP_BUCKETS } from './constants';
16-
import { SettingsWidget } from './settings_widget';
16+
import { PieToolbar } from './toolbar';
1717

1818
function newLayerState(layerId: string): LayerState {
1919
return {
@@ -204,10 +204,10 @@ export const pieVisualization: Visualization<PieVisualizationState, PieVisualiza
204204
toExpression,
205205
toPreviewExpression,
206206

207-
renderLayerContextMenu(domElement, props) {
207+
renderToolbar(domElement, props) {
208208
render(
209209
<I18nProvider>
210-
<SettingsWidget {...props} />
210+
<PieToolbar {...props} />
211211
</I18nProvider>,
212212
domElement
213213
);

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

Lines changed: 6 additions & 0 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 { Position } from '@elastic/charts';
1011
import { I18nProvider } from '@kbn/i18n/react';
1112
import {
1213
IInterpreterRenderHandlers,
@@ -73,6 +74,11 @@ export const pie: ExpressionFunctionDefinition<
7374
types: ['boolean'],
7475
help: '',
7576
},
77+
legendPosition: {
78+
types: ['string'],
79+
options: [Position.Top, Position.Right, Position.Bottom, Position.Left],
80+
help: '',
81+
},
7682
percentDecimals: {
7783
types: ['number'],
7884
help: '',

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ describe('PieVisualization component', () => {
6565
};
6666
}
6767

68+
test('it shows legend on correct side', () => {
69+
const component = shallow(
70+
<PieComponent args={{ ...args, legendPosition: 'top' }} {...getDefaultArgs()} />
71+
);
72+
expect(component.find(Settings).prop('legendPosition')).toEqual('top');
73+
});
74+
6875
test('it shows legend for 2 groups using default legendDisplay', () => {
6976
const component = shallow(<PieComponent args={args} {...getDefaultArgs()} />);
7077
expect(component.find(Settings).prop('showLegend')).toEqual(true);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
PartitionFillLabel,
2323
RecursivePartial,
2424
LayerValue,
25+
Position,
2526
} from '@elastic/charts';
2627
import { FormatFactory, LensFilterEvent } from '../types';
2728
import { VisualizationContainer } from '../visualization_container';
@@ -55,6 +56,7 @@ export function PieComponent(
5556
numberDisplay,
5657
categoryDisplay,
5758
legendDisplay,
59+
legendPosition,
5860
nestedLegend,
5961
percentDecimals,
6062
hideLabels,
@@ -237,6 +239,7 @@ export function PieComponent(
237239
(legendDisplay === 'show' ||
238240
(legendDisplay === 'default' && columnGroups.length > 1 && shape !== 'treemap'))
239241
}
242+
legendPosition={legendPosition || Position.Right}
240243
legendMaxDepth={nestedLegend ? undefined : 1 /* Color is based only on first layer */}
241244
onElementClick={(args) => {
242245
const context = getFilterContext(

x-pack/plugins/lens/public/pie_visualization/settings_widget.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 230 deletions
This file was deleted.

x-pack/plugins/lens/public/pie_visualization/to_expression.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function expressionHelper(
4141
numberDisplay: [layer.numberDisplay],
4242
categoryDisplay: [layer.categoryDisplay],
4343
legendDisplay: [layer.legendDisplay],
44+
legendPosition: [layer.legendPosition || 'right'],
4445
percentDecimals: [layer.percentDecimals ?? DEFAULT_PERCENT_DECIMALS],
4546
nestedLegend: [!!layer.nestedLegend],
4647
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.lnsPieToolbar__popover {
2+
width: $euiFormMaxWidth;
3+
}

0 commit comments

Comments
 (0)