diff --git a/web/public/src/index.ts b/web/public/src/index.ts index dc2bd0f..adc3500 100644 --- a/web/public/src/index.ts +++ b/web/public/src/index.ts @@ -2,12 +2,13 @@ import * as data from "./data.ts"; type Color = { r: number; g: number; b: number }; -function lerp(ratio: number, start: number, middle: number, end: number) { - if (ratio < 0.5) { - return (1 - ratio) * start + ratio * middle; - } else { - return (1 - ratio) * middle + ratio * end; - } +function lerp2(ratio: number, start: number, end: number) { + return (1 - ratio) * start + ratio * end; +} + +function lerp3(ratio: number, start: number, middle: number, end: number) { + return (1 - ratio) * lerp2(ratio, start, middle) + + ratio * lerp2(ratio, middle, end); } function colorLerp( @@ -17,9 +18,9 @@ function colorLerp( end: Color, ): Color { return { - r: lerp(ratio, start.r, middle.r, end.r), - g: lerp(ratio, start.g, middle.g, end.g), - b: lerp(ratio, start.b, middle.b, end.b), + r: lerp3(ratio, start.r, middle.r, end.r), + g: lerp3(ratio, start.g, middle.g, end.g), + b: lerp3(ratio, start.b, middle.b, end.b), }; } @@ -41,7 +42,7 @@ function loadCodeCoverage( let line = 1; let col = 1; const maxCovers = entries.map((v) => v.covers).reduce((acc, v) => - acc > v ? acc : v + acc > Math.log10(v) ? acc : Math.log10(v) ); for (let index = 0; index < text.length; ++index) { if (text[index] === "\n") { @@ -73,7 +74,7 @@ function loadCodeCoverage( const span = document.createElement("span"); span.style.backgroundColor = backgroundColor( - Math.log10((entry.covers / maxCovers) * 10), + Math.log10(entry.covers) / maxCovers, ); span.innerText = text[index]; span.dataset.covers = entry.covers.toString();