1239 lines
55 KiB
HTML
1239 lines
55 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{{ player.name }} - Player Stats</title>
|
|
<link rel="stylesheet" href="/static/css/base.css">
|
|
<link rel="stylesheet" href="/static/css/navbar.css">
|
|
<link rel="stylesheet" href="/static/css/buttons.css">
|
|
<link rel="stylesheet" href="/static/css/components.css">
|
|
<link rel="stylesheet" href="/static/css/responsive.css">
|
|
<link rel="stylesheet" href="/static/css/pages/modern_player_stats.css">
|
|
<script src="/static/js/chart.min.js"></script>
|
|
<script src="/static/js/i18n.js"></script>
|
|
</head>
|
|
<body>
|
|
<!-- Navigation Bar -->
|
|
<div class="navbar">
|
|
<div class="navbar-title">📊 {{ player.name }} - <span data-i18n="players.player_stats">Stats</span></div>
|
|
<div class="navbar-controls">
|
|
<a href="/archive/player-analysis" class="nav-btn active">👤 <span data-i18n="players.player_analysis">Player Analysis</span></a>
|
|
<a href="/archive" class="nav-btn">📚 <span data-i18n="navigation.archive">Archive</span></a>
|
|
<a href="/" class="nav-btn">✕</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="ps-layout">
|
|
|
|
<!-- LEFT: stats card -->
|
|
<div class="ps-card ps-left">
|
|
|
|
<!-- Card header: filter buttons -->
|
|
<div class="ps-topbar ps-topbar-header">
|
|
<div class="tournament-type-buttons ps-type-btns">
|
|
<button class="type-btn active targets-40" data-type="40 Targets"><span>💪</span> 40T</button>
|
|
<button class="type-btn targets-20" data-type="20 Targets"><span>⚡</span> 20T</button>
|
|
<button class="type-btn targets-4" data-type="4 Targets"><span>🎯</span> 4T</button>
|
|
</div>
|
|
<div class="ps-mini-stats">
|
|
<div class="chart-stat"><div class="chart-stat-value" id="gameCount">0</div><div class="chart-stat-label">Iger</div></div>
|
|
<div class="chart-stat"><div class="chart-stat-value" id="bestScore">0</div><div class="chart-stat-label">Najboljši</div></div>
|
|
<div class="chart-stat"><div class="chart-stat-value" id="avgScore">0</div><div class="chart-stat-label">Povprečje</div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="ps-sections">
|
|
|
|
<!-- Section 1: Natančnost -->
|
|
<div class="ps-section">
|
|
<div class="ps-section-header">
|
|
<span class="ps-section-title">🎯 Natančnost strelov</span>
|
|
<span class="ps-section-desc">Kako pogosto zadeneš posamezno vrednost</span>
|
|
</div>
|
|
<div class="ps-section-body">
|
|
<div class="ps-chart-wrap"><canvas id="accuracyChart"></canvas></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Section 2: Napredek + Profil -->
|
|
<div class="ps-section">
|
|
<div class="ps-section-body">
|
|
<div style="display:flex; flex-direction:column; flex:1; min-width:0; min-height:0;">
|
|
<div class="ps-section-header">
|
|
<span class="ps-section-title">📈 Napredek</span>
|
|
<span class="ps-section-desc">Rezultati skozi čas po turnirjih</span>
|
|
</div>
|
|
<div class="ps-chart-wrap" style="flex:1; min-height:0;"><canvas id="tournamentChart"></canvas></div>
|
|
</div>
|
|
<div style="display:flex; flex-direction:column; flex:0 0 32%; min-height:0; border-left:1px solid #e9ecef; padding-left:10px;">
|
|
<div class="ps-section-header">
|
|
<span class="ps-section-title">🕸 Profil</span>
|
|
<span class="ps-section-desc">Razporeditev strelov</span>
|
|
</div>
|
|
<div class="ps-chart-wrap" style="flex:1; min-height:0;"><canvas id="accuracyRadarChart"></canvas></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div><!-- ps-left card -->
|
|
|
|
<!-- RIGHT: history card -->
|
|
<div class="ps-card ps-right">
|
|
<div class="ps-hist-header">
|
|
<div class="ps-hist-title">📜 Zgodovina</div>
|
|
<div class="history-tabs ps-hist-tabs">
|
|
<button class="history-tab active" data-tab="tournaments">🎯 T</button>
|
|
<button class="history-tab" data-tab="leagues">🏆 L</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="ps-history-body">
|
|
<!-- Tournament History -->
|
|
<div id="tournaments-tab" class="history-tab-content active">
|
|
{% if stats.tournament_history %}
|
|
{% for tournament in stats.tournament_history %}
|
|
<div class="ps-hist-item" onclick="window.location.href='/archive/tournament/{{ tournament.filename }}'">
|
|
<div class="ps-hist-date">{{ tournament.date[:10] if tournament.date != 'Unknown' else '?' }}</div>
|
|
<div class="ps-hist-info">
|
|
<span class="tournament-type-badge" data-tournament-type="{{ tournament.tournament_type }}">{{ tournament.tournament_type.replace('_targets','T') }}</span>
|
|
</div>
|
|
<div class="ps-hist-score">{{ tournament.score }}</div>
|
|
<div class="ps-hist-arrow">→</div>
|
|
</div>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="empty-state"><div class="empty-icon">🎯</div><div>Ni zgodovine</div></div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- League History -->
|
|
<div id="leagues-tab" class="history-tab-content">
|
|
{% if stats.league_history %}
|
|
{% for league in stats.league_history %}
|
|
<div class="ps-hist-item" onclick="window.location.href='/archive/league/{{ league.filename }}'">
|
|
<div class="ps-hist-date">{{ league.date[:10] if league.date != 'Unknown' else '?' }}</div>
|
|
<div class="ps-hist-info ps-league-scores">
|
|
{% if league.tournament_results %}
|
|
{% for i in range(league.tournament_results|length) %}
|
|
{% set result = league.tournament_results[i] %}
|
|
{% set is_excluded = league.excluded_tournament and league.excluded_tournament == (i+1) %}
|
|
{% set is_joker = result.joker or not result.participated %}
|
|
<span class="ps-ls {% if is_joker %}ps-ls-joker{% elif is_excluded %}ps-ls-excl{% endif %}">
|
|
{% if is_joker %}🃏{% elif is_excluded %}<s>{{ result.score if result else '-' }}</s>{% else %}{{ result.score if result else '-' }}{% endif %}
|
|
</span>
|
|
{% endfor %}
|
|
{% endif %}
|
|
</div>
|
|
<div class="ps-hist-score">{{ league.final_score }}</div>
|
|
<div class="ps-hist-arrow">→</div>
|
|
</div>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="empty-state"><div class="empty-icon">🏆</div><div>Ni zgodovine</div></div>
|
|
{% endif %}
|
|
</div>
|
|
</div><!-- ps-history-body -->
|
|
</div><!-- ps-right card -->
|
|
|
|
</div><!-- ps-layout -->
|
|
|
|
<script>
|
|
// Player data from Flask
|
|
const playerStats = {{ stats|tojson }};
|
|
|
|
// Tournament type configuration
|
|
const tournamentTypes = {
|
|
'40 Targets': { color: '#9C27B0', icon: '💪', class: 'targets-40' },
|
|
'20 Targets': { color: '#FF9800', icon: '⚡', class: 'targets-20' },
|
|
'4 Targets': { color: '#4CAF50', icon: '🎯', class: 'targets-4' }
|
|
};
|
|
|
|
let currentChart = null;
|
|
let currentTournamentType = '40 Targets'; // Will be updated based on available data
|
|
let tournamentsByType = {};
|
|
let shotAccuracyData = {};
|
|
|
|
// Format date from YYYY-MM-DD to DD.MM.YY
|
|
function formatDate(dateString) {
|
|
if (!dateString || dateString === 'Unknown') return 'Unknown';
|
|
const parts = dateString.split('-');
|
|
if (parts.length !== 3) return dateString;
|
|
const year = parts[0].slice(-2); // Get last 2 digits of year
|
|
const month = parts[1];
|
|
const day = parts[2];
|
|
return `${day}.${month}.${year}`;
|
|
}
|
|
|
|
|
|
// Translate tournament types in history tables
|
|
function translateTournamentTypes() {
|
|
const tournamentTypeBadges = document.querySelectorAll('.tournament-type-badge[data-tournament-type]');
|
|
tournamentTypeBadges.forEach(badge => {
|
|
const type = badge.getAttribute('data-tournament-type');
|
|
const translationKey = `tournament_types.${type}`;
|
|
// Use the global t() function from i18n.js
|
|
const translatedText = typeof t === 'function' ? t(translationKey) : type.replace(/_/g, ' ').toUpperCase();
|
|
badge.textContent = translatedText;
|
|
});
|
|
}
|
|
|
|
// Initialize page
|
|
function initializePage() {
|
|
groupTournamentsByType();
|
|
setupEventListeners();
|
|
loadShotAccuracyData();
|
|
formatDateCells();
|
|
populatePlacerStats();
|
|
populateOverallAccuracy();
|
|
translateTournamentTypes();
|
|
updateChart();
|
|
}
|
|
|
|
// Format all date cells in history tables
|
|
function formatDateCells() {
|
|
const dateCells = document.querySelectorAll('.date-cell');
|
|
dateCells.forEach(cell => {
|
|
const dateText = cell.textContent.trim();
|
|
cell.textContent = formatDate(dateText);
|
|
});
|
|
}
|
|
|
|
// Populate placer statistics card with total shot counts
|
|
function populatePlacerStats() {
|
|
const statsData = {{ stats|tojson }};
|
|
if (!statsData || !statsData.shot_accuracy) return;
|
|
|
|
// Aggregate all shot counts across all tournament types
|
|
const totalCounts = {
|
|
tens: 0, nines: 0, eights: 0, sevens: 0, sixes: 0,
|
|
fives: 0, fours: 0, threes: 0, twos: 0, ones: 0, zeros: 0
|
|
};
|
|
|
|
// Iterate through all tournament types and sum up the counts
|
|
Object.values(statsData.shot_accuracy).forEach(typeData => {
|
|
if (typeData.tens !== undefined) {
|
|
totalCounts.tens += typeData.tens || 0;
|
|
totalCounts.nines += typeData.nines || 0;
|
|
totalCounts.eights += typeData.eights || 0;
|
|
totalCounts.sevens += typeData.sevens || 0;
|
|
totalCounts.sixes += typeData.sixes || 0;
|
|
totalCounts.fives += typeData.fives || 0;
|
|
totalCounts.fours += typeData.fours || 0;
|
|
totalCounts.threes += typeData.threes || 0;
|
|
totalCounts.twos += typeData.twos || 0;
|
|
totalCounts.ones += typeData.ones || 0;
|
|
totalCounts.zeros += typeData.zeros || 0;
|
|
}
|
|
});
|
|
|
|
// Update the placer stat cards
|
|
const placerCards = document.querySelectorAll('.placer-stat-card');
|
|
const scoreMap = ['zeros', 'ones', 'twos', 'threes', 'fours', 'fives', 'sixes', 'sevens', 'eights', 'nines', 'tens'];
|
|
|
|
placerCards.forEach((card, index) => {
|
|
const key = scoreMap[index];
|
|
const countElement = card.querySelector('.placer-stat-count');
|
|
if (countElement) {
|
|
countElement.textContent = totalCounts[key] || 0;
|
|
}
|
|
});
|
|
}
|
|
|
|
// Populate overall shot accuracy card with all tournament data (no filters)
|
|
function populateOverallAccuracy() {
|
|
const statsData = {{ stats|tojson }};
|
|
if (!statsData || !statsData.shot_accuracy) return;
|
|
|
|
// Aggregate all shot counts across all tournament types
|
|
const totalCounts = {
|
|
tens: 0, nines: 0, eights: 0, sevens: 0, sixes: 0,
|
|
fives: 0, fours: 0, threes: 0, twos: 0, ones: 0, zeros: 0
|
|
};
|
|
|
|
// Iterate through all tournament types and sum up the counts
|
|
Object.values(statsData.shot_accuracy).forEach(typeData => {
|
|
if (typeData.tens !== undefined) {
|
|
totalCounts.tens += typeData.tens || 0;
|
|
totalCounts.nines += typeData.nines || 0;
|
|
totalCounts.eights += typeData.eights || 0;
|
|
totalCounts.sevens += typeData.sevens || 0;
|
|
totalCounts.sixes += typeData.sixes || 0;
|
|
totalCounts.fives += typeData.fives || 0;
|
|
totalCounts.fours += typeData.fours || 0;
|
|
totalCounts.threes += typeData.threes || 0;
|
|
totalCounts.twos += typeData.twos || 0;
|
|
totalCounts.ones += typeData.ones || 0;
|
|
totalCounts.zeros += typeData.zeros || 0;
|
|
}
|
|
});
|
|
|
|
// Create overall bar chart
|
|
createOverallAccuracyChart(totalCounts);
|
|
|
|
// Create overall pie chart
|
|
createOverallRadarChart(totalCounts);
|
|
|
|
// Populate shot count cards
|
|
populateShotCountCards(totalCounts);
|
|
}
|
|
|
|
// Populate shot count cards below charts
|
|
function populateShotCountCards(totalCounts) {
|
|
const scoreMap = {
|
|
10: totalCounts.tens,
|
|
9: totalCounts.nines,
|
|
8: totalCounts.eights,
|
|
7: totalCounts.sevens,
|
|
6: totalCounts.sixes,
|
|
5: totalCounts.fives,
|
|
4: totalCounts.fours,
|
|
3: totalCounts.threes,
|
|
2: totalCounts.twos,
|
|
1: totalCounts.ones,
|
|
0: totalCounts.zeros
|
|
};
|
|
|
|
// Update shot count cards
|
|
for (const [score, count] of Object.entries(scoreMap)) {
|
|
const countElement = document.getElementById(`count-${score}`);
|
|
if (countElement) {
|
|
countElement.textContent = count;
|
|
}
|
|
}
|
|
|
|
// Update top stat badges
|
|
updateTopStatsBadges(totalCounts);
|
|
}
|
|
|
|
// Update top stat badges with overall metrics
|
|
function updateTopStatsBadges(totalCounts) {
|
|
// Perfect 10s count
|
|
const totalTensBadge = document.getElementById('totalTens-badge');
|
|
if (totalTensBadge) {
|
|
totalTensBadge.textContent = totalCounts.tens;
|
|
}
|
|
|
|
// Calculate most common shot value
|
|
let mostCommonShot = 0;
|
|
let maxCount = 0;
|
|
|
|
const shotScores = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
|
|
const shotCountsArray = [
|
|
totalCounts.tens, totalCounts.nines, totalCounts.eights,
|
|
totalCounts.sevens, totalCounts.sixes, totalCounts.fives,
|
|
totalCounts.fours, totalCounts.threes, totalCounts.twos,
|
|
totalCounts.ones, totalCounts.zeros
|
|
];
|
|
|
|
for (let i = 0; i < shotScores.length; i++) {
|
|
if (shotCountsArray[i] > maxCount) {
|
|
maxCount = shotCountsArray[i];
|
|
mostCommonShot = shotScores[i];
|
|
}
|
|
}
|
|
|
|
const mostCommonBadge = document.getElementById('mostCommon-badge');
|
|
if (mostCommonBadge) {
|
|
mostCommonBadge.textContent = mostCommonShot;
|
|
}
|
|
}
|
|
|
|
// Create overall accuracy bar chart
|
|
let overallAccuracyChartInstance = null;
|
|
|
|
function createOverallAccuracyChart(totalCounts) {
|
|
const canvas = document.getElementById('overallAccuracyChart');
|
|
if (!canvas) {
|
|
console.warn('Overall accuracy chart canvas not found');
|
|
return;
|
|
}
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Destroy existing chart if it exists
|
|
if (overallAccuracyChartInstance) {
|
|
overallAccuracyChartInstance.destroy();
|
|
}
|
|
|
|
const labels = ['10', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0'];
|
|
const counts = [
|
|
totalCounts.tens, totalCounts.nines, totalCounts.eights, totalCounts.sevens,
|
|
totalCounts.sixes, totalCounts.fives, totalCounts.fours, totalCounts.threes,
|
|
totalCounts.twos, totalCounts.ones, totalCounts.zeros
|
|
];
|
|
|
|
// Use colorful array for overall accuracy - different color for each shot value
|
|
const colors = generateColorfulArray();
|
|
|
|
overallAccuracyChartInstance = new Chart(ctx, {
|
|
type: 'bar',
|
|
data: {
|
|
labels: labels,
|
|
datasets: [{
|
|
label: 'Overall Shot Count',
|
|
data: counts,
|
|
backgroundColor: colors,
|
|
borderColor: colors,
|
|
borderWidth: 1,
|
|
borderRadius: 8
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
indexAxis: 'x',
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
backgroundColor: 'rgba(0,0,0,0.7)',
|
|
titleColor: '#fff',
|
|
bodyColor: '#fff',
|
|
padding: 10,
|
|
displayColors: false,
|
|
callbacks: {
|
|
title: function(context) {
|
|
return 'Shot Score: ' + context[0].label;
|
|
},
|
|
label: function(context) {
|
|
return 'Total Count: ' + context.parsed.y;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true,
|
|
ticks: {
|
|
stepSize: 1,
|
|
color: '#666',
|
|
font: {
|
|
size: 12
|
|
}
|
|
},
|
|
grid: {
|
|
color: '#e9ecef',
|
|
drawBorder: true
|
|
}
|
|
},
|
|
x: {
|
|
ticks: {
|
|
color: '#666',
|
|
font: {
|
|
size: 12,
|
|
weight: 'bold'
|
|
}
|
|
},
|
|
grid: {
|
|
display: false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log('Overall accuracy chart created successfully with data:', counts);
|
|
}
|
|
|
|
// Create overall pie chart
|
|
let overallRadarChartInstance = null;
|
|
|
|
function createOverallRadarChart(totalCounts) {
|
|
const canvas = document.getElementById('overallRadarChart');
|
|
if (!canvas) {
|
|
console.warn('Overall pie chart canvas not found');
|
|
return;
|
|
}
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Destroy existing chart if it exists
|
|
if (overallRadarChartInstance) {
|
|
overallRadarChartInstance.destroy();
|
|
}
|
|
|
|
const labels = ['10', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0'];
|
|
const data = [
|
|
totalCounts.tens, totalCounts.nines, totalCounts.eights, totalCounts.sevens,
|
|
totalCounts.sixes, totalCounts.fives, totalCounts.fours, totalCounts.threes,
|
|
totalCounts.twos, totalCounts.ones, totalCounts.zeros
|
|
];
|
|
|
|
// Use colorful array for pie chart
|
|
const colors = generateColorfulArray();
|
|
|
|
overallRadarChartInstance = new Chart(ctx, {
|
|
type: 'pie',
|
|
data: {
|
|
labels: labels.map(label => `Score ${label}`),
|
|
datasets: [{
|
|
label: 'Shot Distribution',
|
|
data: data,
|
|
backgroundColor: colors,
|
|
borderColor: '#fff',
|
|
borderWidth: 2
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: true,
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
callbacks: {
|
|
label: function(context) {
|
|
const label = context.label || '';
|
|
const value = context.parsed || 0;
|
|
const total = context.dataset.data.reduce((a, b) => a + b, 0);
|
|
const percentage = ((value / total) * 100).toFixed(1);
|
|
return `${label}: ${value} (${percentage}%)`;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Create accuracy gauge chart (doughnut showing overall accuracy percentage)
|
|
let accuracyGaugeChartInstance = null;
|
|
|
|
function createAccuracyGaugeChart(totalCounts) {
|
|
const canvas = document.getElementById('accuracyGaugeChart');
|
|
if (!canvas) {
|
|
console.warn('Accuracy gauge chart canvas not found');
|
|
return;
|
|
}
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Destroy existing chart if it exists
|
|
if (accuracyGaugeChartInstance) {
|
|
accuracyGaugeChartInstance.destroy();
|
|
}
|
|
|
|
// Calculate accuracy percentage (perfect shots 8-10 / total shots)
|
|
const perfectShots = totalCounts.tens + totalCounts.nines + totalCounts.eights;
|
|
const totalShots = Object.values(totalCounts).reduce((a, b) => a + b, 0);
|
|
const accuracyPercentage = totalShots > 0 ? Math.round((perfectShots / totalShots) * 100) : 0;
|
|
|
|
// Calculate consistency score (lower variance = higher consistency)
|
|
const shotValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
|
|
const shotCounts = [totalCounts.tens, totalCounts.nines, totalCounts.eights, totalCounts.sevens, totalCounts.sixes, totalCounts.fives, totalCounts.fours, totalCounts.threes, totalCounts.twos, totalCounts.ones, totalCounts.zeros];
|
|
|
|
let mean = 0;
|
|
if (totalShots > 0) {
|
|
mean = shotValues.reduce((sum, val, i) => sum + (val * shotCounts[i]), 0) / totalShots;
|
|
}
|
|
|
|
let variance = 0;
|
|
if (totalShots > 0) {
|
|
variance = shotValues.reduce((sum, val, i) => sum + (Math.pow(val - mean, 2) * shotCounts[i]), 0) / totalShots;
|
|
}
|
|
const consistency = Math.max(0, Math.round(100 - (variance * 5))); // Scale variance to 0-100
|
|
|
|
// Update DOM with percentages
|
|
document.getElementById('accuracyPercentage').textContent = accuracyPercentage + '%';
|
|
document.getElementById('consistencyScore').textContent = consistency;
|
|
|
|
const gaugeData = [accuracyPercentage, 100 - accuracyPercentage];
|
|
|
|
accuracyGaugeChartInstance = new Chart(ctx, {
|
|
type: 'doughnut',
|
|
data: {
|
|
labels: ['Accuracy', 'Missed'],
|
|
datasets: [{
|
|
data: gaugeData,
|
|
backgroundColor: ['#28a745', '#f0f0f0'],
|
|
borderColor: ['#28a745', '#e0e0e0'],
|
|
borderWidth: 3,
|
|
circumference: 180,
|
|
rotation: 270
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
callbacks: {
|
|
label: function(context) {
|
|
return context.label + ': ' + context.parsed + '%';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Update stat cards with performance metrics
|
|
function updateStatCards(statsData, totalCounts) {
|
|
try {
|
|
// Count tournaments
|
|
const tournaments = statsData.tournament_history ? statsData.tournament_history.length : 0;
|
|
document.getElementById('totalTournaments').textContent = tournaments;
|
|
|
|
// Count total 10s
|
|
const totalTens = totalCounts.tens || 0;
|
|
document.getElementById('totalTens').textContent = totalTens;
|
|
|
|
// Calculate variance
|
|
const shotValues = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
|
|
const shotCounts = [totalCounts.tens, totalCounts.nines, totalCounts.eights, totalCounts.sevens, totalCounts.sixes, totalCounts.fives, totalCounts.fours, totalCounts.threes, totalCounts.twos, totalCounts.ones, totalCounts.zeros];
|
|
const totalShots = shotCounts.reduce((a, b) => a + b, 0);
|
|
|
|
let mean = 0;
|
|
if (totalShots > 0) {
|
|
mean = shotValues.reduce((sum, val, i) => sum + (val * shotCounts[i]), 0) / totalShots;
|
|
}
|
|
|
|
let variance = 0;
|
|
if (totalShots > 0) {
|
|
variance = shotValues.reduce((sum, val, i) => sum + (Math.pow(val - mean, 2) * shotCounts[i]), 0) / totalShots;
|
|
}
|
|
document.getElementById('scoreVariance').textContent = variance.toFixed(2);
|
|
|
|
// Calculate range (highest - lowest non-zero score)
|
|
let minScore = null;
|
|
let maxScore = null;
|
|
|
|
for (let i = 0; i < shotValues.length; i++) {
|
|
if (shotCounts[i] > 0) {
|
|
if (maxScore === null) maxScore = shotValues[i];
|
|
minScore = shotValues[i];
|
|
}
|
|
}
|
|
|
|
const range = maxScore !== null ? (maxScore - minScore) : 0;
|
|
document.getElementById('scoreRange').textContent = range;
|
|
} catch (error) {
|
|
console.error('Error updating stat cards:', error);
|
|
}
|
|
}
|
|
|
|
// Load shot accuracy data from template context
|
|
function loadShotAccuracyData() {
|
|
try {
|
|
// Get shot accuracy data directly from template context
|
|
const statsData = {{ stats|tojson }};
|
|
console.log('Stats data from template:', statsData);
|
|
|
|
if (statsData && statsData.shot_accuracy) {
|
|
shotAccuracyData = statsData.shot_accuracy;
|
|
console.log('Shot accuracy data loaded from template:', shotAccuracyData);
|
|
|
|
// Map backend keys to display names
|
|
const typeMapping = {
|
|
'40_targets': '40 Targets',
|
|
'20_targets': '20 Targets',
|
|
'4_targets': '4 Targets'
|
|
};
|
|
|
|
// Auto-select the first tournament type with data
|
|
const availableTypes = Object.keys(shotAccuracyData);
|
|
if (availableTypes.length > 0) {
|
|
// Find the first type with actual data
|
|
for (const backendType of availableTypes) {
|
|
const typeData = shotAccuracyData[backendType];
|
|
const hasData = Object.values(typeData).some(v => v > 0);
|
|
if (hasData) {
|
|
// Convert backend key to display name
|
|
currentTournamentType = typeMapping[backendType] || backendType;
|
|
console.log('Selected tournament type:', currentTournamentType, 'from backend key:', backendType);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Update button states
|
|
updateActiveButton();
|
|
}
|
|
|
|
updateChart(); // Refresh chart with accuracy data
|
|
} else {
|
|
console.log('No shot accuracy data available in template');
|
|
updateChart();
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading shot accuracy data:', error);
|
|
updateChart();
|
|
}
|
|
}
|
|
|
|
// Update active button based on current tournament type
|
|
function updateActiveButton() {
|
|
const typeButtons = document.querySelectorAll('.type-btn');
|
|
typeButtons.forEach(btn => {
|
|
btn.classList.remove('active');
|
|
if (btn.dataset.type === currentTournamentType) {
|
|
btn.classList.add('active');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Setup event listeners
|
|
function setupEventListeners() {
|
|
const typeButtons = document.querySelectorAll('.type-btn');
|
|
typeButtons.forEach(btn => {
|
|
btn.addEventListener('click', () => {
|
|
// Update active button
|
|
typeButtons.forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
|
|
// Update current type and chart
|
|
currentTournamentType = btn.dataset.type;
|
|
updateChart();
|
|
});
|
|
});
|
|
|
|
// History tab switching
|
|
const historyTabs = document.querySelectorAll('.history-tab');
|
|
historyTabs.forEach(tab => {
|
|
tab.addEventListener('click', () => {
|
|
const tabName = tab.dataset.tab;
|
|
|
|
// Update active tab button
|
|
historyTabs.forEach(t => t.classList.remove('active'));
|
|
tab.classList.add('active');
|
|
|
|
// Update active tab content
|
|
const tabContents = document.querySelectorAll('.history-tab-content');
|
|
tabContents.forEach(content => content.classList.remove('active'));
|
|
document.getElementById(tabName + '-tab').classList.add('active');
|
|
});
|
|
});
|
|
}
|
|
|
|
// Group tournaments by type based on tournament_type field or shots fired
|
|
function groupTournamentsByType() {
|
|
const tournamentHistory = playerStats.tournament_history || [];
|
|
tournamentsByType = {};
|
|
|
|
tournamentHistory.forEach(tournament => {
|
|
let type;
|
|
|
|
// First try to use the tournament_type field if it exists
|
|
if (tournament.tournament_type) {
|
|
const typeField = tournament.tournament_type.toLowerCase();
|
|
if (typeField.includes('40') || typeField.includes('forty')) {
|
|
type = '40 Targets';
|
|
} else if (typeField.includes('20') || typeField.includes('twenty')) {
|
|
type = '20 Targets';
|
|
} else if (typeField.includes('4') || typeField.includes('four')) {
|
|
type = '4 Targets';
|
|
}
|
|
}
|
|
|
|
// If we couldn't determine from tournament_type, fall back to shots_fired
|
|
if (!type) {
|
|
const shots = tournament.shots_fired;
|
|
if (shots >= 30) {
|
|
type = '40 Targets';
|
|
} else if (shots >= 10 && shots <= 29) {
|
|
type = '20 Targets';
|
|
} else if (shots <= 9) {
|
|
type = '4 Targets';
|
|
}
|
|
}
|
|
|
|
// Skip tournaments that don't match our types
|
|
if (!type) {
|
|
console.log('Could not categorize tournament:', tournament);
|
|
return;
|
|
}
|
|
|
|
if (!tournamentsByType[type]) {
|
|
tournamentsByType[type] = [];
|
|
}
|
|
tournamentsByType[type].push(tournament);
|
|
});
|
|
|
|
// Sort each type by date
|
|
Object.keys(tournamentsByType).forEach(type => {
|
|
tournamentsByType[type].sort((a, b) => new Date(a.date) - new Date(b.date));
|
|
});
|
|
|
|
console.log('Tournaments grouped by type:', tournamentsByType);
|
|
console.log('Available tournament types from database:', Object.keys(tournamentsByType));
|
|
|
|
// If no 40 Targets tournaments, try to default to an available type
|
|
if (!tournamentsByType['40 Targets'] && Object.keys(tournamentsByType).length > 0) {
|
|
const availableTypes = Object.keys(tournamentsByType);
|
|
currentTournamentType = availableTypes[0];
|
|
console.log(`No 40 Targets tournaments found. Defaulting to: ${currentTournamentType}`);
|
|
updateActiveButton();
|
|
}
|
|
}
|
|
|
|
// Update chart and statistics for current tournament type
|
|
function updateChart() {
|
|
const tournaments = tournamentsByType[currentTournamentType] || [];
|
|
updateChartInfo(tournaments);
|
|
createChart(tournaments);
|
|
}
|
|
|
|
// Update chart information and statistics
|
|
function updateChartInfo(tournaments) {
|
|
const gameCount = tournaments.length;
|
|
const scores = tournaments.map(t => t.score);
|
|
const avgScore = gameCount > 0 ? Math.round(scores.reduce((a, b) => a + b, 0) / gameCount) : 0;
|
|
const bestScore = gameCount > 0 ? Math.max(...scores) : 0;
|
|
|
|
// Calculate most common shot value
|
|
let mostCommonShot = 0;
|
|
const shotCounts = { 10: 0, 9: 0, 8: 0, 7: 0, 6: 0, 5: 0, 4: 0, 3: 0, 2: 0, 1: 0, 0: 0 };
|
|
|
|
tournaments.forEach(tournament => {
|
|
if (tournament.shot_breakdown) {
|
|
const breakdown = tournament.shot_breakdown;
|
|
shotCounts[10] += breakdown.tens || 0;
|
|
shotCounts[9] += breakdown.nines || 0;
|
|
shotCounts[8] += breakdown.eights || 0;
|
|
shotCounts[7] += breakdown.sevens || 0;
|
|
shotCounts[6] += breakdown.sixes || 0;
|
|
shotCounts[5] += breakdown.fives || 0;
|
|
shotCounts[4] += breakdown.fours || 0;
|
|
shotCounts[3] += breakdown.threes || 0;
|
|
shotCounts[2] += breakdown.twos || 0;
|
|
shotCounts[1] += breakdown.ones || 0;
|
|
shotCounts[0] += breakdown.zeros || 0;
|
|
}
|
|
});
|
|
|
|
// Find shot value with highest count
|
|
let maxCount = 0;
|
|
for (const [score, count] of Object.entries(shotCounts)) {
|
|
if (count > maxCount) {
|
|
maxCount = count;
|
|
mostCommonShot = parseInt(score);
|
|
}
|
|
}
|
|
|
|
// Update basic stats
|
|
document.getElementById('gameCount').textContent = gameCount;
|
|
document.getElementById('bestScore').textContent = bestScore;
|
|
document.getElementById('avgScore').textContent = avgScore;
|
|
const mcEl = document.getElementById('mostCommonShot'); if (mcEl) mcEl.textContent = mostCommonShot;
|
|
|
|
// Update shot accuracy stats (if available in tournament data)
|
|
updateAccuracyStats(tournaments);
|
|
}
|
|
|
|
// Update shot accuracy statistics
|
|
function renderShotCountTable(counts) {
|
|
const el = document.getElementById('shotCountTable');
|
|
if (!el) return;
|
|
const labels = [10,9,8,7,6,5,4,3,2,1,0];
|
|
const colors = [
|
|
'#1a7a3c','#2d9e54','#3db86a','#5ec47c','#88d4a0',
|
|
'#b0dfc0','#c5c5c5','#e0a89a','#e07a6e','#d95050','#c0392b'
|
|
];
|
|
el.innerHTML = labels.map((lbl, i) => `
|
|
<div class="ps-sc-row">
|
|
<div class="ps-sc-badge" style="background:${colors[i]}">${lbl}</div>
|
|
<div class="ps-sc-count">${counts[i]}</div>
|
|
</div>`).join('');
|
|
}
|
|
|
|
function updateAccuracyStats(tournaments) {
|
|
let tens = 0, nines = 0, eights = 0, sevens = 0, sixes = 0;
|
|
let fives = 0, fours = 0, threes = 0, twos = 0, ones = 0, zeros = 0;
|
|
let hasData = false;
|
|
|
|
tournaments.forEach(tournament => {
|
|
// Check if we have shot breakdown data for this tournament
|
|
if (tournament.shot_breakdown) {
|
|
hasData = true;
|
|
const breakdown = tournament.shot_breakdown;
|
|
tens += breakdown.tens || 0;
|
|
nines += breakdown.nines || 0;
|
|
eights += breakdown.eights || 0;
|
|
sevens += breakdown.sevens || 0;
|
|
sixes += breakdown.sixes || 0;
|
|
fives += breakdown.fives || 0;
|
|
fours += breakdown.fours || 0;
|
|
threes += breakdown.threes || 0;
|
|
twos += breakdown.twos || 0;
|
|
ones += breakdown.ones || 0;
|
|
zeros += breakdown.zeros || 0;
|
|
}
|
|
});
|
|
|
|
// Also check if we have aggregated shot accuracy data for this tournament type
|
|
console.log('Current tournament type:', currentTournamentType);
|
|
console.log('Available keys in shotAccuracyData:', Object.keys(shotAccuracyData));
|
|
|
|
// Map display names to backend keys
|
|
const typeMapping = {
|
|
'40 Targets': '40_targets',
|
|
'20 Targets': '20_targets',
|
|
'4 Targets': '4_targets'
|
|
};
|
|
|
|
const backendKey = typeMapping[currentTournamentType] || currentTournamentType;
|
|
console.log('Looking for data with key:', backendKey);
|
|
|
|
if (shotAccuracyData && shotAccuracyData[backendKey]) {
|
|
hasData = true;
|
|
const typeData = shotAccuracyData[backendKey];
|
|
console.log('Found shot accuracy data for type:', typeData);
|
|
tens = typeData.tens || 0;
|
|
nines = typeData.nines || 0;
|
|
eights = typeData.eights || 0;
|
|
sevens = typeData.sevens || 0;
|
|
sixes = typeData.sixes || 0;
|
|
fives = typeData.fives || 0;
|
|
fours = typeData.fours || 0;
|
|
threes = typeData.threes || 0;
|
|
twos = typeData.twos || 0;
|
|
ones = typeData.ones || 0;
|
|
zeros = typeData.zeros || 0;
|
|
} else {
|
|
console.log('No shot accuracy data found for type:', currentTournamentType, 'mapped to:', backendKey);
|
|
console.log('Full shotAccuracyData object:', shotAccuracyData);
|
|
}
|
|
|
|
if (!hasData) {
|
|
console.log(`No shot accuracy data available for ${currentTournamentType}`);
|
|
return;
|
|
}
|
|
|
|
// Render accuracy bar chart
|
|
createAccuracyChart(tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros);
|
|
|
|
// Render shot count table
|
|
renderShotCountTable([tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros]);
|
|
|
|
console.log(`Shot accuracy for ${currentTournamentType}:`, {
|
|
tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros
|
|
});
|
|
}
|
|
|
|
// Generate solid color array - all bars same color based on tournament type
|
|
function generateColorGradient(baseColor, numColors) {
|
|
// Return array with same color for all bars
|
|
const colors = [];
|
|
for (let i = 0; i < numColors; i++) {
|
|
colors.push(baseColor);
|
|
}
|
|
return colors;
|
|
}
|
|
|
|
// Generate colorful array for overall accuracy - different color for each shot value
|
|
function generateColorfulArray() {
|
|
// Color mapping from green (perfect 10) to red (misses 0): labels are [10,9,8,7,6,5,4,3,2,1,0]
|
|
return [
|
|
'#4A9D6F', // 10 - medium green (perfect)
|
|
'#5BA97A', // 9 - medium green
|
|
'#6CB585', // 8 - medium green
|
|
'#7DC285', // 7 - medium light green
|
|
'#8FCC7F', // 6 - medium lime green
|
|
'#D4B84D', // 5 - medium yellow
|
|
'#CDA642', // 4 - medium golden yellow
|
|
'#D99A5D', // 3 - medium orange
|
|
'#D87A6C', // 2 - medium light orange-red
|
|
'#C85C5C', // 1 - medium red
|
|
'#B84A4A' // 0 - medium dark red (miss)
|
|
];
|
|
}
|
|
|
|
// Create bar chart for shot accuracy distribution using Chart.js
|
|
let accuracyChartInstance = null;
|
|
|
|
function createAccuracyChart(tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros) {
|
|
const canvas = document.getElementById('accuracyChart');
|
|
if (!canvas) {
|
|
console.warn('Accuracy chart canvas not found');
|
|
return;
|
|
}
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Destroy existing chart if it exists
|
|
if (accuracyChartInstance) {
|
|
accuracyChartInstance.destroy();
|
|
}
|
|
|
|
const labels = ['10', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0'];
|
|
const counts = [tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros];
|
|
|
|
// Get the theme color for current tournament type
|
|
const typeConfig = tournamentTypes[currentTournamentType];
|
|
const baseColor = typeConfig.color;
|
|
|
|
// Generate gradient colors from lighter to darker
|
|
const colors = generateColorGradient(baseColor, 11); // 11 bars for 0-10
|
|
|
|
accuracyChartInstance = new Chart(ctx, {
|
|
type: 'bar',
|
|
data: {
|
|
labels: labels,
|
|
datasets: [{
|
|
label: 'Shot Count',
|
|
data: counts,
|
|
backgroundColor: colors,
|
|
borderColor: colors,
|
|
borderWidth: 1,
|
|
borderRadius: 8
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
indexAxis: 'x',
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
backgroundColor: 'rgba(0,0,0,0.7)',
|
|
titleColor: '#fff',
|
|
bodyColor: '#fff',
|
|
padding: 10,
|
|
displayColors: false,
|
|
callbacks: {
|
|
title: function(context) {
|
|
return 'Shot Score: ' + context[0].label;
|
|
},
|
|
label: function(context) {
|
|
return 'Count: ' + context.parsed.y;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true,
|
|
ticks: {
|
|
stepSize: 1,
|
|
color: '#666',
|
|
font: {
|
|
size: 12
|
|
}
|
|
},
|
|
grid: {
|
|
color: '#e9ecef',
|
|
drawBorder: true
|
|
}
|
|
},
|
|
x: {
|
|
ticks: {
|
|
color: '#666',
|
|
font: {
|
|
size: 12,
|
|
weight: 'bold'
|
|
}
|
|
},
|
|
grid: {
|
|
display: false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log('Bar chart created successfully with data:', {tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros});
|
|
|
|
// Create radar chart as well
|
|
createAccuracyRadarChart(tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros);
|
|
}
|
|
|
|
// Create radar chart for shot accuracy
|
|
let accuracyRadarChartInstance = null;
|
|
|
|
function createAccuracyRadarChart(tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros) {
|
|
const canvas = document.getElementById('accuracyRadarChart');
|
|
if (!canvas) {
|
|
console.warn('Accuracy radar chart canvas not found');
|
|
return;
|
|
}
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Destroy existing chart if it exists
|
|
if (accuracyRadarChartInstance) {
|
|
accuracyRadarChartInstance.destroy();
|
|
}
|
|
|
|
const labels = ['10', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0'];
|
|
const counts = [tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros];
|
|
const typeConfig = tournamentTypes[currentTournamentType];
|
|
|
|
accuracyRadarChartInstance = new Chart(ctx, {
|
|
type: 'radar',
|
|
data: {
|
|
labels: labels,
|
|
datasets: [{
|
|
label: 'Shot Count',
|
|
data: counts,
|
|
fill: true,
|
|
backgroundColor: typeConfig.color + '30',
|
|
borderColor: typeConfig.color,
|
|
borderWidth: 2,
|
|
pointRadius: 5,
|
|
pointBackgroundColor: typeConfig.color,
|
|
pointBorderColor: '#fff',
|
|
pointBorderWidth: 2,
|
|
pointHoverRadius: 7
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
legend: { display: false }
|
|
},
|
|
scales: {
|
|
r: {
|
|
beginAtZero: true,
|
|
ticks: {
|
|
color: '#666',
|
|
font: { size: 10 }
|
|
},
|
|
grid: {
|
|
color: '#e9ecef'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log('Radar chart created successfully with data:', {tens, nines, eights, sevens, sixes, fives, fours, threes, twos, ones, zeros});
|
|
}
|
|
|
|
// Create chart for current tournament type
|
|
function createChart(tournaments) {
|
|
const canvas = document.getElementById('tournamentChart');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// Destroy existing chart if it exists
|
|
if (currentChart) {
|
|
currentChart.destroy();
|
|
}
|
|
|
|
if (tournaments.length === 0) {
|
|
// Show no data message
|
|
ctx.font = '16px Arial';
|
|
ctx.fillStyle = '#666';
|
|
ctx.textAlign = 'center';
|
|
ctx.fillText(`No ${currentTournamentType} tournaments found`, canvas.width / 2, canvas.height / 2);
|
|
return;
|
|
}
|
|
|
|
const typeConfig = tournamentTypes[currentTournamentType];
|
|
const scores = tournaments.map(t => t.score);
|
|
|
|
currentChart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: scores.map((_, i) => `${i + 1}`),
|
|
datasets: [{
|
|
label: `${currentTournamentType} Score`,
|
|
data: scores,
|
|
borderColor: typeConfig.color,
|
|
backgroundColor: typeConfig.color + '20',
|
|
borderWidth: 5,
|
|
fill: true,
|
|
tension: 0.4,
|
|
pointRadius: 6,
|
|
pointHoverRadius: 10,
|
|
pointBackgroundColor: typeConfig.color,
|
|
pointBorderColor: '#fff',
|
|
pointBorderWidth: 3,
|
|
pointHoverBackgroundColor: typeConfig.color,
|
|
pointHoverBorderColor: '#fff'
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
backgroundColor: typeConfig.color + 'E6',
|
|
titleColor: '#fff',
|
|
bodyColor: '#fff',
|
|
borderColor: typeConfig.color,
|
|
borderWidth: 2,
|
|
callbacks: {
|
|
title: function(context) {
|
|
const tournament = tournaments[context[0].dataIndex];
|
|
return `Game ${context[0].dataIndex + 1} - ${tournament.date.split(' ')[0]}`;
|
|
},
|
|
label: function(context) {
|
|
const tournament = tournaments[context.dataIndex];
|
|
const labels = [`Score: ${context.parsed.y}`, `Shots: ${tournament.shots_fired}`];
|
|
|
|
// Add tournament type if available
|
|
if (tournament.tournament_type) {
|
|
labels.push(`Type: ${tournament.tournament_type.replace('_', ' ')}`);
|
|
}
|
|
|
|
// Add shot breakdown if available
|
|
if (tournament.shot_breakdown) {
|
|
const breakdown = tournament.shot_breakdown;
|
|
const shots = [];
|
|
if (breakdown.tens) shots.push(`10s: ${breakdown.tens}`);
|
|
if (breakdown.nines) shots.push(`9s: ${breakdown.nines}`);
|
|
if (breakdown.eights) shots.push(`8s: ${breakdown.eights}`);
|
|
if (breakdown.sevens) shots.push(`7s: ${breakdown.sevens}`);
|
|
if (breakdown.sixes) shots.push(`6s: ${breakdown.sixes}`);
|
|
if (breakdown.fives) shots.push(`5s: ${breakdown.fives}`);
|
|
if (breakdown.fours) shots.push(`4s: ${breakdown.fours}`);
|
|
if (breakdown.threes) shots.push(`3s: ${breakdown.threes}`);
|
|
if (breakdown.twos) shots.push(`2s: ${breakdown.twos}`);
|
|
if (breakdown.ones) shots.push(`1s: ${breakdown.ones}`);
|
|
if (breakdown.zeros) shots.push(`0s: ${breakdown.zeros}`);
|
|
|
|
if (shots.length > 0) {
|
|
// Show only top scoring shots to keep tooltip readable
|
|
const topShots = shots.slice(0, 5);
|
|
labels.push(topShots.join(', '));
|
|
if (shots.length > 5) {
|
|
labels.push('+ more...');
|
|
}
|
|
}
|
|
}
|
|
|
|
return labels;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true,
|
|
grid: {
|
|
color: typeConfig.color + '20'
|
|
},
|
|
ticks: {
|
|
color: typeConfig.color,
|
|
font: { size: 12, weight: 'bold' }
|
|
}
|
|
},
|
|
x: {
|
|
grid: {
|
|
color: typeConfig.color + '20'
|
|
},
|
|
ticks: {
|
|
color: typeConfig.color,
|
|
font: { size: 12, weight: 'bold' }
|
|
}
|
|
}
|
|
},
|
|
interaction: {
|
|
intersect: false,
|
|
mode: 'index'
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
if (window.self !== window.top) document.body.classList.add('in-iframe');
|
|
|
|
// Initialize page when i18n is ready
|
|
window.addEventListener('i18nReady', initializePage);
|
|
</script>
|
|
</body>
|
|
</html> |