Skip to content

Commit

Permalink
Use natural log for snapshot selector bar height, linear for color
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Mar 8, 2021
1 parent b5ac359 commit 07b4155
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ function SnapshotCommitListItem({data: itemData, index, style}: Props) {
const commitDuration = commitDurations[index];
const commitTime = commitTimes[index];

// Guard against commits with duration 0
const percentage =
// Use natural log for bar height.
// This prevents one (or a few) outliers from squishing the majority of other commits.
// So rather than e.g. _█_ we get something more like e.g. ▄█_
const heightScale =
Math.min(
1,
Math.max(0, Math.log(commitDuration) / Math.log(maxDuration)),
) || 0;

// Use a linear scale for color.
// This gives some visual contrast between cheaper and more expensive commits
// and somewhat compensates for the log scale height.
const colorScale =
Math.min(1, Math.max(0, commitDuration / maxDuration)) || 0;

const isSelected = selectedCommitIndex === index;

// Leave a 1px gap between snapshots
Expand Down Expand Up @@ -80,9 +89,9 @@ function SnapshotCommitListItem({data: itemData, index, style}: Props) {
<div
className={styles.Inner}
style={{
height: `${Math.round(percentage * 100)}%`,
height: `${Math.round(heightScale * 100)}%`,
backgroundColor:
commitDuration > 0 ? getGradientColor(percentage) : undefined,
commitDuration > 0 ? getGradientColor(colorScale) : undefined,
}}
/>
</div>
Expand Down

0 comments on commit 07b4155

Please sign in to comment.