Spaces:
Running
Running
it still doesnt work, live preview doesnt show the sankey diagram. make sure to update the live view every time user add a new link. maybe you can add an update button to update the live preview section.
Browse files- index.html +5 -2
- script.js +6 -4
- style.css +1 -1
index.html
CHANGED
|
@@ -21,10 +21,13 @@
|
|
| 21 |
<div class="p-4 border-b border-gray-200">
|
| 22 |
<h2 class="text-xl font-semibold text-gray-700">Live Preview</h2>
|
| 23 |
</div>
|
| 24 |
-
<div id="diagram-container" class="p-4 h-96 w-full">
|
| 25 |
<svg id="sankey-diagram" class="w-full h-full"></svg>
|
|
|
|
|
|
|
|
|
|
| 26 |
</div>
|
| 27 |
-
|
| 28 |
|
| 29 |
<!-- Control Panel Section -->
|
| 30 |
<section class="bg-white rounded-xl shadow-md overflow-hidden">
|
|
|
|
| 21 |
<div class="p-4 border-b border-gray-200">
|
| 22 |
<h2 class="text-xl font-semibold text-gray-700">Live Preview</h2>
|
| 23 |
</div>
|
| 24 |
+
<div id="diagram-container" class="p-4 h-96 w-full relative">
|
| 25 |
<svg id="sankey-diagram" class="w-full h-full"></svg>
|
| 26 |
+
<button id="update-diagram" class="absolute top-4 right-4 bg-blue-500 hover:bg-blue-600 text-white px-3 py-1 rounded-md text-sm shadow-md transition">
|
| 27 |
+
<i data-feather="refresh-cw" class="mr-1"></i> Update
|
| 28 |
+
</button>
|
| 29 |
</div>
|
| 30 |
+
</section>
|
| 31 |
|
| 32 |
<!-- Control Panel Section -->
|
| 33 |
<section class="bg-white rounded-xl shadow-md overflow-hidden">
|
script.js
CHANGED
|
@@ -151,13 +151,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 151 |
initDiagram();
|
| 152 |
}
|
| 153 |
});
|
| 154 |
-
|
| 155 |
// Add link
|
| 156 |
document.getElementById('add-link').addEventListener('click', () => {
|
| 157 |
const sourceIndex = parseInt(document.getElementById('source-node').value);
|
| 158 |
const targetIndex = parseInt(document.getElementById('target-node').value);
|
| 159 |
-
|
| 160 |
-
|
|
|
|
| 161 |
sankeyData.links.push({
|
| 162 |
source: sourceIndex,
|
| 163 |
target: targetIndex,
|
|
@@ -169,7 +169,9 @@ if (!isNaN(sourceIndex) && !isNaN(targetIndex) && !isNaN(value) && value > 0) {
|
|
| 169 |
}
|
| 170 |
});
|
| 171 |
|
| 172 |
-
//
|
|
|
|
|
|
|
| 173 |
document.addEventListener('click', (e) => {
|
| 174 |
if (e.target.closest('button[data-index]')) {
|
| 175 |
const button = e.target.closest('button[data-index]');
|
|
|
|
| 151 |
initDiagram();
|
| 152 |
}
|
| 153 |
});
|
|
|
|
| 154 |
// Add link
|
| 155 |
document.getElementById('add-link').addEventListener('click', () => {
|
| 156 |
const sourceIndex = parseInt(document.getElementById('source-node').value);
|
| 157 |
const targetIndex = parseInt(document.getElementById('target-node').value);
|
| 158 |
+
const value = parseInt(document.getElementById('link-value').value) || 1;
|
| 159 |
+
|
| 160 |
+
if (!isNaN(sourceIndex) && !isNaN(targetIndex) && !isNaN(value) && value > 0) {
|
| 161 |
sankeyData.links.push({
|
| 162 |
source: sourceIndex,
|
| 163 |
target: targetIndex,
|
|
|
|
| 169 |
}
|
| 170 |
});
|
| 171 |
|
| 172 |
+
// Manual diagram update
|
| 173 |
+
document.getElementById('update-diagram').addEventListener('click', initDiagram);
|
| 174 |
+
// Delete node or link
|
| 175 |
document.addEventListener('click', (e) => {
|
| 176 |
if (e.target.closest('button[data-index]')) {
|
| 177 |
const button = e.target.closest('button[data-index]');
|
style.css
CHANGED
|
@@ -5,11 +5,11 @@
|
|
| 5 |
background: #f8fafc;
|
| 6 |
border-radius: 0.5rem;
|
| 7 |
}
|
| 8 |
-
|
| 9 |
#diagram-container {
|
| 10 |
background: white;
|
| 11 |
border-radius: 0.5rem;
|
| 12 |
margin: 0.5rem;
|
|
|
|
| 13 |
}
|
| 14 |
.node rect {
|
| 15 |
cursor: move;
|
|
|
|
| 5 |
background: #f8fafc;
|
| 6 |
border-radius: 0.5rem;
|
| 7 |
}
|
|
|
|
| 8 |
#diagram-container {
|
| 9 |
background: white;
|
| 10 |
border-radius: 0.5rem;
|
| 11 |
margin: 0.5rem;
|
| 12 |
+
position: relative;
|
| 13 |
}
|
| 14 |
.node rect {
|
| 15 |
cursor: move;
|