diff --git a/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.test.ts b/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.test.ts index aa13813e37b82..322bfa2fb2da1 100644 --- a/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.test.ts +++ b/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.test.ts @@ -122,3 +122,97 @@ test('generates gauge chart config', async () => { } `); }); + +test('generates gauge chart config with goal and max', async () => { + const result = await buildGauge( + { + chartType: 'gauge', + title: 'test', + dataset: { + esql: 'from test | count=count() | eval max=1000 | eval goal=500', + }, + value: 'count', + queryMaxValue: 'max', + queryGoalValue: 'goal', + }, + { + dataViewsAPI: mockDataViewsService() as any, + formulaAPI: {} as any, + } + ); + expect(result).toMatchInlineSnapshot(` + Object { + "references": Array [ + Object { + "id": "test", + "name": "indexpattern-datasource-layer-layer_0", + "type": "index-pattern", + }, + ], + "state": Object { + "adHocDataViews": Object { + "test": Object {}, + }, + "datasourceStates": Object { + "textBased": Object { + "layers": Object { + "layer_0": Object { + "allColumns": Array [ + Object { + "columnId": "metric_formula_accessor", + "fieldName": "count", + }, + Object { + "columnId": "metric_formula_accessor_max", + "fieldName": "max", + }, + Object { + "columnId": "metric_formula_accessor_goal", + "fieldName": "goal", + }, + ], + "columns": Array [ + Object { + "columnId": "metric_formula_accessor", + "fieldName": "count", + }, + Object { + "columnId": "metric_formula_accessor_max", + "fieldName": "max", + }, + Object { + "columnId": "metric_formula_accessor_goal", + "fieldName": "goal", + }, + ], + "index": "test", + "query": Object { + "esql": "from test | count=count() | eval max=1000 | eval goal=500", + }, + }, + }, + }, + }, + "filters": Array [], + "internalReferences": Array [], + "query": Object { + "language": "kuery", + "query": "", + }, + "visualization": Object { + "goalAccessor": "metric_formula_accessor_goal", + "labelMajorMode": "auto", + "layerId": "layer_0", + "layerType": "data", + "maxAccessor": "metric_formula_accessor_max", + "metricAccessor": "metric_formula_accessor", + "shape": "horizontalBullet", + "showBar": true, + "ticksPosition": "auto", + }, + }, + "title": "test", + "visualizationType": "lnsGauge", + } + `); +}); diff --git a/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.ts b/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.ts index ebb6f36861189..29689e52c36fd 100644 --- a/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.ts +++ b/packages/kbn-lens-embeddable-utils/config_builder/charts/gauge.ts @@ -116,11 +116,9 @@ function getValueColumns(layer: LensGaugeConfig) { return [ getValueColumn(ACCESSOR, layer.value), ...(layer.queryMaxValue ? [getValueColumn(getAccessorName('max'), layer.queryMaxValue)] : []), - ...(layer.queryMinValue - ? [getValueColumn(getAccessorName('secondary'), layer.queryMinValue)] - : []), + ...(layer.queryMinValue ? [getValueColumn(getAccessorName('min'), layer.queryMinValue)] : []), ...(layer.queryGoalValue - ? [getValueColumn(getAccessorName('secondary'), layer.queryGoalValue)] + ? [getValueColumn(getAccessorName('goal'), layer.queryGoalValue)] : []), ]; }