Public
Edited
Feb 16
Insert cell
Insert cell
url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vR_a8mD7I3cNHg0oVtckTZ9H1S-Hcn9q3msHOELP1sj-hoHXSveFF1v2cyegk5Bi49wYtIRIgXmh11B/pub?gid=0&single=true&output=tsv"
Insert cell
dataset = d3.tsv(url, d3.autoType)
Insert cell
Inputs.table(dataset)
Insert cell
a = {
const a = new d3.Adder()
for(let i = 0; i <3; i++) {
a.add(0.1)
}
return a
}
Insert cell
a.valueOf()
Insert cell
Insert cell
d3.fsum([0.1,0.1])
Insert cell
d3.fsum(dataset,(d) => d.Views)
Insert cell
Insert cell
d3.cumsum([0.1,0.1,0.1])
Insert cell
values = d3.fcumsum(dataset,(d) => d.Views)
Insert cell
Insert cell
bin = d3.bin().thresholds((values) => [d3.median(values)]);
Insert cell
ex_bin = bin(values)
Insert cell
Insert cell
binThresholdFreedmanDiaconis = d3.bin().thresholds(d3.thresholdFreedmanDiaconis);
Insert cell
binThresholdFreedmanDiaconis(values)
Insert cell
binThresholdScott = d3.bin().thresholds(d3.thresholdScott);
Insert cell
binThresholdScott(values)
Insert cell
Insert cell
binThresholdSturges = d3.bin().thresholds(d3.thresholdSturges);
Insert cell
binThresholdSturges(values)
Insert cell
Insert cell
cents = d3.ticks(0, 100, 1000)
Insert cell
index = d3.bisect(cents, Math.PI)
Insert cell
sorted = {
const sorted = []
do {
const x = Math.random()
const y = Math.random() - 1
const i = d3.bisect(sorted, x)
sorted.splice(i, 0, x,y)//splice(start, deleteCount, item1,)start:インデックス、deleteCount: 減らす要素の数、挿入するアイテム
yield sorted
} while (sorted.length < 255)
}

