Public
Edited
Mar 6, 2023
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
mutable logHistoryUpdated = false;
Insert cell
// https://observablehq.com/@sorig/console-log-without-leaving-your-notebook
consoleHook = {
// replay
if (!console.stdlog) {
console.stdlog = console.log.bind(console);
console.logs = [];
}
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments)
mutable logHistoryUpdated = true;
}
}
Insert cell
button3 = {
const button = html`<button>Clear output<i>x</i></button>`;
// button.onclick = () => a.push(mutable x++);
button.onclick = () => mutable switcher = -1*switcher;
return button;
}
Insert cell
mutable switcher = 1
Insert cell
log2 = {

consoleHook
logHistoryUpdated
// return console.logs
return console.logs.slice();

}
Insert cell
log = {

if (switcher<0) {
console.clear()
console.logs = []
mutable logHistoryUpdated = true
return []
} else {
// consoleHook
// logHistoryUpdated
// return console.logs
return console.logs.slice();
}
}
Insert cell
log2[3]

Insert cell
// Object.getOwnPropertyDescriptor(graph_all_links, 'y_indent').value
Insert cell
Insert cell
function sendDataToDash(data) {
console.log(data);
window.parent.parent.postMessage({type: 'my-message-type', data: data}, '*');
}
Insert cell
// margin = ({top: 305, right: 5, bottom: 5, left: 460})
margin = ({top: 0, right: 0, bottom: 0, left: 0})
Insert cell
Insert cell
height = 680
Insert cell
//data = FileAttachment("json_G.json").json()
data = FileAttachment("test.json").json()
Insert cell
types = Array.from(new Set(links.map(d => d.predicate)))
Insert cell
Insert cell
measureWidth = {
const context = document.createElement("canvas").getContext("2d");
return text => context.measureText(text).width;
}
Insert cell
stroke_width_key = d3.scaleOrdinal()
.domain(["1", undefined])
.range(["4", "0"]);
Insert cell
color3 = d3.scaleOrdinal()
.domain(["Activation", "Inhibition", "IncreaseAmount", "DecreaseAmount", "Associated", "HAS_A_TRIAL"])
.range(["#d5f2bd", "#edc2bb", "#d5f2bd","#edc2bb","#f5d0b0", "#c3c3e3"]);

Insert cell
color2 = d3.scaleOrdinal(types, d3.schemeCategory10)
Insert cell
color = {
const scale = d3.scaleOrdinal(d3.schemeCategory10);
//const scale = d3.scaleOrdinal([`#383867`, `#584c77`, `#33431e`, `#a36629`, `#92462f`, `#b63e36`, `#b74a70`, `#946943`]); // [`#383867`, `#584c77`, `#33431e`, `#a36629`, `#92462f`, `#b63e36`, `#b74a70`, `#946943`]
return d => scale(d.group);
}
Insert cell
d3.schemeCategory10
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
d3 = require("d3@6")
Insert cell
function clamp(x, lo, hi) {
return x < lo ? lo : x > hi ? hi : x;
}
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