summaryrefslogtreecommitdiff
path: root/symbol_analyzer/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'symbol_analyzer/index.html')
-rw-r--r--symbol_analyzer/index.html137
1 files changed, 137 insertions, 0 deletions
diff --git a/symbol_analyzer/index.html b/symbol_analyzer/index.html
new file mode 100644
index 0000000..3f0257b
--- /dev/null
+++ b/symbol_analyzer/index.html
@@ -0,0 +1,137 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="./analysis.js"></script>
+ <style>
+body {
+ background-color: #141514;4;4;4;
+}
+ </style>
+ </head>
+ <body>
+ <canvas id="main" width="1000" height="1000" style="border:1px solid #fff;">
+ </canvas>
+ <script>
+const RADIUS = 20;
+const WIDTH = 1000;
+const HEIGHT = 1000;
+const RING_RADIUS = Math.min(WIDTH, HEIGHT) / 2 - 2 * RADIUS;
+const ignore_files = [
+ "stdbool.h",
+ "queen.c",
+ "rook.c",
+ "king.c",
+ "pawn.c",
+ "bishop.c",
+ "knight.c"
+];
+
+data = data.filter(x => !ignore_files.includes(x.name));
+
+const c = document.getElementById("main");
+const ctx = c.getContext("2d");
+ctx.textAlign = "center";
+ctx.font = "bold 10pt Courier";
+
+function canvas_arrow(fromx, fromy, tox, toy) {
+ var headlen = 10; // length of head in pixels
+ var dx = tox - fromx;
+ var dy = toy - fromy;
+ var angle = Math.atan2(dy, dx);
+ ctx.moveTo(
+ fromx + Math.cos(angle) * RADIUS,
+ fromy + Math.sin(angle) * RADIUS
+ );
+ ctx.lineTo(
+ tox + Math.cos(Math.PI + angle) * RADIUS,
+ toy + Math.sin(Math.PI + angle) * RADIUS
+ );
+ ctx.lineTo(
+ tox - headlen * Math.cos(angle - Math.PI / 6) + Math.cos(Math.PI + angle) * RADIUS,
+ toy - headlen * Math.sin(angle - Math.PI / 6) + Math.sin(Math.PI + angle) * RADIUS
+ );
+ ctx.moveTo(
+ tox + Math.cos(Math.PI + angle) * RADIUS,
+ toy + Math.sin(Math.PI + angle) * RADIUS
+ );
+ ctx.lineTo(
+ tox - headlen * Math.cos(angle + Math.PI / 6) + Math.cos(Math.PI + angle) * RADIUS,
+ toy - headlen * Math.sin(angle + Math.PI / 6) + Math.sin(Math.PI + angle) * RADIUS
+ );
+}
+
+let mapping = {}
+
+for (let i = 0; i < data.length; i++) {
+ mapping[data[i].name] = i;
+ const angle = i * 2 * Math.PI / data.length;
+ const [x, y] = [
+ RING_RADIUS * Math.cos(angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(angle) + HEIGHT / 2
+ ];
+ ctx.fillStyle = `hsl(${i * 255 / data.length}, 50%, 50%)`;
+ ctx.beginPath();
+ ctx.arc(x, y, RADIUS, 0, 2 * Math.PI);
+ ctx.fill();
+ ctx.fillStyle = "white";
+ ctx.fillText(data[i].name, x, y);
+}
+
+for (let i = 0; i < data.length; i++) {
+ for (let j = 0; j < data[i].imports.length; j++) {
+ if (!(data[i].imports[j] in mapping)) continue;
+ const to_idx = mapping[data[i].name];
+ const from_idx = mapping[data[i].imports[j]];
+ const from_angle = from_idx * 2 * Math.PI / data.length;
+ const [from_x, from_y] = [
+ RING_RADIUS * Math.cos(from_angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(from_angle) + HEIGHT / 2
+ ];
+ const to_angle = to_idx * 2 * Math.PI / data.length;
+ const [to_x, to_y] = [
+ RING_RADIUS * Math.cos(to_angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(to_angle) + HEIGHT / 2
+ ];
+ ctx.beginPath();
+ ctx.strokeStyle = `hsl(${from_idx * 255 / data.length}, 50%, 40%)`;
+ canvas_arrow(from_x, from_y, to_x, to_y);
+ ctx.stroke();
+ }
+}
+
+function getCursorPosition(canvas, event) {
+ const rect = canvas.getBoundingClientRect()
+ const x = event.clientX - rect.left
+ const y = event.clientY - rect.top
+ return [x, y]
+}
+
+const canvas = document.querySelector('canvas')
+canvas.addEventListener('mousedown', function(e) {
+ const [x, y] = getCursorPosition(canvas, e)
+ for (let i = 0; i < data.length; i++) {
+ const angle = i * 2 * Math.PI / data.length;
+ const [point_x, point_y] = [
+ RING_RADIUS * Math.cos(angle) + WIDTH / 2,
+ RING_RADIUS * Math.sin(angle) + HEIGHT / 2
+ ];
+
+
+ if (Math.pow(point_x - x, 2) + Math.pow(point_y - y, 2) > Math.pow(RADIUS, 2)) {
+ continue;
+ }
+
+ console.clear()
+ console.log(data[i].symbols)
+ console.log(data[i].unused)
+ console.log(data[i].used)
+ // for (let j = 0; j < data[i].unused.length; j++) {
+ // console.log(data[i].unused[j]);
+ // }
+ // console.log(data[i].unused.length);
+ }
+})
+
+ </script>
+ </body>
+</html>