import { PaletteOutput } from 'src/plugins/charts/common' ; import { EsaggsExpressionFunctionDefinition , IndexPatternLoadExpressionFunctionDefinition , } from '../../../data/public' ; import { buildExpression , buildExpressionFunction } from '../../../expressions/public' ; import { getVisSchemas , SchemaConfig , VisToExpressionAst } from '../../../visualizations/public' ; import { TagCloudVisParams } from './types' ; const prepareDimension = ( params ) => { const visdimension = buildExpressionFunction ( 'visdimension' , { accessor : params . accessor } ) ; if ( params . format ) { visdimension . addArgument ( 'format' , params . format . id ) ; visdimension . addArgument ( 'formatParams' , JSON . stringify ( params . format . params ) ) ; } return buildExpression ( [ visdimension ] ) ; } ; const preparePalette = ( palette ? ) => { const paletteExpressionFunction = buildExpressionFunction ( 'system_palette' , { name : palette ?. name , } ) ; return buildExpression ( [ paletteExpressionFunction ] ) ; } ; export const toExpressionAst = ( vis , params ) => { const esaggs = buildExpressionFunction < EsaggsExpressionFunctionDefinition > ( 'esaggs' , { index : buildExpression ( [ buildExpressionFunction < IndexPatternLoadExpressionFunctionDefinition > ( 'indexPatternLoad' , { id : vis . data . indexPattern ! . id ! , } ) , ] ) , metricsAtAllLevels : vis . isHierarchical ( ) , partialRows : false , aggs : vis . data . aggs ! . aggs . map ( ( agg ) => buildExpression ( agg . toExpressionAst ( ) ) ) , } ) ; const schemas = getVisSchemas ( vis , params ) ; const { scale , orientation , minFontSize , maxFontSize , showLabel , palette } = vis . params ; const tagcloud = buildExpressionFunction ( 'tagcloud' , { scale , orientation , minFontSize , maxFontSize , showLabel , metric : prepareDimension ( schemas . metric [ 0 ] ) , palette : preparePalette ( palette ) , } ) ; if ( schemas . segment ) { tagcloud . addArgument ( 'bucket' , prepareDimension ( schemas . segment [ 0 ] ) ) ; } const ast = buildExpression ( [ esaggs , tagcloud ] ) ; return ast . toAst ( ) ; } ;