dist/hdsf-hive.js
/**
  * Formats the text of an SVG.  Removes existing text, inserts new formatted text.
  *
  * @param object HTML text element
  * @param number text configuration
  * @return formatted text metrics
  */
Formats the text of an SVG.  Removes existing text, inserts new formatted text.
@param object HTML text element
@param number text configuration
@return formatted text metrics
Formats the text of an SVG . Removes existing text inserts new formatted text . @param object HTML text element @param number text configuration @return formatted text metrics
static replace(e, cfg) {
    ['height', 'width'].forEach((param, i) => {
      let p = cfg.text[param];
      ['vw','vh','bw','iw','ih'].forEach((unit, i) => {
        if (p && typeof p == 'string' && p.endsWith(unit))
          cfg.text[param] = (parseInt(p)/100) * cfg[unit];
      });
    });
    let content = e.innerHTML;
    let format = cfg.text.format?cfg.text.format:d=>d;
    if(!format(content).length) return {h:0,w:0};
    let id = e.getAttribute('id');
    let x = e.getAttribute('x');
    let y = e.getAttribute('y');
    let rotate;
    (e.getAttribute('transform')||'').replace(/rotate\([\d ]+\)/, d=>rotate=parseFloat(d.slice(7)));
    let def = {x:+x, y:+y};
    if (rotate) def.rotate = rotate;
    let attr = {};
    [...e.attributes].filter(d=>d.name.startsWith('font-')||d.name=='fill').forEach((a, i) => {
      attr[a.name] = a.nodeValue;
    });
    cfg = {...def, ...cfg.text, attr};
    let rv = this.format(content, cfg);
    rv.e.setAttribute('id', id);
    e.parentElement.append(rv.e);
    e.remove();
    return rv.bbox;
  }
static replace ( e , cfg ) { [ 'height' , 'width' ] . forEach ( ( param , i ) => { let p = cfg . text [ param ] ; [ 'vw' , 'vh' , 'bw' , 'iw' , 'ih' ] . forEach ( ( unit , i ) => { if ( p && typeof p == 'string' && p . endsWith ( unit ) ) cfg . text [ param ] = ( parseInt ( p ) / 100 ) * cfg [ unit ] ; } ) ; } ) ; let content = e . innerHTML ; let format = cfg . text . format ? cfg . text . format : d => d ; if ( ! format ( content ) . length ) return { h : 0 , w : 0 } ; let id = e . getAttribute ( 'id' ) ; let x = e . getAttribute ( 'x' ) ; let y = e . getAttribute ( 'y' ) ; let rotate ; ( e . getAttribute ( 'transform' ) || '' ) . replace ( / rotate\([\d ]+\) / , d => rotate = parseFloat ( d . slice ( 7 ) ) ) ; let def = { x : + x , y : + y } ; if ( rotate ) def . rotate = rotate ; let attr = { } ; [ ... e . attributes ] . filter ( d => d . name . startsWith ( 'font-' ) || d . name == 'fill' ) . forEach ( ( a , i ) => { attr [ a . name ] = a . nodeValue ; } ) ; cfg = { ... def , ... cfg . text , attr } ; let rv = this . format ( content , cfg ) ; rv . e . setAttribute ( 'id' , id ) ; e . parentElement . append ( rv . e ) ; e . remove ( ) ; return rv . bbox ; }
Formats the text of an SVG.
Formats the text of an SVG .
// resolve w/h units // vis width/height, axis bandwidth, (largest) guide icon height/width // if(cfg.text.format && !cfg.text.format(content).length) return {h:0,w:0}; // let textAnchor = e.getAttribute('text-anchor'); // if (textAnchor) def.textAnchor = textAnchor;