Published unlisted
Edited
Jan 8, 2021
Fork of Glider map
1 star
Insert cell
Insert cell
Insert cell
{
replay;
const container = html`<div style="height:600px;">`;
yield container; // Give the container dimensions.
// mutable name = 0;
// d3.interval((elapsed, i) => {
// mutable name = mutable name + 1;
// }, (speed * 4000) / 147);attrTween

const map = (container.value = new mapboxgl.Map({
container,
// Bogotá 4.7110° N, 74.0721° W
center: [-114.4659426, 49.07319046],
zoom: 8,
style: "mapbox://styles/jguerrag/cjuerw13z2vja1fndc9wzk7eo",
scrollZoom: false
}));

// Setup our svg layer that we can manipulate with d3
const bb = container.getBoundingClientRect();

const height = 500;
const svg = d3
.select(container)
.append("svg")
.style("position", "absolute")
.style("top", 0)
.style("left", 0)
.attr("width", bb.width)
.attr("height", bb.height)
.style("pointer-events", "none");
// .call(zoom);

let cg = svg.append("g").attr("transform", `translate(${685},${135})`);

// function calendar(element) {
// element.selectAll("*").remove();

cg.append("text")
.classed("calendar-date", true)
.text("")
.attr("dy", "-5")
.attr("font-size", "23px")
.attr("text-anchor", "start")
.attr("text-transform", "uppercase")
.attr("font-family", "monospace")
.attr("font-weight", "bold")
.attr("fill", "black");
// }
// calendar(cg);

let count = 0;

d3.interval(() => {
d3.select(".calendar-date")
.transition()
.text(
bear_data[0].properties.dates[count].toLocaleString(undefined, {
year: "numeric",
month: "short",
day: "numeric"
})
);
count++;
}, (speed * 1000) / bear_data[0].properties.dates.length);
//Project any point to map's current state
function projectPoint(lon, lat) {
// let dateIndex = bear_data[0].geometry.coordinates.findIndex(
// d => d[0] === lon
// );
// console.log(lon, lat);
// if (dateIndex !== -1) {
// mutable name = newBear.properties.dates[dateIndex];
// }
var point = map.project(new mapboxgl.LngLat(lon, lat));
this.stream.point(point.x, point.y);
}

//Projection function
var transform = d3.geoTransform({ point: projectPoint });
var path = d3.geoPath().projection(transform);
// console.log("h", path);

const g = svg.append("g").attr("id", "map-layers");

let current_circle = undefined;

function tweenDash() {
// console.log(this);
var l = this.getTotalLength(),
i = d3.interpolateString("0," + l, l + "," + l);
return function(t) {
// console.log(t);
return i(t);
};
}

const bearPath = g
.append("g")
.selectAll("path")
.data(bear_data)
.join("path")
.attr("class", "lines")
.attr("d", path)
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke", (d, i) => {
// console.log("here", d);
return "steelblue";
// return color(d.properties);
})
.attr("stroke-opacity", 0.5)
.attr("stroke-linecap", "round");

const circle = svg
.append("circle")
.attr("r", 6)
.attr(
"transform",
"translate(" + bear_data[0].geometry.coordinates[0] + ")"
)
.style("fill", "yellow")
.style("stroke", "#444");

// transition();
animatePath();
function transition() {
circle
.transition()
.ease(d3.easeLinear)
.duration(speed * 1000)
.attrTween("transform", translateAlong(bearPath.node()))
.end()
.then(transition);
}

// Returns an attrTween for translating along the specified path element.
function translateAlong(circuitLine) {
var l = circuitLine.getTotalLength();
return function(d, i, a) {
return function(t) {
var p = circuitLine.getPointAtLength(t * l);
// console.log(p);
return "translate(" + p.x + "," + p.y + ")";
};
};
}

function animatePath() {
g.selectAll(".lines")
.transition()
.ease(d3.easeLinear)
.duration(speed * 1000)
.attrTween("stroke-dasharray", tweenDash);
}

