| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { scale } from "chroma-js";
- export function checkDateOrder(first: string, second: string) {
- const firstTs = Date.parse(first);
- const secondTs = Date.parse(second);
- return firstTs <= secondTs;
- }
- export function mustCheckDateOrder(first: string, second: string) {
- if (!checkDateOrder(first, second)) {
- throw new Error(
- "La fecha inicial no puede ser posterior a la fecha final."
- );
- }
- }
- function campYear(ISOFrom: string): number {
- // El año de la temporada 2021 - 2022 es 2022
- // "El año empieza el 1 de Octubre"
- // Offset desde el 1 de Octubre hasta el 1 de Enero
- const offset = 7948800000;
- const offsetDate = new Date(Date.parse(ISOFrom) + offset);
- return offsetDate.getFullYear();
- }
- // Computa un string para que el usuario identifique la temporada que esta viendo
- export function campString(
- ISOFrom: string,
- ISOTo: string,
- withVintage?: boolean
- ) {
- const yr = campYear(ISOFrom);
- // Con vendimia
- if (withVintage) {
- return `${yr - 1} - ${yr} - Vendimia ${yr} `;
- }
- // Sin vendimia
- return `${yr - 1} - ${yr}`;
- }
- // Escalas de colores
- export const orangeScale = (domain: number[]) =>
- scale(["white", "orange"]).domain(domain);
- export const redScale = (domain: number[]) =>
- scale(["white", "rgb(192, 0, 0)"]).domain(domain);
- export const blueScale = (domain: number[]) =>
- scale(["white", "rgb(58, 145, 207)"]).domain(domain);
- export const greenScale = (domain: number[]) =>
- scale(["white", "rgb(169, 208, 142)"]).domain(domain);
- export const yellowScale = (domain: number[]) =>
- scale(["white", "rgb(255, 255, 0)"]).domain(domain);
- export const grayScale = (domain: number[]) =>
- scale(["white", "rgb(169, 169, 169)"]).domain(domain);
|