Skip to content

Commit 908eaaf

Browse files
authored
Merge pull request #1842 from eth3lbert/chart-range
Full Range Benchmark Result Chart
2 parents fcd48e1 + 11d255f commit 908eaaf

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

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

Lines changed: 31 additions & 20 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} 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 {
58-
start: getPastDate(date, DAY_RANGE),
65+
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 = 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 = getPastDate(date, daysInPast);
8290
return {
8391
start,
8492
end,
85-
date,
93+
date: end_date,
8694
};
8795
}
8896
}
@@ -214,7 +222,8 @@ async function renderGraph(
214222
215223
function getGraphTitle() {
216224
const {start, end, date} = graphRange.value;
217-
const msg = `${DAY_RANGE} day history`;
225+
const days = daysBetweenDates(new Date(start), new Date(end));
226+
const msg = `${days} day history`;
218227
if (date !== null) {
219228
return `${msg} (${start} → ${end})`;
220229
} else {
@@ -270,7 +279,9 @@ const cargoProfile = computed((): CargoProfileMetadata => {
270279
271280
const relativeChartElement: Ref<HTMLElement | null> = ref(null);
272281
const absoluteChartElement: Ref<HTMLElement | null> = ref(null);
273-
const graphRange = computed(() => getGraphRange(props.artifact));
282+
const graphRange = computed(() =>
283+
getGraphRange(props.artifact, props.baseArtifact)
284+
);
274285
275286
const sectionsDetail: Ref<CompileDetailSections | null> = ref(null);
276287
onMounted(() => {

site/frontend/src/pages/compare/compile/table/utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
/**
22
* Returns a date that is the given days in the past from the passed `date`.
33
*/
4-
export function getPastDate(date: Date, days: number): string {
4+
export function getPastDate(date: Date, days: number): Date {
55
const past = new Date(date.getTime());
66
past.setUTCDate(date.getUTCDate() - days);
7-
return format_ymd(past);
7+
return past;
88
}
99

1010
/**
1111
* Returns a date that is the given days in the future from the passed `date`.
1212
*/
13-
export function getFutureDate(date: Date, days: number): string {
13+
export function getFutureDate(date: Date, days: number): Date {
1414
const future = new Date(date.getTime());
1515
future.setUTCDate(date.getUTCDate() + days);
16-
return format_ymd(future);
16+
return future;
1717
}
1818

19-
function format_ymd(date: Date): string {
19+
/**
20+
* Returns a formated date string
21+
*/
22+
export function formatDate(date: Date): string {
2023
const year = date.getUTCFullYear();
2124
const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
2225
const day = date.getUTCDate().toString().padStart(2, "0");

0 commit comments

Comments
 (0)