Spaces:
Running
Running
thibaud frere
commited on
Commit
·
95e6b80
1
Parent(s):
c59bbe1
update
Browse files
app/src/content/chapters/available-blocks.mdx
CHANGED
|
@@ -340,7 +340,7 @@ desc={`Memory usage with recomputation — <a href="https://huggingface.co/space
|
|
| 340 |
<HtmlEmbed
|
| 341 |
src="d3-pie.html"
|
| 342 |
title="Category distribution (4 metrics)"
|
| 343 |
-
desc="Pie charts by category
|
| 344 |
align="center"
|
| 345 |
/>
|
| 346 |
</FullWidth>
|
|
|
|
| 340 |
<HtmlEmbed
|
| 341 |
src="d3-pie.html"
|
| 342 |
title="Category distribution (4 metrics)"
|
| 343 |
+
desc="Pie charts by category"
|
| 344 |
align="center"
|
| 345 |
/>
|
| 346 |
</FullWidth>
|
app/src/content/embeds/d3-pie.html
CHANGED
|
@@ -52,20 +52,11 @@
|
|
| 52 |
{ key:'total_images', name:'Number of Images', title:'Weighted by Number of Images', letter:'d' }
|
| 53 |
];
|
| 54 |
|
| 55 |
-
// CSV:
|
| 56 |
const CSV_PATHS = [
|
| 57 |
-
'/data/finevision.csv'
|
| 58 |
-
'/assets/data/finevision.csv',
|
| 59 |
-
'./assets/data/finevision.csv',
|
| 60 |
-
'../assets/data/finevision.csv',
|
| 61 |
-
'../../assets/data/finevision.csv'
|
| 62 |
];
|
| 63 |
|
| 64 |
-
const getInlineCsv = () => {
|
| 65 |
-
const el = container.querySelector('script.d3-pie__csv[type="text/csv"]');
|
| 66 |
-
return el ? el.textContent.trim() : '';
|
| 67 |
-
};
|
| 68 |
-
|
| 69 |
const fetchFirstAvailable = async (paths) => {
|
| 70 |
for (const p of paths) {
|
| 71 |
try {
|
|
@@ -73,7 +64,7 @@
|
|
| 73 |
if (res.ok) { return await res.text(); }
|
| 74 |
} catch (_) { /* try next */ }
|
| 75 |
}
|
| 76 |
-
throw new Error('CSV
|
| 77 |
};
|
| 78 |
|
| 79 |
const parseCsv = (text) => d3.csvParse(text, (d) => ({
|
|
@@ -101,7 +92,7 @@
|
|
| 101 |
const legendHeight = 60;
|
| 102 |
gLegend.attr('x', 0).attr('y', innerHeight + LEGEND_GAP).attr('width', innerWidth).attr('height', legendHeight);
|
| 103 |
const root = gLegend.selectAll('div').data([0]).join('xhtml:div');
|
| 104 |
-
root.html(`<div class="items">${categories.map(c => `<div class="item"><span class="swatch" style="background:${colorOf(c)}"></span><span style="font-weight:
|
| 105 |
}
|
| 106 |
|
| 107 |
function drawPies(rows){
|
|
@@ -199,8 +190,7 @@
|
|
| 199 |
|
| 200 |
async function init(){
|
| 201 |
try {
|
| 202 |
-
|
| 203 |
-
if (!text) { text = await fetchFirstAvailable(CSV_PATHS); }
|
| 204 |
const rows = parseCsv(text);
|
| 205 |
drawPies(rows);
|
| 206 |
|
|
|
|
| 52 |
{ key:'total_images', name:'Number of Images', title:'Weighted by Number of Images', letter:'d' }
|
| 53 |
];
|
| 54 |
|
| 55 |
+
// CSV: load from public path
|
| 56 |
const CSV_PATHS = [
|
| 57 |
+
'/data/finevision.csv'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
];
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
const fetchFirstAvailable = async (paths) => {
|
| 61 |
for (const p of paths) {
|
| 62 |
try {
|
|
|
|
| 64 |
if (res.ok) { return await res.text(); }
|
| 65 |
} catch (_) { /* try next */ }
|
| 66 |
}
|
| 67 |
+
throw new Error('CSV not found: finevision.csv');
|
| 68 |
};
|
| 69 |
|
| 70 |
const parseCsv = (text) => d3.csvParse(text, (d) => ({
|
|
|
|
| 92 |
const legendHeight = 60;
|
| 93 |
gLegend.attr('x', 0).attr('y', innerHeight + LEGEND_GAP).attr('width', innerWidth).attr('height', legendHeight);
|
| 94 |
const root = gLegend.selectAll('div').data([0]).join('xhtml:div');
|
| 95 |
+
root.html(`<div class="items">${categories.map(c => `<div class="item"><span class="swatch" style="background:${colorOf(c)}"></span><span style="font-weight:500">${c}</span></div>`).join('')}</div>`);
|
| 96 |
}
|
| 97 |
|
| 98 |
function drawPies(rows){
|
|
|
|
| 190 |
|
| 191 |
async function init(){
|
| 192 |
try {
|
| 193 |
+
const text = await fetchFirstAvailable(CSV_PATHS);
|
|
|
|
| 194 |
const rows = parseCsv(text);
|
| 195 |
drawPies(rows);
|
| 196 |
|