1
1
use serde:: Serialize ;
2
2
3
+ // expected to mirror
4
+ // https://hediet.github.io/visualization/docs/visualization-data-schema.json
5
+ //
6
+ // implements the grid visualizer as an example
7
+
8
+ pub type Label = String ;
9
+
10
+ /// `GridVisualizationData` in schema
3
11
#[ derive( Debug , Serialize ) ]
4
- struct Label {
5
- label : Option < String > ,
6
- }
7
- # [ derive ( Debug , Serialize ) ]
8
- struct Row {
9
- label : Option < String > ,
10
- columns : Vec < Column > ,
12
+ pub struct Grid {
13
+ kind : Kind ,
14
+ rows : Vec < Row > ,
15
+
16
+ # [ serde ( rename = "columnLabels" ) ]
17
+ # [ serde ( skip_serializing_if= " Option::is_none" ) ]
18
+ column_labels : Option < Vec < Label > > ,
11
19
}
20
+
12
21
#[ derive( Debug , Serialize ) ]
13
- struct Column {
14
- content : Option < String > ,
15
- tag : Option < String > ,
16
- color : Option < String > ,
22
+ pub struct Kind {
23
+ grid : bool ,
17
24
}
25
+
18
26
#[ derive( Debug , Serialize ) ]
19
- struct Marker {
20
- id : String ,
21
- row : u64 ,
22
- column : u64 ,
23
- rows : Option < u64 > ,
24
- columns : Option < u64 > ,
25
- label : Option < String > ,
26
- color : Option < String > ,
27
- }
27
+ pub struct Row {
28
+ columns : Vec < Column > ,
28
29
29
- #[ allow( clippy:: trivially_copy_pass_by_ref) ]
30
- fn is_false ( b : & bool ) -> bool {
31
- !* b
30
+ #[ serde( skip_serializing_if="Option::is_none" ) ]
31
+ label : Option < Label > ,
32
32
}
33
33
34
34
#[ derive( Debug , Serialize ) ]
35
- struct Kind {
36
- # [ serde ( skip_serializing_if = "is_false" ) ]
37
- array : bool ,
38
- }
35
+ pub struct Column {
36
+ /// value to display to the user
37
+ # [ serde ( skip_serializing_if= "Option::is_none" ) ]
38
+ content : Option < String > ,
39
39
40
- # [ derive ( Debug , Serialize ) ]
41
- pub struct Grid {
42
- kind : Kind ,
43
- # [ serde ( rename = "columnLabels" ) ]
44
- column_labels : Option < Vec < Label > > ,
45
- rows : Vec < Row > ,
46
- markers : Option < Vec < Marker > > ,
40
+ /// unique value to identify this cell, if desired
41
+ # [ serde ( skip_serializing_if= "Option::is_none" ) ]
42
+ tag : Option < String > ,
43
+
44
+ // TODO: valid values / syntax?
45
+ # [ serde ( skip_serializing_if= "Option::is_none" ) ]
46
+ color : Option < String > ,
47
47
}
48
48
49
49
fn show_arr ( a : & [ i32 ] ) -> String {
50
- let n = a. len ( ) ;
51
- let labels: Vec < Label > = ( 0 ..n)
52
- . map ( |i| Label {
53
- label : Some ( i. to_string ( ) ) ,
54
- } )
55
- . collect ( ) ;
56
50
let columns: Vec < Column > = a
57
51
. iter ( )
58
52
. map ( |x| Column {
59
53
content : Some ( format ! ( "{:?}" , x) ) ,
60
- tag : Some ( x. to_string ( ) ) ,
61
- color : None ,
54
+ tag : None ,
55
+
56
+ // TODO: `color` value doesn't seem to change visualizer's output at all
57
+ color : "who-knows" . to_owned ( ) . into ( ) ,
62
58
} )
63
59
. collect ( ) ;
60
+
64
61
let row = Row {
65
- label : None ,
66
62
columns,
63
+ // TODO: visualizer doesn't seem to render this
64
+ label : "my row" . to_owned ( ) . into ( ) ,
67
65
} ;
68
- let kind = Kind { array : true } ;
66
+
67
+ let kind = Kind { grid : true } ;
69
68
70
69
let grid = Grid {
71
70
kind,
72
- column_labels : Some ( labels) ,
73
71
rows : vec ! [ row] ,
74
- markers : None ,
72
+
73
+ // TODO: visualizer doesn't seem to work if this is non-`None`
74
+ column_labels : None ,
75
75
} ;
76
76
77
77
serde_json:: to_string ( & grid) . unwrap ( )
@@ -81,9 +81,9 @@ fn main() {
81
81
let mut arr = vec ! [ 1 , 2 , 3 ] ;
82
82
let mut _s = show_arr ( & arr) ;
83
83
for _ in 0 ..5 {
84
- arr. swap ( 0 , 2 ) ; // break point
84
+ arr. swap ( 0 , 2 ) ; // set a break- point here, to easily observe the change
85
85
_s = show_arr ( & arr) ;
86
86
}
87
- dbg ! ( arr) ; // break point
88
- println ! ( "Hello, world! " ) ;
87
+ dbg ! ( arr) ;
88
+ println ! ( "break-point here, too " ) ;
89
89
}
0 commit comments