Rename some properties for uniformity

This commit is contained in:
barsdeveloper
2025-01-25 16:12:44 +02:00
parent 41988b1599
commit b4fdb99819
7 changed files with 108 additions and 98 deletions

View File

@@ -9,23 +9,23 @@ export default class IFromToPositionedTemplate extends ITemplate {
/** @param {PropertyValues} changedProperties */
update(changedProperties) {
super.update(changedProperties)
const [fromX, fromY, toX, toY] = [
Math.round(this.element.fromX),
Math.round(this.element.fromY),
Math.round(this.element.toX),
Math.round(this.element.toY),
const [originX, originY, targetX, targetY] = [
Math.round(this.element.originX),
Math.round(this.element.originY),
Math.round(this.element.targetX),
Math.round(this.element.targetY),
]
const [left, top, width, height] = [
Math.min(fromX, toX),
Math.min(fromY, toY),
Math.abs(fromX - toX),
Math.abs(fromY - toY),
Math.min(originX, targetX),
Math.min(originY, targetY),
Math.abs(originX - targetX),
Math.abs(originY - targetY),
]
if (changedProperties.has("fromX") || changedProperties.has("toX")) {
if (changedProperties.has("originX") || changedProperties.has("targetX")) {
this.element.style.left = `${left}px`
this.element.style.width = `${width}px`
}
if (changedProperties.has("fromY") || changedProperties.has("toY")) {
if (changedProperties.has("originY") || changedProperties.has("targetY")) {
this.element.style.top = `${top}px`
this.element.style.height = `${height}px`
}

View File

@@ -68,8 +68,8 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
const targetPin = this.element.target
const isOriginAKnot = originPin?.isKnot()
const isTargetAKnot = targetPin?.isKnot()
const from = this.element.fromX
const to = this.element.toX
const from = this.element.originX
const to = this.element.targetX
// Switch actual input/output pins if allowed and makes sense
if (isOriginAKnot && (!targetPin || isTargetAKnot)) {
@@ -105,13 +105,13 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
let sameDirection = originPin?.isOutputVisually() == targetPin?.isOutputVisually()
// Actual computation
const dx = Math.max(Math.abs(this.element.fromX - this.element.toX), 1)
const dy = Math.max(Math.abs(this.element.fromY - this.element.toY), 1)
const dx = Math.max(Math.abs(this.element.originX - this.element.targetX), 1)
const dy = Math.max(Math.abs(this.element.originY - this.element.targetY), 1)
const width = Math.max(dx, Configuration.linkMinWidth)
const fillRatio = dx / width
const xInverted = this.element.originatesFromInput
? this.element.fromX < this.element.toX
: this.element.toX < this.element.fromX
? this.element.originX < this.element.targetX
: this.element.targetX < this.element.originX
this.element.startPixels = dx < width // If under minimum width
? (width - dx) / 2 // Start from half the empty space
: 0 // Otherwise start from the beginning
@@ -172,7 +172,12 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
/** @param {PropertyValues} changedProperties */
willUpdate(changedProperties) {
super.willUpdate(changedProperties)
if (changedProperties.has("fromX") || changedProperties.has("toX")) {
const originDX = (changedProperties.get("originX") ?? this.element.originX) - this.element.originX
const originDY = (changedProperties.get("originY") ?? this.element.originY) - this.element.originY
const targetDX = (changedProperties.get("targetX") ?? this.element.targetX) - this.element.targetX
const targetDY = (changedProperties.get("targetY") ?? this.element.targetY) - this.element.targetY
if (originDX != targetDX || originDY != targetDY) {
// Only if it changes shape
this.#calculateSVGPath(changedProperties)
}
}
@@ -186,7 +191,7 @@ export default class LinkTemplate extends IFromToPositionedTemplate {
}
this.element.style.setProperty("--ueb-start-percentage", `${Math.round(this.element.startPercentage)}%`)
this.element.style.setProperty("--ueb-link-start", `${Math.round(this.element.startPixels)}`)
const mirrorV = (this.element.fromY > this.element.toY ? -1 : 1) // If from is below to => mirror
const mirrorV = (this.element.originY > this.element.targetY ? -1 : 1) // If from is below to => mirror
* (this.element.originatesFromInput ? -1 : 1) // Unless fro refers to an input pin
* (this.element.origin?.isInputVisually() && this.element.target?.isInputVisually() ? -1 : 1)
const mirrorH = (this.element.origin?.isInputVisually() && this.element.target?.isInputVisually() ? -1 : 1)