mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-13 23:37:30 +08:00
Various fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import html from "./html"
|
||||
import sanitizeText from "./sanitizeText"
|
||||
import Template from "./Template"
|
||||
import Configuration from "../Configuration"
|
||||
|
||||
/**
|
||||
* @typedef {import("../graph/GraphLink").default} GraphLink
|
||||
@@ -15,7 +16,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 d="M 0 0 C 20 0, 30 0, 50 50 S 70 100, 100 100" stroke="black" stroke-width="2" fill="none" vector-effect="non-scaling-stroke" />
|
||||
<path stroke="black" fill="none" vector-effect="non-scaling-stroke" />
|
||||
</svg>
|
||||
`
|
||||
}
|
||||
@@ -27,28 +28,31 @@ export default class LinkTemplate extends Template {
|
||||
apply(link) {
|
||||
super.apply(link)
|
||||
link.classList.add("ueb-positioned")
|
||||
link.pathElement = link.querySelector("path")
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the style relative to the source pin location.
|
||||
* @param {GraphLink} link Link element
|
||||
*/
|
||||
applySourceLocation(link, initialPosition) {
|
||||
applySourceLocation(link) {
|
||||
link.style.setProperty("--ueb-from-input", link.originatesFromInput ? "1" : "0")
|
||||
// Set initial position
|
||||
link.style.setProperty("--ueb-from-x", sanitizeText(initialPosition[0]))
|
||||
link.style.setProperty("--ueb-from-y", sanitizeText(initialPosition[1]))
|
||||
link.style.setProperty("--ueb-from-x", sanitizeText(link.sourceLocation[0]))
|
||||
link.style.setProperty("--ueb-from-y", sanitizeText(link.sourceLocation[1]))
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the style relative to the destination pin location.
|
||||
* @param {GraphLink} link Link element
|
||||
*/
|
||||
applyDestinationLocation(link, finalPosition) {
|
||||
link.style.setProperty("--ueb-to-x", sanitizeText(finalPosition[0]))
|
||||
link.style.setProperty("--ueb-to-y", sanitizeText(finalPosition[1]))
|
||||
const height = Math.abs(link.style.getPropertyValue("--ueb-from-y") - finalPosition[1])
|
||||
let skew = Math.atan(height / (finalPosition[0] - link.style.getPropertyValue("--ueb-from-x"))) - Math.PI / 2
|
||||
link.style.setProperty("--ueb-link-skew", skew)
|
||||
applyDestinationLocation(link) {
|
||||
link.style.setProperty("--ueb-to-x", sanitizeText(link.destinationLocation[0]))
|
||||
link.style.setProperty("--ueb-to-y", sanitizeText(link.destinationLocation[1]))
|
||||
const r = Math.max(Math.abs(link.sourceLocation[0] - link.destinationLocation[0]), 1)
|
||||
/ Math.max(Math.abs(link.sourceLocation[1] - link.destinationLocation[1]), 1)
|
||||
const d = Configuration.linkRightSVGPath(20, Math.max(40 / r, 30))
|
||||
// TODO move to CSS when Firefox will support property d
|
||||
link.pathElement.setAttribute("d", d)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user