Graph link work in progress

This commit is contained in:
barsdeveloper
2021-12-22 22:24:13 +01:00
parent 93acfb5d33
commit 352f235610
14 changed files with 399 additions and 159 deletions

View File

@@ -1,21 +1,62 @@
import GraphElement from "./GraphElement"
import LinkTemplate from "../template/LinkTemplate"
import GraphPin from "./GraphPin"
/**
* @type {import("./GraphPin").default} GraphPin
*/
export default class GraphLink extends GraphElement {
/** @type {GraphPin} */
#source
/** @type {GraphPin} */
#destination
#nodeDeleteHandler = _ => this.blueprint.removeGraphElement(this)
#nodeDragSourceHandler = _ => this.setSourceLocation(this.#source.getLinkLocation())
#nodeDragDestinatonHandler = _ => this.setDestinationLocation(this.#destination.getLinkLocation())
/**
*
* @typedef {{
* node: String,
* pin: String
* }} PinReference
* @param {?PinReference} source
* @param {?PinReference} destination
* @param {?GraphPin} source
* @param {?GraphPin} destination
*/
constructor(source, destination) {
super(this, new LinkTemplate())
this.source = source
this.destination = destination
/** @type {import("../template/LinkTemplate").default} */
this.template
this.setSource(source)
this.setDestination(destination)
}
setSourceLocation(location) {
this.template.applySourceLocation(this.#source.getLinkLocation())
}
setDestinationLocation(location) {
this.template.applyDestinationLocation(this.#destination.getLinkLocation())
}
/**
* @param {GraphPin} graphPin
*/
setSourcePin(graphPin) {
this.#source?.removeEventListener("ueb-node-delete", this.#nodeDeleteHandler)
this.#source?.removeEventListener("ueb-node-drag", this.#nodeDragSourceHandler)
this.#source = graphPin
this.#source?.addEventListener("ueb-node-delete", this.#nodeDeleteHandler)
this.#source?.addEventListener("ueb-node-drag", this.#nodeDragSourceHandler)
}
/**
*
* @param {GraphPin} graphPin
*/
setDestinationPin(graphPin) {
this.#destination?.removeEventListener("ueb-node-delete", this.#nodeDeleteHandler)
this.#destination?.removeEventListener("ueb-node-drag", this.#nodeDragDestinatonHandler)
this.#destination = graphPin
this.#destination?.addEventListener("ueb-node-delete", this.#nodeDeleteHandler)
this.#destination?.addEventListener("ueb-node-drag", this.#nodeDragDestinatonHandler)
}
}