Public
Edited
Feb 21, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.call(xAxis);

svg.append("g")
.call(yAxis);

svg.append("g")
.selectAll("circle")
.data(temperament)
.join("circle")
//.filter(d => d.Note)
.attr("cx", d => x(d.Hertz))
.attr("cy", d => y(d.Octave))
.attr("r", Math.log10(edoInput/octavesInput*5)); // (octavesInput/edoInput)

return svg.node();
}
Insert cell
temperament
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
temperament = Array(1).fill(tempTempTemp(rootLetterInput, rootNoteInput, rootOctaveInput, octavesInput, edoInput)).flat()
Insert cell
Array(1).fill([]).flat()
Insert cell
tempTempTemp = (rootLetterInput, rootNoteInput, rootOctaveInput, octavesInput, edoInput) => {
// initial setup
let lowestNote = rootNoteInput * 2 ** (rootOctaveInput - octavesInput)
let totalNotes = edoInput*octavesInput
let stepRatio = round((Math.pow(2,1/edoInput)),5)
let tempTemp = Array(totalNotes)
const centConst = 1200/Math.log10(2)
let stepCents = 1200*Math.log2((rootNoteInput*stepRatio)/rootNoteInput)
let keepTheChange = round(stepCents,0)

// define lowest note
tempTemp[0] = {Octave: 1, Hertz: lowestNote, Note: rootLetterInput}

// fill out each note
for (let i=1; i<(totalNotes-1); i++){
let lastNote = tempTemp[i-1].Hertz
let lastOctave = tempTemp[i-1].Octave
tempTemp[i] = {
Octave: Math.ceil((i+1)/(edoInput-1)),
Hertz: round(lastNote * stepRatio,3),
Note: ""
}
}

// outputs
return tempTemp
}
Insert cell
Insert cell
Insert cell
x = d3.scaleLog()
.domain(d3.extent(temperament, d => d.Hertz)).nice()
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(temperament, d => d.Octave))
.range([height - margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(octavesInput))
Insert cell
margin = ({top: 25, right: 20, bottom: 35, left: 40})
Insert cell
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