Skip to content
Draft
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: 23 additions & 1 deletion docs/shared/static/js/graphs.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,34 @@ function server_chart(div, data, options) {
.attr("y1", 0)
.attr("y2", h);

// Custom 24-hour time formatter to avoid 12-hour format in minute displays
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom24HourFormatter function appears to be identically implemented here as in graphs.zone.js. Extracting this common logic to a shared module could improve maintainability and consistency.

Copilot uses AI. Check for mistakes.
function custom24HourFormatter() {
var formatMillisecond = d3.utcFormat(".%L"),
formatSecond = d3.utcFormat(":%S"),
formatMinute = d3.utcFormat("%H:%M"), // Always use 24-hour format
formatHour = d3.utcFormat("%H"), // Always use 24-hour format
formatDay = d3.utcFormat("%a %d"),
formatWeek = d3.utcFormat("%b %d"),
formatMonth = d3.utcFormat("%B"),
formatYear = d3.utcFormat("%Y");

return function(date) {
return (d3.utcSecond(date) < date ? formatMillisecond
: d3.utcMinute(date) < date ? formatSecond
: d3.utcHour(date) < date ? formatMinute
: d3.utcDay(date) < date ? formatHour
: d3.utcMonth(date) < date ? (d3.utcWeek(date) < date ? formatDay : formatWeek)
: d3.utcYear(date) < date ? formatMonth
: formatYear)(date);
};
}

xrule.append("text")
.attr("x", x)
.attr("y", h + 3)
.attr("dy", ".71em")
.attr("text-anchor", "middle")
.text(x.tickFormat(xticks));
.text(custom24HourFormatter());

/* offset y lines */
var yrule = svg.selectAll("g.y")
Expand Down
24 changes: 23 additions & 1 deletion docs/shared/static/js/graphs.zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,34 @@ function zone_chart(div, data, options) {
.attr("y1", 0)
.attr("y2", h);

// Custom 24-hour time formatter to avoid 12-hour format in minute displays
Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom24HourFormatter function is duplicated in multiple files. Consider extracting it to a shared utility module to reduce redundancy and simplify future maintenance.

Copilot uses AI. Check for mistakes.
function custom24HourFormatter() {
var formatMillisecond = d3.utcFormat(".%L"),
formatSecond = d3.utcFormat(":%S"),
formatMinute = d3.utcFormat("%H:%M"), // Always use 24-hour format
formatHour = d3.utcFormat("%H"), // Always use 24-hour format
formatDay = d3.utcFormat("%a %d"),
formatWeek = d3.utcFormat("%b %d"),
formatMonth = d3.utcFormat("%B"),
formatYear = d3.utcFormat("%Y");

return function(date) {
return (d3.utcSecond(date) < date ? formatMillisecond
: d3.utcMinute(date) < date ? formatSecond
: d3.utcHour(date) < date ? formatMinute
: d3.utcDay(date) < date ? formatHour
: d3.utcMonth(date) < date ? (d3.utcWeek(date) < date ? formatDay : formatWeek)
: d3.utcYear(date) < date ? formatMonth
: formatYear)(date);
};
}

xrule.append("text")
.attr("x", x)
.attr("y", h + 3)
.attr("dy", ".71em")
.attr("text-anchor", "middle")
.text(x.tickFormat(10));
.text(custom24HourFormatter());

/* offset y lines */
var y_ticks = y_max > 8 ? 8 : y_max;
Expand Down