davidardz07 commited on
Commit
7db744a
·
1 Parent(s): f046562
Files changed (2) hide show
  1. index.html +31 -27
  2. script.js +15 -4
index.html CHANGED
@@ -15,45 +15,29 @@
15
  <div class="flex flex-1">
16
  <!-- Sidebar -->
17
  <div class="w-80 bg-white shadow-lg flex flex-col">
18
- <div class="p-4 border-b">
19
- <h1 class="text-xl font-bold text-gray-800">Sankey Flow Wizard 🧙‍♂️</h1>
 
 
 
20
  </div>
21
 
22
  <div class="flex-1 overflow-y-auto p-4 space-y-6">
23
- <!-- Import/Export -->
24
- <div class="bg-gray-50 p-4 rounded-lg">
25
- <h3 class="font-medium text-gray-700 mb-3 flex items-center">
26
- <i data-feather="upload" class="mr-2"></i> Import/Export
27
- </h3>
28
- <div class="grid grid-cols-2 gap-2">
29
- <button id="import-csv" class="bg-blue-500 hover:bg-blue-600 text-white px-3 py-2 rounded-md text-sm transition">
30
- <i data-feather="upload" class="mr-1"></i> Import CSV
31
- </button>
32
- <button id="export-csv" class="bg-green-500 hover:bg-green-600 text-white px-3 py-2 rounded-md text-sm transition">
33
- <i data-feather="download" class="mr-1"></i> Export CSV
34
- </button>
35
- <button id="center-diagram" class="bg-purple-500 hover:bg-purple-600 text-white px-3 py-2 rounded-md text-sm transition col-span-2">
36
- <i data-feather="crosshair" class="mr-1"></i> Center Diagram
37
- </button>
38
- </div>
39
- <input type="file" id="csv-file" accept=".csv" class="hidden">
40
- </div>
41
-
42
- <!-- Appearance -->
43
- <div class="bg-gray-50 p-4 rounded-lg">
44
  <h3 class="font-medium text-gray-700 mb-3 flex items-center">
45
- <i data-feather="eye" class="mr-2"></i> Appearance
46
  </h3>
47
  <div class="space-y-4">
48
  <div>
49
  <label class="block text-sm text-gray-600 mb-1">Text Color</label>
50
- <input type="color" id="text-color" value="#ffffff" class="w-full h-10">
51
  </div>
52
  <div>
53
  <label class="block text-sm text-gray-600 mb-1">Text Position</label>
54
  <select id="text-position" class="w-full p-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
 
55
  <option value="middle">Middle</option>
56
- <option value="top">Top</option>
57
  <option value="bottom">Bottom</option>
58
  </select>
59
  </div>
@@ -71,6 +55,26 @@
71
  </div>
72
  </div>
73
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  <!-- Nodes Management -->
76
  <div class="bg-gray-50 p-4 rounded-lg">
@@ -110,7 +114,7 @@
110
  <div class="flex-1 flex flex-col">
111
  <!-- Diagram Area -->
112
  <div class="flex-1 p-6">
113
- <div id="diagram-container" class="bg-gray-200 rounded-xl shadow-md h-full relative">
114
  <svg id="sankey-diagram" class="w-full h-full"></svg>
115
  </div>
116
  </div>
 
15
  <div class="flex flex-1">
16
  <!-- Sidebar -->
17
  <div class="w-80 bg-white shadow-lg flex flex-col">
18
+ <div class="p-4 border-b flex items-center justify-between">
19
+ <h1 class="text-xl font-bold text-gray-800">Sankey Flow Wizard</h1>
20
+ <button id="settings-btn" class="bg-gray-100 hover:bg-gray-200 text-gray-800 px-3 py-2 rounded-md text-sm flex items-center space-x-2">
21
+ <i data-feather="settings" class="mr-1"></i>
22
+ </button>
23
  </div>
24
 
25
  <div class="flex-1 overflow-y-auto p-4 space-y-6">
26
+ <!-- Settings panel (hidden by default) -->
27
+ <div id="settings-panel" class="bg-gray-50 p-4 rounded-lg hidden">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  <h3 class="font-medium text-gray-700 mb-3 flex items-center">
29
+ <i data-feather="sliders" class="mr-2"></i> Configuración
30
  </h3>
31
  <div class="space-y-4">
32
  <div>
33
  <label class="block text-sm text-gray-600 mb-1">Text Color</label>
34
+ <input type="color" id="text-color" value="#000000" class="w-full h-10">
35
  </div>
36
  <div>
37
  <label class="block text-sm text-gray-600 mb-1">Text Position</label>
38
  <select id="text-position" class="w-full p-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
39
+ <option value="top" selected>Top</option>
40
  <option value="middle">Middle</option>
 
41
  <option value="bottom">Bottom</option>
42
  </select>
43
  </div>
 
55
  </div>
