mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-13 23:37:30 +08:00
Link path fixed
This commit is contained in:
@@ -2,6 +2,7 @@ import html from "./html"
|
||||
import sanitizeText from "./sanitizeText"
|
||||
import Template from "./Template"
|
||||
import Configuration from "../Configuration"
|
||||
import Utility from "../Utility"
|
||||
|
||||
/**
|
||||
* @typedef {import("../graph/GraphLink").default} GraphLink
|
||||
@@ -16,7 +17,7 @@ export default class LinkTemplate extends Template {
|
||||
render(link) {
|
||||
return html`
|
||||
<svg version="1.2" baseProfile="tiny" width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none">
|
||||
<path stroke="black" fill="none" vector-effect="non-scaling-stroke" />
|
||||
<path stroke="green" fill="none" vector-effect="non-scaling-stroke" />
|
||||
</svg>
|
||||
`
|
||||
}
|
||||
@@ -36,7 +37,7 @@ export default class LinkTemplate extends Template {
|
||||
* @param {GraphLink} link Link element
|
||||
*/
|
||||
applySourceLocation(link) {
|
||||
link.style.setProperty("--ueb-from-output", link.originatesFromOutput ? "0" : "1")
|
||||
link.style.setProperty("--ueb-from-input", link.originatesFromInput ? "0" : "1")
|
||||
link.style.setProperty("--ueb-from-x", sanitizeText(link.sourceLocation[0]))
|
||||
link.style.setProperty("--ueb-from-y", sanitizeText(link.sourceLocation[1]))
|
||||
}
|
||||
@@ -46,24 +47,28 @@ export default class LinkTemplate extends Template {
|
||||
* @param {GraphLink} link Link element
|
||||
*/
|
||||
applyDestinationLocation(link) {
|
||||
const dx = Math.abs(link.sourceLocation[0] - link.destinationLocation[0])
|
||||
const dx = Math.max(Math.abs(link.sourceLocation[0] - link.destinationLocation[0]), 1)
|
||||
const width = Math.max(dx, Configuration.linkMinWidth)
|
||||
const height = Math.abs(link.sourceLocation[1] - link.destinationLocation[1])
|
||||
const ratio = Math.max(width, 1) / Math.max(height, 1)
|
||||
let start = dx < width ? (width - dx) / width * 100 / 2 : 0
|
||||
const fillRatio = dx / width
|
||||
const aspectRatio = Math.max(width, 1) / Math.max(height, 1)
|
||||
let start = dx < width
|
||||
? (width - dx) / width * 100 / 2
|
||||
: 0
|
||||
link.style.setProperty("--ueb-to-x", sanitizeText(link.destinationLocation[0]))
|
||||
link.style.setProperty("--ueb-to-y", sanitizeText(link.destinationLocation[1]))
|
||||
link.style.setProperty("margin-left", `-${start}px`)
|
||||
const xInverted = link.destinationLocation[0] < link.sourceLocation[0]
|
||||
if (xInverted) {
|
||||
if (dx < width) {
|
||||
start = start + dx / width * 100
|
||||
} else {
|
||||
start = 100
|
||||
}
|
||||
let c1 = 20
|
||||
const xInverted = link.originatesFromInput
|
||||
? link.sourceLocation[0] < link.destinationLocation[0]
|
||||
: link.destinationLocation[0] < link.sourceLocation[0]
|
||||
if (!xInverted) {
|
||||
c1 = start + c1 * fillRatio
|
||||
} else {
|
||||
start = start + fillRatio * 100
|
||||
c1 = start + c1 * fillRatio * 100 / width
|
||||
}
|
||||
const c1 = start + 20
|
||||
const c2 = Math.max(40 / ratio, 30) + start * 1.5
|
||||
const c2 = Math.max(40 / aspectRatio, 30) + start * 1.5
|
||||
const d = Configuration.linkRightSVGPath(start, c1, c2)
|
||||
// TODO move to CSS when Firefox will support property d
|
||||
link.pathElement.setAttribute("d", d)
|
||||
|
||||
Reference in New Issue
Block a user