You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

6 days ago
5 days ago
6 days ago
  1. export const cmdNameMap = {
  2. pump_rotate_start: '泵开始转动',
  3. pump_rotate_stop: '泵停止转动',
  4. solution_pre_fill_start: '预充',
  5. solution_add_start: '加液',
  6. solution_drain_start: '排空',
  7. }
  8. export const generateColors = (count: number): string[] => {
  9. const colors: string[] = []
  10. for (let i = 0; i < count; i++) {
  11. // Increase hue step to make colors more distinct
  12. const hue = (i * 360) / count
  13. // Introduce variation in saturation and lightness with larger steps
  14. const saturation = 30 + (i % 5) * 20 // Alternate between 30, 50, 70, 90, 110
  15. const lightness = 30 + (i % 4) * 20 // Alternate between 30, 50, 70, 90
  16. // Convert HSL to RGB
  17. const rgb = hslToRgb(hue, saturation, lightness)
  18. // Convert RGB to hex
  19. const hex = rgbToHex(rgb.r, rgb.g, rgb.b)
  20. colors.push(hex)
  21. }
  22. return colors
  23. }
  24. const hslToRgb = (h: number, s: number, l: number): { r: number, g: number, b: number } => {
  25. s /= 100
  26. l /= 100
  27. const k = (n: number) => (n + h / 30) % 12
  28. const a = s * Math.min(l, 1 - l)
  29. const f = (n: number) =>
  30. l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)))
  31. return {
  32. r: Math.round(f(0) * 255),
  33. g: Math.round(f(8) * 255),
  34. b: Math.round(f(4) * 255),
  35. }
  36. }
  37. const rgbToHex = (r: number, g: number, b: number): string => {
  38. const toHex = (c: number) => `0${c.toString(16)}`.slice(-2)
  39. return `#${toHex(r)}${toHex(g)}${toHex(b)}`
  40. }
  41. export const colors = generateColors(100)
  42. export function isNumber(value: any) {
  43. return typeof value === 'number' && !Number.isNaN(value)
  44. }
  45. export function formatDateTime(template: string = 'YYYY/MM/DD HH:mm:ss', now: Date = new Date()): string {
  46. const tokens: Record<string, string> = {
  47. YYYY: String(now.getFullYear()),
  48. MM: String(now.getMonth() + 1).padStart(2, '0'),
  49. DD: String(now.getDate()).padStart(2, '0'),
  50. HH: String(now.getHours()).padStart(2, '0'),
  51. mm: String(now.getMinutes()).padStart(2, '0'),
  52. ss: String(now.getSeconds()).padStart(2, '0'),
  53. }
  54. return template.replace(/YYYY|MM|DD|HH|mm|ss/g, token => tokens[token]!)
  55. }
  56. export function allPropertiesDefined(obj: Record<string, any>, excludeKeys: string[] = []): boolean {
  57. return Object.entries(obj).every(([key, value]) => {
  58. return excludeKeys.includes(key) || value === false ? true : value
  59. })
  60. }