@@ -8,10 +8,11 @@ import {
88import  {computed , onMounted , Ref , ref } from  " vue" 
99import  Tooltip  from  " ../../tooltip.vue" 
1010import  {ArtifactDescription } from  " ../../types" 
11- import  {getDateInPast } from  " ./utils" 
12- import  {renderPlots } from  " ../../../../graph/render" 
11+ import  {daysBetweenDates ,  getFutureDate ,  getPastDate } from  " ./utils" 
12+ import  {GraphRenderOpts ,  renderPlots } from  " ../../../../graph/render" 
1313import  {GRAPH_RESOLVER } from  " ../../../../graph/resolver" 
1414import  {GraphKind } from  " ../../../../graph/data" 
15+ import  uPlot  from  " uplot" 
1516
1617const =  defineProps <{
1718  testCase:  CompileTestCase ; 
@@ -20,23 +21,116 @@ const props = defineProps<{
2021  benchmarkMap:  CompileBenchmarkMap ; 
2122}>(); 
2223
24+ type  GraphRange  =  {
25+   start:  string ; 
26+   end:  string ; 
27+   date:  Date  |  null ; 
28+ }; 
29+ 
30+ //  How many days are shown in the graph
31+ const =  30 ;
32+ 
33+ /** 
34+  * Calculates the start and end range for a history graph for this benchmark 
35+  * and artifact. 
36+  */  
37+ function  getGraphRange(artifact :  ArtifactDescription ):  GraphRange  {
38+   const =  new  Date (artifact .date ); 
39+ 
40+   //  If this is a try commit, we don't know its future, so always we just display 
41+   //  the last `DAY_RANGE` days. 
42+   if  (artifact .type  ===  " try"  
43+     return  { 
44+       start: getPastDate (date , DAY_RANGE ), 
45+       end: artifact .commit , 
46+       date: null , 
47+     }; 
48+   } else  { 
49+     //  If this is a master commit, then we try to display `dayRange` days 
50+     //  "centered" around the commit date. 
51+ 
52+     //  Calculate the end of the range, which is commit date + half of the 
53+     //  amount of days we want to show. If this date is in the future, 
54+     //  the server will clip the result at the current date. 
55+     const =  getFutureDate (date , DAY_RANGE  /  2 ); 
56+ 
57+     //  Calculate how many days there have been from the commit date 
58+     const =  Math .min ( 
59+       DAY_RANGE  /  2 , 
60+       daysBetweenDates (date , new  Date ()) 
61+     ); 
62+ 
63+     //  Calculate how many days we should go into the past, taking into account 
64+     //  the days that will be clipped by the server. 
65+     const =  DAY_RANGE  -  daysInFuture ; 
66+ 
67+     const =  getPastDate (date , daysInPast ); 
68+     return  { 
69+       start , 
70+       end , 
71+       date , 
72+     }; 
73+   } 
74+ } 
75+ 
76+ /** 
77+  * Hook into the uPlot drawing machinery to draw a vertical line at the 
78+  * position of the given `date`. 
79+  */  
80+ function  drawCurrentDate(opts :  GraphRenderOpts , date :  Date ) {
81+   opts .hooks  =  { 
82+     drawSeries : (u :  uPlot ) =>  { 
83+       let  ctx =  u .ctx ; 
84+       ctx .save (); 
85+ 
86+       const =  u .bbox .top ; 
87+       const =  y0  +  u .bbox .height ; 
88+       const =  u .valToPos (date .getTime () /  1000 , " x" true ); 
89+ 
90+       ctx .beginPath (); 
91+       ctx .moveTo (x , y0 ); 
92+       ctx .strokeStyle  =  " red"  
93+       ctx .setLineDash ([5 , 5 ]); 
94+       ctx .lineTo (x , y1 ); 
95+       ctx .stroke (); 
96+ 
97+       ctx .restore (); 
98+     }, 
99+   }; 
100+ } 
101+ 
23102async  function  renderGraph() {
103+   const =  graphRange .value ; 
24104  const =  { 
25105    benchmark: props .testCase .benchmark , 
26106    profile: props .testCase .profile , 
27107    scenario: props .testCase .scenario , 
28108    stat: props .metric , 
29-     start:  getDateInPast ( props . artifact ) , 
30-     end:  props . artifact . commit , 
109+     start , 
110+     end , 
31111    //  We want to be able to see noise "blips" vs. a previous artifact. 
32112    //  The "percent relative from previous commit" graph should be the best to 
33113    //  see these kinds of changes. 
34114    kind: " percentrelative" as  GraphKind , 
35115  }; 
36116  const =  await  GRAPH_RESOLVER .loadGraph (selector ); 
37-   renderPlots ( graphData ,  selector ,  chartElement . value ,  { 
117+   const  opts :   GraphRenderOpts   =  { 
38118    renderTitle: false , 
39-   }); 
119+   }; 
120+   if  (date  !==  null ) { 
121+     drawCurrentDate (opts , date ); 
122+   } 
123+   renderPlots (graphData , selector , chartElement .value , opts ); 
124+ } 
125+ 
126+ function  getGraphTitle() {
127+   const =  graphRange .value ; 
128+   const =  ` ${DAY_RANGE } day history ` ; 
129+   if  (date  !==  null ) { 
130+     return  ` ${msg } (${start } - ${end }) ` ; 
131+   } else  { 
132+     return  ` ${msg } (up to benchmarked commit) ` ; 
133+   } 
40134} 
41135
42136const =  computed (
@@ -58,6 +152,7 @@ const cargoProfile = computed((): CargoProfileMetadata => {
58152}); 
59153
60154const :  Ref <HTMLElement  |  null > =  ref (null );
155+ const =  computed (() =>  getGraphRange (props .artifact ));
61156
62157onMounted (() =>  renderGraph ());
63158script >
@@ -113,7 +208,7 @@ onMounted(() => renderGraph());
113208    </div >
114209    <div >
115210      <div  class =" title" 
116-         <div  class =" bold" 30 day history (up to benchmarked commit) </div >
211+         <div  class =" bold" {{ getGraphTitle() }} </div >
117212        <div  style =" font-size 0.8em  " 
118213          Each plotted value is relative to its previous commit
119214        </div >
0 commit comments