Public
Edited
Feb 24
Insert cell
Insert cell
Insert cell
Insert cell
Dashboard2 = html`
<div class='dashboardOuter' style='height:1000px; width:1600px; position:relative;'>

<!-- Borders (full coverage) -->
<div class='borders' style='position:absolute; height:600px; width:1350px; z-index:1;pointer-events: none;'>
${chart}
</div>




<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:60px'>
${viewof woodrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:90px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((woodrem/1575)*co2[3].difference),2)}
</div>



<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:120px'>
${viewof radrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:150px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((radrem/1575)*co2[3].difference),2)}
</div>



<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:180px'>
${viewof plasrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:210px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((plasrem/1575)*co2[3].difference),2)}
</div>


<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:240px'>
${viewof drywallrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:270px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((drywallrem/1575)*co2[3].difference),2)}
</div>


<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:300px'>
${viewof glframerem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:330px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((glframerem/1575)*co2[3].difference),2)}
</div>



<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:360px'>
${viewof glglassrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:390px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((glglassrem/1575)*co2[3].difference),2)}
</div>



<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:420px'>
${viewof doorframesrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:450px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((doorframesrem/1575)*co2[3].difference),2)}
</div>



<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:480px'>
${viewof doorsrem}
</div>
<!-- Map container (left side, 300px from left) -->
<div class='map' style='position:absolute; height:100px; width:900px; left:1410px;top:510px'>
embodied pounds of co2 ${Math.round(co2[3].goodtotal+((doorsrem/1575)*co2[3].difference),2)}
</div>


<div class='map' style='position:absolute; height:10px; width:900px; left:1410px;top:30px'>
Materials To Landfill (lbs)
</div>



</div>
`
Insert cell
viewof doorsrem = Inputs.range([0, 9790], {step: 10, value : 0, label : "Doors"})
Insert cell
viewof doorframesrem = Inputs.range([0, 9790], {step: 10, value : 0, label : "Door Frames"})
Insert cell
viewof glglassrem = Inputs.range([0, 1610], {step: 10, value : 0, label : "Glazing Glass"})
Insert cell
viewof glframerem = Inputs.range([0, 6860], {step: 10, value : 0, label : "Glazing Frames"})
Insert cell
viewof drywallrem = Inputs.range([0, 4452], {step: 5, value : 0, label : "Drywall"})
Insert cell
viewof plasrem = Inputs.range([0, 11280], {step: 10, value : 0, label : "Plaster"})
Insert cell
viewof radrem = Inputs.range([0, 12600], {step: 50, value : 0, label : "Radiators"})
Insert cell
viewof woodrem = Inputs.range([0, 1575], {step: 5, value : 0, label : "Timber"})
Insert cell
viewof removal = Inputs.range([0, 57957], {step: 50, value : 0, label : "DivertedRemoval"})
Insert cell
chart = {
// Specify the dimensions of the chart.
const width = 1600;
const height = 900;
const format = d3.format(",.0f");

// Create a SVG container.
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "max-width: 100%; height: auto; font: 10px sans-serif;");

// Constructs and configures a Sankey generator.
const sankey = d3.sankey()
.nodeId(d => d.name)
.nodeAlign(d3[nodeAlign]) // d3.sankeyLeft, etc.
.nodeWidth(15)
.nodePadding(10)
.extent([[1, 5], [width - 1, height - 5]]);

// Applies it to the data. We make a copy of the nodes and links objects
// so as to avoid mutating the original.
const {nodes, links} = sankey({
nodes: data.nodes.map(d => Object.assign({}, d)),
links: data.links.map(d => Object.assign({}, d))
});

// Defines a color scale.
//const color = d3.schemeBuPu;
const color = d3.scaleOrdinal(["#fff7ec","#feebcf","#fddcaf","#fdca94","#fdb07a","#fa8e5d","#f16c49","#e04530","#c81d13","#a70403","#7f0000"]);
//const color = ["#fff5f0","#fee3d6","#fdc9b4","#fcaa8e","#fc8a6b","#f9694c","#ef4533","#d92723","#bb151a","#970b13","#67000d"]

// Creates the rects that represent the nodes.
const rect = svg.append("g")
.attr("stroke", "#000")
.selectAll()
.data(nodes)
.join("rect")
.attr("x", d => d.x0)
.attr("y", d => d.y0)
.attr("height", d => d.y1 - d.y0)
.attr("width", d => d.x1 - d.x0)
.attr("fill", d => color(d.category));

// Adds a title on the nodes.
rect.append("title")
.text(d => `${d.name}\n${format(d.value)} TWh`);

// Creates the paths that represent the links.
const link = svg.append("g")
.attr("fill", "none")
.attr("stroke-opacity", 0.5)
.selectAll()
.data(links)
.join("g")
.style("mix-blend-mode", "multiply");

// Creates a gradient, if necessary, for the source-target color option.
if (linkColor === "source-target") {
const gradient = link.append("linearGradient")
.attr("id", d => (d.uid = DOM.uid("link")).id)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", d => d.source.x1)
.attr("x2", d => d.target.x0);
gradient.append("stop")
.attr("offset", "0%")
.attr("stop-color", d => color(d.source.category));
gradient.append("stop")
.attr("offset", "100%")
.attr("stop-color", d => color(d.target.category));
}

link.append("path")
.attr("d", d3.sankeyLinkHorizontal())
.attr("stroke", linkColor === "source-target" ? (d) => d.uid
: linkColor === "source" ? (d) => color(d.source.category)
: linkColor === "target" ? (d) => color(d.target.category)
: linkColor)
.attr("stroke-width", d => Math.max(1, d.width));

link.append("title")
.text(d => `${d.source.name} → ${d.target.name}\n${format(d.value)} TWh`);

// Adds labels on the nodes.
svg.append("g")
.selectAll()
.data(nodes)
.join("text")
.attr("x", d => d.x0 < width / 2 ? d.x1 + 6 : d.x0 - 6)
.attr("y", d => (d.y1 + d.y0) / 2)
.attr("dy", "0.35em")
.attr("text-anchor", d => d.x0 < width / 2 ? "start" : "end")
.text(d => d.name);

return svg.node();
}
Insert cell
co2 = FileAttachment("MATERIAL_LCA - Sheet1@1.csv").csv({typed: true});
Insert cell
Insert cell
tweakedData = {
var originalData = links
var removalTotal = 57957
var removal = woodrem + radrem + plasrem + drywallrem + glframerem + glglassrem + doorframesrem + doorsrem

originalData[52].value = removal
//say reusing is removalTotal - slidervalue , times .77
originalData[51].value = (removalTotal - removal)*.7
originalData[50].value = (removalTotal - removal)*.3
return originalData

}
Insert cell
MATERIAL_LCA - Sheet1@1.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data = {//good job turning the numbers into strings
const links = tweakedData
const nodes = Array.from(new Set(links.flatMap(l => [l.source, l.target])), name => ({name, category: name.replace(/ .*/, "")}));
return {nodes, links};
}
Insert cell
// [d3-sankey](https://github.com/d3/d3-sankey) is not part of the D3 bundle
d3 = require("d3@7", "d3-sankey@0.12")
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