File size: 3,050 Bytes
01aa854
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
document.addEventListener('DOMContentLoaded', function() {
    // Create nodes and edges for the brain map
    const nodes = new vis.DataSet([
        { id: 1, label: 'Persona', color: '#0ea5e9', shape: 'box', value: 30 },
        { id: 2, label: 'Dialogue', color: '#0ea5e9', value: 25 },
        { id: 3, label: 'Memory', color: '#8b5cf6', value: 40 },
        { id: 4, label: 'Knowledge', color: '#0ea5e9', value: 35 },
        { id: 5, label: 'Emotion', color: '#22c55e', value: 20 },
        { id: 6, label: 'Safety', color: '#22c55e', value: 20 },
        { id: 7, label: 'Profiling', color: '#22c55e', value: 15 }
    ]);

    const edges = new vis.DataSet([
        { from: 1, to: 2, arrows: 'to', color: { color: '#64748b' } },
        { from: 2, to: 3, arrows: 'to', color: { color: '#64748b' } },
        { from: 3, to: 4, arrows: 'to', color: { color: '#64748b' } },
        { from: 4, to: 1, arrows: 'to', color: { color: '#10b981' }, dashes: true },
        { from: 5, to: 2, arrows: 'to', color: { color: '#3b82f6' }, dashes: true },
        { from: 6, to: 2, arrows: 'to', color: { color: '#3b82f6' }, dashes: true },
        { from: 7, to: 1, arrows: 'to', color: { color: '#64748b' } }
    ]);

    // Create the network
    const container = document.getElementById('brainMapContainer');
    const data = {
        nodes: nodes,
        edges: edges
    };
    const options = {
        nodes: {
            shape: 'dot',
            size: 30,
            font: {
                size: 14,
                color: '#1f2937'
            },
            borderWidth: 2,
            shadow: true
        },
        edges: {
            width: 2,
            shadow: true,
            smooth: {
                type: 'continuous'
            }
        },
        physics: {
            stabilization: {
                enabled: true,
                iterations: 1000
            },
            barnesHut: {
                gravitationalConstant: -2000,
                centralGravity: 0.3,
                springLength: 200
            }
        },
        layout: {
            improvedLayout: true
        }
    };

    const network = new vis.Network(container, data, options);

    // Handle node selection
    network.on('selectNode', function(params) {
        const nodeId = params.nodes[0];
        const node = nodes.get(nodeId);
        const details = `
            <h4 class="font-medium text-gray-900">${node.label}</h4>
            <p class="mt-1">Module ID: ${node.id}</p>
            <p class="mt-1">Status: <span class="text-green-600">Active</span></p>
            <p class="mt-1">Connections: ${edges.get().filter(e => e.from === nodeId || e.to === nodeId).length}</p>
        `;
        document.getElementById('nodeDetails').innerHTML = details;
    });

    // Center and stabilize network
    network.once('stabilizationIterationsDone', function() {
        network.fit({
            animation: {
                duration: 1000,
                easingFunction: 'easeInOutQuad'
            }
        });
    });
});