This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] move gauge to chart expression plugin (elastic#120623)
* gauge_expression * fix * CI fix * make plugin required to use its methods * move non-types from types * share icon * bundle, plugin * load gaugeComponent async * fix types * async heatmap * don't use d3 * optimizations * feedback * types * adjusting the tests to the new max Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
b6013d1
commit 4dc3643
Showing
66 changed files
with
1,514 additions
and
1,079 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,3 +118,4 @@ pageLoadAssetSize: | |
reporting: 57003 | ||
visTypeHeatmap: 25340 | ||
screenshotting: 17017 | ||
expressionGauge: 25000 |
31 changes: 31 additions & 0 deletions
31
src/plugins/chart_expressions/expression_gauge/common/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const EXPRESSION_GAUGE_NAME = 'gauge'; | ||
export const GAUGE_FUNCTION_RENDERER_NAME = 'gauge_renderer'; | ||
|
||
export const GaugeShapes = { | ||
horizontalBullet: 'horizontalBullet', | ||
verticalBullet: 'verticalBullet', | ||
} as const; | ||
|
||
export const GaugeTicksPositions = { | ||
auto: 'auto', | ||
bands: 'bands', | ||
} as const; | ||
|
||
export const GaugeLabelMajorModes = { | ||
auto: 'auto', | ||
custom: 'custom', | ||
none: 'none', | ||
} as const; | ||
|
||
export const GaugeColorModes = { | ||
palette: 'palette', | ||
none: 'none', | ||
} as const; |
47 changes: 47 additions & 0 deletions
47
...ns/expression_gauge/common/expression_functions/__snapshots__/gauge_function.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
...ins/chart_expressions/expression_gauge/common/expression_functions/gauge_function.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { gaugeFunction } from './gauge_function'; | ||
import type { GaugeArguments } from '..'; | ||
import { functionWrapper } from '../../../../expressions/common/expression_functions/specs/tests/utils'; | ||
import { Datatable } from '../../../../expressions/common/expression_types/specs'; | ||
|
||
describe('interpreter/functions#gauge', () => { | ||
const fn = functionWrapper(gaugeFunction()); | ||
const context: Datatable = { | ||
type: 'datatable', | ||
rows: [{ 'col-0-1': 0 }], | ||
columns: [ | ||
{ id: 'col-0-1', name: 'Count', meta: { type: 'number' } }, | ||
{ id: 'col-1-2', name: 'Dest', meta: { type: 'string' } }, | ||
], | ||
}; | ||
const args: GaugeArguments = { | ||
ticksPosition: 'auto', | ||
labelMajorMode: 'custom', | ||
labelMajor: 'title', | ||
shape: 'horizontalBullet', | ||
colorMode: 'none', | ||
minAccessor: 'col-1-2', | ||
metricAccessor: 'col-0-1', | ||
}; | ||
|
||
it('returns an object with the correct structure', () => { | ||
const actual = fn(context, args, undefined); | ||
expect(actual).toMatchSnapshot(); | ||
}); | ||
}); |
107 changes: 107 additions & 0 deletions
107
src/plugins/chart_expressions/expression_gauge/common/expression_functions/gauge_function.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { GaugeExpressionFunctionDefinition } from '../types'; | ||
import { EXPRESSION_GAUGE_NAME } from '../constants'; | ||
|
||
export const gaugeFunction = (): GaugeExpressionFunctionDefinition => ({ | ||
name: EXPRESSION_GAUGE_NAME, | ||
type: 'render', | ||
inputTypes: ['datatable'], | ||
help: i18n.translate('expressionGauge.functions.help', { | ||
defaultMessage: 'Gauge visualization', | ||
}), | ||
args: { | ||
shape: { | ||
types: ['string'], | ||
options: ['horizontalBullet', 'verticalBullet'], | ||
help: i18n.translate('expressionGauge.functions.shape.help', { | ||
defaultMessage: 'Type of gauge chart', | ||
}), | ||
}, | ||
metricAccessor: { | ||
types: ['string'], | ||
help: i18n.translate('expressionGauge.functions.metricAccessor.help', { | ||
defaultMessage: 'Current value', | ||
}), | ||
}, | ||
minAccessor: { | ||
types: ['string'], | ||
help: i18n.translate('expressionGauge.functions.minAccessor.help', { | ||
defaultMessage: 'Minimum value', | ||
}), | ||
}, | ||
maxAccessor: { | ||
types: ['string'], | ||
help: i18n.translate('expressionGauge.functions.maxAccessor.help', { | ||
defaultMessage: 'Maximum value', | ||
}), | ||
}, | ||
goalAccessor: { | ||
types: ['string'], | ||
help: i18n.translate('expressionGauge.functions.goalAccessor.help', { | ||
defaultMessage: 'Goal Value', | ||
}), | ||
}, | ||
colorMode: { | ||
types: ['string'], | ||
default: 'none', | ||
options: ['none', 'palette'], | ||
help: i18n.translate('expressionGauge.functions.colorMode.help', { | ||
defaultMessage: 'If set to palette, the palette colors will be applied to the bands', | ||
}), | ||
}, | ||
palette: { | ||
types: ['palette'], | ||
help: i18n.translate('expressionGauge.functions..metric.palette.help', { | ||
defaultMessage: 'Provides colors for the values', | ||
}), | ||
}, | ||
ticksPosition: { | ||
types: ['string'], | ||
options: ['auto', 'bands'], | ||
help: i18n.translate('expressionGauge.functions..gaugeChart.config.ticksPosition.help', { | ||
defaultMessage: 'Specifies the placement of ticks', | ||
}), | ||
required: true, | ||
}, | ||
labelMajor: { | ||
types: ['string'], | ||
help: i18n.translate('expressionGauge.functions..gaugeChart.config.labelMajor.help', { | ||
defaultMessage: 'Specifies the labelMajor of the gauge chart displayed inside the chart.', | ||
}), | ||
required: false, | ||
}, | ||
labelMajorMode: { | ||
types: ['string'], | ||
options: ['none', 'auto', 'custom'], | ||
help: i18n.translate('expressionGauge.functions..gaugeChart.config.labelMajorMode.help', { | ||
defaultMessage: 'Specifies the mode of labelMajor', | ||
}), | ||
required: true, | ||
}, | ||
labelMinor: { | ||
types: ['string'], | ||
help: i18n.translate('expressionGauge.functions..gaugeChart.config.labelMinor.help', { | ||
defaultMessage: 'Specifies the labelMinor of the gauge chart', | ||
}), | ||
required: false, | ||
}, | ||
}, | ||
fn(data, args) { | ||
return { | ||
type: 'render', | ||
as: EXPRESSION_GAUGE_NAME, | ||
value: { | ||
data, | ||
args, | ||
}, | ||
}; | ||
}, | ||
}); |
9 changes: 9 additions & 0 deletions
9
src/plugins/chart_expressions/expression_gauge/common/expression_functions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { gaugeFunction } from './gauge_function'; |
34 changes: 34 additions & 0 deletions
34
src/plugins/chart_expressions/expression_gauge/common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const PLUGIN_ID = 'expressionGauge'; | ||
export const PLUGIN_NAME = 'expressionGauge'; | ||
|
||
export type { | ||
GaugeExpressionProps, | ||
FormatFactory, | ||
GaugeRenderProps, | ||
CustomPaletteParams, | ||
ColorStop, | ||
RequiredPaletteParamTypes, | ||
GaugeArguments, | ||
GaugeShape, | ||
GaugeLabelMajorMode, | ||
GaugeTicksPosition, | ||
GaugeState, | ||
} from './types'; | ||
|
||
export { gaugeFunction } from './expression_functions'; | ||
|
||
export { | ||
EXPRESSION_GAUGE_NAME, | ||
GaugeShapes, | ||
GaugeColorModes, | ||
GaugeTicksPositions, | ||
GaugeLabelMajorModes, | ||
} from './constants'; |
69 changes: 69 additions & 0 deletions
69
src/plugins/chart_expressions/expression_gauge/common/types/expression_functions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { | ||
Datatable, | ||
ExpressionFunctionDefinition, | ||
ExpressionValueRender, | ||
} from '../../../../expressions'; | ||
import { CustomPaletteState, PaletteOutput } from '../../../../charts/common'; | ||
import { | ||
EXPRESSION_GAUGE_NAME, | ||
GAUGE_FUNCTION_RENDERER_NAME, | ||
GaugeShapes, | ||
GaugeTicksPositions, | ||
GaugeLabelMajorModes, | ||
GaugeColorModes, | ||
} from '../constants'; | ||
import { CustomPaletteParams } from '.'; | ||
|
||
export type GaugeType = 'gauge'; | ||
export type GaugeColorMode = keyof typeof GaugeColorModes; | ||
export type GaugeShape = keyof typeof GaugeShapes; | ||
export type GaugeLabelMajorMode = keyof typeof GaugeLabelMajorModes; | ||
export type GaugeTicksPosition = keyof typeof GaugeTicksPositions; | ||
|
||
export interface GaugeState { | ||
metricAccessor?: string; | ||
minAccessor?: string; | ||
maxAccessor?: string; | ||
goalAccessor?: string; | ||
ticksPosition: GaugeTicksPosition; | ||
labelMajorMode: GaugeLabelMajorMode; | ||
labelMajor?: string; | ||
labelMinor?: string; | ||
colorMode?: GaugeColorMode; | ||
palette?: PaletteOutput<CustomPaletteParams>; | ||
shape: GaugeShape; | ||
} | ||
|
||
export type GaugeArguments = GaugeState & { | ||
shape: GaugeShape; | ||
colorMode: GaugeColorMode; | ||
palette?: PaletteOutput<CustomPaletteState>; | ||
}; | ||
|
||
export type GaugeInput = Datatable; | ||
|
||
export interface GaugeExpressionProps { | ||
data: Datatable; | ||
args: GaugeArguments; | ||
} | ||
|
||
export interface GaugeRender { | ||
type: 'render'; | ||
as: typeof GAUGE_FUNCTION_RENDERER_NAME; | ||
value: GaugeExpressionProps; | ||
} | ||
|
||
export type GaugeExpressionFunctionDefinition = ExpressionFunctionDefinition< | ||
typeof EXPRESSION_GAUGE_NAME, | ||
GaugeInput, | ||
GaugeArguments, | ||
ExpressionValueRender<GaugeExpressionProps> | ||
>; |
Oops, something went wrong.