@@ -8,7 +8,12 @@ import {
88import {capitalize , computed , onMounted , Ref , ref } from " vue" ;
99import Tooltip from " ../../tooltip.vue" ;
1010import {ArtifactDescription } from " ../../types" ;
11- import {daysBetweenDates , getFutureDate , getPastDate } from " ./utils" ;
11+ import {
12+ daysBetweenDates ,
13+ getFutureDate ,
14+ getPastDate ,
15+ formatDate ,
16+ } from " ./utils" ;
1217import {GraphRenderOpts , renderPlots } from " ../../../../graph/render" ;
1318import {GraphData , GraphKind , GraphsSelector } from " ../../../../graph/data" ;
1419import 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
215223function 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
271280const relativeChartElement: Ref <HTMLElement | null > = ref (null );
272281const 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
275286const sectionsDetail: Ref <CompileDetailSections | null > = ref (null );
276287onMounted (() => {
0 commit comments