-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmlb.html
More file actions
239 lines (227 loc) · 7.66 KB
/
mlb.html
File metadata and controls
239 lines (227 loc) · 7.66 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2025 MLB Home Run Leaders & Projections - All Players (with Position)</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #f0f4f8;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
box-sizing: border-box;
}
.container {
background-color: #ffffff;
border-radius: 15px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
padding: 30px;
width: 100%;
max-width: 800px;
text-align: center;
}
h1 {
color: #1a202c;
margin-bottom: 25px;
font-size: 2.25rem; /* text-4xl */
font-weight: 700; /* font-bold */
}
.chart-container {
position: relative;
height: 400px;
width: 100%;
margin-top: 30px;
}
.bar {
transition: height 0.5s ease-out;
}
.tooltip {
position: absolute;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 8px 12px;
border-radius: 8px;
font-size: 0.875rem;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease-in-out;
z-index: 10;
white-space: nowrap;
}
.tooltip.active {
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-4xl font-bold text-gray-900">2025 MLB Home Run Leaders & Projections - All MLB Players</h1>
<p class="text-lg text-gray-600 mb-2">Current home run totals and projected full-season totals (as of May 31, 2025)</p>
<p id="gameInfo" class="text-md text-gray-500 mb-6"></p>
<div class="chart-container">
<canvas id="homeRunChart"></canvas>
</div>
<div class="mt-8 text-left">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">MLB Home Run Leaders:</h2>
<ul id="playerList" class="list-disc list-inside text-gray-700">
</ul>
<p class="text-sm text-gray-500 mt-4">
*Actual results may vary due to performance fluctuations, injuries, and other factors. Detailed position and games played may not be available for all players in this league-wide view. Batting order information is not available. The term '162-game season' is used as a general reference point.
</p>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
// Data for the Detroit Tigers home run hitters in the 2025 season (as of May 31, 2025)
// Source: FOX Sports, StatMuse, and Yahoo Sports MLB stats (current as of search date)
const allHrData = [
{ name: "Spencer Torkelson", team: "DET", currentHr: 14, gamesPlayed: 56, position: "1B" },
{ name: "Riley Greene", team: "DET", currentHr: 13, gamesPlayed: 56, position: "LF" },
{ name: "Kerry Carpenter", team: "DET", currentHr: 10, gamesPlayed: 53, position: "RF" },
{ name: "Javier Báez", team: "DET", currentHr: 6, gamesPlayed: 47, position: "CF" },
{ name: "Gleyber Torres", team: "DET", currentHr: 5, gamesPlayed: 44, position: "2B" },
{ name: "Dillon Dingler", team: "DET", currentHr: 4, gamesPlayed: 41, position: "C" },
{ name: "Colt Keith", team: "DET", currentHr: 4, gamesPlayed: 50, position: "2B" },
{ name: "Trey Sweeney", team: "DET", currentHr: 4, gamesPlayed: 55, position: "SS" },
{ name: "Zach McKinstry", team: "DET", currentHr: 3, gamesPlayed: 51, position: "RF" },
{ name: "Andy Ibáñez", team: "DET", currentHr: 2, gamesPlayed: 40, position: "3B" },
{ name: "Justyn-Henry Malloy", team: "DET", currentHr: 1, gamesPlayed: 44, position: "RF" },
{ name: "Wenceel Pérez", team: "DET", currentHr: 1, gamesPlayed: 2, position: "CF" }
];
// Overall MLB Home Run Leaders (as of May 31, 2025) - This data is manually compiled from search results.
// In a real-world application, this would come from a live API.
const mlbHrLeaders = [
{ name: "Shohei Ohtani", hr: 22 },
{ name: "Cal Raleigh", hr: 21 },
{ name: "Aaron Judge", hr: 19 },
{ name: "Kyle Schwarber", hr: 19 },
{ name: "Corbin Carroll", hr: 16 },
{ name: "James Wood", hr: 16 },
// Assuming some other players would be around this range based on previous data
{ name: "Pete Crow-Armstrong", hr: 15 }, // Kept from previous, adjust if new data contradicts
{ name: "Eugenio Suárez", hr: 15 }, // Kept from previous
{ name: "Taylor Ward", hr: 15 }, // Kept from previous
{ name: "Spencer Torkelson", hr: 14 }, // DET - Updated
{ name: "Logan O'Hoppe", hr: 14 }, // Kept from previous
{ name: "Seiya Suzuki", hr: 14 }, // Kept from previous
{ name: "Riley Greene", hr: 13 }, // DET - Updated
// Add a few more if they were close and not surpassed by much
{ name: "Matt Olson", hr: 12 }, // From original data, as a placeholder if still relevant
{ name: "Kyle Tucker", hr: 12 } // From original data
];
const totalSeasonGames = 162;
// Update the game info paragraph
document.getElementById('gameInfo').textContent = "Displaying league-wide MLB home run data. Projections are based on a 162-game season.";
// Filter data to only include Detroit Tigers players who have played at least 70% of the current season's games
// const hrData = allHrData.filter(player => player.gamesPlayed >= minGamesForCurrent70Percent);
const hrData = mlbHrLeaders.map(player => ({ ...player, currentHr: player.hr, name: player.name, position: player.position || 'N/A', gamesPlayed: player.gamesPlayed || 0 }));
// Sort data by projected total home runs in descending order for better visual grouping
hrData.sort((a, b) => b.projectedHr - a.projectedHr);
// Prepare labels and data for the chart
// Changed label formatting to put percentile on a new line
const labels = hrData.map(player => `${player.name} (${player.position})`);
const currentHomeRuns = hrData.map(player => player.currentHr);
// Get the canvas element
const ctx = document.getElementById('homeRunChart').getContext('2d');
// Destroy existing chart instance if it exists to prevent conflicts
if (window.homeRunChartInstance) {
window.homeRunChartInstance.destroy();
}
// Create the bar chart
window.homeRunChartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: 'Current Home Runs',
data: currentHomeRuns,
backgroundColor: 'rgba(255, 159, 64, 0.8)', // Orange for current
borderColor: 'rgba(255, 159, 64, 1)',
borderWidth: 1,
borderRadius: 8,
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
indexAxis: 'y', // Make it a horizontal bar chart
plugins: {
legend: {
display: true, // Show legend for current vs. projected
position: 'top',
labels: {
color: '#4a5568'
}
},
tooltip: {
callbacks: {
title: function(context) {
// For stacked bars, context[0].label might contain both lines.
// We want just the name and position for the tooltip title.
const fullLabel = context[0].label;
return fullLabel.split('\n')[0]; // Get only the first line
},
label: function(context) {
let datasetLabel = context.dataset.label || 'HR'; // Fallback label
return `${datasetLabel}: ${context.raw}`;
}
}
}
},
scales: {
x: {
beginAtZero: true,
stacked: false, // Crucial for stacking bars
title: {
display: true,
text: 'Home Runs',
color: '#4a5568'
},
ticks: {
color: '#4a5568'
},
grid: {
color: 'rgba(203, 213, 224, 0.5)'
}
},
y: {
stacked: false, // Crucial for stacking bars
title: {
display: true,
text: 'Player',
color: '#4a5568'
},
ticks: {
color: '#4a5568'
},
grid: {
color: 'rgba(203, 213, 224, 0.5)'
}
}
}
}
});
// Populate the player list below the chart
const playerList = document.getElementById('playerList');
playerList.innerHTML = ''; // Clear previous list items
if (hrData.length === 0) {
const noDataMessage = document.createElement('li');
noDataMessage.textContent = "No Detroit Tigers players found who have played in at least 70% of the team's games to date.";
playerList.appendChild(noDataMessage);
} else {
hrData.forEach(player => {
const listItem = document.createElement('li');
listItem.textContent = `${player.name} (${player.position}): Current HR: ${player.currentHr}`;
playerList.appendChild(listItem);
});
}
</script>
</body>
</html>