Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cancel first visible length check #1501

Merged
merged 3 commits into from
Oct 16, 2024
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
14 changes: 8 additions & 6 deletions packages/vrender-components/src/axis/overlap/auto-hide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,21 @@ export function autoHide(labels: IText[], config: HideConfig) {
do {
items = reduce(items, sep);
} while (items.length >= 3 && hasOverlap(items, sep));
/**
* 0.17.10 之前,当最后label个数小于3 的时候,才做最后的label强制显示的策略
*/

const shouldCheck = (length: number, visibility: boolean) => length < 3 || visibility;
const shouldCheck = (length: number, visibility: boolean, checkLength: boolean = true) => {
return checkLength ? length < 3 || visibility : visibility;
};

const checkFirst = shouldCheck(items.length, config.firstVisible);
const checkFirst = shouldCheck(items.length, config.firstVisible, false);
/**
* 0.17.10 之前,当最后 label 个数小于 3 的时候,才做最后的label强制显示的策略
*/
let checkLast = shouldCheck(items.length, config.lastVisible);

const firstSourceItem = source[0];
const lastSourceItem = last(source);

if (intersect(firstSourceItem, lastSourceItem, sep)) {
if (intersect(firstSourceItem, lastSourceItem, sep) && checkFirst && checkLast) {
lastSourceItem.setAttribute('opacity', 0); // Or firstSourceItem, depending on preference
checkLast = false;
}
Expand Down
8 changes: 3 additions & 5 deletions packages/vrender-components/src/axis/tick-data/continuous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ export const continuousTicks = (scale: ContinuousScale, op: ITickDataOpt): ITick
items = samplingMethod(items, labelGap);
}

const shouldCheck = (length: number, visibility: boolean) => length < 3 || visibility;

const checkFirst = shouldCheck(items.length, op.labelFirstVisible);
let checkLast = shouldCheck(items.length, op.labelLastVisible);
const checkFirst = op.labelFirstVisible;
let checkLast = op.labelLastVisible; // 这里和 auto-hide 里的逻辑有差异,不根据 length 自动强制显示最后一个(会引起 vtable 较多 badcase)。

if (intersect(firstSourceItem as any, lastSourceItem as any, labelGap)) {
if (items.includes(lastSourceItem) && items.length > 1) {
if (items.includes(lastSourceItem) && items.length > 1 && checkFirst && checkLast) {
items.splice(items.indexOf(lastSourceItem), 1);
checkLast = false;
}
Expand Down
Loading