@@ -3,6 +3,7 @@ import { summarizeTrajectories } from './uncertainty.js'
33import { human } from './model.js'
44import { inSelectionOrder } from './state.js'
55import { displayUnit , inDisplayUnit , unitOptions } from './units.js'
6+ import { columnNumberFormat , formatNumber } from './numbers.js'
67function trajectorySeries ( study , current , supported , spec ) {
78 const configColor = ( config ) => current . configColors [ config . key ]
89 const color = ( run ) =>
@@ -15,6 +16,7 @@ function trajectorySeries(study, current, supported, spec) {
1516 id : run . key ,
1617 name : `${ run . name } ${ run . record . parameters . seed == null ? '' : ` · seed ${ run . record . parameters . seed } ` } ` ,
1718 type : 'line' ,
19+ encode : { x : 0 , y : 1 , tooltip : [ 1 ] } ,
1820 step : 'end' ,
1921 showSymbol : false ,
2022 connectNulls : false ,
@@ -64,7 +66,7 @@ function trajectorySeries(study, current, supported, spec) {
6466 type : 'custom' ,
6567 silent : true ,
6668 z : 1 ,
67- encode : { x : [ 0 , 3 ] , y : [ 1 , 2 ] } ,
69+ encode : { x : [ 0 , 3 ] , y : [ 1 , 2 ] , tooltip : [ 1 , 2 ] } ,
6870 data : points
6971 . slice ( 0 , - 1 )
7072 . flatMap ( ( p , i ) =>
@@ -99,6 +101,7 @@ function trajectorySeries(study, current, supported, spec) {
99101 id : `summary-${ config . key } ` ,
100102 name : `${ config . name } · ${ human ( s . timeStat ) } ` ,
101103 type : 'line' ,
104+ encode : { x : 0 , y : 1 , tooltip : [ 1 ] } ,
102105 step : 'end' ,
103106 showSymbol : false ,
104107 connectNulls : false ,
@@ -172,10 +175,28 @@ export function prepareTrajectory(
172175 : trajectorySeries ( study , settings , supported , spec ) ) ,
173176 }
174177}
175- export function trajectoryOptions ( series , alignment , zoom ) {
178+ export function trajectoryOptions ( series , alignment , zoom , spec , magnitude ) {
179+ const tooltipUnit = displayUnit ( spec . unit , magnitude / spec . factor )
180+ const numberFormat = columnNumberFormat (
181+ magnitude / spec . factor / tooltipUnit . factor ,
182+ )
183+ const formatValue = ( value ) => {
184+ const formatted = formatNumber ( inDisplayUnit ( value , tooltipUnit ) , numberFormat )
185+ return [ '1' , 'unknown' ] . includes ( tooltipUnit . unit )
186+ ? formatted
187+ : `${ formatted } ${ tooltipUnit . unit } `
188+ }
176189 return {
177190 useUTC : true ,
178- tooltip : { trigger : 'axis' , renderMode : 'richText' , confine : true } ,
191+ tooltip : {
192+ trigger : 'axis' ,
193+ renderMode : 'richText' ,
194+ confine : true ,
195+ valueFormatter : ( value ) =>
196+ Array . isArray ( value )
197+ ? value . map ( formatValue ) . join ( ' – ' )
198+ : formatValue ( value ) ,
199+ } ,
179200 axisPointer : { link : [ { xAxisIndex : 'all' } ] } ,
180201 grid : { top : 20 , left : 80 , right : 30 , bottom : 75 } ,
181202 xAxis : {
0 commit comments