diff --git a/src/plugins/vis_type_xy/public/config/get_axis.ts b/src/plugins/vis_type_xy/public/config/get_axis.ts index 91647f02e2a1e..120f0ee521df2 100644 --- a/src/plugins/vis_type_xy/public/config/get_axis.ts +++ b/src/plugins/vis_type_xy/public/config/get_axis.ts @@ -167,21 +167,22 @@ function getAxisDomain( return; } - const { min, max, defaultYExtents, boundsMargin } = scale; - const fit = defaultYExtents; + const { min, max, defaultYExtents, boundsMargin, useLogMinLimit } = scale; + const fit = defaultYExtents || useLogMinLimit; const padding = boundsMargin; + const logMinLimit = useLogMinLimit ? scale.logMinLimit : undefined; if (!isNil(min) && !isNil(max)) { - return { fit, padding, min, max }; + return { fit, logMinLimit, padding, min, max }; } if (!isNil(min)) { - return { fit, padding, min }; + return { fit, logMinLimit, padding, min }; } if (!isNil(max)) { - return { fit, padding, max }; + return { fit, logMinLimit, padding, max }; } - return { fit, padding }; + return { fit, logMinLimit, padding }; } diff --git a/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/custom_extents_options.tsx b/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/custom_extents_options.tsx index 9efb92bbf3730..6f8e384fcb9b0 100644 --- a/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/custom_extents_options.tsx +++ b/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/custom_extents_options.tsx @@ -9,6 +9,8 @@ import React, { useCallback, useEffect } from 'react'; import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { EuiIconTip } from '@elastic/eui'; import { NumberInputOption, SwitchOption } from '../../../../../../vis_default_editor/public'; @@ -21,6 +23,7 @@ export interface CustomExtentsOptionsProps { setMultipleValidity(paramName: string, isValid: boolean): void; setValueAxis(paramName: T, value: ValueAxis[T]): void; setValueAxisScale: SetScale; + showLogOptions: boolean; } function CustomExtentsOptions({ @@ -28,6 +31,7 @@ function CustomExtentsOptions({ setMultipleValidity, setValueAxis, setValueAxisScale, + showLogOptions, }: CustomExtentsOptionsProps) { const invalidBoundsMarginMessage = i18n.translate( 'visTypeXy.controls.pointSeries.valueAxes.scaleToDataBounds.minNeededBoundsMargin', @@ -66,6 +70,26 @@ function CustomExtentsOptions({ [axisScale, setValueAxis] ); + const setAxisLogMinLimit = useCallback( + (paramName: 'logMinLimit', value: number | '') => { + setValueAxisScale(paramName, value === '' ? 1 : value); + }, + [setValueAxisScale] + ); + + const setUselogLimit = useCallback( + (paramName: 'useLogMinLimit', value: boolean) => { + setValueAxisScale(paramName, value); + }, + [setValueAxisScale] + ); + + useEffect(() => { + if (!showLogOptions) { + setUselogLimit('useLogMinLimit', false); + } + }, [setUselogLimit, showLogOptions]); + useEffect(() => { setMultipleValidity('boundsMargin', isBoundsMarginValid); @@ -120,6 +144,37 @@ function CustomExtentsOptions({ setMultipleValidity={setMultipleValidity} /> )} + + {showLogOptions && ( + <> + + + {axisScale.useLogMinLimit && ( + + {' '} + + + } + isInvalid={(axisScale.logMinLimit ?? 1) <= 0} + paramName="logMinLimit" + value={axisScale.logMinLimit} + setValue={setAxisLogMinLimit} + /> + )} + + )} ); } diff --git a/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/value_axes_panel.tsx b/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/value_axes_panel.tsx index 02bdb7b185288..1f42e000085c1 100644 --- a/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/value_axes_panel.tsx +++ b/src/plugins/vis_type_xy/public/editor/components/options/metrics_axes/value_axes_panel.tsx @@ -20,9 +20,10 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { SeriesParam, ValueAxis } from '../../../../types'; +import { ChartMode, ScaleType, SeriesParam, ValueAxis } from '../../../../types'; import { ValueAxisOptions } from './value_axis_options'; import { SetParamByIndex } from '.'; +import { ChartType } from '../../../../../common'; export interface ValueAxesPanelProps { addValueAxis: () => ValueAxis; @@ -94,6 +95,22 @@ function ValueAxesPanel(props: ValueAxesPanelProps) { }, [getSeries] ); + + const shouldShowLogOptions = useCallback( + (axis: ValueAxis) => { + if (axis.scale.type !== ScaleType.Log) return false; + + const isFirst = valueAxes[0].id === axis.id; + const series = seriesParams.filter( + (serie) => serie.valueAxis === axis.id || (isFirst && !serie.valueAxis) + ); + return series.some( + (serie) => serie.type === ChartType.Line && serie.mode === ChartMode.Normal + ); + }, + [seriesParams, valueAxes] + ); + return ( @@ -145,6 +162,7 @@ function ValueAxesPanel(props: ValueAxesPanelProps) { void; setParamByIndex: SetParamByIndex; valueAxis: ValueAxis; + showLogOptions: boolean; setMultipleValidity: (paramName: string, isValid: boolean) => void; } @@ -45,6 +46,7 @@ export function ValueAxisOptions({ onValueAxisPositionChanged, setParamByIndex, setMultipleValidity, + showLogOptions, }: ValueAxisOptionsParams) { const setValueAxis = useCallback( (paramName: T, value: ValueAxis[T]) => @@ -188,6 +190,7 @@ export function ValueAxisOptions({