| 85 | }; |
| 86 | |
| 87 | createPath(){ |
| 88 | const root = this.root; |
| 89 | const fill = this.fill; |
| 90 | const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); |
| 91 | path.setAttribute('fill', fill); |
| 92 | path.setAttribute('stroke', fill); |
| 93 | svg.appendChild(path); |
| 94 | if (settings.fill) { |
| 95 | svg.setAttribute('class','path'); |
| 96 | } else { |
| 97 | svg.setAttribute('class','stroke'); |
| 98 | } |
| 99 | |
| 100 | // first & second points |
| 101 | let d = `M -${overflow} ${winH + overflow}`; |
| 102 | d += ` L ${root[0].x} ${root[0].y}`; |
| 103 | |
| 104 | // magic points |
| 105 | for (let i = 1; i < this.root.length - 1; i++) { |
| 106 | let prevPoint = root[i - 1]; |
| 107 | let actualPoint = root[i]; |
| 108 | let diffX = (actualPoint.x - prevPoint.x) / settings.smoothness; |
| 109 | let x1 = prevPoint.x + diffX; |
| 110 | let x2 = actualPoint.x - diffX; |
| 111 | let x = actualPoint.x; |
| 112 | let y1 = prevPoint.y; |
| 113 | let y2 = actualPoint.y; |
| 114 | let y = actualPoint.y; |
| 115 | |
| 116 | d += ` C ${x1} ${y1}, ${x2} ${y2}, ${x} ${y}`; |
| 117 | } |
| 118 | |
| 119 | // Second last |
| 120 | const reverseRoot = root.reverse(); |
| 121 | d += ` L ${reverseRoot[0].x} ${reverseRoot[0].y}`; |
| 122 | root.reverse(); |
| 123 | |
| 124 | // Last point |
| 125 | d += ` L ${winW + overflow} ${winH + overflow}`; |
| 126 | |
| 127 | // Close path |
| 128 | d += ` Z`; |
| 129 | |
| 130 | path.setAttribute('d', d); |
| 131 | }; |
| 132 | |
| 133 | createfrequency(){ |
| 134 | const root = this.root; |