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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more