|
| 1 | +<script setup> |
| 2 | +import { nextTick, ref } from 'vue' |
| 3 | +import { Panel, VueFlow, useVueFlow } from '@vue-flow/core' |
| 4 | +import { Background } from '@vue-flow/background' |
| 5 | +import Icon from './Icon.vue' |
| 6 | +
|
| 7 | +import { initialEdges, initialNodes } from './initial-elements.js' |
| 8 | +import { useLayout } from './useLayout' |
| 9 | +
|
| 10 | +const nodes = ref(initialNodes) |
| 11 | +
|
| 12 | +const edges = ref(initialEdges) |
| 13 | +
|
| 14 | +const { layout } = useLayout() |
| 15 | +
|
| 16 | +const { fitView } = useVueFlow() |
| 17 | +
|
| 18 | +async function layoutGraph(direction) { |
| 19 | + nodes.value = layout(nodes.value, edges.value, direction) |
| 20 | +
|
| 21 | + nextTick(() => { |
| 22 | + fitView() |
| 23 | + }) |
| 24 | +} |
| 25 | +</script> |
| 26 | + |
| 27 | +<template> |
| 28 | + <div class="layout-flow"> |
| 29 | + <VueFlow :nodes="nodes" :edges="edges" @nodes-initialized="layoutGraph('LR')"> |
| 30 | + <Background /> |
| 31 | + |
| 32 | + <Panel class="process-panel" position="top-right"> |
| 33 | + <div class="layout-panel"> |
| 34 | + <button title="set horizontal layout" @click="layoutGraph('LR')"> |
| 35 | + <Icon name="horizontal" /> |
| 36 | + </button> |
| 37 | + |
| 38 | + <button title="set vertical layout" @click="layoutGraph('TB')"> |
| 39 | + <Icon name="vertical" /> |
| 40 | + </button> |
| 41 | + </div> |
| 42 | + </Panel> |
| 43 | + </VueFlow> |
| 44 | + </div> |
| 45 | +</template> |
| 46 | + |
| 47 | +<style> |
| 48 | +.layout-flow { |
| 49 | + background-color: #1a192b; |
| 50 | + height: 100%; |
| 51 | + width: 100%; |
| 52 | +} |
| 53 | +
|
| 54 | +.process-panel, |
| 55 | +.layout-panel { |
| 56 | + display: flex; |
| 57 | + gap: 10px; |
| 58 | +} |
| 59 | +
|
| 60 | +.process-panel { |
| 61 | + background-color: #2d3748; |
| 62 | + padding: 10px; |
| 63 | + border-radius: 8px; |
| 64 | + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); |
| 65 | + display: flex; |
| 66 | + flex-direction: column; |
| 67 | +} |
| 68 | +
|
| 69 | +.process-panel button { |
| 70 | + border: none; |
| 71 | + cursor: pointer; |
| 72 | + background-color: #4a5568; |
| 73 | + border-radius: 8px; |
| 74 | + color: white; |
| 75 | + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); |
| 76 | +} |
| 77 | +
|
| 78 | +.process-panel button { |
| 79 | + font-size: 16px; |
| 80 | + width: 40px; |
| 81 | + height: 40px; |
| 82 | + display: flex; |
| 83 | + align-items: center; |
| 84 | + justify-content: center; |
| 85 | +} |
| 86 | +
|
| 87 | +.checkbox-panel { |
| 88 | + display: flex; |
| 89 | + align-items: center; |
| 90 | + gap: 10px; |
| 91 | +} |
| 92 | +
|
| 93 | +.process-panel button:hover, |
| 94 | +.layout-panel button:hover { |
| 95 | + background-color: #2563eb; |
| 96 | + transition: background-color 0.2s; |
| 97 | +} |
| 98 | +
|
| 99 | +.process-panel label { |
| 100 | + color: white; |
| 101 | + font-size: 12px; |
| 102 | +} |
| 103 | +
|
| 104 | +.stop-btn svg { |
| 105 | + display: none; |
| 106 | +} |
| 107 | +
|
| 108 | +.stop-btn:hover svg { |
| 109 | + display: block; |
| 110 | +} |
| 111 | +
|
| 112 | +.stop-btn:hover .spinner { |
| 113 | + display: none; |
| 114 | +} |
| 115 | +
|
| 116 | +.spinner { |
| 117 | + border: 3px solid #f3f3f3; |
| 118 | + border-top: 3px solid #2563eb; |
| 119 | + border-radius: 50%; |
| 120 | + width: 10px; |
| 121 | + height: 10px; |
| 122 | + animation: spin 1s linear infinite; |
| 123 | +} |
| 124 | +
|
| 125 | +@keyframes spin { |
| 126 | + 0% { |
| 127 | + transform: rotate(0deg); |
| 128 | + } |
| 129 | + 100% { |
| 130 | + transform: rotate(360deg); |
| 131 | + } |
| 132 | +} |
| 133 | +</style> |
0 commit comments