Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[Gauge] Vis Type (elastic#126048)
Browse files Browse the repository at this point in the history
* Added transparent background

* Added gauge/goal visType.

* Fixed palette, scale, and types.

* Set legacy chart as default.

* Removed deprecation message.

* Added percent format params, coming from visdimensions.

* Added support of labels/sublabels.

* Updated i18n label.

* Added support of showElasticChartsOptions

* Added autoextend ranges elastic charts tooltip.

* The outline elastic-charts message added.

* outline renaming and metric/buckets limitations

* reverted mistaken change of sample_vis.test.mocks.

* Warning message added to gauge split chart.

* Added warning message to the splitChart button at goal/gauge.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Kuznietsov and kibanamachine authored Mar 4, 2022
1 parent 6c0526b commit 2b6885a
Show file tree
Hide file tree
Showing 45 changed files with 1,228 additions and 378 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"usageCollection": "src/plugins/usage_collection",
"utils": "packages/kbn-securitysolution-utils/src",
"visDefaultEditor": "src/plugins/vis_default_editor",
"visTypeGauge": "src/plugins/vis_types/gauge",
"visTypeHeatmap": "src/plugins/vis_types/heatmap",
"visTypeMarkdown": "src/plugins/vis_type_markdown",
"visTypeMetric": "src/plugins/vis_types/metric",
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ It acts as a container for a particular visualization and options tabs. Contains
The plugin exposes the static DefaultEditorController class to consume.
|{kib-repo}blob/{branch}/src/plugins/vis_types/gauge[visTypeGauge]
|WARNING: Missing README.
|{kib-repo}blob/{branch}/src/plugins/vis_types/heatmap[visTypeHeatmap]
|WARNING: Missing README.
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ pageLoadAssetSize:
expressionPartitionVis: 26338
sharedUX: 16225
ux: 20784
visTypeGauge: 24113
cloudSecurityPosture: 19109
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const PLUGIN_ID = 'expressionGauge';
export const PLUGIN_NAME = 'expressionGauge';

export type {
GaugeExpressionFunctionDefinition,
GaugeExpressionProps,
FormatFactory,
GaugeRenderProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Chart, Goal, Settings } from '@elastic/charts';
import { FormattedMessage } from '@kbn/i18n-react';
import type { CustomPaletteState } from '../../../../charts/public';
import { EmptyPlaceholder } from '../../../../charts/public';
import { isVisDimension } from '../../../../visualizations/common/utils';
import {
GaugeRenderProps,
GaugeLabelMajorMode,
Expand Down Expand Up @@ -234,17 +235,22 @@ export const GaugeComponent: FC<GaugeRenderProps> = memo(
/>
);
}
const customMetricFormatParams = isVisDimension(args.metric) ? args.metric.format : undefined;
const tableMetricFormatParams = metricColumn?.meta?.params?.params
? metricColumn?.meta?.params
: undefined;

const defaultMetricFormatParams = {
id: 'number',
params: {
pattern: max - min > 5 ? `0,0` : `0,0.0`,
},
};

const tickFormatter = formatFactory(
metricColumn?.meta?.params?.params
? metricColumn?.meta?.params
: {
id: 'number',
params: {
pattern: max - min > 5 ? `0,0` : `0,0.0`,
},
}
customMetricFormatParams ?? tableMetricFormatParams ?? defaultMetricFormatParams
);

const colors = palette?.params?.colors ? normalizeColors(palette.params, min, max) : undefined;
const bands: number[] = (palette?.params as CustomPaletteState)
? normalizeBands(args.palette?.params as CustomPaletteState, { min, max })
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/vis_types/gauge/common/index.ts
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 const LEGACY_GAUGE_CHARTS_LIBRARY = 'visualization:visualize:legacyGaugeChartsLibrary';
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
* Side Public License, v 1.
*/

import { VisTypeDefinition } from 'src/plugins/visualizations/public';
import { gaugeVisTypeDefinition } from './gauge';
import { goalVisTypeDefinition } from './goal';
import { schema, TypeOf } from '@kbn/config-schema';

export { pieVisTypeDefinition } from './pie';
export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
});

export const visLibVisTypeDefinitions: Array<VisTypeDefinition<any>> = [
gaugeVisTypeDefinition,
goalVisTypeDefinition,
];
export type ConfigSchema = TypeOf<typeof configSchema>;
18 changes: 18 additions & 0 deletions src/plugins/vis_types/gauge/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../..',
roots: ['<rootDir>/src/plugins/vis_types/gauge'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/vis_types/gauge',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
'<rootDir>/src/plugins/vis_types/gauge/{common,public,server}/**/*.{ts,tsx}',
],
};
16 changes: 16 additions & 0 deletions src/plugins/vis_types/gauge/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "visTypeGauge",
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["charts", "data", "expressions", "visualizations"],
"requiredBundles": ["visDefaultEditor"],
"optionalPlugins": ["expressionGauge"],
"extraPublicDirs": ["common/index"],
"owner": {
"name": "Vis Editors",
"githubTeam": "kibana-vis-editors"
},
"description": "Contains the gauge chart implementation using the elastic-charts library. The goal is to eventually deprecate the old implementation and keep only this. Until then, the library used is defined by the Legacy charts library advanced setting."
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
*/

