Public
Edited
Sep 23, 2024
Insert cell
# 2024 fall studio 9/23 - fleet's version - this is a great map
Insert cell
chart = {
const width = 800,
height = 800;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
var g = svg.selectAll('g').attr("id", "paths");//qgis lines variable //one variable for each geometry type
var c = svg.selectAll('circle')
//static lines are input here
polyline(square_test,'red','1','1','0','black')
polyline(plus_outline,'rgb(220,220,220)','.5','1','2','black')
polyline(plus_details,'rgb(220,220,220)','.5','1','.75','black')
polyline(boat,'none','.5','1','3','blue')

function polyline(data, sfill, fillO, sOpac, sW, stroke){

g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style("fill-opacity", fillO)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}

g.enter().append("polyline")
.data(rhinoLines) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d.pts}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'purple')
.style("fill-opacity", '1')
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", 'black')
.on('mouseover',rhinoText)

function rhinoText(event,d){

svg
.append("text")
.attr("x",200)
.attr("y",200)
.attr("class","pointsText")
.attr('font-weight','bold')
.attr("font-family","helvetica")
.attr("font-size","12px")
.text(d.zoning)
}


c.enter().append('circle')
.data(points)
.enter()
.append('circle')
.attr('cx',function(d){return d.xVal})
.attr('cy',function(d){return d.yVal})
.attr('r',ptRad)
.attr('fill',ptColor)
.on('mouseover',pointsHover)
.on('mouseout',pointsHoverOff)

function ptColor(d){
var color = 'red'
if(d.Type == 'clt'){color = 'blue'}
if(d.Type == 'other'){color = 'cyan'}

return color
}

function ptRad(d){
var radius = '4'
if(d.Type == 'clt'){radius = '8'}
return radius
}


function pointsHover(event,d){
svg
.append("rect")
.attr("x",d.xVal+20)
.attr("y",d.yVal+20)
.attr("width","120")
.attr("height","80")
.attr("class","hoverRect")
.attr("fill","rgb(200,200,200)")
.attr("stroke","black")
.attr("stroke-width","1")
svg
.append("text")
.attr("x",d.xVal+40)
.attr("y",d.yVal+40)
.attr("class","pointsText")
.attr('font-weight','bold')
.attr("font-family","helvetica")
.attr("font-size","12px")
.text(d.Name)

svg
.append("text")
.attr("x",d.xVal+40)
.attr("y",d.yVal+60)
.attr("class","pointsText")
.attr('font-weight','lighter')
.attr("font-family","helvetica")
.attr("font-size","12px")
.text(d.Description)

var wrap = svg.selectAll("text.pointsText")
.each(function(d, i) { wrap_text(d3.select(this), 80) });
}

function pointsHoverOff(event,d){
svg.selectAll('text.pointsText').remove()
svg.selectAll('rect.hoverRect').remove()
}


svg
.append("text")
.attr("x","100")
.attr("y","115")
.attr("class","hoverText")
.attr("font-family","helvetica")
.attr("font-size","12px")
.text("I love CASE 😀")





return svg.node();
}
Insert cell
square_test = FileAttachment("square_test.txt").tsv({array:true})
Insert cell
plus_outline = FileAttachment("plus_outline.txt").tsv({array:true})
Insert cell
Insert cell
boat = FileAttachment("boat.txt").tsv({array:true})
Insert cell
Insert cell
points = d3.csv(pointsLink,d3.autoType)
Insert cell
Insert cell
hexes = d3.csv(hexLink,d3.autoType)
Insert cell
hexes1 = FileAttachment("hexes.txt").tsv({array:true})
Insert cell
rhinoLines = {

var list = hexes1 //file from rhino
var spreadsheet = hexes //name of the spreadsheet
var cleanLines = []
for (let i = 0; i < list.length-1; i=i+2) {
var id = list[i+1][0]
var idNum = Number(id)

var zoning //you need to add a variable for each attribute in the spreadsheet - except id
var water
for (let k = 0; k < spreadsheet.length; k++) {
if(idNum==spreadsheet[k].id){
//console.log("match!!!!!!!")
zoning = spreadsheet[k].zoning //assign our new variables to spreadsheet[k].attributeName
water = spreadsheet[k].water
}
}
//create a name for each spreadsheet attribute, and add the corresponding variable to it
cleanLines.push({pts:list[i],id:idNum,zoning:zoning,water:water,})
}

return cleanLines
}
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"
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