Public
Edited
Nov 6, 2022
Insert cell
Insert cell
target_year = 2022 // 2013-2021
Insert cell
WordCloud(keywords_years_top60, { width: 1200, height: 600, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2013, { width: 1000, height: 400, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2014, { width: 900, height: 350, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2015, { width: 850, height: 350, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2016, { width: 950, height: 350, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2017, { width: 950, height: 350, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2018, { width: 1000, height: 400, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2019, { width: 900, height: 350, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2020, { width: 1000, height: 450, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2021, { width: 1100, height: 450, invalidation })
Insert cell
WordCloud(keywords_30_20_uni_bi_2022, { width: 900, height: 350, invalidation })
Insert cell
Insert cell
fill = d3.scaleOrdinal(d3.schemeCategory10)
Insert cell
WordCloud = {
function WordCloud(text, {
size = group => group.length, // Given a grouping of words, returns the size factor for that word
word = d => d, // Given an item of the data array, returns the word
marginTop = 0, // top margin, in pixels
marginRight = 0, // right margin, in pixels
marginBottom = 0, // bottom margin, in pixels
marginLeft = 0, // left margin, in pixels
width = 640, // outer width, in pixels
height = 400, // outer height, in pixels
maxWords = 250, // maximum number of words to extract from the text
fontFamily = "sans-serif", // font family
fontScale = 15, // base font size
padding = 0, // amount of padding between the words (in pixels)
rotate = 0, // a constant or function to rotate the words
invalidation // when this promise resolves, stop the simulation
} = {}) {
const words = typeof text === "string" ? text.split(/\W+/g) : Array.from(text);
const data = d3.rollups(words, size, w => w)
.sort(([, a], [, b]) => d3.descending(a, b))
.slice(0, maxWords)
.map(([key, size]) => ({text: word(key), size}));
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", width)
.attr("font-family", fontFamily)
.attr("text-anchor", "middle")
.attr("style", "max-width: 100%; height: auto; height: intrinsic;");
const g = svg.append("g").attr("transform", `translate(${marginLeft},${marginTop})`);

const debug = []
const cloud = d3Cloud()
.size([width - marginLeft - marginRight, height - marginTop - marginBottom])
.words(data)
.padding(padding)
.rotate(rotate)
.font(fontFamily)
.fontSize(d => Math.sqrt(d.size) * fontScale)
.on("word", ({size, x, y, rotate, text}) => {
g.append("text")
.attr("font-size", size)
.attr("transform", `translate(${x},${y}) rotate(${rotate})`)
.attr("fill", _ => fill(size * 2)) // 2, 5, 14, 15, 16
.text(text);
});
cloud.start();
invalidation && invalidation.then(() => cloud.stop());
return svg.node();
}
return WordCloud
}
Insert cell
final_30_20_uni_bi = FileAttachment("30_20_uni_bi.json").json()
Insert cell
years_top60 = FileAttachment("10years_top60.json").json()
Insert cell
keywords_30_20_uni_bi_2013 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2013])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2014 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2014])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2015 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2015])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2016 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2016])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2017 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2017])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2018 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2018])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2019 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2019])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2020 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2020])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2021 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2021])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_30_20_uni_bi_2022 = {
var keywords = []
for (var [i, j] of Object.entries(final_30_20_uni_bi[2022])) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i.toLowerCase()))
}
return keywords
}
Insert cell
keywords_years_top60 = {
var keywords = []
for (var [i, j] of Object.entries(years_top60)) {
keywords = keywords.concat(new Array(Math.round(j)).fill(i))
}
return keywords
}
Insert cell
d3 = import("d3@6")
Insert cell
d3Cloud = require("d3-cloud@1")
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