Public
Edited
Mar 27, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
wind1 = windDirchart("WSPD", "GST")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
testArray = newdata.map(item => Number(item.sea_surface_elevation))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function windDirchart(index, indb = undefined) {
// console.log(indb);
const height = 120;
const margin = { top: 20, right: 30, bottom: 30, left: 40 };

const x = d3
.scaleTime()
.domain(d3.extent(buoyData, (d) => d.date))
.range([margin.left, width - margin.right]);

let y;

if (indb) {
y = d3
.scaleLinear()
.domain([0, d3.max(buoyData, (d) => d[indb])])
.nice()
.range([height - margin.bottom, margin.top]);
} else {
y = d3
.scaleLinear()
.domain([0, d3.max(buoyData, (d) => d[index])])
.nice()
.range([height - margin.bottom, margin.top]);
}

const svg = d3.select(DOM.svg(width, height)).style("width", "100%");

svg
.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x));

svg
.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(d3.axisLeft(y).ticks(4))
.call((g) =>
g
.select(".tick:last-of-type text")
.clone()
.attr("x", 3)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("kts")
);
if (indb) {
svg
.append("path")
.datum(buoyData)
.attr("fill", "none")
.attr("stroke", "#e31a1c")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr(
"d",
d3
.line()
.x((d) => x(d.date))
.y((d) => y(d[indb]))
);
}

svg
.append("path")
.datum(buoyData)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr(
"d",
d3
.line()
.x((d) => x(d.date))
.y((d) => y(d[index]))
);

// if (index === "WDIR") {
// console.log(buoyData);

// }

svg
.selectAll("circle")
.data(buoyData)
.enter()
.append("path")
.attr("d", "M-5,0 L-15,15 L15,0 L-15,-15 Z")
.attr("class", "arrowHead")
.attr("fill", "grey")
.attr("transform", function (d, i) {
// console.log("d", d[index]);
// console.log(getAngle(d[index]));
return (
"translate(" +
x(d.date) +
"," +
y(d[index]) +
") rotate(" +
getAngle(d["WDIR"]) +
") scale(0.5)"
);
});

svg
.append("g")
.selectAll("text")
.data(buoyData)
.enter()
.append("text")
.text(
(d, i) => getText(d["WDIR"])
// return d[index];
)
.attr("x", (d) => x(d.date))
.attr("y", (d) => y(d[index]))
.attr("font-family", "sans-serif")
.attr("font-size", "16px")
.attr("fill", "green");
// .append("circle")
// .attr("cx", d => x(d.date))
// .attr("cy", d => y(d[index]))
// .attr("r", d => 2);
// }

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
buoyohbuoy = {
return dd === "Quadra"
? d3.json("https://goose.hakai.org/ccv/QuadraBuoyData.json")
: d3.json("https://goose.hakai.org/ccv/CalvertBuoyData.json");
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
newdata = {
let data, ll;
dd === "Quadra" ? (ll = [50.2058, -125.2682]) : (ll = [51.5529, -128.0056]);
// console.log(ll, 50.2058, -125.2682);
const newd = tideMod.map(({ date, ...row }) => {
date = d3.isoParse(date);
const sun = suncalc.getTimes(new Date(date), ll[0], ll[1]);
// console.log(sun);

let day;
if (d3.isoParse(sun.sunrise) < date && date < d3.isoParse(sun.sunset)) {
day = 0;
} else {
day = 10;
}
return { ...row, date, day };
});
newd.sort((a, b) => a.date - b.date);
return newd;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// $ = require("jquery")
Insert cell
Insert cell
Insert cell
Insert cell
h = 100
Insert cell
import {slideshow} from '@asg017/slideshow'
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