Skip to content

Commit

Permalink
fixing goal max and goal value configuration (elastic#179133)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Mar 25, 2024
1 parent a49b7c1 commit e551625
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
: []),
];
}
Expand Down

0 comments on commit e551625

Please sign in to comment.