@@ -31,9 +31,9 @@ import {
31
31
// Add state for panel and checkbox controls
32
32
let isPanelOpen = false ;
33
33
let showMetadata = {
34
- language: false ,
35
- functionName: false ,
36
- lineCount: false ,
34
+ language: true ,
35
+ functionName: true ,
36
+ lineCount: true ,
37
37
nodeCount: false ,
38
38
edgeCount: false ,
39
39
cyclomaticComplexity: false ,
@@ -44,32 +44,32 @@ const metadataFields = [
44
44
{
45
45
key: " language" ,
46
46
label: " Language" ,
47
- value : () => functionAndCFGMetadata .functionData .language ,
47
+ value : () => functionAndCFGMetadata .functionData ? .language ,
48
48
},
49
49
{
50
50
key: " functionName" ,
51
51
label: " Function Name" ,
52
- value : () => functionAndCFGMetadata .functionData .name ,
52
+ value : () => functionAndCFGMetadata .functionData ? .name ,
53
53
},
54
54
{
55
55
key: " lineCount" ,
56
56
label: " Line Count" ,
57
- value : () => functionAndCFGMetadata .functionData .lineCount ,
57
+ value : () => functionAndCFGMetadata .functionData ? .lineCount ,
58
58
},
59
59
{
60
60
key: " nodeCount" ,
61
61
label: " Node Count" ,
62
- value : () => functionAndCFGMetadata .cfgGraphData .nodeCount ,
62
+ value : () => functionAndCFGMetadata .cfgGraphData ? .nodeCount ,
63
63
},
64
64
{
65
65
key: " edgeCount" ,
66
66
label: " Edge Count" ,
67
- value : () => functionAndCFGMetadata .cfgGraphData .edgeCount ,
67
+ value : () => functionAndCFGMetadata .cfgGraphData ? .edgeCount ,
68
68
},
69
69
{
70
70
key: " cyclomaticComplexity" ,
71
71
label: " Cyclomatic Complexity" ,
72
- value : () => functionAndCFGMetadata .cfgGraphData .cyclomaticComplexity ,
72
+ value : () => functionAndCFGMetadata .cfgGraphData ? .cyclomaticComplexity ,
73
73
},
74
74
];
75
75
@@ -283,22 +283,23 @@ async function createCFG(params: Params): Promise<CFG> {
283
283
284
284
let functionAndCFGMetadata: FunctionAndCFGMetadata | undefined ;
285
285
286
- function updateMetadata(func : SyntaxNode , language : Language , CFG : CFG ) {
287
- // Update function metadata
288
- const name: string | undefined = extractFunctionName (func , language );
289
- const lineCount: number = func .endPosition .row - func .startPosition .row + 1 ;
286
+ function updateMetadata(CFG : CFG , func ? : SyntaxNode , language ? : Language ) {
287
+ // Update function metadata (GitHub only)
288
+ let name: string | undefined = undefined ;
289
+ let lineCount: number | undefined = undefined ;
290
+
291
+ if (func && language ) {
292
+ name = extractFunctionName (func , language );
293
+ lineCount = func .endPosition .row - func .startPosition .row + 1 ;
294
+ }
290
295
291
296
// Update CFG metadata
292
297
const nodeCount: number = CFG .graph .order ;
293
298
const edgeCount: number = CFG .graph .size ;
294
- const cyclomaticComplexity: number = CFG .graph .size - nodeCount + 2 ;
299
+ const cyclomaticComplexity: number = CFG .graph .size - nodeCount + 2 ; // (https://en.wikipedia.org/wiki/Cyclomatic_complexity)
295
300
296
301
return {
297
- functionData: {
298
- name ,
299
- lineCount ,
300
- language ,
301
- },
302
+ functionData: name && lineCount ? { name , lineCount , language } : undefined ,
302
303
cfgGraphData: {
303
304
nodeCount ,
304
305
edgeCount ,
@@ -318,7 +319,10 @@ async function render() {
318
319
if (params .type === " GitHub" ) {
319
320
codeUrl = params .codeUrl ;
320
321
const { func, language } = await fetchFunctionAndLanguage (params );
321
- functionAndCFGMetadata = updateMetadata (func , language , cfg );
322
+ functionAndCFGMetadata = updateMetadata (cfg , func , language );
323
+ } else {
324
+ // Graph
325
+ functionAndCFGMetadata = updateMetadata (cfg );
322
326
}
323
327
324
328
const graphviz = await Graphviz .load ();
@@ -390,9 +394,9 @@ onMount(() => {
390
394
</div >
391
395
{#if functionAndCFGMetadata }
392
396
<!-- Metadata display -->
393
- {#if Object . values ( showMetadata ). some (value => value )}
397
+ {#if metadataFields . some (field => showMetadata [ field . key ] && field . value () !== undefined )}
394
398
<div class ="metadata" class:panel-open ={isPanelOpen }>
395
- {#each metadataFields as { key, label, value }}
399
+ {#each metadataFields . filter ( field => field . value () !== undefined ) as { key, label , value}}
396
400
{#if showMetadata [key ]}
397
401
<span >{label }: {value ()}</span >
398
402
{/if }
@@ -405,8 +409,8 @@ onMount(() => {
405
409
<!-- Control panel -->
406
410
<div class ="control-panel" class:open ={isPanelOpen }>
407
411
<h3 >Display Options</h3 >
408
- {#each metadataFields as { key, label }}
409
- <label >
412
+ {#each metadataFields . filter ( field => field . value () !== undefined ) as { key, label }}
413
+ <label >
410
414
<input type ="checkbox" bind:checked ={showMetadata [key ]} />
411
415
{label }
412
416
</label >
@@ -473,12 +477,9 @@ onMount(() => {
473
477
color : var (--toggle-color );
474
478
border : none ;
475
479
font-size : 1em ;
480
+ cursor : pointer ;
476
481
}
477
482
478
- .panel-toggle :hover {
479
- cursor : pointer ;
480
- }
481
-
482
483
.control-panel {
483
484
position : fixed ;
484
485
top : 4em ;
0 commit comments