davidardz07 commited on
Commit
5f08e7c
·
1 Parent(s): 76f6f02

Slider para modificar pading de texto

Browse files
Files changed (2) hide show
  1. index.html +5 -0
  2. script.js +11 -7
index.html CHANGED
@@ -90,6 +90,11 @@
90
  <option value="bottom">Bottom</option>
91
  </select>
92
  </div>
 
 
 
 
 
93
  <div>
94
  <label class="block text-sm text-gray-600 mb-1">Node Width</label>
95
  <input type="range" id="node-width" min="10" max="80" value="40" class="w-full">
 
90
  <option value="bottom">Bottom</option>
91
  </select>
92
  </div>
93
+ <div>
94
+ <label class="block text-sm text-gray-600 mb-1">Text Padding (px)</label>
95
+ <input type="range" id="text-padding" min="2" max="30" value="6" class="w-full">
96
+ <div class="text-xs text-gray-500 mt-1">Distance between text and node</div>
97
+ </div>
98
  <div>
99
  <label class="block text-sm text-gray-600 mb-1">Node Width</label>
100
  <input type="range" id="node-width" min="10" max="80" value="40" class="w-full">
script.js CHANGED
@@ -664,25 +664,28 @@ function initDiagram() {
664
  // Add text with customizable position
665
  let textX, textY, textAnchor;
666
 
 
 
 
667
  function getDefaultTextPosition(node) {
668
  const diagramWidth = width - textPadding;
669
  const xRatio = node.x / diagramWidth;
670
 
671
  if (xRatio < 0.33) { // Left nodes
672
  return {
673
- x: node.dx + 6, // Position text on right side
674
  y: node.dy / 2,
675
  anchor: "start"
676
  };
677
  } else if (xRatio > 0.66) { // Right nodes
678
  return {
679
- x: -6, // Position text on left side
680
  y: node.dy / 2,
681
  anchor: "end"
682
  };
683
  } else { // Middle nodes
684
  return {
685
- x: node.dx + 6, // Position text on right side
686
  y: node.dy / 2,
687
  anchor: "start"
688
  };
@@ -697,23 +700,23 @@ function initDiagram() {
697
  textAnchor = d => getDefaultTextPosition(d).anchor;
698
  break;
699
  case 'left':
700
- textX = -6;
701
  textY = d => d.dy / 2;
702
  textAnchor = "end";
703
  break;
704
  case 'right':
705
- textX = d => d.dx + 6;
706
  textY = d => d.dy / 2;
707
  textAnchor = "start";
708
  break;
709
  case 'top':
710
  textX = d => d.dx / 2;
711
- textY = -6;
712
  textAnchor = "middle";
713
  break;
714
  case 'bottom':
715
  textX = d => d.dx / 2;
716
- textY = d => d.dy + 6;
717
  textAnchor = "middle";
718
  break;
719
  }
@@ -1114,6 +1117,7 @@ document.addEventListener('DOMContentLoaded', () => {
1114
  // Color and options changes
1115
  document.getElementById('text-color').addEventListener('input', initDiagram);
1116
  document.getElementById('text-position').addEventListener('change', initDiagram);
 
1117
  document.getElementById('node-width').addEventListener('input', initDiagram);
1118
  document.getElementById('diagram-height').addEventListener('input', initDiagram);
1119
  document.getElementById('link-alpha').addEventListener('input', initDiagram);
 
664
  // Add text with customizable position
665
  let textX, textY, textAnchor;
666
 
667
+ // Get the text padding value from the settings
668
+ const textPaddingValue = parseInt(document.getElementById('text-padding').value);
669
+
670
  function getDefaultTextPosition(node) {
671
  const diagramWidth = width - textPadding;
672
  const xRatio = node.x / diagramWidth;
673
 
674
  if (xRatio < 0.33) { // Left nodes
675
  return {
676
+ x: node.dx + textPaddingValue, // Position text on right side
677
  y: node.dy / 2,
678
  anchor: "start"
679
  };
680
  } else if (xRatio > 0.66) { // Right nodes
681
  return {
682
+ x: -textPaddingValue, // Position text on left side
683
  y: node.dy / 2,
684
  anchor: "end"
685
  };
686
  } else { // Middle nodes
687
  return {
688
+ x: node.dx + textPaddingValue, // Position text on right side
689
  y: node.dy / 2,
690
  anchor: "start"
691
  };
 
700
  textAnchor = d => getDefaultTextPosition(d).anchor;
701
  break;
702
  case 'left':
703
+ textX = -textPaddingValue;
704
  textY = d => d.dy / 2;
705
  textAnchor = "end";
706
  break;
707
  case 'right':
708
+ textX = d => d.dx + textPaddingValue;
709
  textY = d => d.dy / 2;
710
  textAnchor = "start";
711
  break;
712
  case 'top':
713
  textX = d => d.dx / 2;
714
+ textY = -textPaddingValue;
715
  textAnchor = "middle";
716
  break;
717
  case 'bottom':
718
  textX = d => d.dx / 2;
719
+ textY = d => d.dy + textPaddingValue;
720
  textAnchor = "middle";
721
  break;
722
  }
 
1117
  // Color and options changes
1118
  document.getElementById('text-color').addEventListener('input', initDiagram);
1119
  document.getElementById('text-position').addEventListener('change', initDiagram);
1120
+ document.getElementById('text-padding').addEventListener('input', initDiagram);
1121
  document.getElementById('node-width').addEventListener('input', initDiagram);
1122
  document.getElementById('diagram-height').addEventListener('input', initDiagram);
1123
  document.getElementById('link-alpha').addEventListener('input', initDiagram);