sparklines.js (690B)
1 const ticks = [`▁`, `▂`, `▃`, `▄`, `▅`, `▆`, `▇`, `█`]; 2 const _ticksLength = ticks.length; 3 const _heightToTickIndex = (maximum, v) => { 4 const suggestedTickIndex = Math.ceil((v / maximum) * _ticksLength) - 1; 5 return Math.max(suggestedTickIndex, 0); 6 }; 7 export const createSparkline = (relativeHeights, maximum = undefined) => { 8 if (relativeHeights.length === 0) { 9 return ""; 10 } 11 else { 12 const usedMaximum = maximum ?? Math.max(...relativeHeights); 13 return relativeHeights 14 .map((v) => _heightToTickIndex(usedMaximum, v)) 15 .map((r) => ticks[r]) 16 .join(""); 17 } 18 }; 19 //# sourceMappingURL=sparklines.js.map