From 72408f7660c03843a156e06ffe2405ed3fa82f63 Mon Sep 17 00:00:00 2001 From: lichengzhan Date: Wed, 27 Nov 2024 10:48:36 +0800 Subject: [PATCH] feat(grid): enhance label containment logic to support directional constraints --- src/coord/cartesian/Grid.ts | 6 ++++++ src/coord/cartesian/GridModel.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/coord/cartesian/Grid.ts b/src/coord/cartesian/Grid.ts index d22ddef556..c43019d2aa 100644 --- a/src/coord/cartesian/Grid.ts +++ b/src/coord/cartesian/Grid.ts @@ -187,6 +187,12 @@ class Grid implements CoordinateSystemMaster { // Minus label size if (isContainLabel) { each(axesList, function (axis) { + if ( + (isContainLabel === 'horizontal' && !axis.isHorizontal()) + || (isContainLabel === 'vertical' && axis.isHorizontal()) + ) { + return; + } if (!axis.model.get(['axisLabel', 'inside'])) { const labelUnionRect = estimateLabelUnionRect(axis); if (labelUnionRect) { diff --git a/src/coord/cartesian/GridModel.ts b/src/coord/cartesian/GridModel.ts index 5e2f438608..d0f514cb6d 100644 --- a/src/coord/cartesian/GridModel.ts +++ b/src/coord/cartesian/GridModel.ts @@ -28,8 +28,8 @@ export interface GridOption extends ComponentOption, BoxLayoutOptionMixin, Shado show?: boolean; - // Whether grid size contain label. - containLabel?: boolean; + // Whether grid size contain label from which direction the labels are contained + containLabel?: boolean | 'horizontal' | 'vertical'; backgroundColor?: ZRColor; borderWidth?: number;