-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
Copy pathdebug_visualizers.dart
85 lines (69 loc) · 1.42 KB
/
debug_visualizers.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'dart:convert';
String graph(List<GraphNode> nodes, List<GraphEdge> edges) {
return jsonEncode({
'kind': {'graph': true},
'nodes': nodes,
'edges': edges,
});
}
String plotly(List<num> values) {
return jsonEncode({
'kind': {'plotly': true},
'data': [
{'y': values}
],
});
}
String tree(TreeNode root) {
return jsonEncode({
'kind': {'tree': true},
'root': root,
});
}
class Graph {
List<GraphNode> nodes;
List<GraphEdge> edges;
}
class GraphEdge {
final String from;
final String to;
final String label;
GraphEdge(this.from, this.to, this.label);
Map<String, dynamic> toJson() => {
'from': from,
'to': to,
'label': label,
};
}
class GraphNode {
final String id;
final String label;
GraphNode(
this.id,
this.label,
);
Map<String, dynamic> toJson() => {
'id': id,
'label': label,
};
}
class TreeNode {
final List<TreeNode> children;
final List<TreeNodeItem> items;
final String segment;
final bool isMarked;
TreeNode(this.children, this.items, this.segment, [this.isMarked = false]);
Map<String, dynamic> toJson() => {
'children': children ?? [],
'items': items,
'segment': segment,
'isMarked': isMarked,
};
}
class TreeNodeItem {
final String text;
TreeNodeItem(this.text);
Map<String, dynamic> toJson() => {
'text': text,
};
}