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

export const DEFAULT_ANIMATION_INTERVAL = 2000;

export const DEFAULT_RADIO_RECORD: RadioRecord = {
  width: 200,
  height: 140,
  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 ? height ** 2 : width ** 2;

  const isLess = temp < 300 * 300;

  const radio = temp / (300 * 300);

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

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