* Render SVG sparkline
(container: HTMLElement, data: TrendDataPoint[])
| 1453 | * Render SVG sparkline |
| 1454 | */ |
| 1455 | private renderSparkline(container: HTMLElement, data: TrendDataPoint[]) { |
| 1456 | container.empty(); |
| 1457 | |
| 1458 | if (data.length === 0) { |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | const width = 100; |
| 1463 | const height = 20; |
| 1464 | const maxValue = Math.max(...data.map((d) => d.value)); |
| 1465 | |
| 1466 | if (maxValue === 0) { |
| 1467 | return; |
| 1468 | } |
| 1469 | |
| 1470 | const svg = activeDocument.createElementNS("http://www.w3.org/2000/svg", "svg"); |
| 1471 | svg.setAttribute("width", width.toString()); |
| 1472 | svg.setAttribute("height", height.toString()); |
| 1473 | svg.setAttribute("viewBox", `0 0 ${width} ${height}`); |
| 1474 | svg.classList.add("stats-view__sparkline-svg"); |
| 1475 | |
| 1476 | // Create path |
| 1477 | const path = activeDocument.createElementNS("http://www.w3.org/2000/svg", "path"); |
| 1478 | |
| 1479 | let pathD = ""; |
| 1480 | data.forEach((point, index) => { |
| 1481 | const x = (index / (data.length - 1)) * width; |
| 1482 | const y = height - (point.value / maxValue) * height; |
| 1483 | |
| 1484 | if (index === 0) { |
| 1485 | pathD += `M ${x} ${y}`; |
| 1486 | } else { |
| 1487 | pathD += ` L ${x} ${y}`; |
| 1488 | } |
| 1489 | }); |
| 1490 | |
| 1491 | path.setAttribute("d", pathD); |
| 1492 | path.setAttribute("fill", "none"); |
| 1493 | path.setAttribute("stroke", "currentColor"); |
| 1494 | path.setAttribute("stroke-width", "1.5"); |
| 1495 | path.setAttribute("opacity", "0.7"); |
| 1496 | |
| 1497 | svg.appendChild(path); |
| 1498 | container.appendChild(svg); |
| 1499 | } |
| 1500 | |
| 1501 | /** |
| 1502 | * Open project drill-down modal |
no test coverage detected