From 7689a1ab64a503c89b66aa9d7da4e5ce29e56517 Mon Sep 17 00:00:00 2001 From: Artem Panchuk Date: Fri, 30 Aug 2024 21:07:53 +0300 Subject: [PATCH 1/4] Add form checks for logarithmic axis type and fallbacks --- .../plugins/datalens/utils/axis-helpers.ts | 21 +++- .../DialogPlaceholder/DialogPlaceholder.tsx | 95 +++++++++++++------ 2 files changed, 87 insertions(+), 29 deletions(-) diff --git a/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts b/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts index 13438eec3f..24ba538ef5 100644 --- a/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts +++ b/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts @@ -60,11 +60,28 @@ export const applyPlaceholderSettingsToAxis = ( placeholder.settings.autoscale === false || (placeholder.settings.scale === 'auto' && placeholder.settings.scaleValue === '0-max') ) { - axis.min = 0; + if (placeholder.settings.type === 'logarithmic') { + // Fallback to null for incorrect case + axis.min = null; + } else { + axis.min = 0; + } } else if (placeholder.settings.scale === 'manual') { axis.endOnTick = false; axis.min = Number((placeholder.settings.scaleValue as [string, string])[0]); axis.max = Number((placeholder.settings.scaleValue as [string, string])[1]); + + if (placeholder.settings.type === 'logarithmic') { + if (axis.min <= 0) { + // Fallback to null for incorrect case + axis.min = null; + } + + if (axis.max <= 0) { + // Fallback to null for incorrect case + axis.max = null; + } + } } const axisTitle = getAxisTitle(placeholder.settings, placeholder.items[0]); @@ -75,7 +92,7 @@ export const applyPlaceholderSettingsToAxis = ( if (isDateField(placeholder.items[0])) { axis.type = 'datetime'; } else { - axis.type = placeholder.settings?.type === 'logarithmic' ? 'logarithmic' : 'linear'; + axis.type = placeholder.settings.type === 'logarithmic' ? 'logarithmic' : 'linear'; } if (!isGridEnabled(placeholder.settings)) { diff --git a/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx b/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx index f5385b35d1..e0cec11f1b 100644 --- a/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx +++ b/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx @@ -762,10 +762,13 @@ class DialogPlaceholder extends React.PureComponent { }; handleScaleRadioButtonsUpdate = (scaleMode: string) => { + const defaultManualValue: [string, string] = + this.state.settings.type === SETTINGS.TYPE.LOGARITHMIC + ? ['0.001', '100'] + : ['0', '100']; + const scaleValue = - scaleMode === SETTINGS.SCALE.MANUAL - ? (['0', '100'] as [string, string]) - : SETTINGS.SCALE_VALUE.MIN_MAX; + scaleMode === SETTINGS.SCALE.MANUAL ? defaultManualValue : SETTINGS.SCALE_VALUE.MIN_MAX; this.setState({ settings: { @@ -786,20 +789,38 @@ class DialogPlaceholder extends React.PureComponent { }, }; - if ( - axisType === SETTINGS.TYPE.LOGARITHMIC && - settings.scaleValue === SETTINGS.SCALE_VALUE.ZERO_MAX - ) { - updatedState.settings = { - ...updatedState.settings, - scaleValue: SETTINGS.SCALE_VALUE.MIN_MAX, - }; - updatedState.tooltipType = 'scaleValue'; - updatedState.tooltipContent = ( - - {i18n('wizard', 'tooltip_zero-to-max-scale')} - - ); + updatedState.tooltipType = undefined; + updatedState.tooltipContent = ''; + + if (axisType === SETTINGS.TYPE.LOGARITHMIC) { + if (settings.scaleValue === SETTINGS.SCALE_VALUE.ZERO_MAX) { + updatedState.settings = { + ...updatedState.settings, + scaleValue: SETTINGS.SCALE_VALUE.MIN_MAX, + }; + updatedState.tooltipType = 'scaleValue'; + updatedState.tooltipContent = ( + + {i18n('wizard', 'tooltip_zero-to-max-scale')} + + ); + } else if ( + settings.scale === SETTINGS.SCALE.MANUAL && + (Number(settings?.scaleValue?.[0]) <= 0 || Number(settings?.scaleValue?.[1]) <= 0) + ) { + updatedState.settings = { + ...updatedState.settings, + scale: SETTINGS.SCALE.AUTO, + scaleValue: SETTINGS.SCALE_VALUE.MIN_MAX, + }; + + updatedState.tooltipType = 'scaleValue'; + updatedState.tooltipContent = ( + + {i18n('wizard', 'tooltip_zero-to-max-scale')} + + ); + } } this.setState( @@ -809,7 +830,7 @@ class DialogPlaceholder extends React.PureComponent { }; handleScaleValueUpdate = (scaleValue: string) => { - const settings = this.state.settings; + const {settings} = this.state; const updatedState: Partial = { settings: { @@ -832,6 +853,9 @@ class DialogPlaceholder extends React.PureComponent { {i18n('wizard', 'tooltip_logarithmic-axis')} ); + } else { + updatedState.tooltipType = undefined; + updatedState.tooltipContent = ''; } this.setState( @@ -846,20 +870,37 @@ class DialogPlaceholder extends React.PureComponent { const [prevMin, prevMax] = scaleValue; - const updatedScaleValue = []; + const updatedState: {settings: State['settings']} & Partial = { + settings: { + ...this.state.settings, + }, + tooltipType: undefined, + tooltipContent: '', + }; if (type === 'min') { - updatedScaleValue.push(value, prevMax); + updatedState.settings.scaleValue = [value, prevMax]; } else { - updatedScaleValue.push(prevMin, value); + updatedState.settings.scaleValue = [prevMin, value]; } - this.setState({ - settings: { - ...this.state.settings, - scaleValue: updatedScaleValue as [string, string], - }, - }); + // Here we need to check whether axis type is logarithmic and min value is 0 or negative + if (settings.type === SETTINGS.TYPE.LOGARITHMIC && Number(value) <= 0) { + // And if axis type was algorithmic, then we need to reset it to linear in that case + updatedState.settings.type = SETTINGS.TYPE.LINEAR; + + updatedState.tooltipType = 'type'; + updatedState.tooltipContent = ( + + {i18n('wizard', 'tooltip_logarithmic-axis')} + + ); + } + + this.setState( + (prevState: State) => ({...prevState, ...updatedState}), + () => this.tooltipRef.current && this.tooltipRef.current.openTooltip(), + ); }; } From 7fd107f3b1f498b09f1eb45d120ab2473094d9c9 Mon Sep 17 00:00:00 2001 From: Artem Panchuk Date: Mon, 2 Sep 2024 13:04:12 +0300 Subject: [PATCH 2/4] PR fixes for server side --- .../plugins/datalens/utils/axis-helpers.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts b/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts index 24ba538ef5..f5248774ac 100644 --- a/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts +++ b/src/server/modes/charts/plugins/datalens/utils/axis-helpers.ts @@ -68,19 +68,16 @@ export const applyPlaceholderSettingsToAxis = ( } } else if (placeholder.settings.scale === 'manual') { axis.endOnTick = false; - axis.min = Number((placeholder.settings.scaleValue as [string, string])[0]); - axis.max = Number((placeholder.settings.scaleValue as [string, string])[1]); - if (placeholder.settings.type === 'logarithmic') { - if (axis.min <= 0) { - // Fallback to null for incorrect case - axis.min = null; - } - - if (axis.max <= 0) { - // Fallback to null for incorrect case - axis.max = null; - } + const minValue = Number((placeholder.settings.scaleValue as [string, string])[0]); + const maxValue = Number((placeholder.settings.scaleValue as [string, string])[1]); + + if (placeholder.settings.type !== 'logarithmic' || 0 < minValue) { + axis.min = minValue; + } + + if (placeholder.settings.type !== 'logarithmic' || 0 < maxValue) { + axis.max = maxValue; } } From a3db5e4713205bac321603973c06e364e058a295 Mon Sep 17 00:00:00 2001 From: Artem Panchuk Date: Mon, 2 Sep 2024 14:57:41 +0300 Subject: [PATCH 3/4] Fix tooltip text and logic --- src/i18n-keysets/wizard/en.json | 4 +-- src/i18n-keysets/wizard/ru.json | 4 +-- .../DialogPlaceholder/DialogPlaceholder.tsx | 27 ++++++++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/i18n-keysets/wizard/en.json b/src/i18n-keysets/wizard/en.json index 5c24a9359d..fca284cd1b 100644 --- a/src/i18n-keysets/wizard/en.json +++ b/src/i18n-keysets/wizard/en.json @@ -355,13 +355,13 @@ "tooltip_dataset-fetch-failed-details-label": "Learn more", "tooltip_filter_item": "To apply a filter, remove the same field from the Filters from dashboard section.", "tooltip_filters_from_dashboard": "Filters from the dashboard applied to the chart. These filters will not be saved in the chart.", - "tooltip_logarithmic-axis": "The scale from 0 cannot be logarithmic", + "tooltip_logarithmic-axis": "The scale with negative values or 0 cannot be logarithmic", "tooltip_no-available-fields": "No suitable fields to add", "tooltip_pagination_unavailable": "Pagination is not available for multidataset charts", "tooltip_parameter-changed-icon": "Parameter value changed", "tooltip_tree-pagination_unavailable": "Pagination is not available in a tree table", "tooltip_tree-total_unavailable": "Total is not available in a tree table", - "tooltip_zero-to-max-scale": "The logarithmic scale cannot contain values of 0", + "tooltip_zero-to-max-scale": "The logarithmic scale cannot contain values of 0 or negative values", "value_geotype-select-geopoint": "Points (Geopoints)", "value_geotype-select-geopoint-with-cluster": "Points with clusters (Geopoints)", "value_geotype-select-geopolygon": "Polygons (Geopolygons)", diff --git a/src/i18n-keysets/wizard/ru.json b/src/i18n-keysets/wizard/ru.json index 10281285f9..4fd788bd7f 100644 --- a/src/i18n-keysets/wizard/ru.json +++ b/src/i18n-keysets/wizard/ru.json @@ -355,13 +355,13 @@ "tooltip_dataset-fetch-failed-details-label": "Подробнее", "tooltip_filter_item": "Чтобы применить фильтр, удалите такое же поле из секции Фильтры с дашборда.", "tooltip_filters_from_dashboard": "К чарту применены фильтры с дашборда. Эти фильтры не будут сохранены в чарте.", - "tooltip_logarithmic-axis": "Шкала от 0 не может быть логарифмической", + "tooltip_logarithmic-axis": "Шкала с 0 или отрицательными значениями не может быть логарифмической", "tooltip_no-available-fields": "Нет подходящих полей для добавления", "tooltip_pagination_unavailable": "Для мультидатасетных чартов пагинация недоступна", "tooltip_parameter-changed-icon": "Значение параметра изменено", "tooltip_tree-pagination_unavailable": "Пагинация недоступна в таблице с деревьями", "tooltip_tree-total_unavailable": "Итоги недоступны в таблице с деревьями", - "tooltip_zero-to-max-scale": "Логарифмическая шкала не может содержать значения 0", + "tooltip_zero-to-max-scale": "Логарифмическая шкала не может содержать значения 0 или отрицательные значения", "value_geotype-select-geopoint": "Точки (Геоточки)", "value_geotype-select-geopoint-with-cluster": "Точки с кластеризацией (Геоточки)", "value_geotype-select-geopolygon": "Полигоны (Геoполигоны)", diff --git a/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx b/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx index e0cec11f1b..e3291ce670 100644 --- a/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx +++ b/src/ui/units/wizard/components/Dialogs/DialogPlaceholder/DialogPlaceholder.tsx @@ -77,7 +77,7 @@ interface State { firstField: Field | undefined; settings: PlaceholderSettings; tooltipContent: React.ReactNode; - tooltipType: 'type' | 'scaleValue' | undefined; + tooltipType: 'type' | 'scale' | 'scaleValue' | undefined; } export type OpenDialogPlaceholderArgs = { @@ -93,6 +93,7 @@ class DialogPlaceholder extends React.PureComponent { tooltipRef = React.createRef(); tooltipScaleValueAnchorRef = React.createRef(); tooltipAxisTypeAnchorRef = React.createRef(); + tooltipScaleAnchorRef = React.createRef(); constructor(props: Props) { super(props); @@ -577,6 +578,7 @@ class DialogPlaceholder extends React.PureComponent { setting={ { renderModalBody() { const {tooltipContent, tooltipType} = this.state; + let anchorRef; + switch (tooltipType) { + case 'type': + anchorRef = this.tooltipAxisTypeAnchorRef; + break; + case 'scale': + anchorRef = this.tooltipScaleAnchorRef; + break; + case 'scaleValue': + anchorRef = this.tooltipScaleValueAnchorRef; + break; + } + return (
{this.renderScaleSettings()} @@ -690,11 +705,7 @@ class DialogPlaceholder extends React.PureComponent { @@ -776,6 +787,8 @@ class DialogPlaceholder extends React.PureComponent { scale: scaleMode, scaleValue, }, + tooltipType: undefined, + tooltipContent: '', }); }; @@ -814,7 +827,7 @@ class DialogPlaceholder extends React.PureComponent { scaleValue: SETTINGS.SCALE_VALUE.MIN_MAX, }; - updatedState.tooltipType = 'scaleValue'; + updatedState.tooltipType = 'scale'; updatedState.tooltipContent = ( {i18n('wizard', 'tooltip_zero-to-max-scale')} From 39390ff2791cbe9d7cb241429056fab9d755073d Mon Sep 17 00:00:00 2001 From: WeblateGravity <150622038+WeblateGravity@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:26:26 +0300 Subject: [PATCH 4/4] Translations update from Weblate Gravity for PR #1433 (#1447) Co-authored-by: Darya Tikhonova Co-authored-by: Matthew Casserly --- src/i18n-keysets/wizard/en.json | 4 ++-- src/i18n-keysets/wizard/ru.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/i18n-keysets/wizard/en.json b/src/i18n-keysets/wizard/en.json index fca284cd1b..35cbd3a2a8 100644 --- a/src/i18n-keysets/wizard/en.json +++ b/src/i18n-keysets/wizard/en.json @@ -355,13 +355,13 @@ "tooltip_dataset-fetch-failed-details-label": "Learn more", "tooltip_filter_item": "To apply a filter, remove the same field from the Filters from dashboard section.", "tooltip_filters_from_dashboard": "Filters from the dashboard applied to the chart. These filters will not be saved in the chart.", - "tooltip_logarithmic-axis": "The scale with negative values or 0 cannot be logarithmic", + "tooltip_logarithmic-axis": "A scale with negative values or 0 cannot be logarithmic", "tooltip_no-available-fields": "No suitable fields to add", "tooltip_pagination_unavailable": "Pagination is not available for multidataset charts", "tooltip_parameter-changed-icon": "Parameter value changed", "tooltip_tree-pagination_unavailable": "Pagination is not available in a tree table", "tooltip_tree-total_unavailable": "Total is not available in a tree table", - "tooltip_zero-to-max-scale": "The logarithmic scale cannot contain values of 0 or negative values", + "tooltip_zero-to-max-scale": "A logarithmic scale cannot contain values of 0 or negative values", "value_geotype-select-geopoint": "Points (Geopoints)", "value_geotype-select-geopoint-with-cluster": "Points with clusters (Geopoints)", "value_geotype-select-geopolygon": "Polygons (Geopolygons)", diff --git a/src/i18n-keysets/wizard/ru.json b/src/i18n-keysets/wizard/ru.json index 4fd788bd7f..8e030d3de7 100644 --- a/src/i18n-keysets/wizard/ru.json +++ b/src/i18n-keysets/wizard/ru.json @@ -361,7 +361,7 @@ "tooltip_parameter-changed-icon": "Значение параметра изменено", "tooltip_tree-pagination_unavailable": "Пагинация недоступна в таблице с деревьями", "tooltip_tree-total_unavailable": "Итоги недоступны в таблице с деревьями", - "tooltip_zero-to-max-scale": "Логарифмическая шкала не может содержать значения 0 или отрицательные значения", + "tooltip_zero-to-max-scale": "Логарифмическая шкала не может содержать 0 или отрицательные значения", "value_geotype-select-geopoint": "Точки (Геоточки)", "value_geotype-select-geopoint-with-cluster": "Точки с кластеризацией (Геоточки)", "value_geotype-select-geopolygon": "Полигоны (Геoполигоны)",