-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Improve duration chart #55339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve duration chart #55339
Changes from all commits
232eab3
8f3be61
a22e912
2ff7a31
ceac5e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import { | |
| import type { PartialEventContext } from "chartjs-plugin-annotation"; | ||
| import annotationPlugin from "chartjs-plugin-annotation"; | ||
| import dayjs from "dayjs"; | ||
| import minMax from "dayjs/plugin/minMax"; | ||
| import { Bar } from "react-chartjs-2"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { useNavigate } from "react-router-dom"; | ||
|
|
@@ -38,6 +39,8 @@ import type { TaskInstanceResponse, GridRunsResponse } from "openapi/requests/ty | |
| import { getComputedCSSVariableValue } from "src/theme"; | ||
| import { DEFAULT_DATETIME_FORMAT } from "src/utils/datetimeUtils"; | ||
|
|
||
| dayjs.extend(minMax); | ||
|
|
||
| ChartJS.register( | ||
| CategoryScale, | ||
| LinearScale, | ||
|
|
@@ -59,10 +62,30 @@ type RunResponse = GridRunsResponse | TaskInstanceResponse; | |
|
|
||
| const getDuration = (start: string, end: string | null) => dayjs.duration(dayjs(end).diff(start)).asSeconds(); | ||
|
|
||
| const getLabelFormat = (entries: Array<RunResponse>) => { | ||
| const timestamps = entries.map(entry => dayjs(entry.run_after)); | ||
| const minTime = dayjs.min(timestamps); | ||
| const maxTime = dayjs.max(timestamps); | ||
|
|
||
| // satisfy null typecheck for dayjs.min/max | ||
| if (minTime === null || maxTime === null) { | ||
| return "MM-DD"; | ||
| } | ||
| const diffInDays = maxTime.diff(minTime, 'days'); | ||
|
|
||
| if (diffInDays < 1) { | ||
| return "hh:mm:ss" | ||
| } else { | ||
| return "MM-DD" | ||
| } | ||
| }; | ||
|
|
||
| export const DurationChart = ({ | ||
| autoRefreshEnabled, | ||
| entries, | ||
| kind, | ||
| }: { | ||
| readonly autoRefreshEnabled?: boolean; | ||
| readonly entries: Array<RunResponse> | undefined; | ||
| readonly kind: "Dag Run" | "Task Instance"; | ||
| }) => { | ||
|
|
@@ -165,6 +188,12 @@ export const DurationChart = ({ | |
| }} | ||
| datasetIdKey="id" | ||
| options={{ | ||
| animation: { | ||
| delay: 0, | ||
| duration: autoRefreshEnabled ? 0 : 1000, | ||
| easing: "easeOutQuart", | ||
| loop: false, | ||
| }, | ||
| onClick: (_event, elements) => { | ||
| const [element] = elements; | ||
|
|
||
|
|
@@ -207,6 +236,9 @@ export const DurationChart = ({ | |
| stacked: true, | ||
| ticks: { | ||
| maxTicksLimit: 3, | ||
| callback: (value) => { | ||
| return(dayjs(value).format(getLabelFormat(entries))) | ||
| } | ||
|
Comment on lines
+239
to
+241
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I didn't notice that the x-axis labels were all the same. I'm not sure that this is a timezone issue though. I hadn't noticed before, but my screenshot above has 12-31 as the time for all despite the onhover being a different day. I spent some time investigating this today. It seems a little more difficult than I thought. I tried to enable
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to ideas but I think the question I'm trying to get at here is is: how do I get all the times to play well with each other:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pierrejeambrun let me know if this makes sense / if you have any advice on how to proceed. I'm not sure this is super easy without significantly changing the Duration chart.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }, | ||
| title: { align: "end", display: true, text: translate("common:dagRun.runAfter") }, | ||
| }, | ||
|
|
||




Uh oh!
There was an error while loading. Please reload this page.