refactor(es modules): migrate a few more functions

This commit is contained in:
Azgaar 2022-06-28 00:04:09 +03:00
parent 63e9b9c87e
commit 865a98199f
18 changed files with 330 additions and 309 deletions

View file

@ -1,6 +1,6 @@
const d3 = window.d3;
const c12 = [
const c12: Hex[] = [
"#dababf",
"#fb8072",
"#80b1d3",
@ -38,3 +38,21 @@ export function getMixedColor(hexColor: string, mixation = 0.2, bright = 0.3) {
return d3.color(mixedColor).brighter(bright).hex();
}
export function getColorScheme(schemeName: string) {
return colorSchemeMap[schemeName] || colorSchemeMap.default;
}
type ColorScheme = (n: number) => RGB;
const colorSchemeMap: Dict<ColorScheme> = {
default: d3.scaleSequential(d3.interpolateSpectral),
bright: d3.scaleSequential(d3.interpolateSpectral),
light: d3.scaleSequential(d3.interpolateRdYlGn),
green: d3.scaleSequential(d3.interpolateGreens),
monochrome: d3.scaleSequential(d3.interpolateGreys)
};
export function getHeightColor(height: number, scheme = getColorScheme("default")) {
const fittedValue = height < 20 ? height - 5 : height;
return scheme(1 - fittedValue / 100);
}