@parca/profile 0.16.0 → 0.16.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/Callgraph/Edge/index.d.ts +22 -0
  3. package/dist/Callgraph/Edge/index.js +30 -0
  4. package/dist/Callgraph/Node/index.d.ts +19 -0
  5. package/dist/Callgraph/Node/index.js +37 -0
  6. package/dist/Callgraph/index.d.ts +8 -0
  7. package/dist/Callgraph/index.js +137 -0
  8. package/dist/Callgraph/mockData/index.d.ts +148 -0
  9. package/dist/Callgraph/mockData/index.js +577 -0
  10. package/dist/Callgraph/utils.d.ts +19 -0
  11. package/dist/Callgraph/utils.js +82 -0
  12. package/dist/GraphTooltip/index.d.ts +19 -0
  13. package/dist/GraphTooltip/index.js +119 -0
  14. package/dist/IcicleGraph.d.ts +35 -0
  15. package/dist/IcicleGraph.js +139 -0
  16. package/dist/MatchersInput/index.d.ts +23 -0
  17. package/dist/MatchersInput/index.js +479 -0
  18. package/dist/MetricsCircle/index.d.ts +7 -0
  19. package/dist/MetricsCircle/index.js +18 -0
  20. package/dist/MetricsGraph/index.d.ts +35 -0
  21. package/dist/MetricsGraph/index.js +349 -0
  22. package/dist/MetricsSeries/index.d.ts +11 -0
  23. package/dist/MetricsSeries/index.js +21 -0
  24. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +19 -0
  25. package/dist/ProfileExplorer/ProfileExplorerCompare.js +38 -0
  26. package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +15 -0
  27. package/dist/ProfileExplorer/ProfileExplorerSingle.js +19 -0
  28. package/dist/ProfileExplorer/index.d.ts +9 -0
  29. package/dist/ProfileExplorer/index.js +203 -0
  30. package/dist/ProfileIcicleGraph.d.ts +10 -0
  31. package/dist/ProfileIcicleGraph.js +28 -0
  32. package/dist/ProfileMetricsGraph/index.d.ts +22 -0
  33. package/dist/ProfileMetricsGraph/index.js +127 -0
  34. package/dist/ProfileSVG.module.css +3 -0
  35. package/dist/ProfileSelector/CompareButton.d.ts +5 -0
  36. package/dist/ProfileSelector/CompareButton.js +41 -0
  37. package/dist/ProfileSelector/MergeButton.d.ts +5 -0
  38. package/dist/ProfileSelector/MergeButton.js +41 -0
  39. package/dist/ProfileSelector/index.d.ts +29 -0
  40. package/dist/ProfileSelector/index.js +133 -0
  41. package/dist/ProfileSource.d.ts +88 -0
  42. package/dist/ProfileSource.js +239 -0
  43. package/dist/ProfileTypeSelector/index.d.ts +20 -0
  44. package/dist/ProfileTypeSelector/index.js +138 -0
  45. package/dist/ProfileView.d.ts +39 -0
  46. package/dist/ProfileView.js +111 -0
  47. package/dist/ProfileView.styles.css +3 -0
  48. package/dist/ProfileViewWithData.d.ts +11 -0
  49. package/dist/ProfileViewWithData.js +116 -0
  50. package/dist/TopTable.d.ts +9 -0
  51. package/dist/TopTable.js +140 -0
  52. package/dist/TopTable.styles.css +7 -0
  53. package/dist/components/DiffLegend.d.ts +2 -0
  54. package/dist/components/DiffLegend.js +62 -0
  55. package/dist/components/ProfileShareButton/ResultBox.d.ts +6 -0
  56. package/dist/components/ProfileShareButton/ResultBox.js +46 -0
  57. package/dist/components/ProfileShareButton/index.d.ts +7 -0
  58. package/dist/components/ProfileShareButton/index.js +119 -0
  59. package/dist/index.d.ts +13 -0
  60. package/dist/index.js +64 -0
  61. package/dist/styles.css +1 -0
  62. package/dist/useDelayedLoader.d.ts +5 -0
  63. package/dist/useDelayedLoader.js +33 -0
  64. package/dist/useQuery.d.ts +13 -0
  65. package/dist/useQuery.js +41 -0
  66. package/dist/utils.d.ts +4 -0
  67. package/dist/utils.js +83 -0
  68. package/package.json +12 -8
  69. package/src/Callgraph/Edge/index.tsx +59 -0
  70. package/src/Callgraph/Node/index.tsx +66 -0
  71. package/src/Callgraph/index.tsx +169 -0
  72. package/src/Callgraph/mockData/index.ts +605 -0
  73. package/src/Callgraph/utils.ts +116 -0
  74. package/src/GraphTooltip/index.tsx +245 -0
  75. package/src/IcicleGraph.tsx +3 -3
  76. package/src/MatchersInput/index.tsx +698 -0
  77. package/src/MetricsCircle/index.tsx +28 -0
  78. package/src/MetricsGraph/index.tsx +614 -0
  79. package/src/MetricsSeries/index.tsx +38 -0
  80. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +109 -0
  81. package/src/ProfileExplorer/ProfileExplorerSingle.tsx +72 -0
  82. package/src/ProfileExplorer/index.tsx +377 -0
  83. package/src/ProfileMetricsGraph/index.tsx +143 -0
  84. package/src/ProfileSelector/CompareButton.tsx +72 -0
  85. package/src/ProfileSelector/MergeButton.tsx +72 -0
  86. package/src/ProfileSelector/index.tsx +270 -0
  87. package/src/ProfileTypeSelector/index.tsx +180 -0
  88. package/src/ProfileView.tsx +2 -7
  89. package/src/index.tsx +11 -0
  90. package/src/useQuery.tsx +1 -0
  91. package/tailwind.config.js +8 -0
  92. package/tsconfig.json +7 -3
  93. package/typings.d.ts +14 -0
