File size: 8,263 Bytes
eaa2438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ground Truth Graph</title>
    <script src="https://cdn.jsdelivr.net/npm/vis-network@9.1.2/dist/vis-network.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            overflow: hidden;
        }

        #mynetwork {
            width: 100%;
            height: 100vh;
            background: white;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
        }

        .header {
            position: absolute;
            top: 20px;
            left: 20px;
            z-index: 1000;
            background: rgba(255, 255, 255, 0.95);
            padding: 15px 25px;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            backdrop-filter: blur(10px);
        }

        .header h1 {
            color: #667eea;
            font-size: 1.2em;
            margin: 0;
            font-weight: 600;
        }

        .badge {
            background: #10b981;
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.75em;
            font-weight: 600;
            margin-left: 10px;
        }

        .loading {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
            color: white;
            font-size: 1.5em;
        }

        .spinner {
            border: 4px solid rgba(255,255,255,0.3);
            border-radius: 50%;
            border-top: 4px solid white;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin: 20px auto;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>📘 Ground Truth<span class="badge">GT</span></h1>
    </div>

    <div id="loading" class="loading">
        <div class="spinner"></div>
        <div>Chargement du Ground Truth...</div>
    </div>

    <div id="mynetwork"></div>

   <script>
    console.log('🔍 Script GT chargé');

    // Récupérer le paramètre 'doc' de l'URL
    const urlParams = new URLSearchParams(window.location.search);
    const docName = urlParams.get('doc');

    console.log('📄 Document demandé:', docName);
    console.log('🌐 URL actuelle:', window.location.href);

    if (!docName) {
        document.getElementById('loading').innerHTML = '<div style="color: #e74c3c; font-size: 1.2em;">❌ Aucun document spécifié dans l\'URL</div>';
    } else {
        // ✅ CORRECTION : Chemin relatif depuis la racine du serveur
        const gtPath = `GT/${docName}.json`;

        console.log('📂 Chemin GT:', gtPath);
        console.log('🔗 Tentative de chargement...');

        fetch(gtPath)
            .then(response => {
                console.log('📡 Réponse reçue:', response.status, response.statusText);

                if (!response.ok) {
                    throw new Error(`Fichier non trouvé (${response.status})`);
                }
                return response.json();
            })
            .then(data => {
                console.log('✅ Données GT chargées:', data);
                console.log('   - Nœuds:', data.nodes?.length || 0);
                console.log('   - Arêtes:', data.edges?.length || 0);

                document.getElementById('loading').style.display = 'none';
                displayGraph(data);
            })
            .catch(error => {
                console.error('❌ Erreur de chargement:', error);
                document.getElementById('loading').innerHTML =
                    `<div style="color: #e74c3c;">
                        <h2>❌ Erreur</h2>
                        <p style="font-size: 1em; margin-top: 10px;">${error.message}</p>
                        <p style="font-size: 0.9em; margin-top: 10px; color: #95a5a6;">
                            Chemin tenté : <code style="background: rgba(255,255,255,0.2); padding: 4px 8px; border-radius: 4px;">${gtPath}</code>
                        </p>
                        <p style="font-size: 0.85em; margin-top: 10px;">
                            💡 Vérifiez la console du navigateur (F12) pour plus de détails
                        </p>
                    </div>`;
            });
    }

    function displayGraph(data) {
        console.log('🎨 Affichage du graphe...');

        if (!data.nodes || !data.edges) {
            console.error('❌ Format de données invalide:', data);
            document.getElementById('loading').innerHTML =
                '<div style="color: #e74c3c;">❌ Format de données invalide</div>';
            return;
        }

        try {
            // Préparer les nœuds
            const nodes = data.nodes.map(node => ({
                id: node.id,
                label: node.label,
                shape: 'box',
                color: {
                    background: '#10b981',
                    border: '#059669',
                    highlight: {
                        background: '#34d399',
                        border: '#059669'
                    }
                },
                font: {
                    color: 'white',
                    size: 14,
                    face: 'Segoe UI',
                    bold: true
                },
                margin: 10,
                borderWidth: 2,
                shadow: {
                    enabled: true,
                    color: 'rgba(0,0,0,0.2)',
                    size: 10,
                    x: 2,
                    y: 2
                }
            }));

            // Préparer les arêtes
            const edges = data.edges.map(edge => ({
                from: edge.source,
                to: edge.target,
                arrows: {
                    to: {
                        enabled: true,
                        scaleFactor: 0.8
                    }
                },
                color: {
                    color: '#10b981',
                    highlight: '#059669'
                },
                width: 2,
                smooth: {
                    type: 'cubicBezier',
                    roundness: 0.5
                }
            }));

            console.log('✅ Nœuds préparés:', nodes.length);
            console.log('✅ Arêtes préparées:', edges.length);

            // Créer le réseau
            const container = document.getElementById('mynetwork');
            const graphData = {
                nodes: new vis.DataSet(nodes),
                edges: new vis.DataSet(edges)
            };

            const options = {
                layout: {
                    hierarchical: {
                        enabled: true,
                        direction: 'UD',
                        sortMethod: 'directed',
                        nodeSpacing: 150,
                        levelSeparation: 120
                    }
                },
                physics: {
                    enabled: false
                },
                interaction: {
                    hover: true,
                    tooltipDelay: 100,
                    navigationButtons: true,
                    keyboard: true
                }
            };

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

            network.on('stabilizationIterationsDone', function() {
                console.log('✅ Graphe stabilisé');
            });

            console.log('✅ Graphe créé avec succès');

        } catch (error) {
            console.error('❌ Erreur lors de la création du graphe:', error);
            document.getElementById('loading').innerHTML =
                `<div style="color: #e74c3c;">❌ Erreur d'affichage : ${error.message}</div>`;
        }
    }
</script>
</body>
</html>