rusackas commented on code in PR #38695:
URL: https://github.com/apache/superset/pull/38695#discussion_r3626194969
##########
superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx:
##########
@@ -201,6 +201,30 @@ function createCustomizeSection(
},
},
],
+ [
+ {
+ name: `label_position${controlSuffix}`,
+ config: {
+ type: 'SelectControl',
+ freeForm: false,
+ label: t('Label Position'),
+ choices: [
+ ['top', t('Top')],
+ ['inside', t('Inside')],
+ ['bottom', t('Bottom')],
+ ['left', t('Left')],
+ ['right', t('Right')],
+ ],
+ default: 'top',
+ renderTrigger: true,
Review Comment:
Good catch, fixed! `auto` is back as a choice and the default too.
##########
superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/controlPanel.tsx:
##########
@@ -201,6 +201,30 @@ function createCustomizeSection(
},
},
],
+ [
+ {
+ name: `label_position${controlSuffix}`,
+ config: {
+ type: 'SelectControl',
+ freeForm: false,
+ label: t('Label Position'),
+ choices: [
+ ['top', t('Top')],
+ ['inside', t('Inside')],
+ ['bottom', t('Bottom')],
+ ['left', t('Left')],
+ ['right', t('Right')],
+ ],
+ default: 'top',
+ renderTrigger: true,
+ description: t(
+ 'Position of the data label relative to the bar segment',
Review Comment:
Same fix as Codeant's thread on this control, default's `auto` now, not
`top`.
##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts:
##########
@@ -416,7 +419,13 @@ export function transformSeries(
symbolSize: markerSize,
label: {
show: !!showValue,
- position: isHorizontal ? 'right' : 'top',
+ position:
+ labelPosition === 'auto' || !labelPosition
+ ? isHorizontal
+ ? 'inside'
+ : 'top'
+ : labelPosition,
+ overflow: 'truncate',
Review Comment:
Same fix as the `transformers.ts:170` thread, `labelPosition` is respected
for negative bars now.
##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts:
##########
@@ -748,7 +757,7 @@ export function getPadding(
left:
yAxisTitlePosition === 'Left'
? TIMESERIES_CONSTANTS.gridOffsetLeft +
- (Number(yAxisTitleMargin) || 0)
+ (Number(yAxisTitleMargin) || 0)
: TIMESERIES_CONSTANTS.gridOffsetLeft,
Review Comment:
I think Copilot's off here, ran prettier against this and it's already
compliant.
##########
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts:
##########
@@ -697,6 +697,146 @@ describe('Does transformProps transform series
correctly', () => {
});
});
+ test('should respect labelPosition configuration', () => {
+ const chartProps = createTestChartProps({
+ formData: {
+ ...formData,
+ labelPosition: 'insideBottom',
+ },
+ queriesData,
+ });
+
+ const transformedSeries = transformProps(chartProps).echartOptions
+ .series as any[];
+
+ transformedSeries.forEach(series => {
+ expect(series.label.position).toBe('insideBottom');
+ expect(series.label.overflow).toBeUndefined();
+ });
+ });
+
+ test('should default to top when labelPosition is auto and orientation is
vertical', () => {
+ const chartProps = createTestChartProps({
+ formData: {
+ ...formData,
+ labelPosition: 'auto',
+ orientation: OrientationType.Vertical,
+ },
+ queriesData,
+ });
+
+ const transformedSeries = transformProps(chartProps).echartOptions
+ .series as any[];
+
+ transformedSeries.forEach(series => {
+ expect(series.label.position).toBe('top');
+ expect(series.label.overflow).toBeUndefined();
+ });
+ });
+
+ test('should default to right when labelPosition is auto and orientation is
horizontal', () => {
+ const chartProps = createTestChartProps({
+ formData: {
+ ...formData,
+ labelPosition: 'auto',
+ orientation: OrientationType.Horizontal,
+ },
+ queriesData,
+ });
+
+ const transformedSeries = transformProps(chartProps).echartOptions
+ .series as any[];
+
+ transformedSeries.forEach(series => {
+ expect(series.label.position).toBe('right');
Review Comment:
I think this one's off. The pre-PR default for horizontal was already
`right`, not `inside`, so there's nothing to preserve back to.
##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts:
##########
@@ -416,7 +428,12 @@ export function transformSeries(
symbolSize: markerSize,
label: {
show: !!showValue,
- position: isHorizontal ? 'right' : 'top',
+ position: (labelPosition === 'auto' || !labelPosition
+ ? isHorizontal
+ ? 'right'
+ : 'top'
+ : labelPosition) as any,
Review Comment:
Same as the other thread on this file, pre-PR default was already `right`
here too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]