diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-09 10:58:28 -0500 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-09 10:58:28 -0500 |
| commit | d57a1130908e920d1b033a268dac6b71a5b88978 (patch) | |
| tree | 0daa00f0d2c289b58bcf7de79105736fb6f5dd7f /src/formats.ts | |
| parent | 90424d59e7f038af6f9b6b69029ab5c43b1a01ee (diff) | |
| download | ao-coverage-d57a1130908e920d1b033a268dac6b71a5b88978.tar.gz ao-coverage-d57a1130908e920d1b033a268dac6b71a5b88978.tar.bz2 ao-coverage-d57a1130908e920d1b033a268dac6b71a5b88978.zip | |
Promisify data flow in POST request
Diffstat (limited to 'src/formats.ts')
| -rw-r--r-- | src/formats.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/formats.ts b/src/formats.ts index 1b5a572..4b432e3 100644 --- a/src/formats.ts +++ b/src/formats.ts @@ -3,7 +3,7 @@ import { InvalidReportDocumentError } from "./errors"; export interface Format { // returns the coverage value as %: Number(90.0), Number(100.0), Number(89.5) parse_coverage: (file: Document) => number | InvalidReportDocumentError; - match_color: (coverage: number, stage_1: number, stage_2: number) => string; + match_color: (coverage: number, style: GradientStyle) => string; } interface FormatList { @@ -16,18 +16,19 @@ interface FormatObj { get_format: (format: string) => Format; } +export interface GradientStyle { + stage_1: number; + stage_2: number; +} + // color is a gradient from green (>=stage_1) -> yellow (stage_2) -> red. Stage values should come from metadata. -const default_color_matches = ( - coverage: number, - stage_1: number, - stage_2: number -) => { +const default_color_matches = (coverage: number, style: GradientStyle) => { const gradient = - coverage >= stage_1 + coverage >= style.stage_1 ? 15 - : coverage >= stage_2 - ? (Math.floor(coverage) - stage_2) * 16 + 15 - : 240 + Math.floor(coverage / (stage_2 / 15)); + : coverage >= style.stage_2 + ? (Math.floor(coverage) - style.stage_2) * 16 + 15 + : 240 + Math.floor(coverage / (style.stage_2 / 15)); return gradient.toString(16) + "0"; }; |
