-
Notifications
You must be signed in to change notification settings - Fork 1
Force directed graph labels #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
76531e3
init
micheal-parks f145022
merge main
micheal-parks b5a44b5
bugfixes
micheal-parks d9f65f9
refactor
micheal-parks c5f0591
separate labels out
micheal-parks d61ee48
Create cuddly-sails-attend.md
micheal-parks 6941b67
Merge branch 'main' into labels
micheal-parks 9ab1dab
cleanup
micheal-parks 6e2914c
Merge branch 'labels' of https://github.com/viamrobotics/acdc into la…
micheal-parks 58baebc
fix
micheal-parks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@viamrobotics/motion-tools": patch | ||
| --- | ||
|
|
||
| Feat: force directed graph labels |
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,25 +1,91 @@ | ||
| <script lang="ts"> | ||
| import type { Entity } from 'koota' | ||
|
|
||
| import { useThrelte } from '@threlte/core' | ||
| import { HTML } from '@threlte/extras' | ||
| import { untrack } from 'svelte' | ||
| import { Group } from 'three' | ||
|
|
||
| import { traits, useTag, useTrait } from '$lib/ecs' | ||
|
|
||
| import { useSettings } from '$lib/hooks/useSettings.svelte' | ||
| import { labels } from './labelLayout/labelStore.svelte' | ||
|
|
||
| interface Props { | ||
| text?: string | ||
| entity: Entity | ||
| } | ||
|
|
||
| let { text }: Props = $props() | ||
| let { entity }: Props = $props() | ||
|
|
||
| const { invalidate } = useThrelte() | ||
|
|
||
| const matrix = useTrait(() => entity, traits.WorldMatrix) | ||
| const name = useTrait(() => entity, traits.Name) | ||
| const color = useTrait(() => entity, traits.Color) | ||
| const selected = useTag(() => entity, traits.Selected) | ||
|
|
||
| let element = $state.raw<HTMLElement>() | ||
|
|
||
| $effect(() => { | ||
| const el = element | ||
|
|
||
| if (!el) return | ||
|
|
||
| return untrack(() => { | ||
| labels.add(el) | ||
| return () => labels.remove(el) | ||
| }) | ||
| }) | ||
|
|
||
| // Re-measure when the label text changes (its width drives slot geometry). | ||
| $effect(() => { | ||
| if (name.current) { | ||
| untrack(() => labels.touch()) | ||
| } | ||
| }) | ||
|
|
||
| const settings = useSettings() | ||
| let ref = $state<Group>() | ||
|
|
||
| const labels = $derived(settings.current.enableLabels) | ||
| $effect(() => { | ||
| if (matrix.current && ref) { | ||
| ref.matrix.copy(matrix.current) | ||
| ref.updateMatrixWorld() | ||
| invalidate() | ||
| } | ||
| }) | ||
| </script> | ||
|
|
||
| {#if labels && text} | ||
| <HTML | ||
| center | ||
| zIndexRange={[3, 0]} | ||
| class="border-gray-7 border bg-white px-2 py-1 text-xs" | ||
| <HTML | ||
| center | ||
| zIndexRange={[3, 0]} | ||
| matrixAutoUpdate={false} | ||
| bind:ref | ||
| > | ||
| <div | ||
| class="label relative h-0 w-0" | ||
| bind:this={element} | ||
| > | ||
| {text} | ||
| </HTML> | ||
| {/if} | ||
| <svg class="link pointer-events-none absolute top-0 left-0 overflow-visible"> | ||
| <line class="stroke-gray-9 stroke-1" /> | ||
| </svg> | ||
| <div | ||
| class="dot border-gray-9 pointer-events-none absolute -top-1 -left-0 z-1 h-2 w-2 -translate-1/2 rounded-full border" | ||
| ></div> | ||
| <button | ||
| class={[ | ||
| 'border-gray-9 text absolute z-2 border px-2 py-1 text-xs text-nowrap', | ||
| { | ||
| 'bg-gray-9 text-white': selected.current, | ||
| 'bg-white': !selected.current, | ||
| }, | ||
| ]} | ||
| style={color.current | ||
| ? `border-color-left: rgb(${color.current.r}, ${color.current.g}, ${color.current.b})` | ||
| : undefined} | ||
| onclick={() => { | ||
| entity.add(traits.Selected) | ||
| }} | ||
| > | ||
| {name.current} | ||
| </button> | ||
| </div> | ||
| </HTML> |
This file contains hidden or 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,36 @@ | ||
| <script lang="ts"> | ||
| import { useTask, useThrelte } from '@threlte/core' | ||
|
|
||
| import { traits, useQuery } from '$lib/ecs' | ||
|
|
||
| import Label from './Label.svelte' | ||
| import { createLabelLayout } from './labelLayout/createLabelLayout' | ||
| import { labels } from './labelLayout/labelStore.svelte' | ||
|
|
||
| const { camera, invalidate, size } = useThrelte() | ||
|
|
||
| const entities = useQuery(traits.Name) | ||
|
|
||
| const layout = createLabelLayout({ camera, size, invalidate, labels }) | ||
|
|
||
| // Wake the on-demand render loop when labels are added/removed or their text | ||
| // changes, so the engine re-solves even while the camera is still. Reading | ||
| // `version` registers the reactive dependency. | ||
| $effect(() => { | ||
| if (labels.version >= 0) invalidate() | ||
| }) | ||
|
|
||
| // `autoInvalidate: false` — the engine drives its own invalidation (camera | ||
| // motion, the version effect above, and while animating), so the task can run | ||
| // without pinning the on-demand Canvas to render every frame. | ||
| useTask( | ||
| (delta) => { | ||
| layout.frame(delta) | ||
| }, | ||
| { autoInvalidate: false } | ||
| ) | ||
| </script> | ||
|
|
||
| {#each entities.current as entity (entity)} | ||
| <Label {entity} /> | ||
| {/each} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Labels are much less invasive when disabled now :)