Public
Edited
Mar 4, 2023
Insert cell
Insert cell
Insert cell
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
console
Insert cell
mutable logHistoryUpdated = false;
Insert cell
import {button} from "@jashkenas/inputs"
Insert cell
val
Insert cell
val = {
b
return !this;
}
Insert cell
viewof b = button2()
Insert cell
function button2(config = {}) {
const {
value = "Reset", title, description, disabled
} = typeof config === "string" ? {value: config} : config;
const form = input({
type: "button", title, description,
attributes: {disabled, value}
});
form.output.remove();
return form;
}
Insert cell
d3format = require("d3-format@1")
Insert cell
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
replay, renderSomething('Button Click Random Number:')
Insert cell
renderSomething = function(cnt){
return cnt +2
}
Insert cell
viewof replay = html`<button>click me</button>`;
// viewof replay = Inputs.button("Replay")
Insert cell
console
Insert cell
button3 = {
const button = html`<button>Switch modes <i>x</i></button>`;
// button.onclick = () => a.push(mutable x++);
button.onclick = () => mutable switcher = -1*switcher;
return button;
}
Insert cell
switcher
Insert cell
// 1- on, -1 - off
mutable switcher = 1
Insert cell
log_print = log
Insert cell
// Object.getOwnPropertyDescriptor(graph_all_links2, 'current_link').value
Insert cell
Insert cell
// graph_all_links2.update(data);
Insert cell
ready = true
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.selectAll("#link_all")
// .style("marker-end", d => `url(${new URL(`#arrow-${d.predicate}`, location)})`)
// //.style("stroke", l => color3(l.predicate))
// .style("stroke", function (l) {
// if (l=== current_link) {
// return color3(l.predicate)
// }else {
// return "lightgrey"
// }})
Insert cell
d3.schemeCategory10
Insert cell
// drag = simulation => {
// function click(event, d) {
// delete d.fx;
// delete d.fy;
// d3.select(this).classed("fixed", false);
// simulation.alpha(1).restart();
// }

// function dragstart() {
// d3.select(this).classed("fixed", true);
// }

// function dragged(event, d) {
// d.fx = clamp(event.x, 0, width);
// d.fy = clamp(event.y, 0, height);
// simulation.alpha(1).restart();
// }
// }
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