Azdeen commited on
Commit
d34c575
·
verified ·
1 Parent(s): 6e0faba

خريطة تفاعلية لانتشار التغطية.

Browse files
Files changed (1) hide show
  1. index.html +100 -28
index.html CHANGED
@@ -158,17 +158,24 @@
158
  </div>
159
  <div class="mt-6 relative">
160
  <div class="h-[400px] w-full rounded-lg overflow-hidden">
161
- <div id="worldMap" class="h-full w-full"></div>
162
- </div>
163
- <div class="absolute top-4 left-4 z-10 bg-white/80 backdrop-blur-sm p-2 rounded-lg shadow-sm">
164
- <div class="flex items-center space-x-2 space-x-reverse">
165
- <span class="w-3 h-3 rounded-full bg-green-500"></span>
166
- <span class="text-sm">إيجابي</span>
167
- <span class="w-3 h-3 rounded-full bg-red-500 ml-2"></span>
168
- <span class="text-sm">سلبي</span>
 
 
 
 
 
 
169
  </div>
170
  </div>
171
- </div>
 
172
  </div>
173
  </div>
174
  </div>
@@ -551,19 +558,25 @@
551
  }
552
  }
553
  });
554
- // Initialize world map
555
  const mapData = {
556
- "SA": { fillKey: "positive", newsCount: 124 },
557
- "US": { fillKey: "neutral", newsCount: 87 },
558
- "GB": { fillKey: "positive", newsCount: 65 },
559
- "FR": { fillKey: "neutral", newsCount: 42 },
560
- "DE": { fillKey: "positive", newsCount: 38 },
561
- "CN": { fillKey: "negative", newsCount: 56 },
562
- "IN": { fillKey: "positive", newsCount: 29 },
563
- "JP": { fillKey: "neutral", newsCount: 21 }
 
 
 
 
 
 
 
564
  };
565
-
566
- const map = new Datamap({
567
  element: document.getElementById('worldMap'),
568
  responsive: true,
569
  geographyConfig: {
@@ -581,13 +594,21 @@
581
  neutral: 'محايد',
582
  negative: 'سلبي'
583
  }[data.fillKey];
584
-
585
- return `<div class="p-2 text-sm">
586
- <div class="font-bold">${geo.properties.name}</div>
587
- <div>عدد الأخبار: ${data.newsCount}</div>
588
- <div>الانطباع: ${sentiment}</div>
 
 
 
 
 
 
 
 
589
  </div>`;
590
- }
591
  },
592
  fills: {
593
  positive: '#408E91',
@@ -595,7 +616,32 @@
595
  negative: '#E49393',
596
  defaultFill: '#F8F5F1'
597
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  data: mapData,
 
 
 
 
 
599
  setProjection: function(element) {
600
  const projection = d3.geo.equirectangular()
601
  .center([50, 20])
@@ -604,14 +650,40 @@
604
  .translate([element.offsetWidth / 2, element.offsetHeight / 2]);
605
  const path = d3.geo.path().projection(projection);
606
  return { path: path, projection: projection };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
  }
608
  });
609
 
610
  window.addEventListener('resize', function() {
611
  map.resize();
 
612
  });
613
-
614
- // Feather Icons
615
  feather.replace();
616
  });
617
  </script>
 
158
  </div>
159
  <div class="mt-6 relative">
160
  <div class="h-[400px] w-full rounded-lg overflow-hidden">
161
+ <div id="worldMap" class="h-full w-full">
162
+ <div class="absolute top-0 right-0 z-10 p-4 bg-white/80 rounded-bl-lg shadow-sm flex items-center space-x-2 space-x-reverse">
163
+ <div class="flex items-center">
164
+ <span class="w-3 h-3 rounded-full bg-green-500"></span>
165
+ <span class="text-xs mr-1">إيجابي</span>
166
+ </div>
167
+ <div class="flex items-center">
168
+ <span class="w-3 h-3 rounded-full bg-red-500"></span>
169
+ <span class="text-xs mr-1">سلبي</span>
170
+ </div>
171
+ <div class="flex items-center">
172
+ <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
173
+ <span class="text-xs mr-1">محايد</span>
174
+ </div>
175
  </div>
176
  </div>
177
+ </div>
178
+ </div>
179
  </div>
180
  </div>
181
  </div>
 
558
  }
559
  }
560
  });