import { i18n } from '@kbn/i18n';

import { colorSchemas } from '../../../../charts/public';
import { getPositions, getScaleTypes } from '../../../xy/public';

import { Alignment, GaugeType } from '../types';

export const getGaugeTypes = () => [
{
text: i18n.translate('visTypeVislib.gauge.gaugeTypes.arcText', {
text: i18n.translate('visTypeGauge.gauge.gaugeTypes.arcText', {
defaultMessage: 'Arc',
}),
value: GaugeType.Arc,
},
{
text: i18n.translate('visTypeVislib.gauge.gaugeTypes.circleText', {
text: i18n.translate('visTypeGauge.gauge.gaugeTypes.circleText', {
defaultMessage: 'Circle',
}),
value: GaugeType.Circle,
Expand All @@ -30,19 +27,19 @@ export const getGaugeTypes = () => [

export const getAlignments = () => [
{
text: i18n.translate('visTypeVislib.gauge.alignmentAutomaticTitle', {
text: i18n.translate('visTypeGauge.gauge.alignmentAutomaticTitle', {
defaultMessage: 'Automatic',
}),
value: Alignment.Automatic,
},
{
text: i18n.translate('visTypeVislib.gauge.alignmentHorizontalTitle', {
text: i18n.translate('visTypeGauge.gauge.alignmentHorizontalTitle', {
defaultMessage: 'Horizontal',
}),
value: Alignment.Horizontal,
},
{
text: i18n.translate('visTypeVislib.gauge.alignmentVerticalTitle', {
text: i18n.translate('visTypeGauge.gauge.alignmentVerticalTitle', {
defaultMessage: 'Vertical',
}),
value: Alignment.Vertical,
Expand All @@ -54,9 +51,3 @@ export const getGaugeCollections = () => ({
alignments: getAlignments(),
colorSchemas,
});

export const getHeatmapCollections = () => ({
legendPositions: getPositions(),
scales: getScaleTypes(),
colorSchemas,
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ import React, { useCallback } from 'react';
import { EuiSpacer } from '@elastic/eui';

import { VisEditorOptionsProps } from 'src/plugins/visualizations/public';
import { GaugeVisParams } from '../../../gauge';
import { GaugeTypeProps, GaugeVisParams } from '../../../types';
import { RangesPanel } from './ranges_panel';
import { StylePanel } from './style_panel';
import { LabelsPanel } from './labels_panel';

export type GaugeOptionsInternalProps = VisEditorOptionsProps<GaugeVisParams> & {
export interface GaugeOptionsProps extends VisEditorOptionsProps<GaugeVisParams>, GaugeTypeProps {}

export type GaugeOptionsInternalProps = GaugeOptionsProps & {
setGaugeValue: <T extends keyof GaugeVisParams['gauge']>(
paramName: T,
value: GaugeVisParams['gauge'][T]
) => void;
};

function GaugeOptions(props: VisEditorOptionsProps<GaugeVisParams>) {
function GaugeOptions(props: GaugeOptionsProps) {
const { stateParams, setValue } = props;

const setGaugeValue: GaugeOptionsInternalProps['setGaugeValue'] = useCallback(
Expand All @@ -37,13 +39,9 @@ function GaugeOptions(props: VisEditorOptionsProps<GaugeVisParams>) {
return (
<>
<StylePanel {...props} setGaugeValue={setGaugeValue} />

<EuiSpacer size="s" />

<RangesPanel {...props} setGaugeValue={setGaugeValue} />

<EuiSpacer size="s" />

<LabelsPanel {...props} setGaugeValue={setGaugeValue} />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function LabelsPanel({ stateParams, setValue, setGaugeValue }: GaugeOptionsInter
<EuiTitle size="xs">
<h3>
<FormattedMessage
id="visTypeVislib.controls.gaugeOptions.labelsTitle"
id="visTypeGauge.controls.gaugeOptions.labelsTitle"
defaultMessage="Labels"
/>
</h3>
</EuiTitle>
<EuiSpacer size="s" />

<SwitchOption
label={i18n.translate('visTypeVislib.controls.gaugeOptions.showLabelsLabel', {
label={i18n.translate('visTypeGauge.controls.gaugeOptions.showLabelsLabel', {
defaultMessage: 'Show labels',
})}
paramName="show"
Expand All @@ -40,7 +40,7 @@ function LabelsPanel({ stateParams, setValue, setGaugeValue }: GaugeOptionsInter

<TextInputOption
disabled={!stateParams.gauge.labels.show}
label={i18n.translate('visTypeVislib.controls.gaugeOptions.subTextLabel', {
label={i18n.translate('visTypeGauge.controls.gaugeOptions.subTextLabel', {
defaultMessage: 'Sub label',
})}
paramName="subText"
Expand Down
Loading

0 comments on commit 2b6885a

Please sign in to comment.