Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions airflow-core/src/airflow/ui/src/components/DurationChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { useNavigate } from "react-router-dom";

import type { TaskInstanceResponse, GridRunsResponse } from "openapi/requests/types.gen";
import { getComputedCSSVariableValue } from "src/theme";
import { DEFAULT_DATETIME_FORMAT } from "src/utils/datetimeUtils";
import { DEFAULT_DATETIME_FORMAT, renderDuration } from "src/utils/datetimeUtils";

ChartJS.register(
CategoryScale,
Expand Down Expand Up @@ -103,7 +103,7 @@ export const DurationChart = ({
borderColor: "grey",
borderWidth: 1,
label: {
content: (ctx: PartialEventContext) => average(ctx, 1).toFixed(2),
content: (ctx: PartialEventContext) => renderDuration(average(ctx, 1), false) ?? "0",
display: true,
position: "end",
},
Expand All @@ -115,7 +115,7 @@ export const DurationChart = ({
borderColor: "grey",
borderWidth: 1,
label: {
content: (ctx: PartialEventContext) => average(ctx, 0).toFixed(2),
content: (ctx: PartialEventContext) => renderDuration(average(ctx, 0), false) ?? "0",
display: true,
position: "end",
},
Expand Down Expand Up @@ -209,6 +209,17 @@ export const DurationChart = ({
runAnnotation,
},
},
tooltip: {
callbacks: {
label: (context) => {
const datasetLabel = context.dataset.label ?? "";

const formatted = renderDuration(context.parsed.y, false) ?? "0";

return datasetLabel ? `${datasetLabel}: ${formatted}` : formatted;
},
},
},
},
responsive: true,
scales: {
Expand All @@ -220,6 +231,13 @@ export const DurationChart = ({
title: { align: "end", display: true, text: translate("common:dagRun.runAfter") },
},
y: {
ticks: {
callback: (value) => {
const num = typeof value === "number" ? value : Number(value);

return renderDuration(num, false) ?? "0";
},
},
title: { align: "end", display: true, text: translate("common:duration") },
},
},
Expand Down
7 changes: 5 additions & 2 deletions airflow-core/src/airflow/ui/src/utils/datetimeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ dayjs.extend(tz);
export const DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
export const DEFAULT_DATETIME_FORMAT_WITH_TZ = `${DEFAULT_DATETIME_FORMAT} z`;

export const renderDuration = (durationSeconds: number | null | undefined): string | undefined => {
export const renderDuration = (
durationSeconds: number | null | undefined,
withMilliseconds: boolean = true,
): string | undefined => {
if (durationSeconds === null || durationSeconds === undefined || durationSeconds <= 0.01) {
return undefined;
}

// If under 60 seconds, render milliseconds
if (durationSeconds < 60) {
if (durationSeconds < 60 && withMilliseconds) {
return dayjs.duration(Number(durationSeconds.toFixed(3)), "seconds").format("HH:mm:ss.SSS");
}

Expand Down