// return svg.node();
// yield container;
}
Insert cell
import { newBear } from '79f3fe6b7d87b530'
Insert cell
// (newBear.geometry.coordinates[1] = [-114.4658438, 49.21817663])
Insert cell
newBear.geometry.coordinates
Insert cell
bear_data[0].properties.dates.length
Insert cell
date
Insert cell
speed = 40
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
projection = d3
.geoAlbers()
.rotate([126, 0])
.center([0, 51.2])
.parallels([50, 58.5])
.scale(25400)
.translate([960, 600 / 2])
Insert cell
filter_index = new_time.indexOf(date)
Insert cell
utcSeconds = time[0]
Insert cell
d = new Date(time[0])
Insert cell
d.setUTCSeconds(utcSeconds)
Insert cell
Insert cell
Insert cell
Insert cell
interval = d3.timeMonth.every(1)
Insert cell
Insert cell
height = 500
Insert cell
d3 = require("d3@6")
Insert cell
_ = require("lodash")
Insert cell
topojson = require("topojson-client@3")
Insert cell
import { bcSiteLocs, flatData, uniqClass } from 'a918fce3c1f416e8'
Insert cell
us.objects
Insert cell
states = topojson.feature(us, us.objects.states)
Insert cell
import { states as us } from "@harrystevens/mapping-gridded-data-with-a-voronoi-diagram"
Insert cell
import { BC_Midres } from '@mbrownshoes/how-i-start-maps-in-d3'
Insert cell
import { Scrubber } from "@mbostock/scrubber"
Insert cell
Insert cell
raw = FileAttachment("Male 150 GPS points.csv").csv({ typed: true })
Insert cell
md`Netcdf processing`
Insert cell
Insert cell
bear_data = {
const data = [];
data.push(newBear);
return data;
}
Insert cell
bear_data[0].geometry.coordinates.findIndex(d => d[0] === -114.926283075)
Insert cell
dt = aq.from(allData)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
last = array => array[array.length - 1]
Insert cell
d3.groups(both, d => d.site)
Insert cell
d3.max(dataBySite, d => d3.max(d.data, dd => dd.depth_mean))
Insert cell
Insert cell
Insert cell
plot_data = dt1.objects()
Insert cell
formatDay = d3.timeFormat("%Y-%m-%d %H")
Insert cell
Insert cell
timeParser = d3.timeParse("%Y-%m-%d %H")
Insert cell
// timeParser(formatDay(new_time[1]))
Insert cell
// new_time[1]
Insert cell
aq.addFunction('parse_mdy', makeHourly, { override: true })
Insert cell
Insert cell
Latscombined = lats.concat(latsEva)
Insert cell
Lonscombined = lons.concat(lonsEva)
Insert cell
Timecombined = time.concat(timeEva)
Insert cell
Sitescombined = site.concat(siteEva)
Insert cell
Insert cell
site = Array.from({ length: lats.length })
.fill(['Mike'])
.flat()
Insert cell
lats = reader.getDataVariable("latitude")
Insert cell
latsEva = readerEva.getDataVariable("latitude")
Insert cell
depthcombined = depth.concat(depthEva)
Insert cell
depthEva = readerEva.getDataVariable("depth")
Insert cell
depth = reader.getDataVariable("depth")
Insert cell
lons = reader.getDataVariable("longitude")
Insert cell
lonsEva = readerEva.getDataVariable("longitude")
Insert cell
new Date(timeEva[0])
Insert cell
new Date(time[0])
Insert cell
timeEva = readerEva.getDataVariable("time")
Insert cell
time = reader.getDataVariable("time")
Insert cell
reader.variables
Insert cell
readerEva.variables
Insert cell
reader = new NetCDFReader(data)
Insert cell
readerEva = new NetCDFReader(data_eva)
Insert cell
data = FileAttachment("mike579.nc").arrayBuffer()
Insert cell
data_eva = FileAttachment("eva.nc").arrayBuffer()
Insert cell
import { aq, op } from '@uwdata/arquero'
Insert cell
mapboxgl = {
const gl = await require("mapbox-gl");
if (!gl.accessToken) {
gl.accessToken =
"pk.eyJ1Ijoiamd1ZXJyYWciLCJhIjoiY2pueW9uMGhzMDA3NDN3bXp5b2Rqbzk1YiJ9.3scgV-j4d394mvOUqtz1XQ";
const href = await require.resolve("mapbox-gl/dist/mapbox-gl.css");
document.head.appendChild(html`<link href=${href} rel=stylesheet>`);
}
return gl;
}
Insert cell
NetCDFReader = require('netcdfjs@1.0.0/dist/netcdfjs.js')
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