Sha256: 3806761a9c2d67b50a075ca909ca445fa8cdd3b4bf2adc973577fe8491919654

Contents?: true

Size: 1.73 KB

Versions: 17

Compression:

Stored size: 1.73 KB

Contents

/*  Last full read through 27/12/2020
 *
 *##############################################
 *# svg label calc  /assets/js/svg_text_width.js
 *##############################################
 *
 */

 // Get the svg text elemnets inside .svg__labels, calulate their length and position with 768 clientWidth condition.

function svg_text_width() {
  // scren width
  const view_width = document.documentElement.clientWidth;
  // Get svg text and lines contained by .svg__labels
  const text = document.querySelectorAll('.svg__labels > .svg--text');
  const lines = document.querySelectorAll('.svg__labels > .svg--line');

  for (let i = 0; i < text.length; i++) {
    // get width of all the text labels
    const width = text[i].getComputedTextLength();
    // set up vars depending on 768 breakpoint
    if(view_width > 768 ){
      var lineLength = 100 ; // length in pixels of the drawn line
      var x_offset = 10 + width ; // offset the text label s.t. last character sits 10 px from end of line
      var y_offset = .5 ;
    } else {
      var lineLength = 70 ;
      var x_offset = 0 ; // offset the text label s.t. first character sits inline with end of line
      var y_offset = -1.5 ;}
      lines[i].setAttribute("stroke-dashoffset", lineLength + 'px')
      lines[i].setAttribute("stroke-dasharray", lineLength + 'px')
    if( text[i].classList.contains('trans-left')){
      lines[i].setAttribute("x2", -lineLength + 'px')
      text[i].setAttribute("x", - lineLength - x_offset + 'px');
      text[i].setAttribute("y", y_offset + 'rem');
    } else {
      lines[i].setAttribute("x2", lineLength + 'px')
      text[i].setAttribute("x", lineLength + x_offset - width + 'px');
      text[i].setAttribute("y", y_offset + 'rem');
    };
  };
}

svg_text_width()

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
slow-steps-0.3.3 assets/js/svg_text_width.js
slow-steps-0.3.2 assets/js/svg_text_width.js
slow-steps-0.3.1 assets/js/svg_text_width.js
slow-steps-0.3.0 assets/js/svg_text_width.js
slow-steps-0.2.1 assets/js/svg_text_width.js
slow-steps-0.2.0 assets/js/svg_text_width.js
slow-steps-0.1.13 assets/js/svg_text_width.js
slow-steps-0.1.12 assets/js/svg_text_width.js
slow-steps-0.1.11 assets/js/svg_text_width.js
slow-steps-0.1.10 assets/js/svg_text_width.js
slow-steps-0.1.9 assets/js/svg_text_width.js
slow-steps-0.1.8 assets/js/svg_text_width.js
slow-steps-0.1.7 assets/js/svg_text_width.js
slow-steps-0.1.6 assets/js/svg_text_width.js
slow-steps-0.1.5 assets/js/svg_text_width.js
slow-steps-0.1.4 assets/js/svg_text_width.js
slow-steps-0.1.3 assets/js/svg_text_width.js