Skip to content
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
22 changes: 20 additions & 2 deletions src/chart/bar/BarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ function updateStyle(
)
)
: (isHorizontalOrRadial
? ((layout as RectLayout).height >= 0 ? 'bottom' : 'top')
: ((layout as RectLayout).width >= 0 ? 'right' : 'left'));
? getLabelPositionForHorizontal(layout as RectLayout, seriesModel.coordinateSystem)
: getLabelPositionForVertical(layout as RectLayout, seriesModel.coordinateSystem));

const labelStatesModels = getLabelStatesModels(itemModel);

Expand Down Expand Up @@ -1288,4 +1288,22 @@ function createBackgroundEl(
});
}

function getLabelPositionForHorizontal(layout: RectLayout, coordSys: CoordSysOfBar): 'top' | 'bottom' {
if (layout.height === 0) {
// For zero height, determine position based on axis inverse status
const valueAxis = (coordSys as Cartesian2D).getOtherAxis((coordSys as Cartesian2D).getBaseAxis());
return valueAxis.inverse ? 'bottom' : 'top';
}
return layout.height > 0 ? 'bottom' : 'top';
}

function getLabelPositionForVertical(layout: RectLayout, coordSys: CoordSysOfBar): 'left' | 'right' {
if (layout.width === 0) {
// For zero width, determine position based on axis inverse status
const valueAxis = (coordSys as Cartesian2D).getOtherAxis((coordSys as Cartesian2D).getBaseAxis());
return valueAxis.inverse ? 'left' : 'right';
}
return layout.width >= 0 ? 'right' : 'left';
}

export default BarView;
119 changes: 119 additions & 0 deletions test/bar-zero-label.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.