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 a setting for the Y-axis of the area chart to connect empty values #1680

Merged
merged 4 commits into from
Oct 31, 2024
Merged
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
1 change: 1 addition & 0 deletions src/i18n-keysets/wizard/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"label_two-color": "Two colors",
"label_type": "Type",
"label_type-preaggregated": "Type (before aggregation)",
"label_use-previous": "Use previous",
"label_value": "Value",
"label_vertical": "Vertical",
"label_violet": "Violet (shades)",
Expand Down
1 change: 1 addition & 0 deletions src/i18n-keysets/wizard/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
"label_two-color": "Два цвета",
"label_type": "Тип",
"label_type-preaggregated": "Тип (до агрегации)",
"label_use-previous": "Использовать предыдущее",
"label_value": "Значение",
"label_vertical": "Вертикальные",
"label_violet": "Фиолетовый (оттенки)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import _isEmpty from 'lodash/isEmpty';
import isNil from 'lodash/isNil';

import type {HighchartsSeriesCustomObject} from '../../../../../../../shared';
import {
AxisMode,
AxisNullsMode,
PlaceholderId,
WizardVisualizationId,
getAxisNullsSettings,
getFakeTitleOrTitle,
getXAxisMode,
isDateField,
Expand Down Expand Up @@ -131,12 +133,6 @@ export function prepareLineData(args: PrepareFunctionArgs) {
measureColorSortLine[getFakeTitleOrTitle(colorItem)] = {data: {}};
}

const defaultNullValue =
visualizationId === WizardVisualizationId.Area ||
visualizationId === WizardVisualizationId.Area100p
? AxisNullsMode.AsZero
: AxisNullsMode.Connect;

const nullsY1 = yPlaceholder?.settings?.nulls;
const nullsY2 = y2Placeholder?.settings?.nulls;

Expand Down Expand Up @@ -335,12 +331,16 @@ export function prepareLineData(args: PrepareFunctionArgs) {
nulls = nullsY2;
}

nulls = nulls || defaultNullValue;
nulls = getAxisNullsSettings(nulls, visualizationId);

const innerLabels = labelsValues[lineKey];

const customSeriesData: HighchartsSeriesCustomObject = {};

const shouldUsePreviousValueForEmptyPoint =
visualizationId === WizardVisualizationId.Area &&
nulls === AxisNullsMode.UsePrevious;
let prevYValue: string | number | null | undefined = null;
const graph: any = {
id: line.id,
title: line.title || 'Null',
Expand All @@ -357,6 +357,14 @@ export function prepareLineData(args: PrepareFunctionArgs) {
value = 0;
}

if (shouldUsePreviousValueForEmptyPoint) {
if (isNil(value)) {
value = prevYValue ?? value;
} else {
prevYValue = value;
}
}

// We can skip a point only if we put x in each point instead of categories
if (
!isXCategoryAxis &&
Expand Down
16 changes: 16 additions & 0 deletions src/shared/modules/wizard/axis-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {WizardVisualizationId} from '../../constants';
import {AxisNullsMode} from '../../types';

export function getAxisNullsSettings(value: AxisNullsMode, visualizationId: string) {
const isArea =
visualizationId === WizardVisualizationId.Area ||
visualizationId === WizardVisualizationId.Area100p;
const defaultValue = isArea ? AxisNullsMode.AsZero : AxisNullsMode.Connect;
const isCurrentValueValid = value && !(value === AxisNullsMode.UsePrevious && !isArea);

if (isCurrentValueValid) {
return value;
}

return defaultValue;
}
1 change: 1 addition & 0 deletions src/shared/modules/wizard/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './axis-mode';
export * from './axis-settings';
export * from './config';
1 change: 1 addition & 0 deletions src/shared/types/wizard/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ export const enum AxisNullsMode {
Ignore = 'ignore',
Connect = 'connect',
AsZero = 'as-0',
UsePrevious = 'use-previous',
}
1 change: 1 addition & 0 deletions src/ui/constants/visualizations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const SETTINGS = {
IGNORE: AxisNullsMode.Ignore,
CONNECT: AxisNullsMode.Connect,
AS_ZERO: AxisNullsMode.AsZero,
USE_PREVIOUS: AxisNullsMode.UsePrevious,
},
HOLIDAYS: {
ON: 'on',
Expand Down
2 changes: 1 addition & 1 deletion src/ui/constants/visualizations/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const LINE_VISUALIZATION: GraphShared['visualization'] = {
availableLabelModes: ['absolute'],
onDesignItemsChange: onLineChartDesignItemsChange,
placeholders: [
LineXPlaceholder,
{...LineXPlaceholder},
LineYPlaceholder,
{
allowedTypes: ITEM_TYPES.DIMENSIONS_AND_MEASURES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import block from 'bem-cn-lite';
import DialogManager from 'components/DialogManager/DialogManager';
import {i18n} from 'i18n';
import type {
AxisNullsMode,
Field,
Placeholder,
PlaceholderSettings,
ServerChartsConfig,
ServerPlaceholderSettings,
ServerSort,
WizardVisualizationId,
} from 'shared';
import {
DialogPlaceholderQa,
Feature,
PlaceholderId,
WizardVisualizationId,
getAxisMode,
getAxisNullsSettings,
hasSortThanAffectAxisMode,
isContinuousAxisModeDisabled,
isFieldHierarchy,
Expand Down Expand Up @@ -206,16 +208,26 @@ class DialogPlaceholder extends React.PureComponent<Props, State> {
nullsOptions.splice(1, 0, connectOption);
}

if (visualizationId === WizardVisualizationId.Area) {
nullsOptions.push({
value: SETTINGS.NULLS.USE_PREVIOUS,
content: i18n('wizard', 'label_use-previous'),
});
}

const selectedValue = getAxisNullsSettings(
settings.nulls as AxisNullsMode,
visualizationId,
);

return (
<DialogPlaceholderRow
settingCustomWidth="400px"
title={i18n('wizard', 'label_nulls')}
setting={
<DialogRadioButtons
stretched={true}
qa="connect-nulls-radio-buttons"
items={nullsOptions}
value={settings.nulls}
value={selectedValue}
onUpdate={this.handleNullsRadioButtonUpdate}
/>
}
Expand Down
8 changes: 6 additions & 2 deletions tests/suites/wizard/placeholder-settings/connectNulls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ datalensTest.describe('Wizard - placeholder dialog ("Empty values (null)") ', ()
});

datalensTest(
'For a chart with areas, only 2 settings are available "Do not display", "Display as 0" and "Display as 0" is selected',
'For a chart with areas, 3 settings are available and "Display as 0" is selected',
async ({page}: {page: Page}) => {
const wizardPage = new WizardPage({page});

const expectedValues = [AxisNullsMode.Ignore, AxisNullsMode.AsZero];
const expectedValues = [
AxisNullsMode.Ignore,
AxisNullsMode.AsZero,
AxisNullsMode.UsePrevious,
];

await openTestPage(page, RobotChartsWizardUrls.WizardForDatasetSampleCh);

Expand Down
Loading