Graph colors, page titles and many more fixes
This commit is contained in:
@@ -5,4 +5,20 @@ export function shuffleArray(array : any[]) {
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts all arrays together with the first. Pass either a list of arrays, or a map. Any key is accepted.
|
||||
* Array|Object arrays [sortableArray, ...otherArrays]; {sortableArray: [], secondaryArray: [], ...}
|
||||
* Function comparator(?,?) -> int optional compareFunction, compatible with Array.sort(compareFunction)
|
||||
*/
|
||||
export function sortArrays(arrays : any[][], comparator = (a:any, b:any) => (a < b) ? 1 : (a > b) ? -1 : 0) {
|
||||
let arrayKeys = Object.keys(arrays);
|
||||
let sortableArray : (typeof arrays[0][0]) = Object.values(arrays)[0];
|
||||
let indexes = Object.keys(sortableArray);
|
||||
let sortedIndexes = indexes.sort((a, b) => comparator(sortableArray[a], sortableArray[b]));
|
||||
|
||||
let sortByIndexes = (array : any[], sortedIndexes : number[]) => sortedIndexes.map(sortedIndex => array[sortedIndex]);
|
||||
|
||||
return arrayKeys.map(arrayIndex => sortByIndexes(arrays[arrayIndex], sortedIndexes));
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DrinkType } from "@prisma/client";
|
||||
|
||||
export function random_rgba(numShades : number) {
|
||||
let o = Math.round, r = Math.random, s = 155, m = 100;
|
||||
|
||||
@@ -24,4 +26,18 @@ export function hexToRGB(hex : string, alpha : number) {
|
||||
} else {
|
||||
return "rgb(" + r + ", " + g + ", " + b + ")";
|
||||
}
|
||||
}
|
||||
|
||||
export function drinkTypeToColor(type: DrinkType){
|
||||
switch(type){
|
||||
default:
|
||||
case DrinkType.Beer:
|
||||
return 'rgba(255, 164, 18, 1)';
|
||||
case DrinkType.Cocktail:
|
||||
return 'rgba(83, 185, 219, 1)';
|
||||
case DrinkType.Soda:
|
||||
return 'rgba(188, 71, 214, 1)';
|
||||
case DrinkType.Wine:
|
||||
return 'rgba(178, 21, 58, 1)'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user