Published
Edited
Apr 24, 2021
1 fork
32 stars
Insert cell
Insert cell
Insert cell
Insert cell
viewof chosen = {
let div = html`<div></div>`;
div.value = sortedProcessed[0];
d3.select(div)
.selectAll("div.emoji")
.data(
sortedProcessed
.filter(d => d.topColors.length)
.sort((a, b) => c2h(a.topColors[0]) - c2h(b.topColors[0]))
)
.join("div")
.classed("emoji", true)
// .style("font-size", d => sizeScale(d.Occurrences) + "px")
.style("display", "inline-block")
// .style("margin-right", "7px")
.style("cursor", "pointer")
// .style("opacity", d => {
// return opacityScale(d.Occurences);
// })
.attr("title", d => d["Unicode name"])
// .text(d => d.Emoji)
.each(function(d) {
let span = html`<span style="display:none">${d.Emoji}</span>`;
d3.select(span)
.style("font-size", `${treemapSize}px`)
.style("line-height", `${treemapSize}px`)
.style("vertical-align", "super");

this.appendChild(span);
this.appendChild(colorTreemap(d));
})
.on("click", (event, d) => {
div.value = d;
div.dispatchEvent(new CustomEvent("input", { bubbles: true }));
})
.on("mouseover", function(event, d) {
d3.select(this)
.select("span")
.style("display", "inline-block");
d3.select(this)
.select("svg")
.style("display", "none");
})
.on("mouseout", function(event, d) {
d3.select(this)
.select("span")
.style("display", "none");
d3.select(this)
.select("svg")
.style("display", "inline-block");
});

return div;
}
Insert cell
c2h = function(c) {
let d = d3.hsl("rgb(" + c.color.join(",") + ")");
return d.l;
}
Insert cell
import { sortedProcessed } from '@codingwithfire/emojis'
Insert cell
treemapSize = 40
Insert cell
colorTreemap(sortedProcessed[0])
Insert cell
sortedProcessed.map(d => d.topColors)
Insert cell
sortedProcessed
Insert cell
function colorTreemap(emoji) {
let treemap = d3
.treemap()
.tile(d3.treemapSquarify)
.size([treemapSize, treemapSize])
.padding(1);
// .round(true)

let data = {
name: "emojis",
children: emoji.topColors
};

let root = d3
.hierarchy(data)
.sum(d => d.value)
.sort((a, b) => b.value - a.value);

let tree = treemap(root);

let svg = d3
.create("svg")
.attr("width", treemapSize)
.attr("height", treemapSize);

let leaf = svg
.selectAll("g")
.data(tree.leaves())
.join("g")
.attr("transform", d => `translate(${d.x0},${d.y0})`);

leaf
.append("rect")
.attr("width", d => d.x1 - d.x0)
.attr("height", d => d.y1 - d.y0)
// .attr("fill", d => { while (d.depth > 1) d = d.parent; return color(d.data.name) })
// .attr("fill", d => { return color(d.data.name) })
.attr(
"fill",
d => `rgb(${d.data.color ? d.data.color.join(",") : "255,255,255"})`
)
.attr("fill-opacity", 1);

return svg.node();
}
Insert cell
sortedProcessed
Insert cell
haveColor = sortedProcessed
.filter(d => d.topColors.length)
.sort((a, b) => c2h(a.topColors[0]) - c2h(b.topColors[0]))
Insert cell
subset = haveColor.slice(0, 150).concat(haveColor.slice(500, 672))
Insert cell
viewof chosen2 = {
let div = html`<div></div>`;
div.value = sortedProcessed[0];
d3.select(div)
.selectAll("div.emoji")
.data(subset)
.join("div")
.classed("emoji", true)
// .style("font-size", d => sizeScale(d.Occurrences) + "px")
.style("display", "inline-block")
// .style("margin-right", "7px")
.style("cursor", "pointer")
// .style("opacity", d => {
// return opacityScale(d.Occurences);
// })
.attr("title", d => d["Unicode name"])
// .text(d => d.Emoji)
.each(function(d) {
let span = html`<span style="display:none">${d.Emoji}</span>`;
d3.select(span)
.style("font-size", `${treemapSize}px`)
.style("line-height", `${treemapSize}px`)
.style("vertical-align", "super");

this.appendChild(span);
this.appendChild(colorTreemap(d));
})
.on("click", (event, d) => {
div.value = d;
div.dispatchEvent(new CustomEvent("input", { bubbles: true }));
})
.on("mouseover", function(event, d) {
d3.select(this)
.select("span")
.style("display", "inline-block");
d3.select(this)
.select("svg")
.style("display", "none");
})
.on("mouseout", function(event, d) {
d3.select(this)
.select("span")
.style("display", "none");
d3.select(this)
.select("svg")
.style("display", "inline-block");
});

return div;
}
Insert cell
d3 = require("d3@6")
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