-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
180 lines (158 loc) · 6.23 KB
/
debug.js
File metadata and controls
180 lines (158 loc) · 6.23 KB
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
/**
* Debug script for vision-language-model-articles dashboard
*
* Add this to the page by pasting in the browser console:
* var script = document.createElement('script'); script.src = 'debug.js'; document.body.appendChild(script);
*/
console.log("✅ Debug script loaded");
// Check if Chart.js is available
if (typeof Chart === 'undefined') {
console.error("❌ Chart.js is not loaded");
} else {
console.log("✅ Chart.js is loaded", Chart.version);
}
// Force initialize tabs
function forceInitTabs() {
console.log("🔄 Force initializing tabs...");
// Get all tab buttons
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
console.log(`Found ${tabButtons.length} tab buttons and ${tabContents.length} tab contents`);
// Force load all tabs
const trendsTab = document.getElementById('trends-tab');
const impactTab = document.getElementById('impact-tab');
if (trendsTab) {
console.log("🔄 Force loading trends tab...");
// Get trend chart elements
const trendChart = document.getElementById('trend-chart');
const timeRange = document.getElementById('time-range');
const trendType = document.getElementById('trend-type');
console.log("Trend elements:", {
trendChart: !!trendChart,
timeRange: !!timeRange,
trendType: !!trendType
});
// Force create a simple chart
if (trendChart) {
console.log("🔄 Creating test chart...");
try {
// Clear any existing chart
if (window.debugChart) {
window.debugChart.destroy();
}
const ctx = trendChart.getContext('2d');
window.debugChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{
label: 'Test Data',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderWidth: 2,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false
}
});
console.log("✅ Test chart created successfully");
} catch (error) {
console.error("❌ Error creating test chart:", error);
}
}
// Try to trigger the real chart loading
if (typeof updateTrendChart === 'function') {
console.log("🔄 Calling updateTrendChart()...");
try {
updateTrendChart();
console.log("✅ updateTrendChart() called successfully");
} catch (error) {
console.error("❌ Error calling updateTrendChart():", error);
}
} else {
console.error("❌ updateTrendChart function not found");
}
}
if (impactTab) {
console.log("🔄 Force loading impact tab...");
// Try to trigger the real data loading
if (typeof loadPaperAttentionData === 'function') {
console.log("🔄 Calling loadPaperAttentionData()...");
try {
loadPaperAttentionData();
console.log("✅ loadPaperAttentionData() called successfully");
} catch (error) {
console.error("❌ Error calling loadPaperAttentionData():", error);
}
} else {
console.error("❌ loadPaperAttentionData function not found");
}
}
}
// Check fetch capability with keyword stats
function testFetch() {
console.log("🔄 Testing fetch capabilities...");
fetch('articles/keyword_stats.json')
.then(response => {
console.log("📊 keyword_stats.json status:", response.status);
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log("✅ Successfully fetched keyword_stats.json");
console.log("📊 Keywords count:", Object.keys(data.keywords || {}).length);
console.log("📊 Updated at:", data.updated_at);
})
.catch(error => {
console.error("❌ Error fetching keyword_stats.json:", error);
});
fetch('paper_attention.json')
.then(response => {
console.log("📊 paper_attention.json status:", response.status);
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log("✅ Successfully fetched paper_attention.json");
console.log("📊 Papers count:", data.length);
})
.catch(error => {
console.error("❌ Error fetching paper_attention.json:", error);
});
}
// Add a debug button to the page
function addDebugButton() {
const button = document.createElement('button');
button.textContent = '🛠️ Debug Dashboard';
button.style.position = 'fixed';
button.style.bottom = '20px';
button.style.right = '20px';
button.style.zIndex = '9999';
button.style.padding = '10px';
button.style.backgroundColor = '#ff0066';
button.style.color = 'white';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
button.addEventListener('click', () => {
console.log("🔄 Running full diagnostics...");
forceInitTabs();
testFetch();
});
document.body.appendChild(button);
console.log("✅ Debug button added to the page");
}
// Start debugging
setTimeout(() => {
console.log("🔄 Starting debug process...");
addDebugButton();
}, 2000);
console.log("✅ Debug script initialized");