Public
Edited
Jan 20
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
runAnimation = (svg, clickedNode, width, animationInterval) => {
const tweets = clickedNode.posts.map((m) => m.Tweet);
const highlightWord = clickedNode.Keyword;
const nodeFill = clickedNode.sentimentSum < 0 ? colors.red : colors.green;
// clear tweet text (and remove tspans)
svg.selectAll(".tweetText").text("").selectAll("tspan").remove();

const populateText = (textClass, tweet, word, textOrder) => {
if (!tweet) return;
const transformY = 5 + 145 * textOrder;

svg
.select(`.${textClass}`)
.text(tweet)
.call(wrap, width * 0.3, 16, word, nodeFill, transformY);
};

//populate tweet text (and call wrap passing in the word)
populateText("tweetText1", tweets[0], highlightWord, 0);
populateText("tweetText2", tweets[1], highlightWord, 1);
populateText("tweetText3", tweets[2], highlightWord, 2);
populateText("tweetText4", tweets[3], highlightWord, 3);
populateText("tweetText5", tweets[4], highlightWord, 4);

let currentTweetIndex = 5;

debugger;
animationInterval = setInterval(() => {
populateText("tweetText1", tweets[currentTweetIndex], highlightWord, 0);
populateText("tweetText2", tweets[currentTweetIndex + 1], highlightWord, 1);
populateText("tweetText3", tweets[currentTweetIndex + 2], highlightWord, 2);
populateText("tweetText4", tweets[currentTweetIndex + 3], highlightWord, 3);
populateText("tweetText5", tweets[currentTweetIndex + 4], highlightWord, 4);
if (tweets[currentTweetIndex + 5]) {
currentTweetIndex += 5;
} else {
currentTweetIndex = 0;
}
}, 3000);

return animationInterval;

//if > 3, loop (until end then restart)
}
Insert cell
Insert cell
Insert cell
Insert cell
fifaWithKeywords = fifa_world_cup_2022_tweets.reduce((acc, dataEntry) => {
const entry = dataEntry;
const posts = top50.filter((f) => dataEntry.Tweet.includes(` ${f} `));
}, [])
Insert cell
top503.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
top502.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
top50.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
fifa_world_cup_2022_tweets.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
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