@@ -184,6 +184,85 @@ function parse(list) {
184
184
185
185
然后就可以使用 React 自定义组件来完成了,具体的组件定义在[ index.js] ( ./index.js ) 中。
186
186
187
+ ## 更新(2020-09-22)
188
+
189
+ 由于有了一个功能很好的 VSCODE 插件, 因此考虑直接集成。 https://hediet.github.io/visualization/
190
+
191
+ 以树的可视化调试为例:
192
+
193
+ ```
194
+
195
+ {
196
+ "kind": { "graph": true },
197
+ "nodes": [
198
+ { "id": "1", "label": "1" },
199
+ { "id": "2", "label": "2", "color": "orange" },
200
+ { "id": "3", "label": "3" }
201
+ ],
202
+ "edges": [
203
+ { "from": "1", "to": "2", "color": "red" },
204
+ { "from": "1", "to": "3" }
205
+ ]
206
+ }
207
+ ```
208
+
209
+ will render:
210
+
211
+ ![ ] ( https://tva1.sinaimg.cn/large/007S8ZIlly1giz7wiwrrej30e108emxi.jpg )
212
+
213
+ 因此我们的目标就是:
214
+
215
+ 1 . 将 LeetCode 的测试用例, 比如 [ 1,2, null, 3, 4] 转化为树结构,树的定义:
216
+
217
+ ``` py
218
+ class TreeNode :
219
+ def __init__ (self , x ):
220
+ self .val = x
221
+ self .left = None
222
+ self .right = None
223
+ ```
224
+ 2 . 将树转化为形如:
225
+
226
+ ``` js
227
+ {
228
+ " kind" : { " graph" : true },
229
+ " nodes" : [
230
+ { " id" : " 1" , " label" : " 1" },
231
+ { " id" : " 2" , " label" : " 2" , " color" : " orange" },
232
+ { " id" : " 3" , " label" : " 3" }
233
+ ],
234
+ " edges" : [
235
+ { " from" : " 1" , " to" : " 2" , " color" : " red" },
236
+ { " from" : " 1" , " to" : " 3" }
237
+ ]
238
+ }
239
+ ```
240
+
241
+ 的数据结构
242
+
243
+ 3 . 在用户代码前后加预处理代码,比如:
244
+
245
+ ``` py
246
+ # this class below
247
+ class TreeNode :
248
+ def __init__ (self , x ):
249
+ self .val = x
250
+ self .left = None
251
+ self .right = None
252
+
253
+
254
+ class Solution :
255
+ def lowestCommonAncestor (self , root : ' TreeNode' , p : ' TreeNode' , q : ' TreeNode' ) -> ' TreeNode' :
256
+ if (root.val - p.val) * (root.val - q.val) <= 0 :
257
+ return root
258
+ if p.val < root.val:
259
+ return self .lowestCommonAncestor(root.left, p, q)
260
+ return self .lowestCommonAncestor(root.right, p, q)
261
+
262
+ # this line below,��中这三个参数应该是从测试用例转化过来的
263
+ Solution().lowestCommonAncestor(root, p,q)
264
+ ```
265
+ 4 . 用户输入自定义的用例,也可以完成转化并执行
187
266
## 扩展
188
267
189
268
- 支持用户手写表达式,类似力扣的“树的可视化”
@@ -194,3 +273,4 @@ function parse(list) {
194
273
- [ ncona] ( https://ncona.com/2020/06/create-diagrams-with-code-using-graphviz/ )
195
274
- [ gdbgui] ( https://github.com/cs01/gdbgui )
196
275
- [ traceId-spanId 全链路追踪] ( https://gist.github.com/azl397985856/2f5bf2c8fb6640d37eec1319faf3b5ec )
276
+ - [ vscode debug visualization] ( https://hediet.github.io/visualization/ )
0 commit comments