Yuxuan-Zhang-Dexter commited on
Commit
09f88c7
·
1 Parent(s): 8dcd7a7

update leaderboard style

Browse files
Files changed (1) hide show
  1. app.py +193 -155
app.py CHANGED
@@ -126,8 +126,9 @@ def prepare_dataframe_for_display(df, for_game=None):
126
  game_name = col.replace(' Score', '')
127
  new_col = f"{game_name}\nScore"
128
  new_columns[col] = new_col
129
- elif col == 'Organization':
130
- new_columns[col] = 'Organi-\nzation'
 
131
 
132
  # Rename columns with new line breaks
133
  if new_columns:
@@ -151,7 +152,7 @@ def update_df_with_height(df):
151
  show_fullscreen_button=True,
152
  line_breaks=True,
153
  show_search="search",
154
- max_height=700,
155
  column_widths=col_widths)
156
 
157
  def update_leaderboard(mario_overall, mario_details,
@@ -497,148 +498,101 @@ def create_timeline_slider():
497
 
498
  def build_app():
499
  with gr.Blocks(css="""
500
- /* Fix for disappearing scrollbar */
501
  html, body {
502
- overflow-y: scroll !important;
 
 
503
  height: 100% !important;
504
- min-height: 100vh !important;
 
505
  }
506
 
507
- /* Prevent content from shrinking to center */
508
- .gradio-container {
509
  width: 100% !important;
510
  max-width: 1200px !important;
511
  margin-left: auto !important;
512
  margin-right: auto !important;
513
- min-height: 100vh !important;
 
 
 
514
  }
515
 
516
- /* Force table to maintain width */
517
- .table-container {
518
- width: 100% !important;
519
- min-width: 100% !important;
520
  }
521
 
522
- .table-container table {
523
- width: 100% !important;
 
524
  }
525
 
526
- .visualization-container .js-plotly-plot {
527
- margin-left: auto !important;
528
- margin-right: auto !important;
529
  display: block !important;
 
530
  }
531
-
532
- /* Optional: limit width for better layout on large screens */
533
- .visualization-container .js-plotly-plot {
534
- max-width: 1000px;
535
  }
536
-
537
- .section-title {
538
- font-size: 1.5em;
539
- font-weight: bold;
540
- color: #2c3e50;
541
- margin-bottom: 15px;
542
- padding-bottom: 10px;
543
- border-bottom: 2px solid #e9ecef;
544
- text-align: center;
545
  }
546
- .container {
547
- max-width: 1400px;
548
- margin: 0 auto;
549
- padding: 0 20px;
550
  }
551
 
552
- /* Enhanced table styling - SIMPLIFIED */
553
  .table-container {
554
- height: auto !important;
555
- min-height: auto !important;
556
- max-height: none !important;
557
- overflow: visible !important;
558
  border-radius: 8px;
559
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
560
  }
561
 
562
- /* Target the specific table elements */
563
  .gradio-dataframe [data-testid="table"],
564
- [data-testid="dataframe"] [data-testid="table"] {
565
- display: block !important;
566
- height: auto !important;
567
- max-height: none !important;
568
- }
569
-
570
- /* Target the tbody that contains the rows */
571
  .gradio-dataframe tbody,
572
- [data-testid="dataframe"] tbody {
573
- display: table-row-group !important;
 
 
574
  max-height: none !important;
575
  }
576
 
577
- /* Responsive height adjustments for different screen sizes */
578
- @media screen and (min-height: 600px) {
579
- .gradio-dataframe [data-testid="table"],
580
- [data-testid="dataframe"] [data-testid="table"] {
581
- min-height: 400px !important;
582
- }
583
- }
584
-
585
- @media screen and (min-height: 800px) {
586
- .gradio-dataframe [data-testid="table"],
587
- [data-testid="dataframe"] [data-testid="table"] {
588
- min-height: 600px !important;
589
- }
590
- }
591
-
592
- @media screen and (min-height: 1000px) {
593
- .gradio-dataframe [data-testid="table"],
594
- [data-testid="dataframe"] [data-testid="table"] {
595
- min-height: 800px !important;
596
- }
597
- }
598
-
599
- @media screen and (min-height: 1200px) {
600
- .gradio-dataframe [data-testid="table"],
601
- [data-testid="dataframe"] [data-testid="table"] {
602
- min-height: 950px !important;
603
- }
604
- }
605
-
606
- @media screen and (min-height: 1400px) {
607
- .gradio-dataframe [data-testid="table"],
608
- [data-testid="dataframe"] [data-testid="table"] {
609
- min-height: 1100px !important;
610
- }
611
- }
612
-
613
- /* Remove unnecessary container styles */
614
- .table-container > div,
615
- .table-container > div > div,
616
- .gradio-dataframe > div,
617
- [data-testid="dataframe"] > div {
618
  overflow: visible !important;
619
- height: auto !important;
620
  max-height: none !important;
 
621
  }
622
 
623
- /* Target Gradio's pagination system and disable it */
624
- .table-container [data-testid="pagination"],
625
- .gradio-container [data-testid="pagination"] {
626
- display: none !important;
 
 
627
  }
628
 
629
- /* Large screen adjustments */
630
- @media screen and (min-height: 1200px) {
631
- .table-container {
632
- height: auto !important;
633
- max-height: none !important;
634
- overflow: visible !important;
635
- }
636
-
637
- .gradio-container {
638
- height: auto !important;
639
- max-height: none !important;
640
- overflow: visible !important;
641
- }
642
  }
643
 
644
  /* Fix table styling */
@@ -649,26 +603,6 @@ def build_app():
649
  table-layout: fixed !important;
650
  }
651
 
652
- /* Targeting row number column directly */
653
- table th[role="cell"][aria-colindex="1"],
654
- table td[role="cell"][aria-colindex="1"],
655
- table col[data-col-index="0"],
656
- .table-container tr > *:first-child[aria-colindex="1"],
657
- th[scope="row"],
658
- th[aria-sort],
659
- td[data-index],
660
- th[data-row-header] {
661
- width: 30px !important;
662
- min-width: 30px !important;
663
- max-width: 30px !important;
664
- padding: 2px 4px !important;
665
- font-size: 0.85em !important;
666
- text-align: center !important;
667
- overflow: hidden !important;
668
- text-overflow: ellipsis !important;
669
- white-space: nowrap !important;
670
- }
671
-
672
  /* Column width customization - adjust for row numbers being first column */
673
  .table-container th:nth-child(2),
674
  .table-container td:nth-child(2) {
@@ -727,15 +661,7 @@ def build_app():
727
  background-color: #f8fafc;
728
  }
729
 
730
- /* Row containing the table */
731
- .gradio-container .gr-row {
732
- min-height: auto !important;
733
- height: auto !important;
734
- overflow: visible !important;
735
- margin-bottom: 20px;
736
- }
737
-
738
- /* Additional specific selectors for row numbers */
739
  .gradio-dataframe thead tr th[id="0"],
740
  .gradio-dataframe tbody tr td:nth-child(1),
741
  [data-testid="dataframe"] thead tr th[id="0"],
@@ -750,27 +676,139 @@ def build_app():
750
  font-size: 0.85em !important;
751
  }
752
 
753
- /* Fix overflow issues */
754
- .table-container {
755
- overflow: auto !important;
756
- max-height: 700px !important;
 
757
  }
 
 
758
 
759
- body, html {
760
- overflow-x: hidden !important;
761
- overflow-y: auto !important;
762
- height: 100% !important;
763
- width: 100% !important;
764
- margin: 0 !important;
765
- padding: 0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766
  }
767
 
768
- .gradio-container {
769
- overflow: visible !important;
770
- max-height: none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
771
  }
772
- """) as demo:
773
- gr.Markdown("# 🎮 Game Arena: Gaming Agent 🎲")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
 
775
  with gr.Tabs():
776
  with gr.Tab("🏆 Leaderboard"):
@@ -880,7 +918,7 @@ def build_app():
880
  show_row_numbers=True,
881
  show_fullscreen_button=True,
882
  line_breaks=True,
883
- max_height=700,
884
  show_search="search",
885
  column_widths=col_widths
886
  )
 
