// Define the default fill and stroke colors const defaultFill = "#dcfce7"; const defaultStroke = "#bbf7d0"; // Define the stroke width const strokeWidth = 4; /** * Draws a sparkline SVG based on the given width, height and points * @param {number} width - The width of the SVG element * @param {number} height - The height of the SVG element * @param {number[]} points - The array of points to plot * @param {string} [fill=defaultFill] - The fill color of the area under the curve * @param {string} [stroke=defaultStroke] - The stroke color of the curve * @returns {string} The SVG markup */ function draw(width, height, points, fill = defaultFill, stroke = defaultStroke) { // Calculate the viewbox dimensions based on the points let vbWidth = points.length - 1; let vbHeight = Math.max(...points); // Return the SVG markup with the paths and attributes return ` `; } /** * Generates the path for the curve * @param {number[]} points - The array of points to plot * @param {number} vbWidth - The viewbox width * @param {number} vbHeight - The viewbox height * @returns {string} The path data */ const path = (points, vbWidth, vbHeight) => [ "M", points .map((value, i) => { let x = i; let y = vbHeight - value; return `${x} ${y}${i < vbWidth ? " L " : ""}`; }) .join("") ].join(""); /** * Generates the path for the area under the curve * @param {number[]} points - The array of points to plot * @param {number} vbWidth - The viewbox width * @param {number} vbHeight - The viewbox height * @returns {string} The path data */ const closedPath = (points, vbWidth, vbHeight) => [ path(points, vbWidth, vbHeight), ` L ${vbWidth} ${vbHeight} L 0 ${vbHeight} Z` ].join(""); // Export the draw function as a module module.exports = draw;