e5d7bb6e9a
* [Lens] Add pie and treemap visualizations * Fix types * Update to new platform * Support 2-layer treemap and legends, dark mode * Significant restructuring of code * Upgrade to latest charts library * Commit yarn.lock * chore: update elastic-charts * fix types after merge master * Add settings panel and merge visualizations * Fix tests * build: upgrade @elastic/charts to 19.0.0 * refactor: onBrushEnd breaking changes * fix: missing onBrushEnd argument changes * More updates * Fix XY rendering issue when all dates are empty * Fix bugs and tests * Use shared services location * Fix bug in XY chart * fix: update ech to 19.1.1 * fix: lens onBrushEnd breaking changes * Change how pie/treemap settings work * [Design] Fix up settings panel * [Design] Update partition chart config styles * fix eslint * Fix legend issues in pie and XY, add some tests * update to 19.1.2 * Fix text color for treemap * Fix chart switch bug * Fix suggestions Co-authored-by: Marta Bondyra <marta.bondyra@elastic.co> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com> Co-authored-by: cchaos <caroline.horn@elastic.co>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/*
|
|
* 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 { Ast } from '@kbn/interpreter/common';
|
|
import { FramePublicAPI, Operation } from '../types';
|
|
import { DEFAULT_PERCENT_DECIMALS } from './constants';
|
|
import { PieVisualizationState } from './types';
|
|
|
|
export function toExpression(state: PieVisualizationState, frame: FramePublicAPI) {
|
|
return expressionHelper(state, frame, false);
|
|
}
|
|
|
|
function expressionHelper(
|
|
state: PieVisualizationState,
|
|
frame: FramePublicAPI,
|
|
isPreview: boolean
|
|
): Ast | null {
|
|
const layer = state.layers[0];
|
|
const datasource = frame.datasourceLayers[layer.layerId];
|
|
const operations = layer.groups
|
|
.map(columnId => ({ columnId, operation: datasource.getOperationForColumnId(columnId) }))
|
|
.filter((o): o is { columnId: string; operation: Operation } => !!o.operation);
|
|
if (!layer.metric || !operations.length) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
type: 'expression',
|
|
chain: [
|
|
{
|
|
type: 'function',
|
|
function: 'lens_pie',
|
|
arguments: {
|
|
shape: [state.shape],
|
|
hideLabels: [isPreview],
|
|
groups: operations.map(o => o.columnId),
|
|
metric: [layer.metric],
|
|
numberDisplay: [layer.numberDisplay],
|
|
categoryDisplay: [layer.categoryDisplay],
|
|
legendDisplay: [layer.legendDisplay],
|
|
percentDecimals: [layer.percentDecimals ?? DEFAULT_PERCENT_DECIMALS],
|
|
nestedLegend: [!!layer.nestedLegend],
|
|
},
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
export function toPreviewExpression(state: PieVisualizationState, frame: FramePublicAPI) {
|
|
return expressionHelper(state, frame, true);
|
|
}
|