Public
Edited
Apr 7, 2023
Insert cell
Insert cell
score_names2.map((name, index) => {
return {
label: name,
position: index,
format: (value, d) => value ? format(value) : "",
x: 670 + (index - 2) * 3,
fill: (value) => null,
};
});
Insert cell
score_names2 = make_names(Object.keys(data))

Insert cell
Insert cell
Insert cell
mapping = ({
"disease": {
"trend": 10,
"mutation": 5
},
"syndromic disease": {
"carrot": 4,
"celery": 7
}
})
Insert cell
// function findAttributesByKey(mapping, keyName) {
// // Find the item in the dictionary by the key name
// if mapping[d] == undefined
// var attributes = item;
// return attributes;
// }
Insert cell
// data2 = FileAttachment("tree2@1.json").json()
Insert cell
Object.keys(data)[0] == "name"
Insert cell
data = FileAttachment("tree_ENSG00000164136_0704.json").json()
// data = FileAttachment("tree2@1.json").json()
Insert cell
Insert cell
mutable cachedColumnData = null
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function make_names(a){
var names = []
for (var i = 0; i < a.length; i++) {
var obj =a[i];
if (obj != "name" & obj !="children") {
names.push(obj);
}
} return names
}
Insert cell
function wrap(text, width) {
let totalLines = 1;
text.each(function() {
let text = d3.select(this),
words = text.text().split(/\s+/).reverse(),
word,
line = [],
lineNumber = 0,
lineHeight = 1.1, // ems
x = text.attr("x"),
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null)
.append("tspan")
.attr("x", x)
.attr("y", y)
.attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan")
.attr("x", x)
.attr("y", y)
.attr("dy", ++lineNumber * lineHeight + dy + "em")
.text(word);

totalLines = Math.max(totalLines, lineNumber + 1);
}
}
});

return totalLines;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function indexEachBefore2(r, nodes) {
let i = 0;
let y = 0;
r.eachBefore(n => {
if (n.parent && n.parent !== r) {
// If the node has a previous sibling, update the y position based on the previous sibling's totalLines
if (n.previousSibling) {
let nodeHeight = nodeSize * (n.previousSibling.totalLines || 1);
y += nodeHeight;
} else {
n.index = i++;
}
return r
} })}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
//import {DescribeObject} from "@tsenyi/json-object-statistics"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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