Skip to content
Open
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
23 changes: 22 additions & 1 deletion packages/g6/__tests__/unit/behaviors/auto-adapt-label.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Point, type Graph } from '@/src';
import { AutoAdaptLabel } from '@/src/behaviors';
import { behaviorAutoAdaptLabel } from '@@/demos';
import { createDemoGraph } from '@@/utils';
import { createDemoGraph, sleep } from '@@/utils';

describe('behavior auto adapt label', () => {
let graph: Graph;
Expand Down Expand Up @@ -34,4 +35,24 @@ describe('behavior auto adapt label', () => {
await expect(graph).toMatchSnapshot(__filename, 'zoom-3');
graph.zoomTo(1, false, origin);
});

it('uses viewport filtering after the first render', async () => {
const getLabelElements = jest.spyOn(AutoAdaptLabel.prototype as any, 'getLabelElements');
const getLabelElementsInView = jest.spyOn(AutoAdaptLabel.prototype as any, 'getLabelElementsInView');
const testGraph = await createDemoGraph(behaviorAutoAdaptLabel, { animation: false });

try {
expect(getLabelElements).toHaveBeenCalled();
const callsAfterInitialRender = getLabelElementsInView.mock.calls.length;

testGraph.zoomTo(3, false, [200, 200, 0]);
await sleep(150);

expect(getLabelElementsInView.mock.calls.length).toBeGreaterThan(callsAfterInitialRender);
} finally {
getLabelElements.mockRestore();
getLabelElementsInView.mockRestore();
testGraph.destroy();
}
});
});
1 change: 1 addition & 0 deletions packages/g6/src/behaviors/auto-adapt-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class AutoAdaptLabel extends BaseBehavior<AutoAdaptLabelOptions> {

private onAfterRender = (event: IEvent) => {
this.onToggleVisibility(event);
this.isFirstRender = false;
this.enableToggle = true;
};

Expand Down
Loading