@@ -4,86 +4,90 @@ import { ColorScale } from 'dvc/src/plots/webview/contract'
44export const createSpec = (
55 title : string ,
66 scale ?: ColorScale
7- ) : VisualizationSpec => ( {
8- $schema : 'https://vega.github.io/schema/vega-lite/v5.json' ,
9- data : { name : 'values' } ,
10- encoding : {
11- x : {
12- axis : { format : '0d' , tickMinStep : 1 } ,
13- field : 'iteration' ,
14- title : 'iteration' ,
15- type : 'quantitative'
7+ ) : VisualizationSpec =>
8+ ( {
9+ $schema : 'https://vega.github.io/schema/vega-lite/v5.json' ,
10+ data : { name : 'values' } ,
11+ encoding : {
12+ color : {
13+ field : 'group' ,
14+ legend : { disable : true } ,
15+ scale,
16+ title : 'rev' ,
17+ type : 'nominal'
18+ } ,
19+ x : {
20+ axis : { format : '0d' , tickMinStep : 1 } ,
21+ field : 'iteration' ,
22+ title : 'iteration' ,
23+ type : 'quantitative'
24+ } ,
25+ y : {
26+ field : 'y' ,
27+ scale : { zero : false } ,
28+ title,
29+ type : 'quantitative'
30+ }
1631 } ,
17- y : {
18- field : 'y' ,
19- scale : { zero : false } ,
20- title,
21- type : 'quantitative'
22- }
23- } ,
24- height : 'container' ,
25- layer : [
26- {
27- encoding : {
28- color : { field : 'group' , legend : null , scale, type : 'nominal' }
32+ height : 'container' ,
33+ layer : [
34+ {
35+ layer : [
36+ { mark : { type : 'line' } } ,
37+ {
38+ mark : { type : 'point' } ,
39+ transform : [
40+ {
41+ filter : { empty : false , param : 'hover' }
42+ }
43+ ]
44+ }
45+ ]
2946 } ,
30-
31- layer : [
32- { mark : { type : 'line' } } ,
33- {
34- mark : { type : 'point' } ,
35- transform : [
47+ {
48+ encoding : {
49+ opacity : { value : 0 } ,
50+ tooltip : [
51+ { field : 'group' , title : 'name' } ,
3652 {
37- filter : { empty : false , param : 'hover' }
53+ field : 'y' ,
54+ title : title . slice ( Math . max ( 0 , title . indexOf ( ':' ) + 1 ) ) ,
55+ type : 'quantitative'
3856 }
3957 ]
40- }
41- ]
42- } ,
43- {
44- encoding : {
45- opacity : { value : 0 } ,
46- tooltip : [
47- { field : 'group' , title : 'name' } ,
58+ } ,
59+ mark : { type : 'rule' } ,
60+ params : [
4861 {
49- field : 'y' ,
50- title : title . slice ( Math . max ( 0 , title . indexOf ( ':' ) + 1 ) ) ,
51- type : 'quantitative'
62+ name : 'hover' ,
63+ select : {
64+ clear : 'mouseout' ,
65+ fields : [ 'iteration' , 'y' ] ,
66+ nearest : true ,
67+ on : 'mouseover' ,
68+ type : 'point'
69+ }
5270 }
5371 ]
5472 } ,
55- mark : { type : 'rule' } ,
56- params : [
57- {
58- name : 'hover' ,
59- select : {
60- clear : 'mouseout' ,
61- fields : [ 'iteration' , 'y' ] ,
62- nearest : true ,
63- on : 'mouseover' ,
64- type : 'point'
73+ {
74+ encoding : {
75+ color : { field : 'group' , scale } ,
76+ x : { aggregate : 'max' , field : 'iteration' , type : 'quantitative' } ,
77+ y : {
78+ aggregate : { argmax : 'iteration' } ,
79+ field : 'y' ,
80+ type : 'quantitative'
6581 }
66- }
67- ]
68- } ,
69- {
70- encoding : {
71- color : { field : 'group' , scale } ,
72- x : { aggregate : 'max' , field : 'iteration' , type : 'quantitative' } ,
73- y : {
74- aggregate : { argmax : 'iteration' } ,
75- field : 'y' ,
76- type : 'quantitative'
77- }
78- } ,
79- mark : { stroke : null , type : 'circle' }
80- }
81- ] ,
82- transform : [
83- {
84- as : 'y' ,
85- calculate : "format(datum['y'],'.5f')"
86- }
87- ] ,
88- width : 'container'
89- } )
82+ } ,
83+ mark : { stroke : null , type : 'circle' }
84+ }
85+ ] ,
86+ transform : [
87+ {
88+ as : 'y' ,
89+ calculate : "format(datum['y'],'.5f')"
90+ }
91+ ] ,
92+ width : 'container'
93+ } as VisualizationSpec )
0 commit comments