functions/index.js
function getSVGGraphPathData(data, width, height) {
  var max = Math.max.apply(null, data);

  var width = 800;
  var height = 100;
  var scaleH = width / (data.length - 1)
  var scaleV = height / max;

  var factor = 0.25;

  var commands = [`m0,${applyScaleV(data[0])}`];

  function round(val) {
    return Math.round(val * 1000) / 1000;
  }

  function applyScaleH(val) {
    return round(val * scaleH);
  }

  function applyScaleV(val) {
    return round(100 - val * scaleV);
  }

  for (let i = 0, max = data.length - 1; i < max; i++) {
    current = data[i];
    next = data[i + 1];

    let x = (i + 0.5);
    let y = current + (next - current) * 0.5

    let sX = (i + (0.5 - factor));
    let sY = current + (next - current) * (0.5 - factor);

    commands.push(`S${applyScaleH(sX)} ${applyScaleV(sY)},${applyScaleH(x)} ${applyScaleV(y)}`);
  }

  var finalY = data[data.length - 1];
  commands.push(`S${width} ${applyScaleV(finalY)},${width} ${applyScaleV(finalY)}`);

  return commands.join(' ');
}
function getSVGGraphPathData(data, width, height) {
  var max = Math.max.apply(null, data);

  var width = 800;
  var height = 100;
  var scaleH = width / (data.length - 1)
  var scaleV = height / max;

  var factor = 0.25;

  var commands = [`m0,${applyScaleV(data[0])}`];

  function round(val) {
    return Math.round(val * 1000) / 1000;
  }

  function applyScaleH(val) {
    return round(val * scaleH);
  }

  function applyScaleV(val) {
    return round(100 - val * scaleV);
  }

  for (let i = 0, max = data.length - 1; i < max; i++) {
    current = data[i];
    next = data[i + 1];

    let x = (i + 0.5);
    let y = current + (next - current) * 0.5

    let sX = (i + (0.5 - factor));
    let sY = current + (next - current) * (0.5 - factor);

    commands.push(`S${applyScaleH(sX)} ${applyScaleV(sY)},${applyScaleH(x)} ${applyScaleV(y)}`);
  }

  var finalY = data[data.length - 1];
  commands.push(`S${width} ${applyScaleV(finalY)},${width} ${applyScaleV(finalY)}`);

  return commands.join(' ');
}
function getSVGGraphPathData ( data , width , height ) { var max = Math . max . apply ( null , data ) ; var width = 800 ; var height = 100 ; var scaleH = width / ( data . length - 1 ) var scaleV = height / max ; var factor = 0.25 ; var commands = [ ` ${ applyScaleV ( data [ 0 ] ) } ` ] ; function round ( val ) { return Math . round ( val * 1000 ) / 1000 ; } function applyScaleH ( val ) { return round ( val * scaleH ) ; } function applyScaleV ( val ) { return round ( 100 - val * scaleV ) ; } for ( let i = 0 , max = data . length - 1 ; i < max ; i ++ ) { current = data [ i ] ; next = data [ i + 1 ] ; let x = ( i + 0.5 ) ; let y = current + ( next - current ) * 0.5 let sX = ( i + ( 0.5 - factor ) ) ; let sY = current + ( next - current ) * ( 0.5 - factor ) ; commands . push ( ` ${ applyScaleH ( sX ) } ${ applyScaleV ( sY ) } ${ applyScaleH ( x ) } ${ applyScaleV ( y ) } ` ) ; } var finalY = data [ data . length - 1 ] ; commands . push ( ` ${ width } ${ applyScaleV ( finalY ) } ${ width } ${ applyScaleV ( finalY ) } ` ) ; return commands . join ( ' ' ) ; }
getSVGGraphPath data converts an array of numbers to valid SVG graph path
data.

@param {Array} data - The data to convert to SVG graph path format.
@param {Integer} width - The width of the SVG.
@param {Integer} height - The height of the SVG.
@return {String} The string representing the SVG path.
getSVGGraphPath data converts an array of numbers to valid SVG graph path data .