Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-03 Thread via GitHub


bbovenzi merged PR #55155:
URL: https://github.com/apache/airflow/pull/55155


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-03 Thread via GitHub


RoyLee1224 commented on code in PR #55155:
URL: https://github.com/apache/airflow/pull/55155#discussion_r2316793467


##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  const counts: Array = [];
+  const mapCreator = granularity === "daily" ? createDailyDataMap : 
createHourlyDataMap;
+  const dataMap = mapCreator(data);
+
+  dataMap.forEach((runs) => {
+const runCounts = calculateRunCounts(runs);
+const targetCount = viewMode === "total" ? runCounts.total : 
runCounts.failed;
+
+if (targetCount > 0) {
+  counts.push(targetCount);
+}
+  });
+
+  if (counts.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  return {
+maxCount: Math.max(...counts),
+minCount: Math.min(...counts),
+  };
+};
+
+export const createCalendarScale = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): CalendarScale => {
+  const { maxCount, minCount } = calculateDataBounds(data, viewMode, 
granularity);
+
+  // Handle empty data case
+  if (maxCount === 0) {
+const emptyColor = { _dark: "gray.700", _light: "gray.100" };
+
+return {
+  getColor: () => emptyColor,
+  legendItems: [{ color: emptyColor, label: "0" }],
+  type: "empty",
+};
+  }
+
+  // Handle single value case
+  if (minCount === maxCount) {
+const singleColor =
+  viewMode === "total"
+? { _dark: "green.500", _light: "green.400" }
+: { _dark: "red.500", _light: "red.400" };
+
+return {
+  getColor: (counts: RunCounts) => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+const targetCount = viewMode === "total" ? counts.total : 
counts.failed;
+
+return targetCount === 0 ? { _dark: "gray.700", _light: "gray.100" } : 
singleColor;

Review Comment:
   You're right, that makes perfect sense. I'll go ahead and refactor this to 
use constants. Thanks for the feedback!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-03 Thread via GitHub


RoyLee1224 commented on code in PR #55155:
URL: https://github.com/apache/airflow/pull/55155#discussion_r2316793467


##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  const counts: Array = [];
+  const mapCreator = granularity === "daily" ? createDailyDataMap : 
createHourlyDataMap;
+  const dataMap = mapCreator(data);
+
+  dataMap.forEach((runs) => {
+const runCounts = calculateRunCounts(runs);
+const targetCount = viewMode === "total" ? runCounts.total : 
runCounts.failed;
+
+if (targetCount > 0) {
+  counts.push(targetCount);
+}
+  });
+
+  if (counts.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  return {
+maxCount: Math.max(...counts),
+minCount: Math.min(...counts),
+  };
+};
+
+export const createCalendarScale = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): CalendarScale => {
+  const { maxCount, minCount } = calculateDataBounds(data, viewMode, 
granularity);
+
+  // Handle empty data case
+  if (maxCount === 0) {
+const emptyColor = { _dark: "gray.700", _light: "gray.100" };
+
+return {
+  getColor: () => emptyColor,
+  legendItems: [{ color: emptyColor, label: "0" }],
+  type: "empty",
+};
+  }
+
+  // Handle single value case
+  if (minCount === maxCount) {
+const singleColor =
+  viewMode === "total"
+? { _dark: "green.500", _light: "green.400" }
+: { _dark: "red.500", _light: "red.400" };
+
+return {
+  getColor: (counts: RunCounts) => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+const targetCount = viewMode === "total" ? counts.total : 
counts.failed;
+
+return targetCount === 0 ? { _dark: "gray.700", _light: "gray.100" } : 
singleColor;

Review Comment:
   You're right, that makes perfect sense! I'll go ahead and refactor this to 
use constants. Thanks for the feedback!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-02 Thread via GitHub


RoyLee1224 commented on code in PR #55155:
URL: https://github.com/apache/airflow/pull/55155#discussion_r2316755103


##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  const counts: Array = [];
+  const mapCreator = granularity === "daily" ? createDailyDataMap : 
createHourlyDataMap;
+  const dataMap = mapCreator(data);
+
+  dataMap.forEach((runs) => {
+const runCounts = calculateRunCounts(runs);
+const targetCount = viewMode === "total" ? runCounts.total : 
runCounts.failed;
+
+if (targetCount > 0) {
+  counts.push(targetCount);
+}
+  });
+
+  if (counts.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  return {
+maxCount: Math.max(...counts),
+minCount: Math.min(...counts),
+  };
+};
+
+export const createCalendarScale = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): CalendarScale => {
+  const { maxCount, minCount } = calculateDataBounds(data, viewMode, 
granularity);
+
+  // Handle empty data case
+  if (maxCount === 0) {
+const emptyColor = { _dark: "gray.700", _light: "gray.100" };
+
+return {
+  getColor: () => emptyColor,
+  legendItems: [{ color: emptyColor, label: "0" }],
+  type: "empty",
+};
+  }
+
+  // Handle single value case
+  if (minCount === maxCount) {
+const singleColor =
+  viewMode === "total"
+? { _dark: "green.500", _light: "green.400" }
+: { _dark: "red.500", _light: "red.400" };
+
+return {
+  getColor: (counts: RunCounts) => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+const targetCount = viewMode === "total" ? counts.total : 
counts.failed;
+
+return targetCount === 0 ? { _dark: "gray.700", _light: "gray.100" } : 
singleColor;
+  },
+  legendItems: [
+{ color: { _dark: "gray.700", _light: "gray.100" }, label: "0" },
+{ color: singleColor, label: maxCount.toString() },
+  ],
+  type: "single_value",
+};
+  }
+
+  // Handle gradient case - create dynamic thresholds
+  const range = maxCount - minCount;
+  const colorScheme =
+viewMode === "total"
+  ? [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "green.300", _light: "green.200" },
+  { _dark: "green.500", _light: "green.400" },
+  { _dark: "green.700", _light: "green.600" },
+  { _dark: "green.900", _light: "green.800" },
+]
+  : [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "red.300", _light: "red.200" },
+  { _dark: "red.500", _light: "red.400" },
+  { _dark: "red.700", _light: "red.600" },
+  { _dark: "red.900", _light: "red.800" },
+];
+
+  const thresholds = [
+0,
+Math.max(1, Math.ceil(minCount + range * 0.25)),
+Math.max(2, Math.ceil(minCount + range * 0.5)),
+Math.max(3, Math.ceil(minCount + range * 0.75)),
+maxCount,
+  ];
+
+  const uniqueThresholds = [...new Set(thresholds)].sort((first, second) => 
first - second);
+
+  const getColor = (counts: RunCounts): string | { _dark: string; _light: 
string } => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+
+const targetCount = viewMode === "total" ? counts.total : counts.failed;
+
+if (targetCount === 0) {
+  return colorScheme[0] ?? { _dark: "gray.700", _light: "gray.100" };
+}
+
+for (let index = uniqueThresholds.length - 1; index >= 1; index -= 1) {
+  const threshold = uniqueThresholds[index];

Review Comment:
   Since this loop needs to run in reverse and exit early with a `return`, I 
guess the classic `for` loop is the best fit here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-02 Thread via GitHub


RoyLee1224 commented on code in PR #55155:
URL: https://github.com/apache/airflow/pull/55155#discussion_r2316758066


##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  const counts: Array = [];
+  const mapCreator = granularity === "daily" ? createDailyDataMap : 
createHourlyDataMap;
+  const dataMap = mapCreator(data);
+
+  dataMap.forEach((runs) => {
+const runCounts = calculateRunCounts(runs);
+const targetCount = viewMode === "total" ? runCounts.total : 
runCounts.failed;
+
+if (targetCount > 0) {
+  counts.push(targetCount);
+}
+  });
+
+  if (counts.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  return {
+maxCount: Math.max(...counts),
+minCount: Math.min(...counts),
+  };
+};
+
+export const createCalendarScale = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): CalendarScale => {
+  const { maxCount, minCount } = calculateDataBounds(data, viewMode, 
granularity);
+
+  // Handle empty data case
+  if (maxCount === 0) {
+const emptyColor = { _dark: "gray.700", _light: "gray.100" };
+
+return {
+  getColor: () => emptyColor,
+  legendItems: [{ color: emptyColor, label: "0" }],
+  type: "empty",
+};
+  }
+
+  // Handle single value case
+  if (minCount === maxCount) {
+const singleColor =
+  viewMode === "total"
+? { _dark: "green.500", _light: "green.400" }
+: { _dark: "red.500", _light: "red.400" };
+
+return {
+  getColor: (counts: RunCounts) => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+const targetCount = viewMode === "total" ? counts.total : 
counts.failed;
+
+return targetCount === 0 ? { _dark: "gray.700", _light: "gray.100" } : 
singleColor;
+  },
+  legendItems: [
+{ color: { _dark: "gray.700", _light: "gray.100" }, label: "0" },
+{ color: singleColor, label: maxCount.toString() },
+  ],
+  type: "single_value",
+};
+  }
+
+  // Handle gradient case - create dynamic thresholds
+  const range = maxCount - minCount;
+  const colorScheme =
+viewMode === "total"
+  ? [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "green.300", _light: "green.200" },
+  { _dark: "green.500", _light: "green.400" },
+  { _dark: "green.700", _light: "green.600" },
+  { _dark: "green.900", _light: "green.800" },
+]
+  : [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "red.300", _light: "red.200" },
+  { _dark: "red.500", _light: "red.400" },
+  { _dark: "red.700", _light: "red.600" },
+  { _dark: "red.900", _light: "red.800" },
+];
+
+  const thresholds = [
+0,
+Math.max(1, Math.ceil(minCount + range * 0.25)),
+Math.max(2, Math.ceil(minCount + range * 0.5)),
+Math.max(3, Math.ceil(minCount + range * 0.75)),
+maxCount,
+  ];
+
+  const uniqueThresholds = [...new Set(thresholds)].sort((first, second) => 
first - second);
+
+  const getColor = (counts: RunCounts): string | { _dark: string; _light: 
string } => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+
+const targetCount = viewMode === "total" ? counts.total : counts.failed;
+
+if (targetCount === 0) {
+  return colorScheme[0] ?? { _dark: "gray.700", _light: "gray.100" };
+}
+
+for (let index = uniqueThresholds.length - 1; index >= 1; index -= 1) {
+  const threshold = uniqueThresholds[index];

Review Comment:
   Is there a different pattern you'd prefer for this situation? I'd be happy 
to change it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-02 Thread via GitHub


RoyLee1224 commented on PR #55155:
URL: https://github.com/apache/airflow/pull/55155#issuecomment-3246342726

   Hi @pierrejeambrun, I've pushed the updates addressing your comments. The 
code should be cleaner now. Please let me know what you think. Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-02 Thread via GitHub


RoyLee1224 commented on code in PR #55155:
URL: https://github.com/apache/airflow/pull/55155#discussion_r2316758066


##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  const counts: Array = [];
+  const mapCreator = granularity === "daily" ? createDailyDataMap : 
createHourlyDataMap;
+  const dataMap = mapCreator(data);
+
+  dataMap.forEach((runs) => {
+const runCounts = calculateRunCounts(runs);
+const targetCount = viewMode === "total" ? runCounts.total : 
runCounts.failed;
+
+if (targetCount > 0) {
+  counts.push(targetCount);
+}
+  });
+
+  if (counts.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  return {
+maxCount: Math.max(...counts),
+minCount: Math.min(...counts),
+  };
+};
+
+export const createCalendarScale = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): CalendarScale => {
+  const { maxCount, minCount } = calculateDataBounds(data, viewMode, 
granularity);
+
+  // Handle empty data case
+  if (maxCount === 0) {
+const emptyColor = { _dark: "gray.700", _light: "gray.100" };
+
+return {
+  getColor: () => emptyColor,
+  legendItems: [{ color: emptyColor, label: "0" }],
+  type: "empty",
+};
+  }
+
+  // Handle single value case
+  if (minCount === maxCount) {
+const singleColor =
+  viewMode === "total"
+? { _dark: "green.500", _light: "green.400" }
+: { _dark: "red.500", _light: "red.400" };
+
+return {
+  getColor: (counts: RunCounts) => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+const targetCount = viewMode === "total" ? counts.total : 
counts.failed;
+
+return targetCount === 0 ? { _dark: "gray.700", _light: "gray.100" } : 
singleColor;
+  },
+  legendItems: [
+{ color: { _dark: "gray.700", _light: "gray.100" }, label: "0" },
+{ color: singleColor, label: maxCount.toString() },
+  ],
+  type: "single_value",
+};
+  }
+
+  // Handle gradient case - create dynamic thresholds
+  const range = maxCount - minCount;
+  const colorScheme =
+viewMode === "total"
+  ? [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "green.300", _light: "green.200" },
+  { _dark: "green.500", _light: "green.400" },
+  { _dark: "green.700", _light: "green.600" },
+  { _dark: "green.900", _light: "green.800" },
+]
+  : [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "red.300", _light: "red.200" },
+  { _dark: "red.500", _light: "red.400" },
+  { _dark: "red.700", _light: "red.600" },
+  { _dark: "red.900", _light: "red.800" },
+];
+
+  const thresholds = [
+0,
+Math.max(1, Math.ceil(minCount + range * 0.25)),
+Math.max(2, Math.ceil(minCount + range * 0.5)),
+Math.max(3, Math.ceil(minCount + range * 0.75)),
+maxCount,
+  ];
+
+  const uniqueThresholds = [...new Set(thresholds)].sort((first, second) => 
first - second);
+
+  const getColor = (counts: RunCounts): string | { _dark: string; _light: 
string } => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+
+const targetCount = viewMode === "total" ? counts.total : counts.failed;
+
+if (targetCount === 0) {
+  return colorScheme[0] ?? { _dark: "gray.700", _light: "gray.100" };
+}
+
+for (let index = uniqueThresholds.length - 1; index >= 1; index -= 1) {
+  const threshold = uniqueThresholds[index];

Review Comment:
   Or is there a cleaner way you'd recommend?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] feat(ui): implement dynamic legend system for calendar [airflow]

2025-09-02 Thread via GitHub


pierrejeambrun commented on code in PR #55155:
URL: https://github.com/apache/airflow/pull/55155#discussion_r2316294688


##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  const counts: Array = [];
+  const mapCreator = granularity === "daily" ? createDailyDataMap : 
createHourlyDataMap;
+  const dataMap = mapCreator(data);
+
+  dataMap.forEach((runs) => {
+const runCounts = calculateRunCounts(runs);
+const targetCount = viewMode === "total" ? runCounts.total : 
runCounts.failed;
+
+if (targetCount > 0) {
+  counts.push(targetCount);
+}
+  });
+
+  if (counts.length === 0) {
+return { maxCount: 0, minCount: 0 };
+  }
+
+  return {
+maxCount: Math.max(...counts),
+minCount: Math.min(...counts),
+  };
+};
+
+export const createCalendarScale = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): CalendarScale => {
+  const { maxCount, minCount } = calculateDataBounds(data, viewMode, 
granularity);
+
+  // Handle empty data case
+  if (maxCount === 0) {
+const emptyColor = { _dark: "gray.700", _light: "gray.100" };
+
+return {
+  getColor: () => emptyColor,
+  legendItems: [{ color: emptyColor, label: "0" }],
+  type: "empty",
+};
+  }
+
+  // Handle single value case
+  if (minCount === maxCount) {
+const singleColor =
+  viewMode === "total"
+? { _dark: "green.500", _light: "green.400" }
+: { _dark: "red.500", _light: "red.400" };
+
+return {
+  getColor: (counts: RunCounts) => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+const targetCount = viewMode === "total" ? counts.total : 
counts.failed;
+
+return targetCount === 0 ? { _dark: "gray.700", _light: "gray.100" } : 
singleColor;
+  },
+  legendItems: [
+{ color: { _dark: "gray.700", _light: "gray.100" }, label: "0" },
+{ color: singleColor, label: maxCount.toString() },
+  ],
+  type: "single_value",
+};
+  }
+
+  // Handle gradient case - create dynamic thresholds
+  const range = maxCount - minCount;
+  const colorScheme =
+viewMode === "total"
+  ? [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "green.300", _light: "green.200" },
+  { _dark: "green.500", _light: "green.400" },
+  { _dark: "green.700", _light: "green.600" },
+  { _dark: "green.900", _light: "green.800" },
+]
+  : [
+  { _dark: "gray.700", _light: "gray.100" }, // 0
+  { _dark: "red.300", _light: "red.200" },
+  { _dark: "red.500", _light: "red.400" },
+  { _dark: "red.700", _light: "red.600" },
+  { _dark: "red.900", _light: "red.800" },
+];
+
+  const thresholds = [
+0,
+Math.max(1, Math.ceil(minCount + range * 0.25)),
+Math.max(2, Math.ceil(minCount + range * 0.5)),
+Math.max(3, Math.ceil(minCount + range * 0.75)),
+maxCount,
+  ];
+
+  const uniqueThresholds = [...new Set(thresholds)].sort((first, second) => 
first - second);
+
+  const getColor = (counts: RunCounts): string | { _dark: string; _light: 
string } => {
+if (counts.planned > 0) {
+  return { _dark: "scheduled.600", _light: "scheduled.200" };
+}
+
+const targetCount = viewMode === "total" ? counts.total : counts.failed;
+
+if (targetCount === 0) {
+  return colorScheme[0] ?? { _dark: "gray.700", _light: "gray.100" };
+}
+
+for (let index = uniqueThresholds.length - 1; index >= 1; index -= 1) {
+  const threshold = uniqueThresholds[index];
+
+  if (threshold !== undefined && targetCount >= threshold) {
+return (
+  colorScheme[Math.min(index, colorScheme.length - 1)] ?? { _dark: 
"gray.700", _light: "gray.100" }
+);
+  }
+}
+
+return colorScheme[1] ?? { _dark: "gray.700", _light: "gray.100" };
+  };
+
+  const legendItems: Array = [];
+
+  for (let index = 0; index < uniqueThresholds.length; index += 1) {
+const threshold = uniqueThresholds[index];

Review Comment:
   nit: forEach



##
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/calendarUtils.ts:
##
@@ -219,6 +150,173 @@ export const generateHourlyCalendarData = (
   return { days: monthData, month: monthStart.format("MMM ") };
 };
 
+export const calculateDataBounds = (
+  data: Array,
+  viewMode: CalendarColorMode,
+  granularity: CalendarGranularity,
+): { maxCount: number; minCount: number } => {
+  if (data.length === 0) {
+return { maxCoun