-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3657030
commit ceea967
Showing
7 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/** | ||
* @typedef { import("elkjs").ElkNode & { absolutePosition: { x: number, y: number } } } ELKNode | ||
*/ | ||
|
||
async function algorithm(GraphBounding, MachineRelation, GraphRelation) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { representation } from "../actions/repr.js" | |
import { createSimulator } from "./simulator.js" | ||
import { machineToGraphRelation } from "../actions/relation.js" | ||
import "https://cdn.jsdelivr.net/npm/[email protected]/lib/elk-api.min.js" | ||
import { getPath, pathToD } from "../actions/svgPath.js" | ||
|
||
/** | ||
* @typedef {Object} Size | ||
|
@@ -65,9 +66,11 @@ onmessage = async ({ data: { type, params } }) => { | |
// simulator.send({ type: "PREVIEW.CLEAR" }) | ||
break | ||
case "DOM.BOUNDED": | ||
// ======================= SET DOM BOUNDING SIZE ====================== | ||
const /** @type {import("types").GraphSize}}*/ { edges, nodes } = params | ||
for (let [id, size] of nodes) GraphBounding.nodes.set(id, { size }) | ||
for (let [id, size] of edges) GraphBounding.edges.set(id, { size }) | ||
// ======================= ELK ALGORITHM ====================== | ||
/** | ||
* @param {string} nodeID | ||
* @returns {import("elkjs").ElkNode} | ||
|
@@ -114,6 +117,7 @@ onmessage = async ({ data: { type, params } }) => { | |
], | ||
} | ||
} | ||
// ==================== LAYOUT EDGES/NODES ====================== | ||
const rootEdges = GraphRelation.nodes.has(undefined) ? GraphRelation.nodes.get(undefined) : [] | ||
const layoutElkNode = await elk.layout({ | ||
id: "root", | ||
|
@@ -130,7 +134,6 @@ onmessage = async ({ data: { type, params } }) => { | |
/** @param {import("elkjs").ElkExtendedEdge} elkEdge */ | ||
const setEdgeLayout = (elkEdge) => { | ||
const lca = GraphRelation.edges.get(elkEdge.id) | ||
// if (!lca) return | ||
const elkLca = stateNodeToElkNodeMap.get(lca) | ||
const edge = GraphBounding.edges.get(elkEdge.id) | ||
if (elkEdge.sections) { | ||
|
@@ -186,8 +189,60 @@ onmessage = async ({ data: { type, params } }) => { | |
} | ||
layoutElkNode.edges.forEach(setEdgeLayout) | ||
setLayout(layoutElkNode.children[0], undefined) | ||
console.log("[worker]", GraphBounding) | ||
postMessage({ type: "DOM.LAYOUT", params: GraphBounding }) | ||
// ======================= LINES ================================= | ||
const lines = new Map() | ||
|
||
for (const [id, edge] of MachineRelation.edges) { | ||
const sourceBound = GraphBounding.nodes.get(edge.source) | ||
const edgeBound = GraphBounding.edges.get(id) | ||
const targetBound = GraphBounding.nodes.get(edge.target) | ||
const sections = edgeBound.sections || [] | ||
const sourceRect = { | ||
...sourceBound.position, | ||
...sourceBound.size, | ||
top: sourceBound.position.y, | ||
bottom: sourceBound.position.y + sourceBound.size.height, | ||
left: sourceBound.position.x, | ||
right: sourceBound.position.x + sourceBound.size.width, | ||
toJSON: () => {}, | ||
} | ||
const edgeRect = { | ||
...edgeBound.position, | ||
...edgeBound.size, | ||
top: edgeBound.position.y, | ||
bottom: edgeBound.position.y + edgeBound.size.height, | ||
left: edgeBound.position.x, | ||
right: edgeBound.position.x + edgeBound.size.width, | ||
toJSON: () => {}, | ||
} | ||
const targetRect = { | ||
...targetBound.position, | ||
...targetBound.size, | ||
top: targetBound.position.y, | ||
bottom: targetBound.position.y + targetBound.size.height, | ||
left: targetBound.position.x, | ||
right: targetBound.position.x + targetBound.size.width, | ||
toJSON: () => {}, | ||
} | ||
if (sourceRect && edgeRect && targetRect) { | ||
/** @type {import("src/actions/svgPath.js").SvgPath | undefined} */ | ||
let path | ||
if (sections.length) { | ||
const section = sections[0] | ||
path = [["M", section.startPoint], ...(section.bendPoints?.map((point) => ["L", point]) || [])] | ||
const preLastPoint = path[path.length - 1][1] | ||
const xSign = Math.sign(section.endPoint.x - preLastPoint.x) | ||
const ySign = Math.sign(section.endPoint.y - preLastPoint.y) | ||
const endPoint = { x: section.endPoint.x - 5 * xSign, y: section.endPoint.y - 5 * ySign } | ||
path.push(["L", endPoint]) | ||
} else path = getPath(sourceRect, edgeRect, targetRect) | ||
if (path) { | ||
lines.set(id, pathToD(path)) | ||
} | ||
} | ||
} | ||
postMessage({ type: "LINES.INIT", params: lines }) | ||
break | ||
default: | ||
console.log("[worker]", type, params) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const svg = String.raw | ||
/** | ||
* @param {string} id | ||
* @param {string} path | ||
* @returns {string} | ||
*/ | ||
export default (id, path) => svg` | ||
<g stroke="#fff" class="line"> | ||
<defs> | ||
<marker id="marker-${id}" viewBox="0 0 10 10" markerWidth="5" markerHeight="5" refX="0" refY="5" markerUnits="strokeWidth" orient="auto"> | ||
<path d="M0,0 L0,10 L10,5 z" /> | ||
</marker> | ||
</defs> | ||
<path d="${path}" id="path-${id}" stroke-width="2" fill="none" marker-end="url(#marker-${id})" opacity="1"/> | ||
</g> | ||
` |