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

feat(graph-viz): simulated demo request data node is centered #958

Merged
merged 4 commits into from
Jul 29, 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
12 changes: 12 additions & 0 deletions src/app/graph-viz/graph-viz.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
>
<app-zoom-toolbar></app-zoom-toolbar>
</plait-board>
<div style="position: absolute;z-index: 9999;left: 0;top: 0;">
<button (click)="fetchForceAtlasData(0)">数据1</button>
<button (click)="fetchForceAtlasData(1)">数据2</button>
<button (click)="fetchForceAtlasData(2)">数据3</button>
<button (click)="fetchForceAtlasData(3)">数据4</button>
<button (click)="fetchForceAtlasData(4)">数据5</button>
<button (click)="fetchForceAtlasData(5)">数据6</button>
<button (click)="fetchForceAtlasData(6)">数据7</button>
<button (click)="fetchForceAtlasData(7)">数据8</button>
<button (click)="fetchForceAtlasData(8)">数据9</button>
<button (click)="fetchForceAtlasData(9)">数据10</button>
</div>
<!-- @if (board) {
<debug-point-display [board]="board"></debug-point-display>
} -->
31 changes: 28 additions & 3 deletions src/app/graph-viz/graph-viz.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
temporaryDisableSelection,
PlaitOptionsBoard,
PlaitPluginKey,
WithSelectionPluginOptions
WithSelectionPluginOptions,
PlaitElement
} from '@plait/core';
import { mockForceAtlasData } from './mock-force-atlas';
import { ForceAtlasElement, ForceAtlasNodeElement, withForceAtlas } from '@plait/graph-viz';
Expand All @@ -29,6 +30,7 @@ import { NgIf } from '@angular/common';
import { OnChangeData, PlaitBoardComponent } from '@plait/angular-board';
import { withForceAtlasExtend } from './with-force-atlas-extend';
import { DebugPointDisplayComponent } from '../components/debug/point-display.component';
import { getData } from './mock-force-atlas-wiki';

@Component({
selector: 'app-basic-graph-viz',
Expand Down Expand Up @@ -75,7 +77,7 @@ export class BasicGraphVizComponent implements OnInit {
const init = params['init'];
switch (init) {
case 'force-atlas':
this.value = mockForceAtlasData;
this.fetchForceAtlasData(0);
break;
default:
this.value = [];
Expand All @@ -84,6 +86,18 @@ export class BasicGraphVizComponent implements OnInit {
});
}

fetchForceAtlasData(index: number = 0) {
setTimeout(() => {
this.value = getData(index);
setTimeout(() => {
const selectedElement = getSelectedElements(this.board)[0];
if (selectedElement) {
this.moveBoardToCenter(selectedElement);
}
}, 0);
}, 300);
}

onChange(event: OnChangeData) {
const selectedElements = getSelectedElements(this.board);
const selectedElement = selectedElements[0];
Expand Down Expand Up @@ -129,7 +143,7 @@ export class BasicGraphVizComponent implements OnInit {
if (targetNodeElement) {
if (this.hasViewportMoved || (!this.hasViewportMoved && this.currentNodeId !== targetNodeElement.id)) {
console.log('move to center');
BoardTransforms.moveToCenter(this.board, targetNodeElement.points![0]);
this.moveBoardToCenter(targetNodeElement);
// to wait moving completing and mark viewport as unmoved
setTimeout(() => {
this.hasViewportMoved = false;
Expand All @@ -142,6 +156,17 @@ export class BasicGraphVizComponent implements OnInit {
}, 250);
};
}

moveBoardToCenter(selectedElement: PlaitElement) {
if (selectedElement && selectedElement.points) {
setTimeout(() => {
BoardTransforms.moveToCenter(this.board, selectedElement.points![0]);
setTimeout(() => {
this.hasViewportMoved = false;
}, 0);
}, 0);
}
}
}

export const getHitForceAtlasNode = (board: PlaitBoard, e: PointerEvent) => {
Expand Down
Loading
Loading