mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* [ML] Display metric rather than distribution chart for script field * [ML] Cleaned up code in getChartType
This commit is contained in:
parent
e06b833932
commit
aaca98d218
2 changed files with 47 additions and 4 deletions
|
@ -201,10 +201,36 @@ describe('ML - chart utils', () => {
|
|||
],
|
||||
};
|
||||
|
||||
const overScriptFieldModelPlotConfig = {
|
||||
metricFunction: 'count',
|
||||
functionDescription: 'count',
|
||||
fieldName: 'highest_registered_domain',
|
||||
entityFields: [
|
||||
{
|
||||
fieldName: 'highest_registered_domain',
|
||||
fieldValue: 'elastic.co',
|
||||
fieldType: 'over',
|
||||
}
|
||||
],
|
||||
datafeedConfig: {
|
||||
script_fields: {
|
||||
highest_registered_domain: {
|
||||
script: {
|
||||
source: 'return domainSplit(doc[\'query\'].value, params).get(1);',
|
||||
lang: 'painless'
|
||||
},
|
||||
ignore_failure: false
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
it('returns single metric chart type as expected for configs', () => {
|
||||
expect(getChartType(singleMetricConfig)).to.be(CHART_TYPE.SINGLE_METRIC);
|
||||
expect(getChartType(multiMetricConfig)).to.be(CHART_TYPE.SINGLE_METRIC);
|
||||
expect(getChartType(varpModelPlotConfig)).to.be(CHART_TYPE.SINGLE_METRIC);
|
||||
expect(getChartType(overScriptFieldModelPlotConfig)).to.be(CHART_TYPE.SINGLE_METRIC);
|
||||
|
||||
});
|
||||
|
||||
it('returns event distribution chart type as expected for configs', () => {
|
||||
|
|
|
@ -140,23 +140,40 @@ const POPULATION_DISTRIBUTION_ENABLED = true;
|
|||
|
||||
// get the chart type based on its configuration
|
||||
export function getChartType(config) {
|
||||
|
||||
let chartType = CHART_TYPE.SINGLE_METRIC;
|
||||
if (
|
||||
EVENT_DISTRIBUTION_ENABLED &&
|
||||
config.functionDescription === 'rare' &&
|
||||
(config.entityFields.some(f => f.fieldType === 'over') === false)
|
||||
) {
|
||||
return CHART_TYPE.EVENT_DISTRIBUTION;
|
||||
chartType = CHART_TYPE.EVENT_DISTRIBUTION;
|
||||
} else if (
|
||||
POPULATION_DISTRIBUTION_ENABLED &&
|
||||
config.functionDescription !== 'rare' &&
|
||||
config.entityFields.some(f => f.fieldType === 'over') &&
|
||||
config.metricFunction !== null // Event distribution chart relies on the ML function mapping to an ES aggregation
|
||||
) {
|
||||
return CHART_TYPE.POPULATION_DISTRIBUTION;
|
||||
chartType = CHART_TYPE.POPULATION_DISTRIBUTION;
|
||||
}
|
||||
|
||||
return CHART_TYPE.SINGLE_METRIC;
|
||||
if (chartType === CHART_TYPE.EVENT_DISTRIBUTION || chartType === CHART_TYPE.POPULATION_DISTRIBUTION) {
|
||||
// Check that the config does not use script fields defined in the datafeed config.
|
||||
if (config.datafeedConfig !== undefined && config.datafeedConfig.script_fields !== undefined) {
|
||||
const scriptFields = Object.keys(config.datafeedConfig.script_fields);
|
||||
const checkFields = config.entityFields.map(entity => entity.fieldName);
|
||||
if (config.metricFieldName) {
|
||||
checkFields.push(config.metricFieldName);
|
||||
}
|
||||
const usesScriptFields =
|
||||
(checkFields.find(fieldName => scriptFields.includes(fieldName)) !== undefined);
|
||||
if (usesScriptFields === true) {
|
||||
// Only single metric chart type supports query of model plot data.
|
||||
chartType = CHART_TYPE.SINGLE_METRIC;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chartType;
|
||||
}
|
||||
|
||||
export function getExploreSeriesLink(series) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue