-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: 노드 생성 버튼 구현 #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
:root { | ||
--text-color: #101010; | ||
} | ||
|
||
body, | ||
button { | ||
color: var(--text-color); | ||
} | ||
|
||
button { | ||
display: inline-block; | ||
border: none; | ||
background-color: transparent; | ||
padding: 0.5rem 1rem; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
font-size: 1.2rem; | ||
} | ||
|
||
button:hover { | ||
background-color: #f4f4f4; | ||
} | ||
|
||
button:active { | ||
background-color: #e4e4e4; | ||
} | ||
|
||
.controller-panel { | ||
position: fixed; | ||
top: 1rem; | ||
right: 1rem; | ||
bottom: 1rem; | ||
width: 300px; | ||
background-color: #fdfdfd; | ||
border: 1px solid #f4f4f4; | ||
padding: 2rem; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05); | ||
border-radius: 16px; | ||
} | ||
|
||
.controller-panel h3 { | ||
margin-top: 0; | ||
} | ||
|
||
.canvas-container { | ||
margin: 1rem; | ||
} | ||
|
||
.controller-panel-header { | ||
display: flex; | ||
justify-content: end; | ||
align-items: center; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
/// <reference path="../types/diagram.d.ts" /> | ||
|
||
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs"; | ||
mermaid.initialize({ startOnLoad: false }); | ||
import { createId, createRandomString } from "./util.js"; | ||
|
||
/// <reference path="../types/diagram.d.ts" /> | ||
mermaid.initialize({ startOnLoad: false }); | ||
|
||
/** @type {WorkflowGraph} */ | ||
const diagram = data; | ||
|
@@ -14,9 +16,9 @@ function draw() { | |
|
||
let mermaidText = `flowchart LR`; | ||
|
||
diagram.vertices?.forEach((vertex) => { | ||
diagram.nodes?.forEach((vertex) => { | ||
mermaidText += ` | ||
${vertex.id}[${vertex.label}] | ||
${vertex.id}["${vertex.label}"] | ||
`; | ||
}); | ||
diagram.edges?.forEach((edge) => { | ||
|
@@ -25,10 +27,29 @@ function draw() { | |
`; | ||
}); | ||
|
||
const mermaidElement = document.getElementById("diagram-canvas"); | ||
mermaidElement.removeAttribute("data-processed"); | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최초 호출되는 이를 해결하기 위해 ref: |
||
|
||
diagramCanvas.textContent = mermaidText; | ||
|
||
mermaid.run(); | ||
} | ||
|
||
function createNode() { | ||
const id = createId(); | ||
const label = `새로운 노드(${createRandomString(3)})`; | ||
diagram.nodes.push({ id, label }); | ||
draw(); | ||
} | ||
|
||
function initListeners() { | ||
const createNodeButton = document.getElementById("create-node"); | ||
if (createNodeButton) { | ||
createNodeButton.onclick = createNode; | ||
} | ||
} | ||
|
||
window.onload = () => { | ||
draw(); | ||
initListeners(); | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. canvas용 별도 css 파일로 분리합니다. ( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @param {number} length | ||
* @returns {string} | ||
*/ | ||
export function createRandomString(length) { | ||
const characters = "abcdefghijklmnopqrstuvwxyz0123456789"; | ||
let result = ""; | ||
for (let i = 0; i < length; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * characters.length)); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* @returns {string} | ||
*/ | ||
export function createId() { | ||
const current = Date.now().toString(36); | ||
const random = createRandomString(6); | ||
return `${current}${random}`.toUpperCase(); | ||
} |
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.
맨 위에 있어야
reference
가 의도대로 동작하여 옮겼습니다.