From fb891ff9c8c6f1d1085fd341a65179f4dddb7f92 Mon Sep 17 00:00:00 2001 From: 019327 Date: Fri, 25 Jul 2025 15:07:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89coord=E7=9A=84=E5=AE=BD=E5=BA=A6?= =?UTF-8?q?=E5=92=8C=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/Axis.ts | 2 ++ src/view/GridView.ts | 32 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/component/Axis.ts b/src/component/Axis.ts index 3488b0f20..ee2536dcd 100644 --- a/src/component/Axis.ts +++ b/src/component/Axis.ts @@ -23,6 +23,8 @@ export interface AxisTick { coord: number value: number | string text: string + height?: number + width?: number } export interface AxisRange extends VisibleRange { diff --git a/src/view/GridView.ts b/src/view/GridView.ts index 0bc3e248b..11902195e 100644 --- a/src/view/GridView.ts +++ b/src/view/GridView.ts @@ -33,12 +33,16 @@ export default class GridView extends View { const horizontalShow = horizontalStyles.show if (horizontalShow) { const yAxis = pane.getAxisComponent() - const attrs: LineAttrs[] = yAxis.getTicks().map(tick => ({ - coordinates: [ - { x: 0, y: tick.coord }, - { x: bounding.width, y: tick.coord } - ] - })) + const attrs: LineAttrs[] = yAxis.getTicks().map(tick => { + // 如果 tick 有自定义的 width,使用 tick.width,否则使用 bounding.width + const lineWidth = tick.width ?? bounding.width + return { + coordinates: [ + { x: 0, y: tick.coord }, + { x: lineWidth, y: tick.coord } + ] + } + }) this.createFigure({ name: 'line', attrs, @@ -49,12 +53,16 @@ export default class GridView extends View { const verticalShow = verticalStyles.show if (verticalShow) { const xAxis = chart.getXAxisPane().getAxisComponent() - const attrs: LineAttrs[] = xAxis.getTicks().map(tick => ({ - coordinates: [ - { x: tick.coord, y: 0 }, - { x: tick.coord, y: bounding.height } - ] - })) + const attrs: LineAttrs[] = xAxis.getTicks().map(tick => { + // 如果 tick 有自定义的 height,使用 tick.height,否则使用 bounding.height + const lineHeight = tick.height ?? bounding.height + return { + coordinates: [ + { x: tick.coord, y: 0 }, + { x: tick.coord, y: lineHeight } + ] + } + }) this.createFigure({ name: 'line', attrs,