util.ts 890 Bytes
export interface RadioRecord {
  width: number;
  height: number;
  isLess: boolean;
  radio: number;
}

export const DEFAULT_ANIMATION_INTERVAL = 2000;

export const DEFAULT_RADIO_RECORD: RadioRecord = {
  width: 300,
  height: 300,
  isLess: false,
  radio: 1,
};

export const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';

export const calcScale = (
  width: number,
  height: number,
  widthRadio: number,
  heightRadio: number
): RadioRecord => {
  width = width * (widthRadio / 100);
  height = height * (heightRadio / 100);

  const temp = width * height;

  const isLess = temp < 300 * 300;

  const radio = temp / (300 * 300);

  return {
    width,
    height,
    isLess,
    radio,
  };
};

export const fontSize = ({ radio, basic, max }: { radio: number; basic: number; max?: number }) => {
  let res = basic * radio;
  if (max && res > max) res = max;
  return res + 'px';
};