Skip to content

Commit 8ec0c8c

Browse files
committed
Allow displaying the benchmark result detail chart for the full range
1 parent bd50d1e commit 8ec0c8c

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

site/frontend/src/pages/compare/compile/table/benchmark-detail.vue

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import {
88
import {capitalize, computed, onMounted, Ref, ref} from "vue";
99
import Tooltip from "../../tooltip.vue";
1010
import {ArtifactDescription} from "../../types";
11-
import {daysBetweenDates, getFutureDate, getPastDate, formatDate} from "./utils";
11+
import {
12+
daysBetweenDates,
13+
getFutureDate,
14+
getPastDate,
15+
formatDate,
16+
} from "./utils";
1217
import {GraphRenderOpts, renderPlots} from "../../../../graph/render";
1318
import {GraphData, GraphKind, GraphsSelector} from "../../../../graph/data";
1419
import uPlot from "uplot";
@@ -48,41 +53,44 @@ const DAY_RANGE = 30;
4853
* Calculates the start and end range for a history graph for this benchmark
4954
* and artifact.
5055
*/
51-
function getGraphRange(artifact: ArtifactDescription): GraphRange {
52-
const date = new Date(artifact.date);
53-
56+
function getGraphRange(
57+
artifact: ArtifactDescription,
58+
baseArtifact: ArtifactDescription
59+
): GraphRange {
5460
// If this is a try commit, we don't know its future, so always we just display
5561
// the last `DAY_RANGE` days.
5662
if (artifact.type === "try") {
63+
const date = new Date(artifact.date);
5764
return {
5865
start: formatDate(getPastDate(date, DAY_RANGE)),
5966
end: artifact.commit,
6067
date: null,
6168
};
6269
} else {
63-
// If this is a master commit, then we try to display `dayRange` days
70+
let [start_date, end_date] = [baseArtifact, artifact].map(
71+
(c) => new Date(c.date)
72+
);
73+
// If this is a master commit, we attempt to display more than the full history for commit
74+
// ranges. If the commit range is not larger than the `dayRange`, the display will likely be
6475
// "centered" around the commit date.
6576
6677
// Calculate the end of the range, which is commit date + half of the
6778
// amount of days we want to show. If this date is in the future,
6879
// the server will clip the result at the current date.
69-
const end = formatDate(getFutureDate(date, DAY_RANGE / 2));
70-
71-
// Calculate how many days there have been from the commit date
72-
const daysInFuture = Math.min(
73-
DAY_RANGE / 2,
74-
daysBetweenDates(date, new Date())
80+
const end = formatDate(getFutureDate(end_date, DAY_RANGE / 2));
81+
82+
// Calculate the start of the range, which is the earlier date between
83+
// the base artifact date and the commit date - half of the amount of days
84+
// we want to show.
85+
const centered_start = getPastDate(end_date, DAY_RANGE / 2);
86+
const start = formatDate(
87+
start_date < centered_start ? start_date : centered_start
7588
);
7689
77-
// Calculate how many days we should go into the past, taking into account
78-
// the days that will be clipped by the server.
79-
const daysInPast = DAY_RANGE - daysInFuture;
80-
81-
const start = formatDate(getPastDate(date, daysInPast));
8290
return {
8391
start,
8492
end,
85-
date,
93+
date: end_date,
8694
};
8795
}
8896
}
@@ -270,7 +278,9 @@ const cargoProfile = computed((): CargoProfileMetadata => {
270278
271279
const relativeChartElement: Ref<HTMLElement | null> = ref(null);
272280
const absoluteChartElement: Ref<HTMLElement | null> = ref(null);
273-
const graphRange = computed(() => getGraphRange(props.artifact));
281+
const graphRange = computed(() =>
282+
getGraphRange(props.artifact, props.baseArtifact)
283+
);
274284
275285
const sectionsDetail: Ref<CompileDetailSections | null> = ref(null);
276286
onMounted(() => {

0 commit comments

Comments
 (0)