-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draw bug age distributions as box & whisker plots.
- Loading branch information
Showing
5 changed files
with
183 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,126 @@ | ||
--- | ||
import type { Temporal } from "@js-temporal/polyfill"; | ||
import { formatRoundAge } from "@lib/formatRoundAge"; | ||
import type { AgeStats } from "@lib/repo-summaries"; | ||
interface Props { | ||
ageStats: AgeStats; | ||
description: string; | ||
/** The global maximum bug age, to render at the right side of the chart. */ | ||
maxAge: Temporal.Duration; | ||
} | ||
const { ageStats, description } = Astro.props; | ||
const { ageStats, description, maxAge } = Astro.props; | ||
const percentiles = [10, 25, 50, 75, 90]; | ||
const maxAgeS = maxAge.total("seconds"); | ||
const p10Frac = | ||
Math.round((ageStats[10].total("seconds") / maxAgeS) * 1000) / 10; | ||
const p25Frac = | ||
Math.round((ageStats[25].total("seconds") / maxAgeS) * 1000) / 10; | ||
const p50Frac = | ||
Math.round((ageStats[50].total("seconds") / maxAgeS) * 1000) / 10; | ||
const p75Frac = | ||
Math.round((ageStats[75].total("seconds") / maxAgeS) * 1000) / 10; | ||
const p90Frac = | ||
Math.round((ageStats[90].total("seconds") / maxAgeS) * 1000) / 10; | ||
const meanFrac = | ||
Math.round((ageStats.mean.total("seconds") / maxAgeS) * 1000) / 10; | ||
--- | ||
|
||
<div class="bugStats"> | ||
<p>{ageStats.count}{' '}{description}: mean age {formatRoundAge(ageStats.mean)}</p> | ||
<table> | ||
<tr>{percentiles.map((p) => <th><span class="ord">{p}th</span> %ile</th>)}</tr> | ||
<tr>{percentiles.map((p) => <td>{formatRoundAge(ageStats[p])}</td>)}</tr | ||
<figure class="bugStats" title={`${ageStats.count} ${description}`}> | ||
<span class="whisker" style={`--start: ${p10Frac}%; --end: ${p90Frac}%`} | ||
></span> | ||
<span class="box" style={`--start: ${p25Frac}%; --end: ${p75Frac}%`}></span> | ||
<ul> | ||
<li | ||
class="p" | ||
style={`--frac: ${p10Frac}%`} | ||
title=`10th percentile: ${formatRoundAge(ageStats[10])}` | ||
> | ||
</table> | ||
</div> | ||
</li> | ||
<li | ||
class="p" | ||
style={`--frac: ${p25Frac}%`} | ||
title=`25th percentile: ${formatRoundAge(ageStats[25])}` | ||
> | ||
</li> | ||
<li | ||
class="median" | ||
style={`--frac: ${p50Frac}%`} | ||
title=`median: ${formatRoundAge(ageStats[50])}` | ||
> | ||
</li> | ||
<li | ||
class="p" | ||
style={`--frac: ${p75Frac}%`} | ||
title=`75th percentile: ${formatRoundAge(ageStats[75])}` | ||
> | ||
</li> | ||
<li | ||
class="p" | ||
style={`--frac: ${p90Frac}%`} | ||
title=`90th percentile: ${formatRoundAge(ageStats[90])}` | ||
> | ||
</li> | ||
<li | ||
class="mean" | ||
style={`--frac: ${meanFrac}%`} | ||
title=`mean: ${formatRoundAge(ageStats.mean)}` | ||
> | ||
</li> | ||
</ul> | ||
</figure> | ||
|
||
<style is:global> | ||
.bugStats { | ||
display: inline-block; | ||
vertical-align: middle; | ||
position: relative; | ||
margin: 0; | ||
padding: 0; | ||
height: 1lh; | ||
width: clamp(50px, 40vw, 500px); | ||
} | ||
.bugStats :is(ul, li) { | ||
display: inline; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.bugStats :is(.box, .whisker) { | ||
position: absolute; | ||
left: var(--start); | ||
right: calc(100% - var(--end)); | ||
border: thin solid black; | ||
} | ||
.bugStats .box { | ||
top: 0; | ||
bottom: 0; | ||
background-color: var(--bg); | ||
} | ||
.bugStats .whisker { | ||
top: 50%; | ||
bottom: 50%; | ||
} | ||
.bugStats :is(.p, .median, .mean) { | ||
position: absolute; | ||
left: calc(var(--frac) - 0.5em); | ||
right: calc(100% - var(--frac) - 0.5em); | ||
top: 0; | ||
bottom: 0; | ||
} | ||
.bugStats .median:after { | ||
position: absolute; | ||
left: 50%; | ||
right: 50%; | ||
top:0; | ||
bottom:0; | ||
border: thin solid black; | ||
content: " "; | ||
} | ||
.bugStats .mean:after { | ||
content: "★"; | ||
position: absolute; | ||
font-size: 50%; | ||
left: 50%; top: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters