@@ -8,7 +8,12 @@ import {
8
8
import {capitalize , computed , onMounted , Ref , ref } from " vue" ;
9
9
import Tooltip from " ../../tooltip.vue" ;
10
10
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" ;
12
17
import {GraphRenderOpts , renderPlots } from " ../../../../graph/render" ;
13
18
import {GraphData , GraphKind , GraphsSelector } from " ../../../../graph/data" ;
14
19
import uPlot from " uplot" ;
@@ -48,41 +53,44 @@ const DAY_RANGE = 30;
48
53
* Calculates the start and end range for a history graph for this benchmark
49
54
* and artifact.
50
55
*/
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 {
54
60
// If this is a try commit, we don't know its future, so always we just display
55
61
// the last `DAY_RANGE` days.
56
62
if (artifact .type === " try" ) {
63
+ const date = new Date (artifact .date );
57
64
return {
58
65
start: formatDate (getPastDate (date , DAY_RANGE )),
59
66
end: artifact .commit ,
60
67
date: null ,
61
68
};
62
69
} 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
64
75
// "centered" around the commit date.
65
76
66
77
// Calculate the end of the range, which is commit date + half of the
67
78
// amount of days we want to show. If this date is in the future,
68
79
// 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
75
88
);
76
89
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 ));
82
90
return {
83
91
start ,
84
92
end ,
85
- date ,
93
+ date: end_date ,
86
94
};
87
95
}
88
96
}
@@ -270,7 +278,9 @@ const cargoProfile = computed((): CargoProfileMetadata => {
270
278
271
279
const relativeChartElement: Ref <HTMLElement | null > = ref (null );
272
280
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
+ );
274
284
275
285
const sectionsDetail: Ref <CompileDetailSections | null > = ref (null );
276
286
onMounted (() => {
0 commit comments