Skip to content

Commit 67d1385

Browse files
authored
Enable startOnTick and endOnTick for line,bar-x and area (#3561)
1 parent 6accd7f commit 67d1385

File tree

38 files changed

+108
-73
lines changed

38 files changed

+108
-73
lines changed

src/server/modes/charts/plugins/datalens/preparers/area/index.ts

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
AreaSeriesData,
44
ChartData,
55
ChartSeries,
6-
ChartYAxis,
76
} from '@gravity-ui/chartkit/gravity-charts';
87
import merge from 'lodash/merge';
98
import sortBy from 'lodash/sortBy';
@@ -31,6 +30,7 @@ import {getFieldFormatOptions} from '../../gravity-charts/utils/format';
3130
import {getConfigWithActualFieldTypes} from '../../utils/config-helpers';
3231
import {getExportColumnSettings} from '../../utils/export-helpers';
3332
import {getAxisFormatting, getAxisType} from '../helpers/axis';
33+
import {DATA_LABEL_DEFAULT_PADDING} from '../helpers/axis/data-labels';
3434
import {getSegmentMap} from '../helpers/segments';
3535
import {prepareLineData} from '../line/prepare-line-data';
3636
import type {PrepareFunctionArgs} from '../types';
@@ -214,6 +214,7 @@ export function prepareGravityChartArea(args: PrepareFunctionArgs) {
214214
enabled: isDataLabelsEnabled,
215215
html: shouldUseHtmlForLabels,
216216
format: labelFormatting,
217+
padding: DATA_LABEL_DEFAULT_PADDING,
217218
},
218219
custom: {
219220
...graph.custom,
@@ -263,51 +264,58 @@ export function prepareGravityChartArea(args: PrepareFunctionArgs) {
263264
}
264265
}
265266

267+
const config: ChartData = {
268+
series: {
269+
data: seriesData as ChartSeries[],
270+
},
271+
xAxis,
272+
legend,
273+
};
274+
266275
const axisLabelNumberFormat = yPlaceholder
267276
? getAxisFormatting({
268277
placeholder: yPlaceholder,
269278
visualizationId,
270279
})
271280
: undefined;
272281

