11import uPlot , { TypedArray } from "uplot" ;
2- import { GraphData , GraphsSelector } from "./state " ;
2+ import { GraphData , GraphsSelector } from "./data " ;
33
44const commonCacheStateColors = {
55 full : "#7cb5ec" ,
@@ -148,7 +148,6 @@ function tooltipPlugin({
148148}
149149
150150function genPlotOpts ( {
151- title,
152151 width,
153152 height,
154153 yAxisLabel,
@@ -159,9 +158,9 @@ function genPlotOpts({
159158 alpha = 0.3 ,
160159 prox = 5 ,
161160 absoluteMode,
161+ hooks,
162162} ) {
163163 return {
164- title,
165164 width,
166165 height,
167166 series,
@@ -239,6 +238,7 @@ function genPlotOpts({
239238 ctx . stroke ( ) ;
240239 } ,
241240 ] ,
241+ ...hooks ,
242242 } ,
243243 } ,
244244 tooltipPlugin ( {
@@ -280,13 +280,22 @@ function normalizeData(data: GraphData) {
280280 }
281281}
282282
283- // Renders the plots data with the given parameters from the `selector`, into a DOM node optionally
284- // selected by the `elementSelector` query.
283+ export type GraphRenderOpts = {
284+ renderTitle ?: boolean ;
285+ hooks ?: { drawSeries : ( uPlot , number ) => void } ;
286+ } ;
287+
288+ // Renders the plots data with the given parameters from the `selector` into
289+ // the passed DOM element.
285290export function renderPlots (
286291 data : GraphData ,
287292 selector : GraphsSelector ,
288- elementSelector : string
293+ plotElement : HTMLElement ,
294+ opts ?: GraphRenderOpts
289295) {
296+ const renderTitle = opts ?. renderTitle ?? true ;
297+ const hooks = opts ?. hooks ?? { } ;
298+
290299 normalizeData ( data ) ;
291300
292301 const names = Object . keys ( data . benchmarks ) . sort ( ) ;
@@ -364,7 +373,6 @@ export function renderPlots(
364373 cacheStates [ Object . keys ( cacheStates ) [ 0 ] ] . interpolated_indices ;
365374
366375 let plotOpts = genPlotOpts ( {
367- title : benchName + "-" + benchKind ,
368376 width : Math . floor ( window . innerWidth / 4 ) - 40 ,
369377 height : 300 ,
370378 yAxisLabel,
@@ -375,13 +383,13 @@ export function renderPlots(
375383 return indices . has ( dataIdx ) ;
376384 } ,
377385 absoluteMode : selector . kind == "raw" ,
386+ hooks,
378387 } ) ;
388+ if ( renderTitle ) {
389+ plotOpts [ "title" ] = `${ benchName } -${ benchKind } ` ;
390+ }
379391
380- new uPlot (
381- plotOpts ,
382- plotData as any as TypedArray [ ] ,
383- document . querySelector < HTMLElement > ( elementSelector )
384- ) ;
392+ new uPlot ( plotOpts , plotData as any as TypedArray [ ] , plotElement ) ;
385393
386394 i ++ ;
387395 }
0 commit comments