diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/components/LabelSelector.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/components/LabelSelector.vue index 72ebce865e..5cd8005491 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/components/LabelSelector.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/components/LabelSelector.vue @@ -220,7 +220,37 @@ const isBarRangeTime = computed(() => { } return false }) +watch( + () => props.chart.customAttr.basicStyle.layout, + () => { + const layout = props.chart.customAttr.basicStyle.layout + if (layout === 'horizontal') { + if (state?.labelForm?.position === 'top') { + state.labelForm.position = 'right' + } + if (state?.labelForm?.position === 'bottom') { + state.labelForm.position = 'left' + } + } + if (layout === 'vertical') { + if (state?.labelForm?.position === 'left') { + state.labelForm.position = 'bottom' + } + if (state?.labelForm?.position === 'right') { + state.labelForm.position = 'top' + } + } + changeLabelAttr('position') + }, + { deep: true } +) +const isBarBidirectionalAndVertical = computed(() => { + if (props.chart.type !== 'bidirectional-bar') { + return true + } + return props.chart.customAttr.basicStyle.layout === 'vertical' +}) onMounted(() => { init() }) @@ -298,7 +328,7 @@ onMounted(() => { { + const layoutHorizontal = options.layout === 'horizontal' if (chart.customAttr) { customAttr = parseJson(chart.customAttr) // label @@ -434,7 +436,33 @@ export class BidirectionalHorizontalBar extends G2PlotChartView< } else { res = valueFormatter(value, l.labelFormatter) } - return res + const group = new G2PlotChartView.engine.Group({}) + const isValue = param['series-field-key'] === 'value' + const textAlign = isValue && layoutHorizontal ? 'end' : 'start' + const isMiddle = label.position === 'middle' + group.addShape({ + type: 'text', + attrs: { + x: + isValue && layoutHorizontal && !isMiddle + ? -6 + : !isValue && layoutHorizontal && !isMiddle + ? 6 + : 0, + y: + isValue && !layoutHorizontal && !isMiddle + ? -8 + : !isValue && !layoutHorizontal && !isMiddle + ? 8 + : 0, + text: res, + textAlign: label.position === 'middle' ? 'start' : textAlign, + textBaseline: 'top', + fontSize: labelCfg.fontSize, + fill: labelCfg.color + } + }) + return group } } } else { @@ -442,6 +470,14 @@ export class BidirectionalHorizontalBar extends G2PlotChartView< } } } + if (!layoutHorizontal) { + if (label.position === 'left') { + label.position = 'bottom' + } + if (label.position === 'right') { + label.position = 'top' + } + } return { ...options, label } }