This commit is contained in:
Paul Gauthier 2025-04-13 08:57:12 -07:00
parent 4a86fea86b
commit aefc250e30
2 changed files with 38 additions and 41 deletions

View file

@ -15,11 +15,15 @@ document.addEventListener('DOMContentLoaded', function () {
label: 'Percent completed correctly', label: 'Percent completed correctly',
data: [], data: [],
backgroundColor: function(context) { backgroundColor: function(context) {
const row = allData[context.dataIndex];
if (row && row.edit_format === 'whole') {
return redDiagonalPattern; // Use red pattern for highlighted whole format
}
const label = leaderboardData.labels[context.dataIndex] || ''; const label = leaderboardData.labels[context.dataIndex] || '';
return (label && HIGHLIGHT_MODEL && label.toLowerCase().includes(HIGHLIGHT_MODEL.toLowerCase())) ? 'rgba(255, 99, 132, 0.2)' : 'rgba(54, 162, 235, 0.2)'; return (label && HIGHLIGHT_MODEL && label.toLowerCase().includes(HIGHLIGHT_MODEL.toLowerCase())) ? 'rgba(255, 99, 132, 0.2)' : 'rgba(54, 162, 235, 0.2)';
}, },
borderColor: function(context) { borderColor: function(context) {
const label = leaderboardData.labels[context.dataIndex] || ''; const label = context.chart.data.labels[context.dataIndex] || '';
return (label && HIGHLIGHT_MODEL && label.toLowerCase().includes(HIGHLIGHT_MODEL.toLowerCase())) ? 'rgba(255, 99, 132, 1)' : 'rgba(54, 162, 235, 1)'; return (label && HIGHLIGHT_MODEL && label.toLowerCase().includes(HIGHLIGHT_MODEL.toLowerCase())) ? 'rgba(255, 99, 132, 1)' : 'rgba(54, 162, 235, 1)';
}, },
borderWidth: 1 borderWidth: 1
@ -42,6 +46,7 @@ document.addEventListener('DOMContentLoaded', function () {
model: '{{ row.model }}', model: '{{ row.model }}',
pass_rate: {{ row[pass_rate_field] }}, pass_rate: {{ row[pass_rate_field] }},
percent_cases_well_formed: {{ row.percent_cases_well_formed }}, percent_cases_well_formed: {{ row.percent_cases_well_formed }},
edit_format: '{{ row.edit_format | default: "diff" }}',
total_cost: {{ row.total_cost | default: 0 }} total_cost: {{ row.total_cost | default: 0 }}
}); });
{% endfor %} {% endfor %}
@ -80,31 +85,29 @@ document.addEventListener('DOMContentLoaded', function () {
const isHighlighted = label && HIGHLIGHT_MODEL && label.toLowerCase().includes(HIGHLIGHT_MODEL.toLowerCase()); const isHighlighted = label && HIGHLIGHT_MODEL && label.toLowerCase().includes(HIGHLIGHT_MODEL.toLowerCase());
if (isHighlighted) { if (isHighlighted) {
return 'rgba(255, 99, 132, 0.2)'; if (row && row.edit_format === 'whole') return redDiagonalPattern;
else return 'rgba(255, 99, 132, 0.2)';
} else if (row && row.edit_format === 'whole') {
return blueDiagonalPattern;
} else { } else {
return 'rgba(54, 162, 235, 0.2)'; return 'rgba(54, 162, 235, 0.2)';
} }
}; };
// Remove row ID assignment and click handler from here,
// as it's now handled in the main markdown file's script
// to accommodate the new details rows.
// Add click handler for chart selection (if needed separately from toggle)
var tableBody = document.querySelector('table tbody'); var tableBody = document.querySelector('table tbody');
var mainRows = tableBody.querySelectorAll('tr[id^="main-row-"]'); allData.forEach(function(row, index) {
mainRows.forEach(function(tr) { var tr = tableBody.children[index];
// Find the cells to make clickable, excluding the toggle button cell (first child) if (!tr) {
var clickableCells = tr.querySelectorAll('td:not(:first-child)'); // If the row doesn't exist, create it
clickableCells.forEach(function(cell) { tr = document.createElement('tr');
cell.style.cursor = 'pointer'; tableBody.appendChild(tr);
cell.onclick = function() { }
// Prevent selection when clicking on links or code inside cells if needed tr.id = 'edit-row-' + index;
// if (event.target.tagName === 'A' || event.target.tagName === 'CODE') return; tr.style.cursor = 'pointer';
tr.classList.toggle('selected'); tr.onclick = function() {
updateChart(); this.classList.toggle('selected');
}; updateChart();
}); };
}); });
var leaderboardChart = new Chart(ctx, { var leaderboardChart = new Chart(ctx, {
@ -123,6 +126,12 @@ document.addEventListener('DOMContentLoaded', function () {
strokeStyle: 'rgba(54, 162, 235, 1)', strokeStyle: 'rgba(54, 162, 235, 1)',
lineWidth: 1 lineWidth: 1
}, },
{
text: 'Whole format',
fillStyle: blueDiagonalPattern,
strokeStyle: 'rgba(54, 162, 235, 1)',
lineWidth: 1
},
{ {
text: 'Total Cost ($)', text: 'Total Cost ($)',
fillStyle: 'rgba(153, 102, 255, 1)', fillStyle: 'rgba(153, 102, 255, 1)',
@ -212,38 +221,26 @@ document.addEventListener('DOMContentLoaded', function () {
document.getElementById('editSearchInput').addEventListener('keyup', function() { document.getElementById('editSearchInput').addEventListener('keyup', function() {
var searchWords = this.value.toLowerCase().split(' ').filter(word => word.length > 0); var searchWords = this.value.toLowerCase().split(' ').filter(word => word.length > 0);
var tableBody = document.querySelector('table:first-of-type tbody'); var tableBody = document.querySelector('table:first-of-type tbody');
// Select only main data rows for filtering logic var rows = tableBody.getElementsByTagName('tr');
var mainRows = tableBody.querySelectorAll('tr[id^="main-row-"]');
displayedData = []; displayedData = [];
leaderboardData.labels = []; leaderboardData.labels = [];
leaderboardData.datasets[0].data = []; leaderboardData.datasets[0].data = [];
leaderboardData.datasets[1].data = []; leaderboardData.datasets[1].data = [];
// Iterate through main rows using their index relative to the allData array for (var i = 0; i < rows.length; i++) {
mainRows.forEach(function(row, i) { var rowText = rows[i].textContent;
// The index `i` corresponds to the index in `allData` because `mainRows` only contains the primary data rows.
var detailsRow = document.getElementById('details-' + i); // Find corresponding details row
var rowText = row.textContent; // Search only within the main row's text content
if (searchWords.every(word => rowText.toLowerCase().includes(word))) { if (searchWords.every(word => rowText.toLowerCase().includes(word))) {
row.style.display = ''; // Show main row rows[i].style.display = '';
displayedData.push(allData[i]); // Add data to chart source displayedData.push(allData[i]);
leaderboardData.labels.push(allData[i].model); leaderboardData.labels.push(allData[i].model);
leaderboardData.datasets[0].data.push(allData[i].pass_rate); leaderboardData.datasets[0].data.push(allData[i].pass_rate);
// Only include cost if it's not zero (placeholder for unknown) // Only include cost if it's not zero (placeholder for unknown)
leaderboardData.datasets[1].data.push(allData[i].total_cost > 0 ? allData[i].total_cost : null); leaderboardData.datasets[1].data.push(allData[i].total_cost > 0 ? allData[i].total_cost : null);
// Ensure details row is hidden and toggle is reset when filtering
if (detailsRow) detailsRow.style.display = 'none';
const toggleButton = row.querySelector('.toggle-details');
if (toggleButton) toggleButton.textContent = '+';
} else { } else {
row.style.display = 'none'; // Hide main row rows[i].style.display = 'none';
if (detailsRow) detailsRow.style.display = 'none'; // Hide details row too
} }
}); }
leaderboardChart.update(); leaderboardChart.update();
}); });
}); });