Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

feat(legend-continonus): set labelOverlap to hide by default #296

Merged
merged 1 commit into from
Jul 6, 2023
Merged
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
19 changes: 18 additions & 1 deletion src/ui/legend/continuous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class Continuous extends GUI<ContinuousStyleProps> {
/** adjust */
this.adjustLabel();
this.adjustHandles();
// this.adjustTitle();
}

private get range() {
Expand Down Expand Up @@ -341,6 +342,22 @@ export class Continuous extends GUI<ContinuousStyleProps> {
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() {
Expand Down Expand Up @@ -473,7 +490,7 @@ export class Continuous extends GUI<ContinuousStyleProps> {
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);
Expand Down