davidardz07 commited on
Commit
0b619ee
·
1 Parent(s): 76f3c6e

Color setting

Browse files
Files changed (2) hide show
  1. index.html +12 -0
  2. script.js +22 -3
index.html CHANGED
@@ -96,6 +96,18 @@
96
  <label class="block text-sm text-gray-600 mb-1">Link Alpha</label>
97
  <input type="range" id="link-alpha" min="0.1" max="1" step="0.1" value="0.5" class="w-full">
98
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
99
  <div>
100
  <label class="block text-sm text-gray-600 mb-1">Diagram Height</label>
101
  <input type="range" id="diagram-height" min="300" max="800" value="400" class="w-full">
 
96
  <label class="block text-sm text-gray-600 mb-1">Link Alpha</label>
97
  <input type="range" id="link-alpha" min="0.1" max="1" step="0.1" value="0.5" class="w-full">
98
  </div>
99
+ <div>
100
+ <label class="block text-sm text-gray-600 mb-1">Link Color Mode</label>
101
+ <select id="link-color-mode" class="w-full p-2 border rounded-md">
102
+ <option value="source">Source Node Color</option>
103
+ <option value="target">Target Node Color</option>
104
+ <option value="static">Static Color</option>
105
+ </select>
106
+ </div>
107
+ <div id="static-link-color-container" class="hidden">
108
+ <label class="block text-sm text-gray-600 mb-1">Link Static Color</label>
109
+ <input type="color" id="static-link-color" value="#93c5fd" class="w-full h-8">
110
+ </div>
111
  <div>
112
  <label class="block text-sm text-gray-600 mb-1">Diagram Height</label>
113
  <input type="range" id="diagram-height" min="300" max="800" value="400" class="w-full">
script.js CHANGED
@@ -544,9 +544,18 @@ function initDiagram() {
544
  .data(links)
545
  .join("path")
546
  .attr("d", sankey.link())
547
- .attr("stroke", d => {
548
- const srcColor = sankeyData.nodes[d.source.index]?.color || "#93c5fd";
549
- const rgb = hexToRgb(srcColor);
 
 
 
 
 
 
 
 
 
550
  return `rgba(${rgb.r},${rgb.g},${rgb.b},${linkAlpha})`;
551
  })
552
  .attr("stroke-width", d => Math.max(1, d.dy))
@@ -973,6 +982,16 @@ document.addEventListener('DOMContentLoaded', () => {
973
  document.getElementById('node-width').addEventListener('input', initDiagram);
974
  document.getElementById('diagram-height').addEventListener('input', initDiagram);
975
  document.getElementById('link-alpha').addEventListener('input', initDiagram);
 
 
 
 
 
 
 
 
 
 
976
 
977
  // Initialize dropdowns and lists
978
  updateLists();
 
544
  .data(links)
545
  .join("path")
546
  .attr("d", sankey.link())
547
+ link.attr("stroke", d => {
548
+ const linkColorMode = document.getElementById('link-color-mode').value;
549
+ let color;
550
+ if (linkColorMode === 'static') {
551
+ color = document.getElementById('static-link-color').value;
552
+ } else {
553
+ color = linkColorMode === 'source'
554
+ ? d.source.color
555
+ : d.target.color;
556
+ }
557
+ const finalColor = color || "#93c5fd";
558
+ const rgb = hexToRgb(finalColor);
559
  return `rgba(${rgb.r},${rgb.g},${rgb.b},${linkAlpha})`;
560
  })
561
  .attr("stroke-width", d => Math.max(1, d.dy))
 
982
  document.getElementById('node-width').addEventListener('input', initDiagram);
983
  document.getElementById('diagram-height').addEventListener('input', initDiagram);
984
  document.getElementById('link-alpha').addEventListener('input', initDiagram);
985
+ document.getElementById('static-link-color').addEventListener('input', initDiagram);
986
+
987
+ // Handle link color mode changes
988
+ const linkColorMode = document.getElementById('link-color-mode');
989
+ const staticColorContainer = document.getElementById('static-link-color-container');
990
+
991
+ linkColorMode.addEventListener('change', () => {
992
+ staticColorContainer.classList.toggle('hidden', linkColorMode.value !== 'static');
993
+ initDiagram();
994
+ });
995
 
996
  // Initialize dropdowns and lists
997
  updateLists();