-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAddNodePanel.vue
More file actions
48 lines (41 loc) · 1.24 KB
/
AddNodePanel.vue
File metadata and controls
48 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<script setup lang="ts">
import GWell from '@ui/graph/GWell.vue';
import GButton from '@ui/graph/button/GButton.vue';
import gsap from 'gsap';
import { ref } from 'vue';
import type { TreeControls } from '../useTree';
const props = defineProps<{
tree: TreeControls;
}>();
const getNumbers = () => {
const treeArr = props.tree.tree
.toArray()
.filter((num): num is number => num !== undefined);
if (treeArr.length === 0) return [1, 2, 3, 4, 5];
const min = Math.min(...treeArr);
const max = Math.max(...treeArr);
const nums: number[] = [];
for (let i = min - 10; i < max + 10; i++) nums.push(i);
const validNums = nums.filter((num) =>
treeArr.every((tNum) => num !== tNum),
);
return gsap.utils.shuffle(validNums).slice(0, 5);
};
const recommendedNodes = ref<number[]>([]);
setTimeout(() => (recommendedNodes.value = getNumbers()), 5);
</script>
<template>
<GWell class="p-2 rounded-xl">
<div class="flex gap-2 flex-col">
<GButton
v-for="node in recommendedNodes"
:key="node"
@click="props.tree.insertNode(node)"
secondary
class="rounded-full w-10 h-10"
>
{{ node }}
</GButton>
</div>
</GWell>
</template>