-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
681 lines (622 loc) · 20 KB
/
scripts.js
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
function showTab(tabId) {
const tabs = document.querySelectorAll('.tab-content');
const buttons = document.querySelectorAll('.tab-button');
tabs.forEach(tab => tab.classList.remove('active'));
buttons.forEach(button => button.classList.remove('active'));
document.getElementById(tabId).classList.add('active');
document.querySelector(`[onclick="showTab('${tabId}')"]`).classList.add('active');
}
document.querySelectorAll('.toggle-btn').forEach(function (btn) {
btn.addEventListener('click', function () {
// Find the nearest details element within the same question-block
const details = this.closest('.question-block').querySelector('.details');
if (details.classList.contains('hidden')) {
details.classList.remove('hidden');
this.textContent = 'Hide Options';
// Add a small delay to ensure the content is rendered before scrolling
setTimeout(() => {
details.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'start'
});
}, 100);
} else {
details.classList.add('hidden');
this.textContent = 'Show Options';
}
});
});
// Root Element
var root = am5.Root.new("chartdiv");
// Theme Setup
root.setThemes([am5themes_Animated.new(root)])
// Create Chart Container
var chart = root.container.children.push(
am5percent.PieChart.new(root, {
layout: root.verticalLayout,
radius: am5.percent(100),
}),
)
// Inner Layer - Categories
var series0 = chart.series.push(
am5percent.PieSeries.new(root, {
valueField: "population",
categoryField: "category",
alignLabels: false,
radius: am5.percent(35),
innerRadius: am5.percent(10),
}),
)
// Middle Layer - Subcategories
var series1 = chart.series.push(
am5percent.PieSeries.new(root, {
valueField: "population",
categoryField: "subcategory",
alignLabels: false,
radius: am5.percent(60),
innerRadius: am5.percent(35),
}),
)
// Outer Layer - Topics
var series2 = chart.series.push(
am5percent.PieSeries.new(root, {
valueField: "population",
categoryField: "topic",
alignLabels: false,
radius: am5.percent(85),
innerRadius: am5.percent(60),
}),
)
// After series2 definition but before the data section
chart.seriesContainer.children.unshift(am5.Circle.new(root, {
radius: 100,
centerX: am5.p50,
centerY: am5.p50,
fill: am5.color(0x055FFF),
fillOpacity: 0.1
}));
/////////////////////////////
// Add the logo using SVG
chart.seriesContainer.children.unshift(am5.Picture.new(root, {
centerX: am5.p50,
centerY: am5.p50,
width: 75,
height: 75,
src: "data:image/svg+xml;charset=UTF-8," + encodeURIComponent(`
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="48" fill="#6a1b9a" opacity="0.9"/>
<text x="50" y="40"
font-size="20"
text-anchor="middle"
fill="white"
font-family="Arial, sans-serif"
font-weight="bold">Mobile</text>
<text x="50" y="65"
font-size="18"
text-anchor="middle"
fill="white"
font-family="Arial, sans-serif"
font-weight="bold">MMLU</text>
</svg>
`)
// src:"images/icons/logo_m_mmlu_v3.png"
}));
/////////////////////////////
// console.log("Starting icon placement...");
var iconData = [
{ angle: 45, icon: "images/icons/education.png" }, // Top right
{ angle: 90, icon: "images/icons/daily_routine.png" }, // Right
{ angle: 135, icon: "images/icons/web_service.png" }, // Bottom right
{ angle: 165, icon: "images/icons/healthcare.png" }, // Bottom
{ angle: 225, icon: "images/icons/self_growth.png" }, // Bottom left
{ angle: 270, icon: "images/icons/family.png" }, // Left
{ angle: 315, icon: "images/icons/palette.png" }, // Top left
{ angle: 350, icon: "images/icons/outdoors.png" } // Top
];
// Get dimensions from chart
var chartWidth = chart.width();
var chartHeight = chart.height();
var centerX = chartWidth / 2;
var centerY = chartHeight / 2;
var chartRadius = Math.min(chartWidth, chartHeight) / 2 * 0.78;
// Create a container at root level
var outerContainer = root.container.children.push(am5.Container.new(root, {
width: am5.p100,
height: am5.p100,
layout: root.verticalLayout,
paddingTop: 0,
paddingBottom: 0
}));
iconData.forEach(function(item, index) {
// Convert angle to radians (subtract 90 to start from top)
var angleRad = ((item.angle - 90) * Math.PI / 180);
// Calculate position (20% larger than chart radius)
var distance = chartRadius * 1.17;
var x = centerX + (distance * Math.cos(angleRad));
var y = centerY + (distance * Math.sin(angleRad));
if (item.angle == 90 || item.angle == 270 ) {
distance = chartRadius*1.15;
x = centerX + (distance * Math.cos(angleRad));
y = centerY + (distance * Math.sin(angleRad));
}
if (item.angle == 315 || item.angle == 45) {
distance = chartRadius*1.15;
x = centerX + (distance * Math.cos(angleRad));
y = centerY + (distance * Math.sin(angleRad));
}
if (item.angle == 350) {
distance = chartRadius*1.13;
x = centerX + (distance * Math.cos(angleRad));
y = centerY + (distance * Math.sin(angleRad));
}
// Create icon
var icon = am5.Picture.new(root, {
x: x,
y: y,
width: 40,
height: 40,
src: item.icon,
layer: 5,
centerX: am5.p50,
centerY: am5.p50,
position: "absolute"
});
// Add to outer container
outerContainer.children.push(icon);
// Add debug circle if needed during development
/*var debugCircle = am5.Circle.new(root, {
x: x,
y: y,
radius: 5,
fill: am5.color(0xFF0000),
layer: 4,
position: "absolute"
});
outerContainer.children.push(debugCircle);*/
});
/////////////////////////////
// Data
var data = {
"Academic & Learning": [
{
subcategory: "Basic Mathematics",
topics: [
{ topic: "elementary_mathematics", population: 254 },
{ topic: "high_school_mathematics", population: 200 },
{ topic: "basic_statistics", population: 219 },
],
},
{
subcategory: "Basic Sciences",
topics: [
{ topic: "conceptual_physics", population: 194 },
{ topic: "science_fundamentals", population: 191 },
],
},
{
subcategory: "Critical Thinking",
topics: [
{ topic: "formal_logic", population: 210 },
{ topic: "logical_fallacies", population: 293 },
],
},
{
subcategory: "Education",
topics: [
{ topic: "education_techniques", population: 146 },
{ topic: "reading_and_literature", population: 248 },
{ topic: "writing_skills", population: 203 },
{ topic: "linguistics", population: 223 },
],
},
{
subcategory: "Social Sciences",
topics: [
{ topic: "social_sciences", population: 207 },
{ topic: "political_systems", population: 193 },
{ topic: "world_history", population: 206 },
{ topic: "geography", population: 211 },
],
},
],
"Business & Career": [
{
subcategory: "Business Studies",
topics: [
{ topic: "project_management", population: 176 },
{ topic: "human_resources", population: 144 },
{ topic: "business_management", population: 167 },
{ topic: "marketing__and_sales_strarigies", population: 162 },
],
},
{
subcategory: "Personal Business",
topics: [
{ topic: "personal_finance", population: 223 },
{ topic: "e_commerce", population: 186 },
{ topic: "shopping", population: 241 },
{ topic: "accounting", population: 205 },
],
},
{
subcategory: "Communication",
topics: [
{ topic: "communication_skills", population: 134 },
{ topic: "social_etiquette", population: 200 },
{ topic: "public_speaking", population: 158 },
],
},
],
"Technology & Digital": [
{
subcategory: "Digital Literacy",
topics: [
{ topic: "digital_literacy", population: 198 },
{ topic: "technical_help", population: 254 },
{ topic: "mobile_customization", population: 230 },
],
},
{
subcategory: "Privacy and Security",
topics: [
{ topic: "cybersecurity", population: 208 },
{ topic: "online_privacy", population: 219 },
],
},
{
subcategory: "Social Media",
topics: [
{ topic: "social_media", population: 217 },
{ topic: "digital_detox", population: 196 },
],
},
],
"Health & Safety": [
{
subcategory: "Health and Wellness",
topics: [
{ topic: "mental_health", population: 130 },
{ topic: "physical_fitness", population: 190 },
{ topic: "medical_and_health_knowledge", population: 183 },
{ topic: "ergonomics", population: 204 },
],
},
{
subcategory: "Everyday Safety",
topics: [
{ topic: "first_aid", population: 221 },
{ topic: "outdoor_survival_skills", population: 277 },
{ topic: "automotive_care", population: 275 },
],
},
],
"Lifestyle & Personal": [
{
subcategory: "Daily Life Skills",
topics: [
{ topic: "basic_life_skills", population: 209 },
{ topic: "time_management", population: 211 },
{ topic: "conflict_resolution", population: 152 },
{ topic: "event_planning", population: 201 },
],
},
{
subcategory: "Personal Growth",
topics: [
{ topic: "creativity", population: 210 },
{ topic: "emotional_intelligence", population: 133 },
{ topic: "personal_branding", population: 186 },
{ topic: "career_development", population: 166 },
],
},
{
subcategory: "Lifestyle",
topics: [
{ topic: "fashion_and_style", population: 200 },
{ topic: "travel_planning", population: 214 },
{ topic: "sports", population: 188 },
{ topic: "gardening_and_horticulture", population: 212 },
],
},
{
subcategory: "Entertainment",
topics: [
{ topic: "entertainment", population: 207 },
{ topic: "movie_and_tv_show", population: 230 },
{ topic: "podcasting", population: 211 },
{ topic: "hobbies", population: 208 },
{ topic: "photography_basics", population: 214 },
],
},
],
"Home & Family": [
{
subcategory: "Home and Living",
topics: [
{ topic: "home_safety", population: 189 },
{ topic: "pet_care", population: 208 },
{ topic: "waste_management", population: 207 },
{ topic: "home_maintenance", population: 261 },
],
},
{
subcategory: "Family",
topics: [
{ topic: "parenting", population: 144 },
{ topic: "relationships", population: 173 },
{ topic: "teens_and_youth", population: 161 },
],
},
{
subcategory: "Food and Cooking",
topics: [
{ topic: "cooking_and_recipes", population: 274 },
{ topic: "food_safety", population: 219 },
{ topic: "nutrition_and_diet", population: 151 },
],
},
],
"Culture & Society": [
{
subcategory: "Arts and Design",
topics: [
{ topic: "art_techniques_and_architecture", population: 175 },
{ topic: "interior_design", population: 200 },
],
},
{
subcategory: "Culture and Religion",
topics: [
{ topic: "cultural_awareness", population: 243 },
{ topic: "religious_studies", population: 215 },
{ topic: "holidays_and_traditions", population: 236 },
],
},
{
subcategory: "Legal",
topics: [
{ topic: "legal_rights", population: 219 },
{ topic: "law", population: 206 },
],
},
{
subcategory: "Ethics and Morality",
topics: [
{ topic: "ethical_living", population: 171 },
{ topic: "ethics", population: 172 },
],
},
],
"Environment": [
{
subcategory: "Environment",
topics: [{ topic: "sustainable_living", population: 178 }],
},
{
subcategory: "Weather",
topics: [{ topic: "weather_forecasting", population: 205 }],
},
],
"Miscellaneous": [
{
subcategory: "Miscellaneous",
topics: [
{ topic: "global_facts", population: 228 },
{ topic: "news_and_information", population: 203 },
],
},
],
}
// Data Processing
var innerData = []
var middleData = []
var outerData = []
am5.object.each(data, function (category, subcategories) {
var totalCategoryPopulation = 0
am5.array.each(subcategories, function (subcategoryEntry) {
var totalSubcategoryPopulation = 0
am5.array.each(subcategoryEntry.topics, function (topicEntry) {
// Process outer layer - topics
outerData.push({
category: category,
subcategory: subcategoryEntry.subcategory,
topic: topicEntry.topic,
population: topicEntry.population,
})
totalSubcategoryPopulation += topicEntry.population
})
// Process middle layer - subcategories
middleData.push({
category: category,
subcategory: subcategoryEntry.subcategory,
population: totalSubcategoryPopulation,
})
totalCategoryPopulation += totalSubcategoryPopulation
})
// Process inner layer - categories
innerData.push({
category: category,
population: totalCategoryPopulation,
})
})
// Capitalize each word in topic
outerData = outerData.map(item => ({
...item,
topic: item.topic.split('_')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
}));
// Set Data
series0.data.setAll(innerData) // Inner Layer
series1.data.setAll(middleData) // Middle Layer
series2.data.setAll(outerData) // Outer Layer
chart.children.unshift(
am5.Label.new(root, {
fontSize: 30,
fontWeight: "bold",
centerX: am5.percent(0),
centerY: am5.percent(50),
textAlign: "center",
}),
)
series0.ticks.template.setAll({ forceHidden: true })
series0.labels.template.setAll({
radius: 5,
text: "{category}",
textType: "radial",
fontSize: 9,
wrap: true,
textAlign: "center",
maxWidth: 85,
hideOversized: true,
oversizedBehavior: "truncate",
centerX: am5.percent(110)
})
series0.slices.template.setAll({
strokeWidth: 0,
stroke: am5.color(0xffffff),
tooltipText:
"{category}: {valuePercentTotal.formatNumber('0.00')}% ({value} questions)",
})
series1.ticks.template.setAll({ forceHidden: true })
series1.labels.template.setAll({
radius: 5,
text: "{subcategory}",
textType: "radial",
fontSize: 9,
wrap: true,
textAlign: "center",
maxWidth: 95,
hideOversized: true,
oversizedBehavior: "truncate",
centerX: am5.percent(105)
})
series1.slices.template.setAll({
strokeWidth: 0,
stroke: am5.color(0xffffff),
fillOpacity: 0.85,
tooltipText:
"{subcategory}: {valuePercentTotal.formatNumber('0.00')}% ({value} questions)",
})
series2.ticks.template.setAll({ forceHidden: true })
series2.labels.template.setAll({
radius: 5,
text: "{topic}",
textType: "radial",
textAlign: "center",
fontSize: 9,
wrap: true,
maxWidth: 95,
rotation: 60,
hideOversized: true,
oversizedBehavior: "truncate",
centerX: am5.percent(100),
})
series2.slices.template.setAll({
strokeWidth: 0,
stroke: am5.color(0xffffff),
fillOpacity: 0.6,
tooltipText:
"{topic}: {valuePercentTotal.formatNumber('0.00')}% ({value} questions)",
})
chart.set("background", null)
root.interfaceColors.set("grid", null)
// Define distinct colors for inner layer slices (categories)
var innerLayerColors = [
am5.color(0x1f77b4), // Blue
am5.color(0xff7f0e), // Orange
am5.color(0x2ca02c), // Green
am5.color(0xd62728), // Red
am5.color(0x9467bd), // Purple
am5.color(0x8c564b), // Brown
am5.color(0xe377c2), // Pink
am5.color(0x7f7f7f), // Grey
am5.color(0xbcbd22), // Olive
am5.color(0x17becf), // Cyan
]
// Assign colors to inner layer slices
series0.events.on("datavalidated", function () {
series0.slices.each(function (slice, index) {
slice.set("fill", innerLayerColors[index % innerLayerColors.length])
})
})
// After data is validated, map colors and make strokes identical to slice colors
series0.events.on("datavalidated", function () {
var categoryColorMap = {}
series0.slices.each(function (slice) {
var category = slice.dataItem.dataContext.category
var fill = slice.get("fill")
categoryColorMap[category] = fill
})
// Assign subcategory colors from category
var subcategoryColorMap = {}
series1.slices.each(function (slice) {
var subcategory = slice.dataItem.dataContext.subcategory
var parentCategory = slice.dataItem.dataContext.category
var parentColor = categoryColorMap[parentCategory]
slice.set("fill", parentColor)
subcategoryColorMap[subcategory] = parentColor
})
// Assign topic colors from subcategory
series2.slices.each(function (slice) {
var subcategory = slice.dataItem.dataContext.subcategory
var parentColor = subcategoryColorMap[subcategory]
slice.set("fill", parentColor)
})
// Make the strokes the same color as the fill
series0.slices.template.adapters.add("stroke", function (stroke, target) {
return target.get("fill")
})
series1.slices.template.adapters.add("stroke", function (stroke, target) {
return target.get("fill")
})
series2.slices.template.adapters.add("stroke", function (stroke, target) {
return target.get("fill")
})
})
// Animations
series0.appear(1000, 100);
series1.appear(1000, 100);
series2.appear(1000, 100);
// Add this to your existing scripts.js file
document.addEventListener('DOMContentLoaded', function() {
// Create modal elements
const modalOverlay = document.createElement('div');
modalOverlay.className = 'modal-overlay';
const modalContent = document.createElement('div');
modalContent.className = 'modal-content';
const modalImage = document.createElement('img');
const closeButton = document.createElement('button');
closeButton.className = 'modal-close';
closeButton.innerHTML = '×';
modalContent.appendChild(modalImage);
modalContent.appendChild(closeButton);
modalOverlay.appendChild(modalContent);
document.body.appendChild(modalOverlay);
// Add click handlers to all expandable images
const images = document.querySelectorAll('.expandable-image');
images.forEach(img => {
img.addEventListener('click', function() {
modalImage.src = this.src;
modalOverlay.classList.add('active');
});
});
// Close modal when clicking the close button or outside the image
closeButton.addEventListener('click', function(e) {
e.stopPropagation();
modalOverlay.classList.remove('active');
});
modalOverlay.addEventListener('click', function() {
modalOverlay.classList.remove('active');
});
modalContent.addEventListener('click', function(e) {
e.stopPropagation();
});
// Close modal with escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && modalOverlay.classList.contains('active')) {
modalOverlay.classList.remove('active');
}
});
});