@@ -5,6 +5,7 @@ use std::convert::TryInto;
5
5
use std:: str;
6
6
use std:: sync:: Arc ;
7
7
8
+ use crate :: api:: graph:: GraphKind ;
8
9
use crate :: api:: { graph, ServerResult } ;
9
10
use crate :: db:: { self , ArtifactId , Benchmark , Profile , Scenario } ;
10
11
use crate :: interpolate:: Interpolated ;
@@ -75,7 +76,7 @@ pub async fn handle_graph(
75
76
start : Bound :: None ,
76
77
end : Bound :: None ,
77
78
stat : String :: from ( "instructions:u" ) ,
78
- absolute : true ,
79
+ kind : graph :: GraphKind :: Raw ,
79
80
} ;
80
81
81
82
if is_default_query {
@@ -106,7 +107,7 @@ pub async fn handle_graph(
106
107
. into_iter ( )
107
108
. map ( |sr| {
108
109
sr. interpolate ( )
109
- . map ( |series| to_graph_data ( & cc, body. absolute , series) . collect :: < Vec < _ > > ( ) )
110
+ . map ( |series| to_graph_data ( & cc, body. kind , series) . collect :: < Vec < _ > > ( ) )
110
111
} )
111
112
. collect :: < Vec < _ > > ( ) ;
112
113
@@ -176,7 +177,7 @@ pub async fn handle_graph(
176
177
. collect ( ) ,
177
178
)
178
179
. map ( |( ( c, d) , i) | ( ( c, Some ( d. expect ( "interpolated" ) / against) ) , i) ) ;
179
- let graph_data = to_graph_data ( & cc, body. absolute , averaged) . collect :: < Vec < _ > > ( ) ;
180
+ let graph_data = to_graph_data ( & cc, body. kind , averaged) . collect :: < Vec < _ > > ( ) ;
180
181
series. push ( selector:: SeriesResponse {
181
182
path : selector:: Path :: new ( )
182
183
. set ( PathComponent :: Benchmark ( "Summary" . into ( ) ) )
@@ -263,10 +264,11 @@ impl CommitIdxCache {
263
264
264
265
fn to_graph_data < ' a > (
265
266
cc : & ' a CommitIdxCache ,
266
- is_absolute : bool ,
267
+ kind : GraphKind ,
267
268
points : impl Iterator < Item = ( ( ArtifactId , Option < f64 > ) , Interpolated ) > + ' a ,
268
269
) -> impl Iterator < Item = graph:: GraphData > + ' a {
269
270
let mut first = None ;
271
+ let mut prev = None ;
270
272
points. map ( move |( ( aid, point) , interpolated) | {
271
273
let commit = if let ArtifactId :: Commit ( commit) = aid {
272
274
commit
@@ -276,15 +278,18 @@ fn to_graph_data<'a>(
276
278
let point = point. expect ( "interpolated" ) ;
277
279
first = Some ( first. unwrap_or ( point) ) ;
278
280
let first = first. unwrap ( ) ;
279
- let percent = ( point - first) / first * 100.0 ;
281
+ let percent_first = ( point - first) / first * 100.0 ;
282
+ let previous_point = prev. unwrap_or ( point) ;
283
+ let percent_prev = ( point - previous_point) / previous_point * 100.0 ;
284
+ prev = Some ( point) ;
280
285
graph:: GraphData {
281
286
commit : cc. lookup ( commit. sha ) ,
282
287
absolute : point as f32 ,
283
- percent : percent as f32 ,
284
- y : if is_absolute {
285
- point as f32
286
- } else {
287
- percent as f32
288
+ percent_first : percent_first as f32 ,
289
+ y : match kind {
290
+ GraphKind :: Raw => point as f32 ,
291
+ GraphKind :: PercentRelative => percent_prev as f32 ,
292
+ GraphKind :: PercentFromFirst => percent_first as f32 ,
288
293
} ,
289
294
x : commit. date . 0 . timestamp ( ) as u64 * 1000 , // all dates are since 1970
290
295
is_interpolated : interpolated. is_interpolated ( ) ,
0 commit comments