From 9e5d333523fed0a02ed90fe6f4596c242ca21c9b Mon Sep 17 00:00:00 2001 From: MiniPear Date: Thu, 6 Jul 2023 11:04:03 +0800 Subject: [PATCH] feat(legend-continous): set labelOverlap to hide by default --- src/ui/legend/continuous.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ui/legend/continuous.ts b/src/ui/legend/continuous.ts index b12fadd50..258b717f2 100644 --- a/src/ui/legend/continuous.ts +++ b/src/ui/legend/continuous.ts @@ -111,6 +111,7 @@ export class Continuous extends GUI { /** adjust */ this.adjustLabel(); this.adjustHandles(); + // this.adjustTitle(); } private get range() { @@ -341,6 +342,22 @@ export class Continuous extends GUI { this.setHandlePosition('end', max); } + private adjustTitle() { + const { titlePosition, orientation } = this.attributes; + const [title] = this.getElementsByClassName(CLASS_NAMES.title.name); + const handle: Handle = this.handlesGroup.select(`.${this.getHandleClassName('start')}`).node(); + if (!title || !handle) return; + if (titlePosition !== 'top-left' || orientation !== 'horizontal') return; + const { + min: [handleX], + } = handle.getLocalBounds(); + const { + min: [titleX], + } = title.getLocalBounds(); + const diffX = handleX - titleX; + title.style.x = +(this.style.x || 0) + diffX; + } + private cacheHandleBBox: DOMRect | null = null; private get handleBBox() { @@ -473,7 +490,7 @@ export class Continuous extends GUI { labelFormatter, }; - const finalLabelStyle = { ...style, ...functionStyle } as LinearAxisStyleProps; + const finalLabelStyle = { ...style, ...functionStyle, labelOverlap: [{ type: 'hide' }] } as LinearAxisStyleProps; this.label = container.maybeAppendByClassName(CLASS_NAMES.label, () => new Axis({ style: finalLabelStyle })).node(); this.label.update(finalLabelStyle, false);