make more generic
This commit is contained in:
parent
f6303b7d23
commit
8468f02d31
|
|
@ -2,15 +2,15 @@ import { FolkBaseSet } from './folk-base-set.ts';
|
||||||
import { PropertyValues } from '@lit/reactive-element';
|
import { PropertyValues } from '@lit/reactive-element';
|
||||||
import { Layout } from 'webcola';
|
import { Layout } from 'webcola';
|
||||||
import { FolkShape } from './folk-shape.ts';
|
import { FolkShape } from './folk-shape.ts';
|
||||||
import { FolkArrow } from './folk-arrow.ts';
|
|
||||||
import { AnimationFrameController, AnimationFrameControllerHost } from './common/animation-frame-controller.ts';
|
import { AnimationFrameController, AnimationFrameControllerHost } from './common/animation-frame-controller.ts';
|
||||||
|
import { FolkBaseConnection } from './folk-base-connection';
|
||||||
|
|
||||||
export class FolkGraph extends FolkBaseSet implements AnimationFrameControllerHost {
|
export class FolkGraph extends FolkBaseSet implements AnimationFrameControllerHost {
|
||||||
static override tagName = 'folk-graph';
|
static override tagName = 'folk-graph';
|
||||||
|
|
||||||
private graphSim = new Layout();
|
private graphSim = new Layout();
|
||||||
private nodes = new Map<FolkShape, number>();
|
private nodes = new Map<FolkShape, number>();
|
||||||
private arrows = new Set<FolkArrow>();
|
private arrows = new Set<FolkBaseConnection>();
|
||||||
#rAF = new AnimationFrameController(this);
|
#rAF = new AnimationFrameController(this);
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
|
|
@ -29,7 +29,7 @@ export class FolkGraph extends FolkBaseSet implements AnimationFrameControllerHo
|
||||||
|
|
||||||
override update(changedProperties: PropertyValues<this>) {
|
override update(changedProperties: PropertyValues<this>) {
|
||||||
super.update(changedProperties);
|
super.update(changedProperties);
|
||||||
this.updateGraph();
|
this.createGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
|
|
@ -48,7 +48,7 @@ export class FolkGraph extends FolkBaseSet implements AnimationFrameControllerHo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateGraph() {
|
private createGraph() {
|
||||||
this.nodes.clear();
|
this.nodes.clear();
|
||||||
this.arrows.clear();
|
this.arrows.clear();
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ export class FolkGraph extends FolkBaseSet implements AnimationFrameControllerHo
|
||||||
|
|
||||||
private createLinks() {
|
private createLinks() {
|
||||||
return Array.from(this.sourceElements)
|
return Array.from(this.sourceElements)
|
||||||
.filter((element): element is FolkArrow => element instanceof FolkArrow)
|
.filter((element): element is FolkBaseConnection => element instanceof FolkBaseConnection)
|
||||||
.map((arrow) => {
|
.map((arrow) => {
|
||||||
this.arrows.add(arrow);
|
this.arrows.add(arrow);
|
||||||
const source = this.nodes.get(arrow.sourceElement as FolkShape);
|
const source = this.nodes.get(arrow.sourceElement as FolkShape);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue