Public
Edited
Jul 29, 2023
1 fork
7 stars
Insert cell
Insert cell
Insert cell
data = [361, 211, 463, 703, 311, 547, 321]
Insert cell
Insert cell
Insert cell
building = function(svg, dime) {
const building = svg.append('g')
const h = height-dime.height-dime.y
const x = { left:dime.x-60, middle:dime.x, right:dime.x + 60 }
const y = { topTop:h-30, topMiddle:h, topBottom:h+30, bottomMiddle:h+dime.height, bottomBottom:h+dime.height+30 }
const colours = { top:'#1F33B5', left:'#18299A', right:'#1A2CA7' }
// roof
building.append('polygon').attr('points',
x.middle+', '+ y.topTop + ' '+
x.right+', '+ y.topMiddle + ' '+
x.middle+', '+ y.topBottom + ' '+
x.left +', '+ y.topMiddle
).attr('fill', colours.top)
.attr('stroke', '#44DADA')
.attr('stroke-width', 1)
// sides
const sides = ['left', 'right']
sides.forEach((side) =>
building.append('polygon').attr('points',
x.middle+','+y.topBottom+' '+
x[side]+','+y.topMiddle+' '+
x[side]+','+y.bottomMiddle+' '+
x.middle+','+y.bottomBottom
).attr('fill', colours[side])
.attr('stroke', '#44DADA')
.attr('stroke-width', 1)
)
const windowSpace = 10;
let windowCount = dime.height/windowSpace;
while(windowCount > 1) {
let top = h + (windowSpace * windowCount)
// floor
building.append('polyline')
.attr('points', x.left+','+(top-9)+' '+x.middle+','+(top+21)+' '+x.right+','+(top-9))
.attr('stroke', '#44DADA')
.attr('fill', 'transparent')
.attr('stroke-width', 2)
.attr('opacity', 0.1)
// hilight
if(Math.random() >= 0.8) {
building.append('polyline')
.attr('points', x.left+','+(top-9)+' '+x.middle+','+(top+21)+' '+x.right+','+(top-9))
.attr('stroke', '#44DADA')
.attr('fill', 'transparent')
.attr('stroke-width', 2)
.attr('opacity', 0.1)
}
// windows
if(Math.random() >= 0.9) {
let positions = [
(x.middle+5)+','+(top+24)+' '+ (x.right-20) + ','+ (top+6),
(x.middle-5)+','+(top+24)+' '+ (x.left+20) + ','+ (top+6),
(x.middle-30)+','+(top+1)+' '+ (x.left+5) + ','+ (top-11),
(x.middle+30)+','+(top+1)+' '+ (x.right-5) + ','+ (top-11),
]
let points = positions[Math.floor(Math.random() * positions.length)]
building.append('polyline')
.attr('points', points)
.attr('stroke', '#BAEAEA')
.attr('fill', 'transparent')
.style("stroke-dasharray", ("1, 7"))
.attr('stroke-linecap', 'round')
.attr('stroke-width', 3)
.attr('opacity', 0.5)
}
--windowCount
}
}
Insert cell
Insert cell
Insert cell
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