generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eirby/drawing modules viz lines (#414)
This PR generates a svg we can use to visualize the controllers system. In subsequent PR's I'll do the following - Style to match current light and dark theme - add zooming and panning of the svg - link sidebar module and verb links to and the zoom and pan feature to zoom to clicked verbs and modules - add module and verb node and edge highlighting based on selection - ... ![Screenshot 2023-09-20 at 4 05 24 PM](https://github.com/TBD54566975/ftl/assets/1058725/61f6a99a-dd76-47b4-b989-76a158683e13) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e046f17
commit fa1582d
Showing
8 changed files
with
223 additions
and
194 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
export const callIconID = 'call-icon' | ||
|
||
export const callIcon = `<defs> | ||
<symbol id="${callIconID}" viewBox="0 0 24 24" stroke-width="1.5"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 3.75v4.5m0-4.5h-4.5m4.5 0l-6 6m3 12c-8.284 0-15-6.716-15-15V4.5A2.25 2.25 0 014.5 2.25h1.372c.516 0 .966.351 1.091.852l1.106 4.423c.11.44-.054.902-.417 1.173l-1.293.97a1.062 1.062 0 00-.38 1.21 12.035 12.035 0 007.143 7.143c.441.162.928-.004 1.21-.38l.97-1.293a1.125 1.125 0 011.173-.417l4.423 1.106c.5.125.852.575.852 1.091V19.5a2.25 2.25 0 01-2.25 2.25h-2.25z" /> | ||
</symbol> | ||
</defs> | ||
` | ||
|
||
export const moduleVerbCls = 'module-verb' | ||
export const moduleTitleCls = 'module-title' |
152 changes: 0 additions & 152 deletions
152
console/client/src/features/modules/create-layout-data-structure.ts
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
import { instance } from '@viz-js/viz' | ||
|
||
export const dotToSVG = async (dot: string) => { | ||
const viz = await instance() | ||
try { | ||
return viz.renderSVGElement(dot) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} |
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,75 @@ | ||
import { callIcon, moduleVerbCls, callIconID } from './constants' | ||
export const formatSVG = (svg: SVGSVGElement): SVGSVGElement => { | ||
svg.insertAdjacentHTML('afterbegin', callIcon) | ||
|
||
for (const $a of svg.querySelectorAll('a')) { | ||
const $g = $a.parentNode! as SVGSVGElement | ||
|
||
const $docFrag = document.createDocumentFragment() | ||
while ($a.firstChild) { | ||
const $child = $a.firstChild | ||
$docFrag.appendChild($child) | ||
} | ||
|
||
$g.replaceChild($docFrag, $a) | ||
|
||
$g.id = $g.id.replace(/^a_/, '') | ||
} | ||
|
||
for (const $el of svg.querySelectorAll('title')) { | ||
$el.remove() | ||
} | ||
|
||
const edgesSources = new Set<string>() | ||
for (const $edge of svg.querySelectorAll('.edge')) { | ||
const [from, to] = $edge.id.split('=>') | ||
$edge.removeAttribute('id') | ||
$edge.setAttribute('data-from', from) | ||
$edge.setAttribute('data-to', to) | ||
edgesSources.add(from) | ||
} | ||
|
||
for (const $el of svg.querySelectorAll('[id*=\\:\\:]')) { | ||
const [tag, id] = $el.id.split('::') | ||
$el.id = id | ||
$el.classList.add(tag) | ||
} | ||
|
||
for (const $path of svg.querySelectorAll('g.edge path')) { | ||
const $newPath = $path.cloneNode() as HTMLElement | ||
$newPath.classList.add('hover-path') | ||
$newPath.removeAttribute('stroke-dasharray') | ||
$path.parentNode?.appendChild($newPath) | ||
} | ||
|
||
for (const $verb of svg.querySelectorAll(`.${moduleVerbCls}`)) { | ||
const texts = $verb.querySelectorAll('text') | ||
texts[0].classList.add('verb-name') | ||
|
||
// Tag verb as a call source | ||
if (edgesSources.has($verb.id)) $verb.classList.add('call-source') | ||
|
||
// Replace icon | ||
const length = texts.length | ||
for (let i = 1; i < length; ++i) { | ||
const str = texts[i].innerHTML | ||
if (str === '{R}') { | ||
const $iconPlaceholder = texts[i] | ||
const height = 22 | ||
const width = 22 | ||
const $useIcon = document.createElementNS('http://www.w3.org/2000/svg', 'use') | ||
$useIcon.setAttributeNS('http://www.w3.org/1999/xlink', 'href', `#${callIconID}`) | ||
$useIcon.setAttribute('width', `${width}px`) | ||
$useIcon.setAttribute('height', `${height}px`) | ||
|
||
//FIXME: remove hardcoded offset | ||
const y = parseInt($iconPlaceholder.getAttribute('y')!) - 15 | ||
$useIcon.setAttribute('x', $iconPlaceholder.getAttribute('x')!) | ||
$useIcon.setAttribute('y', y.toString()) | ||
$verb.replaceChild($useIcon, $iconPlaceholder) | ||
continue | ||
} | ||
} | ||
} | ||
return svg | ||
} |
Oops, something went wrong.