Public
Edited
Jan 8, 2024
Insert cell
Insert cell
function asdf() {
// Declare the chart dimensions and margins.
const width = 640;
const height = 400;
const marginTop = 20;
const marginRight = 20;
const marginBottom = 30;
const marginLeft = 40;

// Declare the x (horizontal position) scale.
const x = d3.scaleUtc()
.domain([new Date("2023-01-01"), new Date("2024-01-01")])
.range([marginLeft, width - marginRight]);

// Declare the y (vertical position) scale.
const y = d3.scaleLinear()
.domain([0, 100])
.range([height - marginBottom, marginTop]);

// Create the SVG container.
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);

// Add the x-axis.
svg.append("g")
.attr("transform", `translate(0,${height - marginBottom})`)
.call(d3.axisBottom(x));

// Add the y-axis.
svg.append("g")
.attr("transform", `translate(${marginLeft},0)`)
.call(d3.axisLeft(y));

// Return the SVG element.
return svg.node();
}

Insert cell
asdf()
Insert cell
function createRoundedBoxPath(top, bottom, left, right, borderRadius) {
const width = right - left;
const height = bottom - top;

const pathData = `
M ${left + borderRadius} ${top}
q 0 -${borderRadius} ${borderRadius} -${borderRadius}
M ${left + 30 + borderRadius * 2} ${top - borderRadius}
h ${width - 2 * borderRadius- 30}
q ${borderRadius} 0 ${borderRadius} ${borderRadius}
v ${height - 2 * borderRadius}
q 0 ${borderRadius} -${borderRadius} ${borderRadius}
h -${width - 2 * borderRadius}
q -${borderRadius} 0 -${borderRadius} -${borderRadius}
v -${height - 2 * borderRadius}

`;

return pathData;
}
Insert cell
function createJaggedPath(x, y, toothSize, length) {
let pathData = `M ${x} ${y}`;

let currentX = x;
let currentY = y;

while (currentX < x + length) {
const nextX = currentX + toothSize;
const nextY = currentY + (currentY === y ? toothSize : -toothSize);

pathData += `L ${nextX} ${nextY}`;
currentX = nextX;
currentY = nextY;
}

return pathData;
}
Insert cell
function blah() {
const pathData = createRoundedBoxPath(50, 450, 50, 350, 20);
const jagged = createJaggedPath(70, 25, 10, 300);

const svg2 = d3.create("svg")
.attr("width", 400)
.attr("height", 600);


svg2.append("path")
.attr("d", pathData)
.style("fill", "none")
.style("stroke-width", "2px")
.style("stroke", "blue");

svg2.append("path")
.attr("d", jagged)
.style("fill", "none")
.style("stroke-width", "2px")
.style("stroke", "blue");
return svg2.node()
}

Insert cell
blah()


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