-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
86 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { theme } from "@chakra-ui/react" | ||
import { tinycolor } from "@ctrl/tinycolor" | ||
|
||
/** | ||
* The color for the edge with given back pressure value. | ||
* | ||
* @param value The back pressure rate, between 0 and 100. | ||
*/ | ||
export function backPressureColor(value: number) { | ||
const colorRange = [ | ||
theme.colors.green["100"], | ||
theme.colors.green["300"], | ||
theme.colors.yellow["400"], | ||
theme.colors.orange["500"], | ||
theme.colors.red["700"], | ||
].map((c) => tinycolor(c)) | ||
|
||
value = Math.max(value, 0) | ||
value = Math.min(value, 100) | ||
|
||
const step = colorRange.length - 1 | ||
const pos = (value / 100) * step | ||
const floor = Math.floor(pos) | ||
const ceil = Math.ceil(pos) | ||
|
||
const color = tinycolor(colorRange[floor]) | ||
.mix(tinycolor(colorRange[ceil]), (pos - floor) * 100) | ||
.toHexString() | ||
|
||
return color | ||
} | ||
|
||
/** | ||
* The width for the edge with given back pressure value. | ||
* | ||
* @param value The back pressure rate, between 0 and 100. | ||
*/ | ||
export function backPressureWidth(value: number, scale: number) { | ||
value = Math.max(value, 0) | ||
value = Math.min(value, 100) | ||
|
||
return scale * (value / 100) + 2 | ||
} |