Public
Edited
Apr 20, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
sampleSVG = FileAttachment("ai export for svg.svg").text()
Insert cell
Insert cell
import {importSVGnode} from "@emfielduva/dvlib"
Insert cell
svg = importSVGnode(sampleSVG)
Insert cell
Insert cell
Insert cell
dots = {
let dots = d3.select(svg);
dots.select("#blueDot").attr("cx", form.blueX);
dots.select("#yellowDot").attr("cx", form.yellowX);
dots.select("#redDot").attr("cx", form.redX);
dots.selectAll("circle").attr("r", form.radius) // uncomment this one to see it apply to all circles
}
Insert cell
Insert cell
Insert cell
Insert cell
FileAttachment("illustrator_sliders.svg").image()
Insert cell
Insert cell
slidersSVG = FileAttachment("illustrator_sliders.svg").text() // notice the .text() rather than .image()
Insert cell
sliders = importSVGnode(slidersSVG)
Insert cell
Insert cell
Insert cell
Insert cell
sliderData = FileAttachment("illustrator_sliders.csv").csv()
Insert cell
Insert cell
scaleX = d3.scaleLinear().domain([0,1]).range([0,600]) // a scale domain/range for X
Insert cell
leftmostX = 200
Insert cell
slidersD3 = d3.select(sliders) // D3 grabs the objects to be able to manipulate.
Insert cell
Insert cell
moveDotsYear = {
sliderData.forEach(function(d,i) { // for each entry in data
let dotPosition = leftmostX + scaleX(+sliderData[i][year]); // get the data in the csv file
slidersD3.select("#dot"+d["question"]) // get the dot for this slider/"question" - this was built from a survey
.transition().duration(1000)
.attr("cx", dotPosition); // set the dot position from data
let line = d3.select("#line"+d["question"]); // the line surrounding the dot needs to extend and contract.
let lineX1,lineX2;
if (dotPosition < line.attr("x1")) {
lineX1 = dotPosition;
} else {
lineX1 = line.attr("x1");
}
if (dotPosition > line.attr("x2")) {
lineX2 = dotPosition;
} else {
lineX2 = line.attr("x2");
}
slidersD3.select("#line"+d["question"])
.transition().duration(1000)
.attr("x1", lineX1)
.attr("x2", lineX2);
})
}
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