Insert cell
items = [0, 1, 1, 2, 3]
Insert cell
d3.bisect(items,1)//6が挿入される位置
Insert cell
d3.bisectLeft(items,1)//第2引数が挿入される位置(同じ数がある場合、左側に挿入する)
Insert cell
d3.bisectRight(items,1)//第2引数が挿入される位置(同じ数がある場合、右側に挿入する)
Insert cell
d3.bisectCenter(items,1)
Insert cell
pos = [d3.bisectLeft(items,1),d3.bisectRight(items, 1)]
Insert cell
data = Array.from(
(function*(){
let date = new Date("2025-02-10"),close = 98.84
for(let i = 0; i < 100; i++){
//if (i % 7 > 5) continue;
date = new Date(date.setDate(date.getDate() + 1))
close = +(close + Math.random() - 0.485).toFixed(3)
yield{date, close}
}
})()
)
//
Insert cell
Insert cell
bisect = d3.bisector(d => d.date)
Insert cell
bisect.right(data, new Date(2025, 4, 9))
Insert cell
d3.bisect(items,1,2,3)//配列内の2~3の間にソートされた状態で1が挿入される位置。
Insert cell
Insert cell
Insert cell
{
const numbers = d3.cumsum({length:100}, () => Math.random() -0.5)
const bluredNum = d3.blur(numbers.slice() ,0.5)//値に対してガウスぼかしで近似する
return {numbers,bluredNum}
}
Insert cell
{
const matrix = {
width: 4,
height: 3,
data: [
1, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 1,
],
}
const blured = d3.blur2(matrix, 2

)
return blured
}
Insert cell
Insert cell
viewof r = Inputs.range([0, 10], {label: "Radius", step: 0.01, value: 1})
Insert cell
Insert cell
Insert cell
radius = {
const sorted = []
do {
const x = Math.random()
const y = Math.random() + 1
const i = d3.bisect(sorted, x)
sorted.splice(i, 0, x,y)//splice(start, deleteCount, item1,)start:インデックス、deleteCount: 減らす要素の数、挿入するアイテム
yield sorted[1] * 50
} while (sorted.length < 255)
}
Insert cell
pixels = ({
width: 40,
data: Array.from({length: 40 * 20},(_, i) => (i % 40) * Math.random())
})
Insert cell
blurred = d3.blur2({
data:pixels.data.slice(),
width: pixels.width
},
0.5)
Insert cell
Plot.plot({
caption: "blurred",
marks:[Plot.cell(blurred.data,{
x:(d,i) => i % pixels.width,
y:(d,i) => Math.floor( i / pixels.width),
fill:(d) => d
}),Plot.frame()
],
padding: 0,
round: false,
color: {scheme: "greys", domain: [0, 20]},
height: 200,
width: 300,
axis: null
})
Insert cell
Insert cell
Insert cell
country = d3.group(dataset,(d) => d.country)
Insert cell
flatCountry = d3.flatGroup(dataset,(d) => d.country)
Insert cell
country.get("アイスランド")
Insert cell
countryAndRelease = d3.group(dataset, (d) => d.country, (d) =>d.year2)
Insert cell
countryAndRelease.get("イギリス").get(1997)
Insert cell
country2 = d3.groups(dataset, (d) => d.country);
Insert cell
Insert cell
countryCount
= d3.rollup(dataset, (D) => D.length, (d) => d.country);
Insert cell
countryCount.get("イギリス")
Insert cell
countryCounts = d3.rollups(dataset, (D) => D.length, (d) => d.country);
Insert cell
index その配列特有の値をインデックスにできる
Insert cell
Artist = d3.index(dataset, (d) => d.Artist);
Insert cell
Artist.get("PSY").Video_title
Insert cell
Artists = d3.indexes(dataset, (d) => d.Artist);
Insert cell
d3.groupSort(dataset, (D) => d3.median(D, (d) => d.Views), (d) => d.country)
Insert cell
Insert cell
Insert cell
Insert cell
{
const map = new Map();
map.set(new Date("2021-01-01"), 42);
return map.get(new Date("2021-01-01"));
}
Insert cell
Insert cell
valueByDate = {const valueByDate = new d3.InternMap([
[new Date("2021-01-01"), 42],
[new Date("2021-01-01"), 43],
[new Date("2022-01-01"), 12]
]);
valueByDate.set(new Date("2021-01-02"), 43)
return valueByDate
}
Insert cell
Insert cell
d3.difference([0, 1, 2, 0], [2])
Insert cell
d3.union([0, 2, 1, 0],[1,4])
Insert cell
d3.superset([0, 2, 1, 3, 0], [1, 3]) // true
Insert cell
d3.disjoint([1,3],[2,4])
Insert cell
array = [39,1,1000,15,39]
Insert cell
array.sort(d3.ascending)
Insert cell
array.sort(d3.descending)
Insert cell
d3.permute(["a","b","c"],[1,2,0])
Insert cell
numbers =
dataset.map(data => data.Views);
Insert cell
dataset.map(data=>d3.permute(data,["Video_title"]))
Insert cell
Insert cell
d3.quickselect(numbers, 0)
Insert cell
d3.reverse(numbers)
Insert cell
d3.shuffle(numbers)
Insert cell
d3.sort(numbers)
Insert cell
d3.count(numbers)
Insert cell
Insert cell
d3.least(dataset,(a,b) => a.Views - b.Views)
Insert cell
d3.extent(numbers)
Insert cell
result = [d3.sum(numbers), d3.mean(numbers),d3.median(numbers)];
Insert cell
d3.quantile(numbers,0.75)
Insert cell
d3.rank(numbers)
Insert cell
variance配列内の平均値の周りにどれだけデータが散らばっているかを示す。
Insert cell
d3.variance(array)
Insert cell
d3.deviation(numbers)
Insert cell
d3.every(numbers,x => x & 700520)
Insert cell
d3.some(numbers,x => x & 1)
Insert cell
Insert cell
d3.ticks(1,9,7)
Insert cell
d3.nice(1, 9, 5)
Insert cell
d3.range(49).map((d) => d / 49)
Insert cell
d3.cross([1,2],["x","y"])
Insert cell
d3.merge([array,numbers])
Insert cell
artists =
dataset.map(data => data.Artist);
Insert cell
d3.transpose([numbers,artists])
Insert cell
d3.zip(numbers,artists)
Insert cell
d3.filter(dataset,(d) => d.Artist)
Insert cell
Insert cell
d3.filter(new Set([0, 2, 3, 4]), (d) => d & 2)
Insert cell
d3.map(new Set([0, 2, 3, 4]), (d) => d & 1)
Insert cell
d3.reduce(new Set([0, 2, 3, 4]), (p, v) => p + v, 0)
Insert cell
Insert cell
csvExample = d3.csvParse("foo,bar\n1,2") // [{foo: "1", bar: "2"}, columns: ["foo", "bar"]]
Insert cell
tsvExmaple = d3.tsvParse("foo\tbar\n1\t2")
Insert cell
d3.csvFormat(csvExample)
Insert cell
d3.tsvFormat(tsvExmaple)
Insert cell
d3.dsvFormat("|").parse("foo|bar\n1|2")
Insert cell
Insert cell
csv = d3.dsvFormat(",")
Insert cell
Insert cell
Insert cell
{
const f = d3.format(".1f");
const number = []
for (let i = 0; i < 10; ++i) {
number.push(f(i * 0.1))
}
return number
}
Insert cell
Insert cell
Array.from({length:10},Math.random)
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