Published
Edited
Jul 3, 2020
Insert cell
md`# Random`
Insert cell
tf = require('@tensorflow/tfjs')
Insert cell
tf.getBackend()
Insert cell
tf.ENV.getBool('WEBGL_RENDER_FLOAT32_CAPABLE')
Insert cell
tf.ENV.getBool('WEBGL_RENDER_FLOAT32_ENABLED')
Insert cell
m = 32
Insert cell
n = m/6*9
Insert cell
u = 320/m;
Insert cell
dataset = tf.randomUniform([m, n]).array()
Insert cell
d3 = require("d3@5")
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, n*u, m*u]);
var g = svg.append("g");
g.selectAll("g")
.data(dataset)
.enter()
.append("g")
.attr("transform", (d, i) => "translate(0," + i*u + ")")
.selectAll("rect")
.data((d) => d)
.enter()
.append("rect")
.attr("x", (d, j) => j*u)
.attr("y", 0)
.attr("width", u)
.attr("height", u)
.attr("fill", d => d3.interpolateRdYlGn(d))
//.attr("fill", d => d3.interpolateGreys(d))
//.attr("fill", d => d3.interpolateLab("#fafafa", "#080808")(d));
//.text((d, j) => d + "," + j)
;
d3.select("head").append("link")
.attr("href", "https://fonts.googleapis.com/css2?family=Work+Sans:wght@800&display=swap")
.attr("rel", "stylesheet");
svg.append("text")
//Math.random() * (max - min) + min
.attr("x", () => { let max = n*u-175, min = 10; return (Math.random() * (max - min) + min); })
.attr("y", () => { let max = m*u-100, min = 50; return (Math.random() * (max - min) + min); })
.attr("style", "font-family: 'Work Sans', sans-serif; font-size: 32pt; fill: white; opacity: 0.8;")
.text("random");
return svg.node();
}
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