@@ -11,7 +11,9 @@ import {
1111 RevisionData ,
1212 TemplateAccumulator ,
1313 collectCommitRevisionDetails ,
14- collectOverrideRevisionDetails
14+ collectOverrideRevisionDetails ,
15+ collectCustomPlotsData ,
16+ getCustomPlotId
1517} from './collect'
1618import { getRevisionFirstThreeColumns } from './util'
1719import {
@@ -24,7 +26,8 @@ import {
2426 DEFAULT_SECTION_SIZES ,
2527 Section ,
2628 SectionCollapsed ,
27- PlotSizeNumber
29+ PlotSizeNumber ,
30+ CustomPlotData
2831} from '../webview/contract'
2932import {
3033 ExperimentsOutput ,
@@ -46,10 +49,13 @@ import {
4649} from '../multiSource/collect'
4750import { isDvcError } from '../../cli/dvc/reader'
4851
52+ export type CustomPlotsOrderValue = { metric : string ; param : string }
53+
4954export class PlotsModel extends ModelWithPersistence {
5055 private readonly experiments : Experiments
5156
5257 private plotSizes : Record < Section , number >
58+ private customPlotsOrder : CustomPlotsOrderValue [ ]
5359 private sectionCollapsed : SectionCollapsed
5460 private commitRevisions : Record < string , string > = { }
5561
@@ -64,6 +70,7 @@ export class PlotsModel extends ModelWithPersistence {
6470 private multiSourceEncoding : MultiSourceEncoding = { }
6571
6672 private checkpointPlots ?: CheckpointPlot [ ]
73+ private customPlots ?: CustomPlotData [ ]
6774 private selectedMetrics ?: string [ ]
6875 private metricOrder : string [ ]
6976
@@ -89,6 +96,8 @@ export class PlotsModel extends ModelWithPersistence {
8996 undefined
9097 )
9198 this . metricOrder = this . revive ( PersistenceKey . PLOT_METRIC_ORDER , [ ] )
99+
100+ this . customPlotsOrder = this . revive ( PersistenceKey . PLOTS_CUSTOM_ORDER , [ ] )
92101 }
93102
94103 public transformAndSetExperiments ( data : ExperimentsOutput ) {
@@ -102,6 +111,8 @@ export class PlotsModel extends ModelWithPersistence {
102111
103112 this . setMetricOrder ( )
104113
114+ this . recreateCustomPlots ( )
115+
105116 return this . removeStaleData ( )
106117 }
107118
@@ -119,6 +130,8 @@ export class PlotsModel extends ModelWithPersistence {
119130 collectMultiSourceVariations ( data , this . multiSourceVariations )
120131 ] )
121132
133+ this . recreateCustomPlots ( )
134+
122135 this . comparisonData = {
123136 ...this . comparisonData ,
124137 ...comparisonData
@@ -127,7 +140,6 @@ export class PlotsModel extends ModelWithPersistence {
127140 ...this . revisionData ,
128141 ...revisionData
129142 }
130-
131143 this . templates = { ...this . templates , ...templates }
132144 this . multiSourceVariations = multiSourceVariations
133145 this . multiSourceEncoding = collectMultiSourceEncoding (
@@ -171,6 +183,49 @@ export class PlotsModel extends ModelWithPersistence {
171183 }
172184 }
173185
186+ public getCustomPlots ( ) {
187+ if ( ! this . customPlots ) {
188+ return
189+ }
190+ return {
191+ plots : this . customPlots ,
192+ size : this . getPlotSize ( Section . CUSTOM_PLOTS )
193+ }
194+ }
195+
196+ public recreateCustomPlots ( ) {
197+ const customPlots : CustomPlotData [ ] = collectCustomPlotsData (
198+ this . getCustomPlotsOrder ( ) ,
199+ this . experiments . getExperiments ( )
200+ )
201+ this . customPlots = customPlots
202+ }
203+
204+ public getCustomPlotsOrder ( ) {
205+ return this . customPlotsOrder
206+ }
207+
208+ public setCustomPlotsOrder ( plotsOrder : CustomPlotsOrderValue [ ] ) {
209+ this . customPlotsOrder = plotsOrder
210+ this . persist ( PersistenceKey . PLOTS_CUSTOM_ORDER , this . customPlotsOrder )
211+ this . recreateCustomPlots ( )
212+ }
213+
214+ public removeCustomPlots ( plotIds : string [ ] ) {
215+ const newCustomPlotsOrder = this . getCustomPlotsOrder ( ) . filter (
216+ ( { metric, param } ) => {
217+ return ! plotIds . includes ( getCustomPlotId ( metric , param ) )
218+ }
219+ )
220+
221+ this . setCustomPlotsOrder ( newCustomPlotsOrder )
222+ }
223+
224+ public addCustomPlot ( metricAndParam : CustomPlotsOrderValue ) {
225+ const newCustomPlotsOrder = [ ...this . getCustomPlotsOrder ( ) , metricAndParam ]
226+ this . setCustomPlotsOrder ( newCustomPlotsOrder )
227+ }
228+
174229 public setupManualRefresh ( id : string ) {
175230 this . deleteRevisionData ( id )
176231 }
0 commit comments