561
+ // Initialize world map with more countries and dynamic data
562
  const mapData = {
563
+ "SA": { fillKey: "positive", newsCount: 124, sentimentScore: 0.87 },
564
+ "US": { fillKey: "neutral", newsCount: 87, sentimentScore: 0.52 },
565
+ "GB": { fillKey: "positive", newsCount: 65, sentimentScore: 0.72 },
566
+ "FR": { fillKey: "neutral", newsCount: 42, sentimentScore: 0.48 },
567
+ "DE": { fillKey: "positive", newsCount: 38, sentimentScore: 0.68 },
568
+ "CN": { fillKey: "negative", newsCount: 56, sentimentScore: 0.34 },
569
+ "IN": { fillKey: "positive", newsCount: 29, sentimentScore: 0.65 },
570
+ "JP": { fillKey: "neutral", newsCount: 21, sentimentScore: 0.45 },
571
+ "RU": { fillKey: "negative", newsCount: 43, sentimentScore: 0.29 },
572
+ "BR": { fillKey: "positive", newsCount: 27, sentimentScore: 0.63 },
573
+ "CA": { fillKey: "neutral", newsCount: 35, sentimentScore: 0.55 },
574
+ "AU": { fillKey: "positive", newsCount: 31, sentimentScore: 0.71 },
575
+ "AE": { fillKey: "positive", newsCount: 48, sentimentScore: 0.78 },
576
+ "EG": { fillKey: "neutral", newsCount: 39, sentimentScore: 0.49 },
577
+ "TR": { fillKey: "negative", newsCount: 33, sentimentScore: 0.41 }
578
  };
579
+ const map = new Datamap({
 
580
  element: document.getElementById('worldMap'),
581
  responsive: true,
582
  geographyConfig: {
 
594
  neutral: 'محايد',
595
  negative: 'سلبي'
596
  }[data.fillKey];
597
+ return `<div class="p-3 text-sm bg-white rounded-lg shadow-lg">
598
+ <div class="font-bold text-primary mb-2">${geo.properties.name}</div>
599
+ <div class="mb-1">عدد الأخبار: <span class="font-medium">${data.newsCount}</span></div>
600
+ <div class="mb-1">الانطباع:
601
+ <span class="font-medium ${data.fillKey === 'positive' ? 'text-green-600' : data.fillKey === 'negative' ? 'text-red-600' : 'text-yellow-600'}">
602
+ ${sentiment}
603
+ </span>
604
+ </div>
605
+ <div class="mb-1">نسبة المشاعر: <span class="font-medium">${Math.round(data.sentimentScore * 100)}%</span></div>
606
+ <div class="w-full bg-gray-200 rounded-full h-2 mt-2">
607
+ <div class="h-2 rounded-full ${data.fillKey === 'positive' ? 'bg-green-500' : data.fillKey === 'negative' ? 'bg-red-500' : 'bg-yellow-500'}"
608
+ style="width: ${Math.round(data.sentimentScore * 100)}%"></div>
609
+ </div>
610
  </div>`;
611
+ }
612
  },
613
  fills: {
614
  positive: '#408E91',
 
616
  negative: '#E49393',
617
  defaultFill: '#F8F5F1'
618
  },
619
+ bubblesConfig: {
620
+ popupOnHover: true,
621
+ highlightOnHover: true,
622
+ highlightFillColor: '#245953',
623
+ highlightBorderColor: '#fff',
624
+ highlightBorderWidth: 2,
625
+ fillOpacity: 0.8,
626
+ borderWidth: 1,
627
+ borderColor: '#fff',
628
+ r: function(data) {
629
+ return Math.min(Math.max(data.newsCount / 2, 5), 20);
630
+ },
631
+ fillKey: 'fillKey',
632
+ popupTemplate: function(geo, data) {
633
+ return `<div class="p-3 text-sm bg-white rounded-lg shadow-lg">
634
+ <div class="font-bold">${geo.properties.name}</div>
635
+ <div>عدد الأخبار: ${data.newsCount}</div>
636
+ </div>`;
637
+ }
638
+ },
639
  data: mapData,
640
+ done: function(datamap) {
641
+ datamap.svg.selectAll('.datamaps-bubble').attr('r', function(d) {
642
+ return Math.min(Math.max(d.newsCount / 2, 5), 20);
643
+ });
644
+ },
645
  setProjection: function(element) {
646
  const projection = d3.geo.equirectangular()
647
  .center([50, 20])
 
650
  .translate([element.offsetWidth / 2, element.offsetHeight / 2]);
651
  const path = d3.geo.path().projection(projection);
652
  return { path: path, projection: projection };
653
+ },
654
+ geographyConfig: {
655
+ borderColor: '#408E91',
656
+ borderWidth: 0.5,
657
+ highlightBorderWidth: 1.5,
658
+ highlightBorderColor: '#245953',
659
+ highlightFillColor: '#E49393',
660
+ popupOnHover: true
661
+ }
662
+ });
663
+ // Add bubbles to the map
664
+ const bubbles = Object.keys(mapData).map(countryCode => {
665
+ return {
666
+ ...mapData[countryCode],
667
+ name: countryCode,
668
+ latitude: Datamap.latLngLookup(countryCode)[0],
669
+ longitude: Datamap.latLngLookup(countryCode)[1]
670
+ };
671
+ });
672
+
673
+ map.bubbles(bubbles, {
674
+ popupTemplate: function(geo, data) {
675
+ return `<div class="p-2 text-sm">
676
+ <div class="font-bold">${geo.properties.name}</div>
677
+ <div>عدد الأخبار: ${data.newsCount}</div>
678
+ </div>`;
679
  }
680
  });
681
 
682
  window.addEventListener('resize', function() {
683
  map.resize();
684
+ map.bubbles(bubbles);
685
  });
686
+ // Feather Icons
 
687
  feather.replace();
688
  });
689
  </script>