heatData = {
const data = d3.csvParse(await FileAttachment("teotw-chapter-pov@2.csv").text(), ({character, chapter_abbr, chapter_order, chapter, word_count}) => ({character, chapter, chapter_abbr, chapter_order: +chapter_order, word_count: +word_count}))
const names = [... new Set(data.map(({character}) => character))];
const values = []
const [firstChapter, lastChapter] = d3.extent(data, d => d.chapter_order)
const chapters = d3.range(firstChapter, lastChapter + 1);
const chapterNames = chapters.map(chapterOrder => data.find(d => d.chapter_order === chapterOrder).chapter);
for (const pov of data) {
const idx = names.findIndex(name => name === pov.character);
(values[idx] || (values[idx] = new Array(chapters.length).fill(0)))[pov.chapter_order - firstChapter] += pov.word_count;
}
return {
names,
values,
chapters,
chapterNames,
chapter_divisor: 30,
firstChapter
};
}