Published
Edited
Oct 18, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
${ tweets.map(t => tweet(t.to_tweetid)) }
Insert cell
Insert cell
politicians = {
let all = [ ...new Set(tutotal.map(t => t.plus.concat(t.minus)).flat()) ]

let scores = all.map( a => {
let who = a
let plus = d3.sum(tutotal.map( t => t.plus.includes(who)? 1 : 0 ))
let minus = d3.sum(tutotal.map( t => t.minus.includes(who)? -1 : 0 ))
let total = plus + minus
return { who, total, plus, minus }
})
return { scores }
}
Insert cell
Insert cell
tutotal = {
return tweets.map(tweet => {
let replyTo = tweet['to_tweetid']
let plus = []
let minus = []
let text = tweet.text
let parts = text.split(' ')
let markers = ['+1', '-1']
let points = new Map()
markers.map(marker => points.set(marker, []))
let current_marker = ''
for (const part of parts) {
if(markers.includes(part)){
current_marker = part
} else {
if(markers.includes(current_marker)){
(points.get(current_marker)).push(part.toLowerCase())
}
}
}
plus = points.get('+1')
minus = points.get('-1')
return { text, replyTo, plus, minus }
})
}
Insert cell
tweets = d3.csv('https://raw.githubusercontent.com/taniki/tutotal2022/main/tutotal2022-taniki.csv')
Insert cell
import { tweet } from '@mbostock/tweet'
Insert cell
d3 = require('d3')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more