lwazi 1.10.2 → 1.10.4
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.
- package/package.json +1 -1
- package/src/Services/GraphVisualizer.php +38 -67
package/package.json
CHANGED
|
@@ -14,94 +14,65 @@ class GraphVisualizer
|
|
|
14
14
|
return "No graph data available.\n";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
$root = $this->normalizeRoot($rootUrl);
|
|
18
17
|
$output = "SITE NAVIGATION GRAPH\n";
|
|
19
18
|
$output .= str_repeat('=', 50) . "\n\n";
|
|
20
|
-
$output .= "Root: {$
|
|
19
|
+
$output .= "Root: {$rootUrl}\n";
|
|
21
20
|
$output .= "Total pages: " . count($nodes) . "\n";
|
|
22
21
|
$output .= "Total links: " . array_sum(array_map('count', $adjacency)) . "\n";
|
|
23
22
|
$output .= "\n" . str_repeat('-', 50) . "\n\n";
|
|
24
23
|
|
|
25
|
-
$output .= $this->
|
|
24
|
+
$output .= $this->buildCompactGraph($adjacency, $nodes);
|
|
26
25
|
|
|
27
26
|
return $output;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
protected function
|
|
29
|
+
protected function buildCompactGraph(array $adjacency, array $nodes): string
|
|
31
30
|
{
|
|
32
|
-
$
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected function renderNodeGraph(
|
|
38
|
-
array $adjacency,
|
|
39
|
-
string $current,
|
|
40
|
-
int $depth,
|
|
41
|
-
int $maxDepth,
|
|
42
|
-
int $maxChildren,
|
|
43
|
-
array &$visited
|
|
44
|
-
): string {
|
|
45
|
-
if ($depth > $maxDepth) {
|
|
46
|
-
return '';
|
|
31
|
+
$outdegree = [];
|
|
32
|
+
foreach ($adjacency as $from => $links) {
|
|
33
|
+
$outdegree[$from] = count($links);
|
|
47
34
|
}
|
|
35
|
+
arsort($outdegree);
|
|
36
|
+
$hubs = array_slice($outdegree, 0, 15, true);
|
|
48
37
|
|
|
49
|
-
$
|
|
50
|
-
$
|
|
51
|
-
$
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (isset($visited[$current])) {
|
|
55
|
-
$output .= " → [cycle]\n";
|
|
56
|
-
return $output;
|
|
38
|
+
$output = "HUBS (most connected pages)\n";
|
|
39
|
+
$output .= str_repeat('-', 40) . "\n";
|
|
40
|
+
foreach ($hubs as $url => $count) {
|
|
41
|
+
$label = $this->getPageLabel($url);
|
|
42
|
+
$output .= sprintf(" %-35s → %3d links\n", $label, $count);
|
|
57
43
|
}
|
|
58
44
|
|
|
59
|
-
$
|
|
60
|
-
$
|
|
45
|
+
$output .= "\n" . str_repeat('-', 40) . "\n";
|
|
46
|
+
$output .= "EDGE LIST (top connections)\n";
|
|
47
|
+
$output .= str_repeat('-', 40) . "\n";
|
|
61
48
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
$edges = [];
|
|
50
|
+
foreach ($adjacency as $from => $links) {
|
|
51
|
+
foreach ($links as $to) {
|
|
52
|
+
$key = $this->getPageLabel($from) . ' → ' . $this->getPageLabel($to);
|
|
53
|
+
if (!isset($edges[$key])) {
|
|
54
|
+
$edges[$key] = 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
65
57
|
}
|
|
66
58
|
|
|
67
|
-
$
|
|
68
|
-
$
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
foreach ($displayChildren as $i => $child) {
|
|
74
|
-
$isLast = ($i === count($displayChildren) - 1) && !$hasMore;
|
|
75
|
-
$childIndent = str_repeat(' ', $depth + 1);
|
|
76
|
-
$childPrefix = $isLast ? '└' : '├';
|
|
77
|
-
|
|
78
|
-
$childLabel = $this->getPageLabel($child);
|
|
79
|
-
$output .= "{$childIndent}{$childPrefix}─ {$childLabel}";
|
|
80
|
-
|
|
81
|
-
if ($depth < $maxDepth) {
|
|
82
|
-
$childVisited = $visited;
|
|
83
|
-
$childChildren = $adjacency[$child] ?? [];
|
|
84
|
-
if (!empty($childChildren)) {
|
|
85
|
-
$output .= " → " . count($childChildren) . " link" . (count($childChildren) !== 1 ? 's' : '') . "\n";
|
|
86
|
-
$output .= $this->renderNodeGraph(
|
|
87
|
-
$adjacency,
|
|
88
|
-
$child,
|
|
89
|
-
$depth + 1,
|
|
90
|
-
$maxDepth,
|
|
91
|
-
$maxChildren,
|
|
92
|
-
$visited
|
|
93
|
-
);
|
|
94
|
-
} else {
|
|
95
|
-
$output .= " (leaf)\n";
|
|
59
|
+
$edgeList = [];
|
|
60
|
+
foreach ($adjacency as $from => $links) {
|
|
61
|
+
foreach ($links as $to) {
|
|
62
|
+
$key = $this->getPageLabel($from) . ' → ' . $this->getPageLabel($to);
|
|
63
|
+
if (!isset($edgeList[$key])) {
|
|
64
|
+
$edgeList[$key] = $key;
|
|
96
65
|
}
|
|
97
|
-
} else {
|
|
98
|
-
$output .= "\n";
|
|
99
66
|
}
|
|
100
67
|
}
|
|
101
68
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
$output .= "{$
|
|
69
|
+
$uniqueEdges = array_slice($edgeList, 0, 30, true);
|
|
70
|
+
foreach ($uniqueEdges as $edge) {
|
|
71
|
+
$output .= " {$edge}\n";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (count($edgeList) > 30) {
|
|
75
|
+
$output .= " ... and " . (count($edgeList) - 30) . " more edges\n";
|
|
105
76
|
}
|
|
106
77
|
|
|
107
78
|
return $output;
|
|
@@ -119,7 +90,7 @@ class GraphVisualizer
|
|
|
119
90
|
$result .= ':' . $port;
|
|
120
91
|
}
|
|
121
92
|
|
|
122
|
-
return
|
|
93
|
+
return $result . '/';
|
|
123
94
|
}
|
|
124
95
|
|
|
125
96
|
protected function getPageLabel(string $url): string
|