Public
Edited
Jan 14, 2021
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
duration = 100
Insert cell
Insert cell
mutable x = null
Insert cell
mutable tick = 0
Insert cell
Insert cell
{
replay;
if (x !== null) {
progress.value = 0;
while (progress.value < progress.max) {
await Promises.delay(duration);
progress.value += 1;
mutable tick = progress.value;
yield progress.value;
}
} else {
progress.value = 0;
}
}
Insert cell
Insert cell
Insert cell
progress = html`<progress max="${dataByDate.features.length - 1}"></progress>`
Insert cell
bearWalks = {
await visibility();
if (visibility()) {
mutable x = 0;
}
replay;

const container = html`<div style="height:600px; ">`;
yield container; // Give the container dimensions.

const map = (container.value = new mapboxgl.Map({
container,
center: [-114.6659426, 49.3],
zoom: r1,
style: r,
scrollZoom: false,
interactive: false
}));
map.addControl(new mapboxgl.ScaleControl({ position: 'bottom-right' }));

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

const height = 600;
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},${35})`);

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", d => {
return r === "mapbox://styles/mapbox/satellite-v9" ? "white" : "black";
});

//Project any point to map's current state
function projectPoint(lon, lat) {
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;

let circle;
// console.log(dataByDate.features[0][0].geometry.coordinates[0]);
circle = svg
.append("circle")
// .append("image")
// .attr("xlink:href", bear)
.attr("r", 6)
.attr(
"transform",
"translate(" + dataByDate.features[0][0].geometry.coordinates[0] + ")"
)
.style("fill", "#8A643C")
.style("stroke", "#8A643C");

function animatePath(ind) {
g.selectAll("#linesMade" + ind)
.transition()
.ease(d3.easeLinear)
.duration(d => {
return duration;
})
.attrTween("stroke-dasharray", tweenDash);
}

// animate
// invalidation;

dataByDate.features.forEach((e, i) => {
setTimeout(function() {
const bearPath = g
.append("g")
.selectAll("path")
.data(e)
.join("path")
.attr("id", "linesMade" + i)
.attr("class", "lines")
.attr("d", path)
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke", (d, i) => {
return "#1E5D6F";
})
// .attr("stroke-opacity", 0.4)
.attr("stroke-linecap", "round");

animatePath(i);

circle
.transition()
.ease(d3.easeLinear)
.duration((d, i) => {
return duration;
})
.attrTween("transform", translateAlong(bearPath.node()))
.end();
// }

// 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) {
// console.log(t);
var p = circuitLine.getPointAtLength(t * l);
// console.log(p);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
}, i * duration);
});
}
Insert cell
bear_data[0].properties.dates
Insert cell
allDates = [...new Set(gf.map(d => d.fullDate))]
Insert cell
Insert cell
bear_data
Insert cell
(577 * 100) / 1000
Insert cell
Insert cell
bear = FileAttachment(
"Google-Noto-Emoji-Animals-Nature-22259-bear-face.ico"
).url()
Insert cell
import { newBear, filledData, gf } from '79f3fe6b7d87b530'
Insert cell
speed = 40
Insert cell
// utcSeconds = time[0]
Insert cell
// d = new Date(time[0])
Insert cell
height = 500
Insert cell
d3 = require("d3@6")
Insert cell
_ = require("lodash")
Insert cell
topojson = require("topojson-client@3")
Insert cell
Insert cell
// raw = FileAttachment("Male 150 GPS points.csv").csv({ typed: true })
Insert cell
filledData[0]
Insert cell
gf[0]
Insert cell
dataByDate = {
const out = {};
const datetime = [];
const coords = [];
const dates = [];
const features = [];

// properties.pickuptime = {}
for (let i = 0; i < gf.length - 1; i++) {
const properties = {};
// datetime.push(d.date);
// coords.push([d.mean_lon, d.mean_lat]);
// properties.pickuptime =
let geometry = {};
features.push([
{
type: "Feature",
pickuptime: gf[i].fullDate,
dropofftime: gf[i + 1].fullDate,
geometry: {
type: "LineString",
coordinates: [
[gf[i].Long, gf[i].Lat],
[gf[i + 1].Long, gf[i + 1].Lat]
]
}
}
]);
out.features = features;
out.type = "FeatureCollection";
}
// mutable debug = d3.extent(datetime);
// out.type = "FeatureCollection";
// out.properties = {};
// out.properties.pickuptime = d3.extent(datetime)[0];
// out.properties.dropofftime = d3.extent(datetime)[1];
// out.properties.dates = datetime;
// out.geometry = {};
// out.geometry.type = "LineString";
// out.geometry.coordinates = {};
// out.geometry.coordinates = coords;

return out;
}
Insert cell
bear_data = {
const data = [];
data.push(newBear);
return data;
}
Insert cell
last = array => array[array.length - 1]
Insert cell
timeParser = d3.timeParse("%Y-%m-%d %H")
Insert cell
// timeParser(formatDay(new_time[1]))
Insert cell
// new_time[1]
Insert cell
// time = reader.getDataVariable("time")
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
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