126
  game_name = col.replace(' Score', '')
127
  new_col = f"{game_name}\nScore"
128
  new_columns[col] = new_col
129
+ # Keep Organization without line breaks
130
+ # elif col == 'Organization':
131
+ # new_columns[col] = 'Organi-\nzation'
132
 
133
  # Rename columns with new line breaks
134
  if new_columns:
 
152
  show_fullscreen_button=True,
153
  line_breaks=True,
154
  show_search="search",
155
+ max_height=None, # Remove height limitation
156
  column_widths=col_widths)
157
 
158
  def update_leaderboard(mario_overall, mario_details,
 
498
 
499
  def build_app():
500
  with gr.Blocks(css="""
501
+ /* Fix for scrolling issues */
502
  html, body {
503
+ overflow-y: hidden !important;
504
+ overflow-x: hidden !important;
505
+ width: 100% !important;
506
  height: 100% !important;
507
+ max-height: none !important;
508
+ position: relative !important;
509
  }
510
 
511
+ /* Force scrolling to work on the main container */
512
+ .gradio-container, #root, #app {
513
  width: 100% !important;
514
  max-width: 1200px !important;
515
  margin-left: auto !important;
516
  margin-right: auto !important;
517
+ min-height: auto !important;
518
+ height: auto !important;
519
+ overflow: visible !important;
520
+ position: relative !important;
521
  }
522
 
523
+ /* Remove ALL inner scrollbars - very important! */
524
+ .gradio-container * {
525
+ scrollbar-width: none !important; /* Firefox */
 
526
  }
527
 
528
+ /* Hide scrollbars for Chrome, Safari and Opera */
529
+ .gradio-container *::-webkit-scrollbar {
530
+ display: none !important;
531
  }
532
 
533
+ /* Only allow scrollbar on body */
534
+ body::-webkit-scrollbar {
 
535
  display: block !important;
536
+ width: 10px !important;
537
  }
538
+
539
+ body::-webkit-scrollbar-track {
540
+ background: #f1f1f1 !important;
 
541
  }
542
+
543
+ body::-webkit-scrollbar-thumb {
544
+ background: #888 !important;
545
+ border-radius: 5px !important;
 
 
 
 
 
546
  }
547
+
548
+ body::-webkit-scrollbar-thumb:hover {
549
+ background: #555 !important;
 
550
  }
551
 
552
+ /* Clean up table styling */
553
  .table-container {
554
+ width: 100% !important;
555
+ overflow: hidden !important;
 
 
556
  border-radius: 8px;
557
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
558
  }
559
 
560
+ /* Remove duplicate scrollbars */
561
  .gradio-dataframe [data-testid="table"],
562
+ [data-testid="dataframe"] [data-testid="table"],
 
 
 
 
 
 
563
  .gradio-dataframe tbody,
564
+ [data-testid="dataframe"] tbody,
565
+ .table-container > div,
566
+ .table-container > div > div {
567
+ overflow: hidden !important;
568
  max-height: none !important;
569
  }
570
 
571
+ /* Ensure table contents are visible without scrollbars */
572
+ .gradio-dataframe,
573
+ [data-testid="dataframe"] {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  overflow: visible !important;
 
575
  max-height: none !important;
576
+ border: none !important;
577
  }
578
 
579
+ /* Visualization styling */
580
+ .visualization-container .js-plotly-plot {
581
+ margin-left: auto !important;
582
+ margin-right: auto !important;
583
+ display: block !important;
584
+ max-width: 1000px;
585
  }
586
 
587
+ /* Section styling */
588
+ .section-title {
589
+ font-size: 1.5em;
590
+ font-weight: bold;
591
+ color: #2c3e50;
592
+ margin-bottom: 15px;
593
+ padding-bottom: 10px;
594
+ border-bottom: 2px solid #e9ecef;
595
+ text-align: center;
 
 
 
 
596
  }
597
 
598
  /* Fix table styling */
 
603
  table-layout: fixed !important;
604
  }
605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
606
  /* Column width customization - adjust for row numbers being first column */
607
  .table-container th:nth-child(2),
608
  .table-container td:nth-child(2) {
 
661
  background-color: #f8fafc;
662
  }
663
 
664
+ /* Row number column styling */
 
 
 
 
 
 
 
 
665
  .gradio-dataframe thead tr th[id="0"],
666
  .gradio-dataframe tbody tr td:nth-child(1),
667
  [data-testid="dataframe"] thead tr th[id="0"],
 
676
  font-size: 0.85em !important;
677
  }
678
 
679
+ /* Fix for Gradio footer causing scroll issues */
680
+ footer {
681
+ position: relative !important;
682
+ width: 100% !important;
683
+ margin-top: 40px !important;
684
  }
685
+ """) as demo:
686
+ gr.Markdown("# 🎮 Game Arena: Gaming Agent 🎲")
687
 
688
+ # Add custom JavaScript for table header line breaks
689
+ gr.HTML("""
690
+ <script>
691
+ // Function to add line breaks to table headers
692
+ function formatTableHeaders() {
693
+ // Find all table headers in the document
694
+ const headers = document.querySelectorAll('th');
695
+
696
+ headers.forEach(header => {
697
+ let text = header.textContent || '';
698
+
699
+ // Skip if already processed
700
+ if (header.getAttribute('data-processed') === 'true') {
701
+ return;
702
+ }
703
+
704
+ // Store original content for reference
705
+ if (!header.getAttribute('data-original')) {
706
+ header.setAttribute('data-original', header.innerHTML);
707
+ }
708
+
709
+ let newContent = header.innerHTML;
710
+
711
+ // Format Super Mario Bros header
712
+ if (text.includes('Super Mario Bros')) {
713
+ newContent = newContent.replace(/Super\s+Mario\s+Bros/g, 'Super<br>Mario Bros');
714
+ }
715
+
716
+ // Format Tetris headers
717
+ if (text.includes('Tetris (complete)')) {
718
+ newContent = newContent.replace(/Tetris\s+\(complete\)/g, 'Tetris<br>(complete)');
719
+ }
720
+
721
+ if (text.includes('Tetris (planning only)')) {
722
+ newContent = newContent.replace(/Tetris\s+\(planning\s+only\)/g, 'Tetris<br>(planning)');
723
+ }
724
+
725
+ // Format Candy Crash header
726
+ if (text.includes('Candy Crash')) {
727
+ newContent = newContent.replace(/Candy\s+Crash/g, 'Candy<br>Crash');
728
+ }
729
+
730
+ // Make Organization header wider and fix its name
731
+ if (text.includes('Organization') || text.includes('Organi-zation')) {
732
+ header.style.minWidth = '150px';
733
+ header.style.width = '150px';
734
+
735
+ // Fix the Organization header name if it has a line break
736
+ if (text.includes('Organi-') || text.includes('zation')) {
737
+ newContent = newContent.replace(/Organi-<br>zation|Organi-zation/, 'Organization');
738
+ }
739
+ }
740
+
741
+ // Update content if changed
742
+ if (newContent !== header.innerHTML) {
743
+ header.innerHTML = newContent;
744
+ header.setAttribute('data-processed', 'true');
745
+
746
+ // Also ensure headers have proper styling
747
+ header.style.whiteSpace = 'normal';
748
+ header.style.lineHeight = '1.2';
749
+ header.style.verticalAlign = 'middle';
750
+ header.style.minHeight = '70px';
751
+ header.style.fontSize = '0.9em';
752
+ }
753
+ });
754
  }
755
 
756
+ // Function to fix player name cells to prevent line breaking
757
+ function fixPlayerCells() {
758
+ // Find all table cells in the document
759
+ const tables = document.querySelectorAll('table');
760
+
761
+ tables.forEach(table => {
762
+ // Process rows starting from index 1 (skip header)
763
+ const rows = table.querySelectorAll('tr');
764
+
765
+ rows.forEach((row, index) => {
766
+ // Skip header row
767
+ if (index === 0) return;
768
+
769
+ // Get the player cell (typically 2nd cell)
770
+ const playerCell = row.querySelector('td:nth-child(2)');
771
+ const orgCell = row.querySelector('td:nth-child(3)');
772
+
773
+ if (playerCell) {
774
+ playerCell.style.whiteSpace = 'nowrap';
775
+ playerCell.style.overflow = 'hidden';
776
+ playerCell.style.textOverflow = 'ellipsis';
777
+ playerCell.style.maxWidth = '230px';
778
+ playerCell.style.textAlign = 'left';
779
+ }
780
+
781
+ if (orgCell) {
782
+ orgCell.style.whiteSpace = 'nowrap';
783
+ orgCell.style.overflow = 'hidden';
784
+ orgCell.style.textOverflow = 'ellipsis';
785
+ orgCell.style.minWidth = '150px';
786
+ orgCell.style.width = '150px';
787
+ }
788
+ });
789
+ });
790
  }
791
+
792
+ // Function to run all formatting
793
+ function formatTable() {
794
+ formatTableHeaders();
795
+ fixPlayerCells();
796
+ }
797
+
798
+ // Run on load and then periodically to catch any new tables
799
+ setInterval(formatTable, 500);
800
+
801
+ // Also run when the DOM content is loaded
802
+ if (document.readyState === 'loading') {
803
+ document.addEventListener('DOMContentLoaded', formatTable);
804
+ } else {
805
+ formatTable();
806
+ }
807
+
808
+ // Run when the page is fully loaded with resources
809
+ window.addEventListener('load', formatTable);
810
+ </script>
811
+ """)
812
 
813
  with gr.Tabs():
814
  with gr.Tab("🏆 Leaderboard"):
 
918
  show_row_numbers=True,
919
  show_fullscreen_button=True,
920
  line_breaks=True,
921
+ max_height=None, # Remove height limitation to avoid scrollbar
922
  show_search="search",
923
  column_widths=col_widths
924
  )