Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add log min limit option to value axis options #93352

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/plugins/vis_type_xy/public/config/get_axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,22 @@ function getAxisDomain<S extends XScaleType | YScaleType>(
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 };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,13 +23,15 @@ export interface CustomExtentsOptionsProps {
setMultipleValidity(paramName: string, isValid: boolean): void;
setValueAxis<T extends keyof ValueAxis>(paramName: T, value: ValueAxis[T]): void;
setValueAxisScale: SetScale;
showLogOptions: boolean;
}

function CustomExtentsOptions({
axisScale,
setMultipleValidity,
setValueAxis,
setValueAxisScale,
showLogOptions,
}: CustomExtentsOptionsProps) {
const invalidBoundsMarginMessage = i18n.translate(
'visTypeXy.controls.pointSeries.valueAxes.scaleToDataBounds.minNeededBoundsMargin',
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -120,6 +144,37 @@ function CustomExtentsOptions({
setMultipleValidity={setMultipleValidity}
/>
)}

{showLogOptions && (
<>
<SwitchOption
label={i18n.translate('visTypeXy.controls.pointSeries.valueAxes.setAxisLogMinLimit', {
defaultMessage: 'Set log min limit',
})}
paramName="useLogMinLimit"
value={axisScale.useLogMinLimit}
setValue={setUselogLimit}
/>

{axisScale.useLogMinLimit && (
<NumberInputOption
label={
<>
<FormattedMessage
id="visTypeXy.controls.pointSeries.valueAxes.LogMinLimit"
defaultMessage="Log min limit"
/>{' '}
<EuiIconTip content="Absolute value to limit visible data on a log scale." />
</>
}
isInvalid={(axisScale.logMinLimit ?? 1) <= 0}
paramName="logMinLimit"
value={axisScale.logMinLimit}
setValue={setAxisLogMinLimit}
/>
)}
</>
)}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<EuiPanel paddingSize="s">
<EuiFlexGroup gutterSize="none" justifyContent="spaceBetween" alignItems="baseline">
Expand Down Expand Up @@ -145,6 +162,7 @@ function ValueAxesPanel(props: ValueAxesPanelProps) {
<ValueAxisOptions
axis={axis}
index={index}
showLogOptions={shouldShowLogOptions(axis)}
valueAxis={valueAxes[index]}
onValueAxisPositionChanged={props.onValueAxisPositionChanged}
setParamByIndex={props.setParamByIndex}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ValueAxisOptionsParams {
onValueAxisPositionChanged: (index: number, value: ValueAxis['position']) => void;
setParamByIndex: SetParamByIndex;
valueAxis: ValueAxis;
showLogOptions: boolean;
setMultipleValidity: (paramName: string, isValid: boolean) => void;
}

Expand All @@ -45,6 +46,7 @@ export function ValueAxisOptions({
onValueAxisPositionChanged,
setParamByIndex,
setMultipleValidity,
showLogOptions,
}: ValueAxisOptionsParams) {
const setValueAxis = useCallback(
<T extends keyof ValueAxis>(paramName: T, value: ValueAxis[T]) =>
Expand Down Expand Up @@ -188,6 +190,7 @@ export function ValueAxisOptions({
<EuiSpacer size="m" />
<CustomExtentsOptions
axisScale={axis.scale}
showLogOptions={showLogOptions}
setMultipleValidity={setMultipleValidity}
setValueAxisScale={setValueAxisScale}
setValueAxis={setValueAxis}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/vis_type_xy/public/types/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface Scale {
mode?: AxisMode;
setYExtents?: boolean;
type: ScaleType;
useLogMinLimit?: boolean;
logMinLimit?: number;
}

export interface CategoryAxis {
Expand Down