Skip to content

Commit fa0c896

Browse files
committed
pie chart v2
1 parent 0d85ac3 commit fa0c896

1 file changed

Lines changed: 64 additions & 55 deletions

File tree

index.html

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -108,64 +108,73 @@ <h1>PS2 Classics on PS3</h1>
108108
Part of the PS3 Classics Project · <a href="https://github.com/ps3classics" style="color:#fff">GitHub</a>
109109
</footer>
110110

111-
<script>
112-
async function loadData() {
113-
try {
114-
const response = await fetch("data.json");
115-
const { stats, last_updated } = await response.json();
116-
117-
document.getElementById("last-updated").textContent =
118-
"Last updated: " + last_updated;
119-
120-
const ctx = document.getElementById("compatChart").getContext("2d");
121-
122-
// Chart with legend white + drop shadow plugin
123-
new Chart(ctx, {
124-
type: "pie",
125-
data: {
126-
labels: Object.keys(stats),
127-
datasets: [{
128-
data: Object.values(stats),
129-
backgroundColor: [
130-
"rgb(0, 136, 238)", // PS2 Classic - blue
131-
"rgb(153, 221, 153)", // Playable - green
132-
"rgb(238, 238, 136)", // Minor Issues - yellow
133-
"rgb(238, 153, 51)", // Major Issues - orange
134-
"rgb(238, 68, 68)", // Unplayable - red
135-
"rgb(187, 187, 187)" // Untested - gray
136-
]
137-
}]
138-
},
139-
options: {
140-
plugins: {
141-
legend: {
142-
labels: {
143-
color: "white"
144-
}
111+
<script>
112+
async function loadData() {
113+
try {
114+
const response = await fetch("data.json");
115+
const { stats, last_updated } = await response.json();
116+
117+
document.getElementById("last-updated").textContent =
118+
"Last updated: " + last_updated;
119+
120+
// Merge PS2 Classic + Playable into "Perfect" for homepage
121+
const mergedStats = {
122+
"Perfect": (stats["PS2 Classic"] || 0) + (stats["Playable"] || 0),
123+
"Playable": stats["Minor Issues"] || 0,
124+
"Major Issues": stats["Major Issues"] || 0,
125+
"Unplayable": stats["Unplayable"] || 0,
126+
"Untested": stats["Untested"] || 0
127+
};
128+
129+
const colorMap = {
130+
"Perfect": "rgb(91, 192, 222)", // Dolphin blue
131+
"Playable": "rgb(153, 221, 153)", // green
132+
"Major Issues": "rgb(238, 153, 51)", // orange
133+
"Unplayable": "rgb(238, 68, 68)", // red
134+
"Untested": "rgb(187, 187, 187)" // gray
135+
};
136+
137+
const ctx = document.getElementById("compatChart").getContext("2d");
138+
139+
new Chart(ctx, {
140+
type: "pie",
141+
data: {
142+
labels: Object.keys(mergedStats),
143+
datasets: [{
144+
data: Object.values(mergedStats),
145+
backgroundColor: Object.keys(mergedStats).map(label => colorMap[label])
146+
}]
147+
},
148+
options: {
149+
plugins: {
150+
legend: {
151+
labels: {
152+
color: "white"
145153
}
146154
}
147-
},
148-
plugins: [{
149-
id: 'shadow',
150-
beforeDraw: (chart) => {
151-
const ctx = chart.ctx;
152-
ctx.save();
153-
ctx.shadowColor = "rgba(0,0,0,0.6)";
154-
ctx.shadowBlur = 20;
155-
ctx.shadowOffsetX = 4;
156-
ctx.shadowOffsetY = 4;
157-
ctx.restore();
158-
}
159-
}]
160-
});
161-
} catch (err) {
162-
document.getElementById("last-updated").textContent =
163-
"Data could not be loaded.";
164-
console.error(err);
165-
}
155+
}
156+
},
157+
plugins: [{
158+
id: 'shadow',
159+
beforeDraw: (chart) => {
160+
const ctx = chart.ctx;
161+
ctx.save();
162+
ctx.shadowColor = "rgba(0,0,0,0.6)";
163+
ctx.shadowBlur = 20;
164+
ctx.shadowOffsetX = 4;
165+
ctx.shadowOffsetY = 4;
166+
ctx.restore();
167+
}
168+
}]
169+
});
170+
} catch (err) {
171+
document.getElementById("last-updated").textContent =
172+
"Data could not be loaded.";
173+
console.error(err);
166174
}
175+
}
167176

168-
loadData();
169-
</script>
177+
loadData();
178+
</script>
170179
</body>
171180
</html>

0 commit comments

Comments
 (0)