@@ -42,6 +42,7 @@ import {
4242 getParent ,
4343 getPathArray
4444} from '../../fileSystem/util'
45+ import { Color } from '../../experiments/model/status/colors'
4546
4647export const getCustomPlotId = ( metric : string , param : string ) =>
4748 `custom-${ metric } -${ param } `
@@ -52,21 +53,28 @@ const getValueFromColumn = (path: string, experiment: Experiment) =>
5253const getValues = (
5354 experiments : Experiment [ ] ,
5455 metricPath : string ,
55- paramPath : string
56+ paramPath : string ,
57+ renderLastIds : Set < string > = new Set < string > ( )
5658) : CustomPlotValues => {
5759 const values : CustomPlotValues = [ ]
5860
5961 for ( const experiment of experiments ) {
6062 const metricValue = getValueFromColumn ( metricPath , experiment )
6163 const paramValue = getValueFromColumn ( paramPath , experiment )
6264
63- if ( metricValue !== undefined && paramValue !== undefined ) {
64- values . push ( {
65- id : experiment . id ,
66- metric : metricValue ,
67- param : paramValue
68- } )
65+ if ( metricValue === undefined || paramValue === undefined ) {
66+ continue
6967 }
68+
69+ const value = {
70+ id : experiment . id ,
71+ metric : metricValue ,
72+ param : paramValue
73+ }
74+
75+ renderLastIds . has ( experiment . id )
76+ ? values . push ( value )
77+ : values . unshift ( value )
7078 }
7179
7280 return values
@@ -76,13 +84,15 @@ const getCustomPlotData = (
7684 orderValue : CustomPlotsOrderValue ,
7785 experiments : Experiment [ ] ,
7886 height : number ,
79- nbItemsPerRow : number
87+ nbItemsPerRow : number ,
88+ completeColorScale : ColorScale ,
89+ renderLastIds : Set < string >
8090) : CustomPlotData => {
8191 const { metric, param } = orderValue
8292 const metricPath = getFullValuePath ( ColumnType . METRICS , metric )
8393 const paramPath = getFullValuePath ( ColumnType . PARAMS , param )
8494
85- const values = getValues ( experiments , metricPath , paramPath )
95+ const values = getValues ( experiments , metricPath , paramPath , renderLastIds )
8696
8797 const [ { param : paramVal , metric : metricVal } ] = values
8898 const yTitle = truncateVerticalTitle ( metric , nbItemsPerRow , height ) as string
@@ -92,7 +102,8 @@ const getCustomPlotData = (
92102 metric ,
93103 param ,
94104 typeof metricVal ,
95- typeof paramVal
105+ typeof paramVal ,
106+ completeColorScale
96107 )
97108
98109 return {
@@ -104,21 +115,54 @@ const getCustomPlotData = (
104115 } as CustomPlotData
105116}
106117
118+ const fillColorScale = (
119+ colorScale : ColorScale | undefined ,
120+ experiments : Experiment [ ]
121+ ) => {
122+ const completeColorScale = {
123+ domain : [ ...( colorScale ?. domain || [ ] ) ] ,
124+ range : [ ...( colorScale ?. range || [ ] ) ]
125+ }
126+
127+ for ( const experiment of experiments ) {
128+ const { id } = experiment
129+ if ( completeColorScale . domain . includes ( id ) ) {
130+ continue
131+ }
132+ completeColorScale . domain . push ( id )
133+ completeColorScale . range . push ( '#4c78a8' as Color )
134+ }
135+ return completeColorScale
136+ }
137+
107138export const collectCustomPlots = ( {
139+ colorScale,
108140 plotsOrderValues,
109141 experiments,
110142 height,
111143 nbItemsPerRow
112144} : {
145+ colorScale : ColorScale | undefined
113146 plotsOrderValues : CustomPlotsOrderValue [ ]
114147 experiments : Experiment [ ]
115148 height : number
116149 nbItemsPerRow : number
117150} ) : CustomPlotData [ ] => {
118151 const plots = [ ]
119152
153+ const completeColorScale = fillColorScale ( colorScale , experiments )
154+
120155 for ( const value of plotsOrderValues ) {
121- plots . push ( getCustomPlotData ( value , experiments , height , nbItemsPerRow ) )
156+ plots . push (
157+ getCustomPlotData (
158+ value ,
159+ experiments ,
160+ height ,
161+ nbItemsPerRow ,
162+ completeColorScale ,
163+ new Set ( colorScale ?. domain )
164+ )
165+ )
122166 }
123167
124168 return plots
0 commit comments