Published
Edited
Jun 22, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {WordCloud} from "@d3/word-cloud"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Ulysses = (await FileAttachment("4300-0.txt").text()).replaceAll('\r','')
Insert cell
Insert cell
chapters = [ '[ 1 ]', '[ 2 ]', '[ 3 ]', '[ 4 ]', '[ 5 ]', '[ 6 ]', '[ 7 ]', '[ 8 ]', '[ 9 ]',
'[ 10 ]', '[ 11 ]', '[ 12 ]', '[ 13 ]', '[ 14 ]', '[ 15 ]', '[ 16 ]', '[ 17 ]', '[ 18 ]']
Insert cell
UlyssesParts = [
{Part: 'The Telemachiad',id:1},
{Part: 'The Odyssey',id:2},
{Part: 'The Nostos',id:3}
]
Insert cell
Insert cell
chapterData[0].text
Insert cell
chapterData = {
let CD = [
{name:'Telemachus',part:1,chapter:1},
{name:'Nestor',part:1,chapter:2},
{name:'Proteus',part:1,chapter:3},
{name:'Calypso',part:2,chapter:4},
{name:'Lotus Eaters',part:2,chapter:5},
{name:'Hades',part:2,chapter:6},
{name:'Aeolus',part:2,chapter:7},
{name:'Lestrygonians',part:2,chapter:8},
{name:'Scylla and Charybdis',part:2,chapter:9},
{name:'Wandering Rocks',part:2,chapter:10},
{name:'Sirens',part:2,chapter:11},
{name:'Cyclops',part:2,chapter:12},
{name:'Nausicaa',part:2,chapter:13},
{name:'Oxen of the Sun',part:2,chapter:14},
{name:'Circe',part:2,chapter:15},
{name:'Eumaeus',part:3,chapter:16},
{name:'Ithaca',part:3,chapter:17},
{name:'Penelope',part:3,chapter:18}
]
let tableOfcontents = Ulysses.indexOf('[ 1 ]') // start of table of contents
let start = Ulysses.indexOf('[ 1 ]',tableOfcontents+1) // where the first chapter starts

let idx = [start] // start of book after table of contence.
CD[0].start = start
for (let i = 1; i < chapters.length; ++i) {
idx.push(Ulysses.indexOf(chapters[i],idx[i-1]+1))
CD[i].start = Ulysses.indexOf(chapters[i],idx[i-1]+1)
CD[i-1].end = CD[i].start
}

CD[17].end = Ulysses.indexOf('Trieste-Zurich-Paris') // end of book
CD.map( (d) => d.text = Ulysses.slice(d.start+6, d.end).replaceAll('\n',' ').trim()) // split the chapters and replace new lines with spaces

return CD
}
Insert cell
Insert cell
// words = {
// let text = ''
// for (let i = 0; i < chapterData.length; ++i) {
// text = text + " " + chapterData[i].text
// }
// return _.words(text.replace(/\d+/g, '')) // remove numbers
// }
Insert cell
words = FileAttachment("words.json").json()
Insert cell
Insert cell
uwords = _.uniq(words)
Insert cell
UlyssesWordOccurences = uwords.map(d => [d.length,d])
Insert cell
// who needs regex :P
sentences = chapterData[chapter-1].text.split('!').join('🥝').split('?').join('🥝').split('.').join('🥝').split('🥝')
Insert cell
Insert cell
colours = {
let nibble = _.words(chapterData[chap-1].text).map(d =>{
return d.length.toString(16)
})

for (let i = 0; i < nibble.length; i+=2) {
nibble[i]+=nibble[i+1]
nibble[i+1]=null
}

nibble = _.compact(nibble)

let cl = ~~(nibble.length/3)
let colours = []
for (let i = 0; i < cl; i+=3) {
colours.push(`#${nibble[i]}${nibble[i+1]}${nibble[i+2]}`)
}
return colours.sort()
}
Insert cell
Insert cell
H = d3.scaleLinear()
.domain([1, 20]) // unit: km
.range([1, 320]) // unit: pixels
Insert cell
S = d3.scaleLinear()
.domain([1, 20]) // unit: km
.range([0, 2]) // unit: pixels
Insert cell
L = d3.scaleLinear()
.domain([1, 20]) // unit: km
.range([0.2, 0.9]) // unit: pixels
Insert cell
w = 600
Insert cell
b = w/8
Insert cell
import {p5 as p5js} from "@tmcw/p5"
Insert cell
chroma = require('chroma-js@2.4.2/chroma.js')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more