56
  </div>
57
  </div>
58
+ <!-- Import/Export -->
59
+ <div class="bg-gray-50 p-4 rounded-lg">
60
+ <h3 class="font-medium text-gray-700 mb-3 flex items-center">
61
+ <i data-feather="upload" class="mr-2"></i> Import/Export
62
+ </h3>
63
+ <div class="grid grid-cols-2 gap-2">
64
+ <button id="import-csv" class="bg-blue-500 hover:bg-blue-600 text-white px-3 py-2 rounded-md text-sm transition">
65
+ <i data-feather="upload" class="mr-1"></i> Import CSV
66
+ </button>
67
+ <button id="export-csv" class="bg-green-500 hover:bg-green-600 text-white px-3 py-2 rounded-md text-sm transition">
68
+ <i data-feather="download" class="mr-1"></i> Export CSV
69
+ </button>
70
+ <button id="center-diagram" class="bg-purple-500 hover:bg-purple-600 text-white px-3 py-2 rounded-md text-sm transition col-span-2">
71
+ <i data-feather="crosshair" class="mr-1"></i> Center Diagram
72
+ </button>
73
+ </div>
74
+ <input type="file" id="csv-file" accept=".csv" class="hidden">
75
+ </div>
76
+
77
+ <!-- Appearance moved into the Settings panel -->
78
 
79
  <!-- Nodes Management -->
80
  <div class="bg-gray-50 p-4 rounded-lg">
 
114
  <div class="flex-1 flex flex-col">
115
  <!-- Diagram Area -->
116
  <div class="flex-1 p-6">
117
+ <div id="diagram-container" class="bg-gray-200 rounded-xl shadow-md h-full overflow-hidden">
118
  <svg id="sankey-diagram" class="w-full h-full"></svg>
119
  </div>
120
  </div>
script.js CHANGED
@@ -48,13 +48,16 @@ function initDiagram() {
48
 
49
  // Set up the sankey diagram properties
50
  const width = document.getElementById('diagram-container').clientWidth;
51
- const height = parseInt(document.getElementById('diagram-height').value);
 
 
 
52
  const linkAlpha = parseFloat(document.getElementById('link-alpha').value);
53
 
54
  const sankey = d3.sankey()
55
  .nodeWidth(parseInt(document.getElementById('node-width').value))
56
  .nodePadding(20)
57
- .extent([[1, 1], [width - 1, height - 6]]);
58
 
59
  // Generate the sankey diagram
60
  const graph = sankey({
@@ -136,12 +139,11 @@ function initDiagram() {
136
  );
137
 
138
  // Add text with customizable position
139
- const textPosition = document.getElementById('text-position').value;
140
  let textY, textDy;
141
 
142
  switch(textPosition) {
143
  case 'top':
144
- textY = -5;
145
  textDy = "0em";
146
  break;
147
  case 'bottom':
@@ -398,6 +400,15 @@ document.addEventListener('DOMContentLoaded', () => {
398
  }
399
  e.target.value = ''; // Reset input
400
  });
 
 
 
 
 
 
 
 
 
401
 
402
  // Center diagram
403
  document.getElementById('center-diagram').addEventListener('click', () => {
 
48
 
49
  // Set up the sankey diagram properties
50
  const width = document.getElementById('diagram-container').clientWidth;
51
+ const baseHeight = parseInt(document.getElementById('diagram-height').value);
52
+ const textPosition = document.getElementById('text-position').value;
53
+ const textPadding = textPosition !== 'middle' ? 50 : 0; // Extra space for text above/below
54
+ const height = baseHeight + textPadding;
55
  const linkAlpha = parseFloat(document.getElementById('link-alpha').value);
56
 
57
  const sankey = d3.sankey()
58
  .nodeWidth(parseInt(document.getElementById('node-width').value))
59
  .nodePadding(20)
60
+ .extent([[textPadding/2, textPadding/2], [width - textPadding/2, height - textPadding/2]]);
61
 
62
  // Generate the sankey diagram
63
  const graph = sankey({
 
139
  );
140
 
141
  // Add text with customizable position
 
142
  let textY, textDy;
143
 
144
  switch(textPosition) {
145
  case 'top':
146
+ textY = -3;
147
  textDy = "0em";
148
  break;
149
  case 'bottom':
 
400
  }
401
  e.target.value = ''; // Reset input
402
  });
403
+
404
+ // Settings panel toggle
405
+ const settingsBtn = document.getElementById('settings-btn');
406
+ const settingsPanel = document.getElementById('settings-panel');
407
+ if (settingsBtn && settingsPanel) {
408
+ settingsBtn.addEventListener('click', () => {
409
+ settingsPanel.classList.toggle('hidden');
410
+ });
411
+ }
412
 
413
  // Center diagram
414
  document.getElementById('center-diagram').addEventListener('click', () => {