Published
Edited
Sep 30, 2020
2 forks
Importers
14 stars
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
sortedEmojis = sorted.map(d => d.Emoji)
Insert cell
sizeScale = d3
.scaleLog()
.domain(d3.extent(emojis, d => d.Occurrences))
.range([2, 64])
Insert cell
opacityScale = d3
.scaleLinear()
.domain(d3.extent(emojis, d => d.Occurrences))
.range([0.1, 1])
Insert cell
emojis = FileAttachment("Emoji_Sentiment_Data_v1.0.csv").csv({ typed: false })
Insert cell
emojisWithMoreData = emojis.map(e => {
e.descLength = e['Unicode name'].length;
e.descWords = e['Unicode name'].split(' ').length;
// e.topColors = topColors(e.Emoji);
return e;
})
Insert cell
//sorted = emojisWithMoreData.sort((a, b) => b.Occurrences - a.Occurrences)
sorted = emojis.sort((a, b) => a.descWords - b.descWords)
Insert cell
Insert cell
// chosen = ({
// // Emoji: "🙈"
// // Emoji: "😱"
// Emoji: "🍁"
// })
// //sorted[6]
Insert cell
// viewof chosen = Scrubber(emojisWithMoreData, {
// delay: 2500,
// autoplay: false,
// format: e => e.Emoji
// })
Insert cell
// chosen = ({ Emoji: "🔥" })
Insert cell
fontSize = 40
Insert cell
canvasSize = fontSize + 10
Insert cell
emojipixels = emojicanvas
.getContext("2d")
.getImageData(0, 0, canvasSize, canvasSize)
Insert cell
seedSize = 100
Insert cell
Insert cell
Insert cell
result = dominantColors(chosen)
Insert cell
topcolors = result.centroids
.filter(d => {
return d.variance && (d[0] < 253 && d[1] < 253 && d[2] < 253);
})
.map(d => {
return {
color: d,
value: d.points.length
};
})
.sort((a, b) => b.value - a.value)
Insert cell
// preprocessed = sorted.slice(0, 1000).map(d => {
// console.log(d.Emoji);
// return {
// ...d,
// topColors: dominantColors(d.Emoji)
// .centroids.filter(d => {
// return d.variance && (d[0] < 252 && d[1] < 252 && d[2] < 252);
// })
// .map(d => {
// return {
// color: d,
// value: d.points.length
// };
// })
// .sort((a, b) => b.value - a.value)
// };
// })
Insert cell
Insert cell
promises = files.map(file => file.json())
Insert cell
datasets = Promise.all(promises)
Insert cell
Insert cell
treemapWidth = 100
Insert cell
treemapHeight = 100
Insert cell
Insert cell
data = ({
name: "emojis",
children: topcolors
})
Insert cell
root = d3
.hierarchy(data)
.sum(d => d.value)
.sort((a, b) => b.value - a.value)
Insert cell
Insert cell
pixelSize = 10
Insert cell
reconstructed = {
let canvas = d3
.create("canvas")
.attr("width", canvasSize * pixelSize)
.attr("height", canvasSize * pixelSize)
.node();
// canvas.width = `${canvasSize}px`;
// canvas.height = `${canvasSize}px`;

let ctx = canvas.getContext("2d");

ctx.fillStyle = "black";
// ctx.fillRect(0, 0, canvasSize, canvasSize);

let a = emojipixels.data;
for (let i = 0; i < emojipixels.data.length; i += 4) {
let x = ((i / 4) % canvasSize) * pixelSize;
let y = Math.floor(i / 4 / canvasSize) * pixelSize;

ctx.fillStyle = `rgba(${[a[i], a[i + 1], a[i + 2], a[i + 3]]})`;
ctx.fillRect(x, y, pixelSize - 2, pixelSize - 2);
}

return canvas;
}
Insert cell
function renderImageData(imageData) {
let canvas = d3
.create("canvas")
.attr("width", canvasSize * pixelSize)
.attr("height", canvasSize * pixelSize)
.node();
// canvas.width = `${canvasSize}px`;
// canvas.height = `${canvasSize}px`;

let ctx = canvas.getContext("2d");

ctx.fillStyle = "black";
// ctx.fillRect(0, 0, canvasSize, canvasSize);

let a = imageData.data;
for (let i = 0; i < a.length; i += 4) {
let x = ((i / 4) % canvasSize) * pixelSize;
let y = Math.floor(i / 4 / canvasSize) * pixelSize;

ctx.fillStyle = `rgba(${[a[i], a[i + 1], a[i + 2], a[i + 3]]})`;
ctx.fillRect(x, y, pixelSize - 2, pixelSize - 2);
}

return canvas;
}
Insert cell
d3.extent(emojipixels.data)
Insert cell
d3.extent(emojis, d => d.Position)
Insert cell
Insert cell
Q5 = require("https://cdn.jsdelivr.net/gh/LingDong-/q5xjs/q5.min.js").catch(
() => window.Q5
)
Insert cell
import { Scrubber } from "@mbostock/scrubber"
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