Skip to content

Commit

Permalink
Add hour and minute to time format on x-axis of all charts using nvd3…
Browse files Browse the repository at this point in the history
….lineChart (#20002)

* Add hour and minute to time format on x-axis in Landing Times

* Make labels of x-axis more readable on line charts

* Add month and date on x-axis

Co-authored-by: Brent Bovenzi <[email protected]>

Co-authored-by: Son Hyoungwoo <[email protected]>
Co-authored-by: Brent Bovenzi <[email protected]>
  • Loading branch information
3 people authored Dec 16, 2021
1 parent 2c80aaa commit 6a77e84
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
PAGE_SIZE = conf.getint('webserver', 'page_size')
FILTER_TAGS_COOKIE = 'tags_filter'
FILTER_STATUS_COOKIE = 'dag_status_filter'
LINECHART_X_AXIS_TICKFORMAT = (
"function (d, i) { let xLabel;"
"if (i === undefined) {xLabel = d3.time.format('%H:%M, %d %b %Y')(new Date(parseInt(d)));"
"} else {xLabel = d3.time.format('%H:%M, %d %b')(new Date(parseInt(d)));} return xLabel;}"
)


def truncate_task_duration(task_duration):
Expand Down Expand Up @@ -2562,10 +2567,20 @@ def duration(self, session=None):
dag = dag.partial_subset(task_ids_or_regex=root, include_upstream=True, include_downstream=False)
chart_height = wwwutils.get_chart_height(dag)
chart = nvd3.lineChart(
name="lineChart", x_is_date=True, height=chart_height, chart_attr=self.line_chart_attr
name="lineChart",
x_custom_format=True,
x_axis_date=True,
x_axis_format=LINECHART_X_AXIS_TICKFORMAT,
height=chart_height,
chart_attr=self.line_chart_attr,
)
cum_chart = nvd3.lineChart(
name="cumLineChart", x_is_date=True, height=chart_height, chart_attr=self.line_chart_attr
name="cumLineChart",
x_custom_format=True,
x_axis_date=True,
x_axis_format=LINECHART_X_AXIS_TICKFORMAT,
height=chart_height,
chart_attr=self.line_chart_attr,
)

y_points = defaultdict(list)
Expand Down Expand Up @@ -2691,8 +2706,9 @@ def tries(self, session=None):
chart_height = wwwutils.get_chart_height(dag)
chart = nvd3.lineChart(
name="lineChart",
x_is_date=True,
y_axis_format='d',
x_custom_format=True,
x_axis_date=True,
x_axis_format=LINECHART_X_AXIS_TICKFORMAT,
height=chart_height,
chart_attr=self.line_chart_attr,
)
Expand Down Expand Up @@ -2768,7 +2784,12 @@ def landing_times(self, session=None):

chart_height = wwwutils.get_chart_height(dag)
chart = nvd3.lineChart(
name="lineChart", x_is_date=True, height=chart_height, chart_attr=self.line_chart_attr
name="lineChart",
x_custom_format=True,
x_axis_date=True,
x_axis_format=LINECHART_X_AXIS_TICKFORMAT,
height=chart_height,
chart_attr=self.line_chart_attr,
)
y_points = {}
x_points = {}
Expand Down

0 comments on commit 6a77e84

Please sign in to comment.