From 2e45b2c31aefda4874611acbba94e95064ba4cb6 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 28 Jun 2023 18:22:29 +0200 Subject: [PATCH] simple clickable --- js/PElems/Edge.ts | 9 ++++++++- js/PElems/Node.ts | 10 ++++++++-- js/graphics/SVGArrow.ts | 10 +++++++++- js/graphics/tragable.ts | 5 +++++ js/index.ts | 3 +++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/js/PElems/Edge.ts b/js/PElems/Edge.ts index 3a16feb..2d3add2 100644 --- a/js/PElems/Edge.ts +++ b/js/PElems/Edge.ts @@ -1,4 +1,4 @@ -import { svgArrows } from ".."; +import { svgArrows, update } from ".."; import { SVGArrow } from "../graphics/SVGArrow"; import { Node } from "./Node"; import { Transition } from "./Transition"; @@ -16,6 +16,13 @@ export class Edge { this.renderedElement = inEdge ? new SVGArrow(end, trans) : new SVGArrow(trans, end); this.renderedElement.appendIt(svgArrows); end.updateList.push(this); + this.renderedElement.onClick(() => { + let aws = parseInt(prompt("Gebe die Dimension ein:", this.dimension + "") || ""); + if (isNaN(aws) || !isFinite(aws) || aws < 1) return; + this.dimension = aws; + this.renderedElement.setDimension(aws + ""); + update(); + }) } canSuck() { return this.end.marks >= this.dimension; diff --git a/js/PElems/Node.ts b/js/PElems/Node.ts index 6f5dfda..feb7e76 100644 --- a/js/PElems/Node.ts +++ b/js/PElems/Node.ts @@ -21,9 +21,15 @@ export class Node implements Positionable { this.renderedElement.appendIt(svgNodes); this.renderedElement.onMove((event) => this.updatePosition(event.x, event.y)); this.renderedElement.onClick((event) => { - if (this.marks < this.capacity) this.marks++ + let aws = parseInt(prompt("Gabe die maximale Anzahl an Marken ein:", this.capacity + "") || ""); + if (isNaN(aws) || !isFinite(aws) || aws < 1) return; + this.capacity = aws; + aws = parseInt(prompt("Gabe die aktuelle Anzahl an Marken ein:", this.marks + "") || ""); + if (isNaN(aws) || !isFinite(aws) || aws < 1) return; + this.marks = aws; + //if (this.marks < this.capacity) this.marks++ update(); - }) + }); } updatePoints() { diff --git a/js/graphics/SVGArrow.ts b/js/graphics/SVGArrow.ts index 0f88512..34f7d24 100644 --- a/js/graphics/SVGArrow.ts +++ b/js/graphics/SVGArrow.ts @@ -1,12 +1,14 @@ import { HTMLappendIt, Positionable, svgNamespace } from "../types"; +import { Tragable } from "./tragable"; -export class SVGArrow implements HTMLappendIt { +export class SVGArrow extends Tragable implements HTMLappendIt { group: SVGElement; lineText: SVGElement; line: SVGElement; from: Positionable; to: Positionable; constructor(from: Positionable, to: Positionable) { + super(); this.from = from; this.to = to; this.group = document.createElementNS(svgNamespace, 'g'); @@ -25,6 +27,8 @@ export class SVGArrow implements HTMLappendIt { this.group.appendChild(this.line); this.group.appendChild(this.lineText); + this.initOnlyClick(this.group); + this.updatePosition(); } updatePosition() { @@ -44,4 +48,8 @@ export class SVGArrow implements HTMLappendIt { svg.appendChild(this.group); } + setDimension(txt: string) { + this.lineText.textContent = txt; + } + } diff --git a/js/graphics/tragable.ts b/js/graphics/tragable.ts index e82f809..a95d7ad 100644 --- a/js/graphics/tragable.ts +++ b/js/graphics/tragable.ts @@ -57,6 +57,11 @@ export class Tragable { selected = false; }); } + initOnlyClick(element: SVGElement) { + element.addEventListener('click', event => { + this.#clickCB(event); + }); + } onMove(cb: (event: InteractionEvent) => any) { this.#moveCB = cb; diff --git a/js/index.ts b/js/index.ts index 4737b95..30dc8e9 100644 --- a/js/index.ts +++ b/js/index.ts @@ -44,6 +44,9 @@ setInterval(loop, 1000); let n1 = new Node("n1", 100, 100); let n2 = new Node("n2", 100, 300); let n3 = new Node("n3", 200, 200); +n1.capacity = 2; +n2.capacity = 2; +n3.capacity = 2; let t1 = new Transition("t1", 100, 200); let t2 = new Transition("t2", 150, 250); let t3 = new Transition("t3", 150, 150);