Skip to content

Commit cbf5c62

Browse files
committed
fix(bar): wrong data label position when bar width/height is 0
1 parent 38116d0 commit cbf5c62

File tree

2 files changed

+139
-2
lines changed

2 files changed

+139
-2
lines changed

src/chart/bar/BarView.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,8 @@ function updateStyle(
10411041
)
10421042
)
10431043
: (isHorizontalOrRadial
1044-
? ((layout as RectLayout).height >= 0 ? 'bottom' : 'top')
1045-
: ((layout as RectLayout).width >= 0 ? 'right' : 'left'));
1044+
? getLabelPositionForHorizontal(layout as RectLayout, seriesModel.coordinateSystem)
1045+
: getLabelPositionForVertical(layout as RectLayout, seriesModel.coordinateSystem));
10461046

10471047
const labelStatesModels = getLabelStatesModels(itemModel);
10481048

@@ -1288,4 +1288,22 @@ function createBackgroundEl(
12881288
});
12891289
}
12901290

1291+
function getLabelPositionForHorizontal(layout: RectLayout, coordSys: CoordSysOfBar): 'top' | 'bottom' {
1292+
if (layout.height === 0) {
1293+
// For zero height, determine position based on axis inverse status
1294+
const valueAxis = (coordSys as Cartesian2D).getOtherAxis((coordSys as Cartesian2D).getBaseAxis());
1295+
return valueAxis.inverse ? 'bottom' : 'top';
1296+
}
1297+
return layout.height > 0 ? 'bottom' : 'top';
1298+
}
1299+
1300+
function getLabelPositionForVertical(layout: RectLayout, coordSys: CoordSysOfBar): 'left' | 'right' {
1301+
if (layout.width === 0) {
1302+
// For zero width, determine position based on axis inverse status
1303+
const valueAxis = (coordSys as Cartesian2D).getOtherAxis((coordSys as Cartesian2D).getBaseAxis());
1304+
return valueAxis.inverse ? 'left' : 'right';
1305+
}
1306+
return layout.width >= 0 ? 'right' : 'left';
1307+
}
1308+
12911309
export default BarView;

test/bar-zero-label.html

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)