@@ -0,0 +1,605 @@
1
+ // Copyright 2022 The Parca Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+
14
+ export const dotGraph = `{
15
+ n1 [Label = "n1"];
16
+ n2 [Label = "n2"];
17
+ n3 [Label = "n3"];
18
+ n1 -- n2;
19
+ n1 -- n3;
20
+ n2 -- n2;
21
+ }`;
22
+
23
+ export const jsonGraph = {
24
+ total: '4358676',
25
+ unit: 'count',
26
+ nodes: [
27
+ {
28
+ id: 'n0',
29
+ label: 'A node',
30
+ value: 30,
31
+ },
32
+ {
33
+ id: 'n1',
34
+ label: 'Another node',
35
+ value: 20,
36
+ },
37
+ {
38
+ id: 'n2',
39
+ label: 'And a last one',
40
+ value: 10,
41
+ },
42
+ {
43
+ id: 'n3',
44
+ label: 'n3',
45
+ value: 2,
46
+ },
47
+ {
48
+ id: 'n4',
49
+ label: 'n4',
50
+ value: 1,
51
+ },
52
+ {
53
+ id: 'n5',
54
+ label: 'n5',
55
+ value: 1,
56
+ },
57
+ ],
58
+ edges: [
59
+ {
60
+ id: 'e0',
61
+ source: 'n0',
62
+ target: 'n1',
63
+ label: 'edge 1',
64
+ },
65
+ {
66
+ id: 'e1',
67
+ source: 'n1',
68
+ target: 'n2',
69
+ label: 'edge 2',
70
+ },
71
+ {
72
+ id: 'e2',
73
+ source: 'n2',
74
+ target: 'n0',
75
+ label: 'edge 3',
76
+ },
77
+ {
78
+ id: 'e3',
79
+ source: 'n0',
80
+ target: 'n2',
81
+ label: 'edge 4',
82
+ },
83
+ {
84
+ id: 'e4',
85
+ source: 'n2',
86
+ target: 'n3',
87
+ label: 'edge 5',
88
+ },
89
+ {
90
+ id: 'e5',
91
+ source: 'n3',
92
+ target: 'n4',
93
+ label: 'edge 6',
94
+ },
95
+ {
96
+ id: 'e5',
97
+ source: 'n4',
98
+ target: 'n5',
99
+ label: 'edge 6',
100
+ },
101
+ {
102
+ id: 'e5',
103
+ source: 'n3',
104
+ target: 'n5',
105
+ label: 'edge 6',
106
+ },
107
+ ],
108
+ };
109
+
110
+ // just a string, doesn't need to be on separate lines
111
+ export const graphvizDot = `
112
+ digraph {
113
+ N1 [id="node1"]
114
+ N2 [id="node2"]
115
+ N3 [id="node3"]
116
+ N4 [id="node4"]
117
+ N1 -> N2 [id="e1" label="e1 fdskjao fdjksaol"]
118
+ N2 -> N3 [id="e2" label="e2"]
119
+ N3 -> N4 [id="e3" label="e3"]
120
+ N3 -> N1 [id="e4" label="e4"]
121
+ }`;
122
+
123
+ export const jsonGraphWithGraphvizPositions = {
124
+ name: '%27',
125
+ directed: true,
126
+ strict: false,
127
+ _draw_: [
128
+ {
129
+ op: 'c',
130
+ grad: 'none',
131
+ color: '#fffffe00',
132
+ },
133
+ {
134
+ op: 'C',
135
+ grad: 'none',
136
+ color: '#ffffff',
137
+ },
138
+ {
139
+ op: 'P',
140
+ points: [
141
+ [0.0, 0.0],
142
+ [0.0, 180.0],
143
+ [59.0, 180.0],
144
+ [59.0, 0.0],
145
+ ],
146
+ },
147
+ ],
148
+ bb: '0,0,59,180',
149
+ xdotversion: '1.7',
150
+ _subgraph_cnt: 0,
151
+ objects: [
152
+ {
153
+ _gvid: 0,
154
+ name: 'n0',
155
+ Label: 'A node',
156
+ _draw_: [
157
+ {
158
+ op: 'c',
159
+ grad: 'none',
160
+ color: '#000000',
161
+ },
162
+ {
163
+ op: 'C',
164
+ grad: 'none',
165
+ color: '#ffffff',
166
+ },
167
+ {
168
+ op: 'E',
169
+ rect: [41.0, 162.0, 18.0, 18.0],
170
+ },
171
+ ],
172
+ _ldraw_: [
173
+ {
174
+ op: 'F',
175
+ size: 14.0,
176
+ face: 'Times-Roman',
177
+ },
178
+ {
179
+ op: 'c',
180
+ grad: 'none',
181
+ color: '#0000ff',
182
+ },
183
+ {
184
+ op: 'T',
185
+ pt: [41.0, 157.8],
186
+ align: 'c',
187
+ width: 14.0,
188
+ text: 'n0',
189
+ },
190
+ ],
191
+ fillcolor: 'white',
192
+ fixedsize: 'true',
193
+ fontcolor: 'blue',
194
+ height: '0.5',
195
+ label: '\\N',
196
+ margin: '0',
197
+ pos: '41,162',
198
+ shape: 'circle',
199
+ style: 'filled',
200
+ width: '0.5',
201
+ },
202
+ {
203
+ _gvid: 1,
204
+ name: 'n1',
205
+ Label: 'Another node',
206
+ _draw_: [
207
+ {
208
+ op: 'c',
209
+ grad: 'none',
210
+ color: '#000000',
211
+ },
212
+ {
213
+ op: 'C',
214
+ grad: 'none',
215
+ color: '#ffffff',
216
+ },
217
+ {
218
+ op: 'E',
219
+ rect: [18.0, 90.0, 18.0, 18.0],
220
+ },
221
+ ],
222
+ _ldraw_: [
223
+ {
224
+ op: 'F',
225
+ size: 14.0,
226
+ face: 'Times-Roman',
227
+ },
228
+ {
229
+ op: 'c',
230
+ grad: 'none',
231
+ color: '#0000ff',
232
+ },
233
+ {
234
+ op: 'T',
235
+ pt: [18.0, 85.8],
236
+ align: 'c',
237
+ width: 14.0,
238
+ text: 'n1',
239
+ },
240
+ ],
241
+ fillcolor: 'white',
242
+ fixedsize: 'true',
243
+ fontcolor: 'blue',
244
+ height: '0.5',
245
+ label: '\\N',
246
+ margin: '0',
247
+ pos: '18,90',
248
+ shape: 'circle',
249
+ style: 'filled',
250
+ width: '0.5',
251
+ },
252
+ {
253
+ _gvid: 2,
254
+ name: 'n2',
255
+ Label: 'And a last one',
256
+ _draw_: [
257
+ {
258
+ op: 'c',
259
+ grad: 'none',
260
+ color: '#000000',
261
+ },
262
+ {
263
+ op: 'C',
264
+ grad: 'none',
265
+ color: '#ffffff',
266
+ },
267
+ {
268
+ op: 'E',
269
+ rect: [41.0, 18.0, 18.0, 18.0],
270
+ },
271
+ ],
272
+ _ldraw_: [
273
+ {
274
+ op: 'F',
275
+ size: 14.0,
276
+ face: 'Times-Roman',
277
+ },
278
+ {
279
+ op: 'c',
280
+ grad: 'none',
281
+ color: '#0000ff',
282
+ },
283
+ {
284
+ op: 'T',
285
+ pt: [41.0, 13.8],
286
+ align: 'c',
287
+ width: 14.0,
288
+ text: 'n2',
289
+ },
290
+ ],
291
+ fillcolor: 'white',
292
+ fixedsize: 'true',
293
+ fontcolor: 'blue',
294
+ height: '0.5',
295
+ label: '\\N',
296
+ margin: '0',
297
+ pos: '41,18',
298
+ shape: 'circle',
299
+ style: 'filled',
300
+ width: '0.5',
301
+ },
302
+ ],
303
+ edges: [
304
+ {
305
+ _gvid: 0,
306
+ tail: 0,
307
+ head: 1,
308
+ _draw_: [
309
+ {
310
+ op: 'c',
311
+ grad: 'none',
312
+ color: '#000000',
313
+ },
314
+ {
315
+ op: 'b',
316
+ points: [
317
+ [35.67, 144.76],
318
+ [32.98, 136.58],
319
+ [29.65, 126.45],
320
+ [26.61, 117.2],
321
+ ],
322
+ },
323
+ ],
324
+ _hdraw_: [
325
+ {
326
+ op: 'S',
327
+ style: 'solid',
328
+ },
329
+ {
330
+ op: 'c',
331
+ grad: 'none',
332
+ color: '#000000',
333
+ },
334
+ {
335
+ op: 'C',
336
+ grad: 'none',
337
+ color: '#000000',
338
+ },
339
+ {
340
+ op: 'P',
341
+ points: [
342
+ [29.91, 116.04],
343
+ [23.47, 107.63],
344
+ [23.26, 118.23],
345
+ ],
346
+ },
347
+ ],
348
+ pos: 'e,23.465,107.63 35.666,144.76 32.976,136.58 29.647,126.45 26.607,117.2',
349
+ },
350
+ {
351
+ _gvid: 1,
352
+ tail: 1,
353
+ head: 2,
354
+ _draw_: [
355
+ {
356
+ op: 'c',
357
+ grad: 'none',
358
+ color: '#000000',
359
+ },
360
+ {
361
+ op: 'b',
362
+ points: [
363
+ [23.33, 72.76],
364
+ [26.02, 64.58],
365
+ [29.35, 54.45],
366
+ [32.39, 45.2],
367
+ ],
368
+ },
369
+ ],
370
+ _hdraw_: [
371
+ {
372
+ op: 'S',
373
+ style: 'solid',
374
+ },
375
+ {
376
+ op: 'c',
377
+ grad: 'none',
378
+ color: '#000000',
379
+ },
380
+ {
381
+ op: 'C',
382
+ grad: 'none',
383
+ color: '#000000',
384
+ },
385
+ {
386
+ op: 'P',
387
+ points: [
388
+ [35.74, 46.23],
389
+ [35.53, 35.63],
390
+ [29.09, 44.04],
391
+ ],
392
+ },
393
+ ],
394
+ pos: 'e,35.535,35.633 23.334,72.765 26.024,64.578 29.353,54.448 32.393,45.195',
395
+ },
396
+ {
397
+ _gvid: 2,
398
+ tail: 2,
399
+ head: 0,
400
+ _draw_: [
401
+ {
402
+ op: 'c',
403
+ grad: 'none',
404
+ color: '#000000',
405
+ },
406
+ {
407
+ op: 'b',
408
+ points: [
409
+ [42.62, 36.17],
410
+ [43.52, 46.53],
411
+ [44.55, 60.01],
412
+ [45.0, 72.0],
413
+ [45.6, 87.99],
414
+ [45.6, 92.01],
415
+ [45.0, 108.0],
416
+ [44.69, 116.33],
417
+ [44.09, 125.39],
418
+ [43.46, 133.62],
419
+ ],
420
+ },
421
+ ],
422
+ _hdraw_: [
423
+ {
424
+ op: 'S',
425
+ style: 'solid',
426
+ },
427
+ {
428
+ op: 'c',
429
+ grad: 'none',
430
+ color: '#000000',
431
+ },
432
+ {
433
+ op: 'C',
434
+ grad: 'none',
435
+ color: '#000000',
436
+ },
437
+ {
438
+ op: 'P',
439
+ points: [
440
+ [39.95, 133.58],
441
+ [42.62, 143.83],
442
+ [46.93, 134.15],
443
+ ],
444
+ },
445
+ ],
446
+ pos: 'e,42.625,143.83 42.625,36.167 43.524,46.533 44.548,60.013 45,72 45.602,87.989 45.602,92.011 45,108 44.686,116.33 44.095,125.39 43.462,133.62',
447
+ },
448
+ ],
449
+ };
450
+
451
+ export const nodeWithMetaData = (
452
+ id: string,
453
+ name: string
454
+ ): {id: string; cumulative: number; meta: any} => ({
455
+ id,
456
+ cumulative: Math.floor(Math.random() * 10),
457
+ meta: {
458
+ location: {
459
+ id: {
460
+ '0': 201,
461
+ '1': 124,
462
+ '2': 147,
463
+ '3': 175,
464
+ '4': 103,
465
+ '5': 42,
466
+ '6': 76,
467
+ '7': 211,
468
+ '8': 186,
469
+ '9': 184,
470
+ '10': 7,
471
+ '11': 19,
472
+ '12': 62,
473
+ '13': 204,
474
+ '14': 76,
475
+ '15': 130,
476
+ },
477
+ address: `${Math.floor(Math.random() * 10)}${Math.floor(Math.random() * 10)}${Math.floor(
478
+ Math.random() * 10
479
+ )}`,
480
+ mappingId: {
481
+ '0': 72,
482
+ '1': 191,
483
+ '2': 155,
484
+ '3': 45,
485
+ '4': 34,
486
+ '5': 49,
487
+ '6': 65,
488
+ '7': 169,
489
+ '8': 170,
490
+ '9': 93,
491
+ '10': 28,
492
+ '11': 111,
493
+ '12': 102,
494
+ '13': 196,
495
+ '14': 92,
496
+ '15': 210,
497
+ },
498
+ isFolded: false,
499
+ },
500
+ mapping: {
501
+ id: {
502
+ '0': 72,
503
+ '1': 191,
504
+ '2': 155,
505
+ '3': 45,
506
+ '4': 34,
507
+ '5': 49,
508
+ '6': 65,
509
+ '7': 169,
510
+ '8': 170,
511
+ '9': 93,
512
+ '10': 28,
513
+ '11': 111,
514
+ '12': 102,
515
+ '13': 196,
516
+ '14': 92,
517
+ '15': 210,
518
+ },
519
+ start: '0',
520
+ limit: '0',
521
+ offset: '0',
522
+ file: '',
523
+ buildId: '',
524
+ hasFunctions: true,
525
+ hasFilenames: false,
526
+ hasLineNumbers: false,
527
+ hasInlineFrames: false,
528
+ },
529
+ function: {
530
+ id: {
531
+ '0': 46,
532
+ '1': 90,
533
+ '2': 8,
534
+ '3': 65,
535
+ '4': 135,
536
+ '5': 181,
537
+ '6': 65,
538
+ '7': 61,
539
+ '8': 148,
540
+ '9': 246,
541
+ '10': 90,
542
+ '11': 244,
543
+ '12': 208,
544
+ '13': 193,
545
+ '14': 40,
546
+ '15': 177,
547
+ },
548
+ startLine: '0',
549
+ name,
550
+ systemName: 'runtime.gopark',
551
+ filename: `/opt/homebrew/Cellar/go/1.18.2/libexec/src/runtime/proc.go/${name}`,
552
+ },
553
+ line: {
554
+ functionId: {
555
+ '0': 46,
556
+ '1': 90,
557
+ '2': 8,
558
+ '3': 65,
559
+ '4': 135,
560
+ '5': 181,
561
+ '6': 65,
562
+ '7': 61,
563
+ '8': 148,
564
+ '9': 246,
565
+ '10': 90,
566
+ '11': 244,
567
+ '12': 208,
568
+ '13': 193,
569
+ '14': 40,
570
+ '15': 177,
571
+ },
572
+ line: '361',
573
+ },
574
+ },
575
+ });
576
+
577
+ export const jsonGraphWithMetaData = {
578
+ total: '4358676',
579
+ nodes: [
580
+ nodeWithMetaData('root', 'root node'),
581
+ nodeWithMetaData('n1', 'normal node'),
582
+ nodeWithMetaData('n2', 'second node'),
583
+ nodeWithMetaData('n3', 'child'),
584
+ ],
585
+ edges: [
586
+ {
587
+ id: 'edge1',
588
+ source: 'root',
589
+ target: 'n1',
590
+ cumulative: '10',
591
+ },
592
+ {
593
+ id: 'edge2',
594
+ source: 'root',
595
+ target: 'n2',
596
+ cumulative: '8',
597
+ },
598
+ {
599
+ id: 'edge2',
600
+ source: 'n1',
601
+ target: 'n3',
602
+ cumulative: '4',
603
+ },
604
+ ],
605
+ };
@@ -0,0 +1,116 @@
1
+ // Copyright 2022 The Parca Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+
14
+ import {CallgraphNode, CallgraphEdge} from '@parca/client';
15
+
16
+ export const pixelsToInches = (pixels: number): number => pixels / 96;
17
+
18
+ export const parseEdgePos = ({
19
+ pos,
20
+ xScale = n => n,
21
+ yScale = n => n,
22
+ source = [],
23
+ target = [],
24
+ nodeRadius,
25
+ isSelfLoop = false,
26
+ }: {
27
+ pos: string;
28
+ xScale?: (pos: number) => void;
29
+ yScale?: (pos: number) => void;
30
+ source?: number[];
31
+ target?: number[];
32
+ nodeRadius: number;
33
+ isSelfLoop?: boolean;
34
+ }): number[] => {
35
+ const parts = pos.split(' ');
36
+ const arrow = parts.shift() ?? '';
37
+ const partsAsArrays = parts.map(part => part.split(','));
38
+ const scalePosArray = (posArr: string[]): number[] => [+xScale(+posArr[0]), +yScale(+posArr[1])];
39
+ const [_start, cp1, cp2, _end] = partsAsArrays.map(posArr => scalePosArray(posArr));
40
+ const arrowEnd: number[] = scalePosArray(arrow.replace('e,', '').split(','));
41
+
42
+ const getTargetWithOffset = (target: number[], lastEdgePoint: number[]): number[] => {
43
+ const diffX = target[0] - lastEdgePoint[0];
44
+ const diffY = target[1] - lastEdgePoint[1];
45
+ const diffZ = Math.hypot(diffX, diffY);
46
+
47
+ const offsetX = (diffX * nodeRadius) / diffZ;
48
+ const offsetY = (diffY * nodeRadius) / diffZ;
49
+
50
+ return [target[0] - offsetX, target[1] - offsetY];
51
+ };
52
+
53
+ if (isSelfLoop) {
54
+ const [sourceX, sourceY] = source;
55
+ const [targetX, targetY] = target;
56
+ return [
57
+ sourceX,
58
+ sourceY + nodeRadius,
59
+ sourceX,
60
+ sourceY + 3 * nodeRadius,
61
+ targetX + 5 * nodeRadius,
62
+ targetY,
63
+ targetX + nodeRadius,
64
+ targetY,
65
+ ];
66
+ }
67
+ return [...source, ...cp1, ...cp2, ...getTargetWithOffset(target, arrowEnd)];
68
+ };
69
+
70
+ export const jsonToDot = ({
71
+ graph,
72
+ width,
73
+ nodeRadius,
74
+ }: {
75
+ graph: {nodes: CallgraphNode[]; edges: CallgraphEdge[]};
76
+ width: number;
77
+ nodeRadius: number;
78
+ }): string => {
79
+ const {nodes, edges} = graph;
80
+
81
+ const objectAsDotAttributes = (obj: {[key: string]: string}): string =>
82
+ Object.entries(obj)
83
+ .map(entry => `${entry[0]}="${entry[1]}"`)
84
+ .join(' ');
85
+
86
+ const nodesAsStrings = nodes.map((node: CallgraphNode) => {
87
+ const dataAttributes = {
88
+ address: node.meta?.location?.address ?? '',
89
+ functionName: node.meta?.function?.name ?? '',
90
+ cumulative: node.cumulative ?? '',
91
+ root: (node.id === 'root').toString(),
92
+ };
93
+
94
+ return `"${node.id}" [${objectAsDotAttributes(dataAttributes)}]`;
95
+ });
96
+
97
+ const edgesAsStrings = edges.map((edge: CallgraphEdge) => {
98
+ const dataAttributes = {
99
+ cumulative: edge.cumulative,
100
+ };
101
+ return `"${edge.source}" -> "${edge.target}" [${objectAsDotAttributes(dataAttributes)}]`;
102
+ });
103
+
104
+ const graphAsDot = `digraph "callgraph" {
105
+ rankdir="TB"
106
+ ratio="1,3"
107
+ size="${pixelsToInches(width)}, ${pixelsToInches(width)}!"
108
+ margin=10
109
+ edge [margin=0]
110
+ node [margin=0 width=${nodeRadius}]
111
+ ${nodesAsStrings.join(' ')}
112
+ ${edgesAsStrings.join(' ')}
113
+ }`;
114
+
115
+ return graphAsDot;
116
+ };