273-
const config: ChartData = {
274-
series: {
275-
data: seriesData as ChartSeries[],
282+
const yAxisBaseConfig = merge(
283+
getYAxisBaseConfig({
284+
placeholder: yPlaceholder,
285+
}),
286+
{
287+
labels: {
288+
numberFormat: axisLabelNumberFormat ?? undefined,
289+
},
290+
startOnTick: true,
291+
endOnTick: true,
292+
maxPadding: 0.001,
276293
},
277-
xAxis,
278-
yAxis: segments.map((d) => {
279-
const baseConfig = getYAxisBaseConfig({
280-
placeholder: yPlaceholder,
281-
});
282-
let axisTitle: ChartYAxis['title'] | null = null;
283-
if (isSplitEnabled) {
284-
let titleText: string = d.title;
285-
if (isSplitWithHtmlValues) {
286-
// @ts-ignore There may be a type mismatch due to the wrapper over html, markup and markdown
287-
titleText = wrapHtml(d.title);
288-
}
289-
290-
axisTitle = {
291-
text: titleText,
292-
rotation: 0,
293-
maxWidth: '25%',
294-
html: isSplitWithHtmlValues,
295-
};
294+
);
295+
296+
if (isSplitEnabled) {
297+
config.yAxis = segments.map((d) => {
298+
let titleText: string = d.title;
299+
if (isSplitWithHtmlValues) {
300+
// @ts-ignore There may be a type mismatch due to the wrapper over html, markup and markdown
301+
titleText = wrapHtml(d.title);
296302
}
297303

298-
return merge(baseConfig, {
299-
lineColor: 'transparent',
300-
labels: {
301-
numberFormat: axisLabelNumberFormat ?? undefined,
302-
},
304+
const axisTitle = {
305+
text: titleText,
306+
rotation: 0,
307+
maxWidth: '25%',
308+
html: isSplitWithHtmlValues,
309+
};
310+
311+
return merge(yAxisBaseConfig, {
303312
plotIndex: d.index,
304313
title: axisTitle,
305-
startOnTick: isSplitEnabled,
306-
endOnTick: isSplitEnabled,
307314
});
308-
}),
309-
legend,
310-
};
315+
});
316+
} else {
317+
config.yAxis = [{...yAxisBaseConfig, lineColor: 'transparent'}];
318+
}
311319

312320
if (isSplitEnabled) {
313321
config.split = {

src/server/modes/charts/plugins/datalens/preparers/bar-x/gravity-charts.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
BarXSeriesData,
44
ChartData,
55
ChartSeries,
6-
ChartYAxis,
76
} from '@gravity-ui/chartkit/gravity-charts';
87
import merge from 'lodash/merge';
98
import sortBy from 'lodash/sortBy';
@@ -40,6 +39,7 @@ import {getConfigWithActualFieldTypes} from '../../utils/config-helpers';
4039
import {getExportColumnSettings} from '../../utils/export-helpers';
4140
import {isGradientMode} from '../../utils/misc-helpers';
4241
import {getAxisFormatting, getAxisType} from '../helpers/axis';
42+
import {DATA_LABEL_DEFAULT_PADDING} from '../helpers/axis/data-labels';
4343
import {isXAxisReversed} from '../helpers/highcharts';
4444
import {getLegendColorScale, shouldUseGradientLegend} from '../helpers/legend';
4545
import {getSegmentMap} from '../helpers/segments';
@@ -253,6 +253,7 @@ export function prepareGravityChartBarX(args: PrepareFunctionArgs) {
253253
inside: shared.extraSettings?.labelsPosition !== LabelsPositions.Outside,
254254
html: shouldUseHtmlForLabels,
255255
format: labelFormatting,
256+
padding: DATA_LABEL_DEFAULT_PADDING,
256257
},
257258
yAxis: graph.yAxis,
258259
rangeSlider,
@@ -351,38 +352,45 @@ export function prepareGravityChartBarX(args: PrepareFunctionArgs) {
351352
},
352353
legend,
353354
xAxis,
354-
yAxis: segments.map((d) => {
355-
const axisBaseConfig = getYAxisBaseConfig({
356-
placeholder: yPlaceholder,
357-
});
355+
};
358356

359-
let axisTitle: ChartYAxis['title'] | null = null;
360-
if (isSplitEnabled) {
361-
let titleText: string = d.title;
362-
if (isSplitWithHtmlValues) {
363-
// @ts-ignore There may be a type mismatch due to the wrapper over html, markup and markdown
364-
titleText = wrapHtml(d.title);
365-
}
357+
const yAxisBaseConfig = merge(
358+
getYAxisBaseConfig({
359+
placeholder: yPlaceholder,
360+
}),
361+
{
362+
labels: {
363+
numberFormat: axisLabelNumberFormat ?? undefined,
364+
},
365+
startOnTick: true,
366+
endOnTick: true,
367+
maxPadding: 0.001,
368+
},
369+
);
366370

367-
axisTitle = {
368-
text: titleText,
369-
rotation: 0,
370-
maxWidth: '25%',
371-
html: isSplitWithHtmlValues,
372-
};
371+
if (isSplitEnabled) {
372+
config.yAxis = segments.map((d) => {
373+
let titleText: string = d.title;
374+
if (isSplitWithHtmlValues) {
375+
// @ts-ignore There may be a type mismatch due to the wrapper over html, markup and markdown
376+
titleText = wrapHtml(d.title);
373377
}
374378

375-
return merge(axisBaseConfig, {
376-
labels: {
377-
numberFormat: axisLabelNumberFormat ?? undefined,
378-
},
379+
const axisTitle = {
380+
text: titleText,
381+
rotation: 0,
382+
maxWidth: '25%',
383+
html: isSplitWithHtmlValues,
384+
};
385+
386+
return merge(yAxisBaseConfig, {
379387
plotIndex: d.index,
380388
title: axisTitle,
381-
startOnTick: isSplitEnabled,
382-
endOnTick: isSplitEnabled,
383389
});
384-
}),
385-
};
390+
});
391+
} else {
392+
config.yAxis = [{...yAxisBaseConfig, lineColor: 'transparent'}];
393+
}
386394

387395
if (isSplitEnabled) {
388396
config.split = {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DATA_LABEL_DEFAULT_PADDING = 3;

src/server/modes/charts/plugins/datalens/preparers/line/gravity-charts.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {getSeriesRangeSliderConfig} from '../../gravity-charts/utils/range-slide
3434
import {getConfigWithActualFieldTypes} from '../../utils/config-helpers';
3535
import {getExportColumnSettings} from '../../utils/export-helpers';
3636
import {getAxisFormatting, getAxisType, getYAxisPlaceholders} from '../helpers/axis';
37+
import {DATA_LABEL_DEFAULT_PADDING} from '../helpers/axis/data-labels';
3738
import {isXAxisReversed} from '../helpers/highcharts';
3839
import {getSegmentMap} from '../helpers/segments';
3940
import type {PrepareFunctionArgs} from '../types';
@@ -203,6 +204,7 @@ export function prepareGravityChartLine(args: PrepareFunctionArgs) {
203204
enabled: isDataLabelsEnabled,
204205
html: shouldUseHtmlForLabels,
205206
format: labelFormatting,
207+
padding: DATA_LABEL_DEFAULT_PADDING,
206208
},
207209
legend: {
208210
symbol: {
@@ -297,19 +299,24 @@ export function prepareGravityChartLine(args: PrepareFunctionArgs) {
297299
};
298300
}
299301

300-
acc.push(
301-
merge(axisBaseConfig, {
302-
title: axisTitle,
303-
plotIndex: d.plotIndex,
304-
labels: {
305-
numberFormat: labelNumberFormat ?? undefined,
306-
},
307-
lineColor: 'transparent',
308-
position: placeholder?.id === PlaceholderId.Y2 ? 'right' : 'left',
309-
startOnTick: true,
310-
endOnTick: true,
311-
}),
312-
);
302+
const chartYAxis = merge(axisBaseConfig, {
303+
title: axisTitle,
304+
plotIndex: d.plotIndex,
305+
labels: {
306+
numberFormat: labelNumberFormat ?? undefined,
307+
},
308+
position: placeholder?.id === PlaceholderId.Y2 ? 'right' : 'left',
309+
});
310+
311+
if (chartYAxis.min === undefined) {
312+
chartYAxis.startOnTick = true;
313+
}
314+
315+
if (chartYAxis.max === undefined) {
316+
chartYAxis.endOnTick = true;
317+
}
318+
319+
acc.push(chartYAxis);
313320

314321
return acc;
315322
}, [] as ChartYAxis[]);
@@ -326,13 +333,24 @@ export function prepareGravityChartLine(args: PrepareFunctionArgs) {
326333
placeholder,
327334
});
328335

329-
return merge(axisBaseConfig, {
336+
const chartYAxis = merge(axisBaseConfig, {
330337
labels: {
331338
numberFormat: labelNumberFormat ?? undefined,
332339
},
333340
lineColor: 'transparent',
334341
position: placeholder?.id === PlaceholderId.Y2 ? 'right' : 'left',
342+
maxPadding: 0.001,
335343
});
344+
345+
if (chartYAxis.min === undefined) {
346+
chartYAxis.startOnTick = true;
347+
}
348+
349+
if (chartYAxis.max === undefined) {
350+
chartYAxis.endOnTick = true;
351+
}
352+
353+
return chartYAxis;
336354
});
337355
}
338356

Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)