Skip to content

Instantly share code, notes, and snippets.

@pbogden
pbogden / README.md
Last active June 17, 2023 17:24
D3 + Leaflet
@pbogden
pbogden / README.md
Last active February 1, 2022 04:53
Clustered Force Layout v4
@pbogden
pbogden / README.md
Last active July 9, 2021 02:28
SVG button
@pbogden
pbogden / README.md
Last active May 6, 2021 11:06
event

Event bubbling & capturing demo

  1. SVG elements are not nested -- they don't bubble to each other. Topmost element is the target.
  2. Blue SVG rect captures the event with d3.event.stopPropagation();
  3. Nested DIV elements bubble to each other up the DOM tree.
  4. Non-nested DIV elements don't bubble to each other.
@pbogden
pbogden / README.md
Last active November 15, 2019 22:36
simple x-y plot
@pbogden
pbogden / 5899e123023fd122@57.js
Last active November 15, 2019 10:22
Observable Leaflet
// https://observablehq.com/@pbogden/hello-leaflet-run-elsewhere@57
export default function define(runtime, observer) {
const main = runtime.module();
main.variable(observer()).define(["md"], function(md){return(
md`# Hello, Leaflet (run elsewhere)
A quick demo of [Leaflet](https://leafletjs.com/).
See below for instructions to download the code and run it in another web page,
where you can access the map and add a layer. If you get it to work, the map
@pbogden
pbogden / README.md
Created October 31, 2019 17:30
My Demo Gist

Hello world

@pbogden
pbogden / README.md
Last active May 16, 2019 01:14
d3 gsheet plugin (JSONP)

Google spreadsheet as a data source (JSONP).

#d3.gsheet(key [, sheet], callback)

Retrieves data from the Google Spreadsheet associated with the spreadsheet key. The optional sheet is a string that corresponds to the name of the desired sheet in the spreadsheet. The default is to read the first sheet. The callback is invoked with an array of objects as the argument, consistent with d3.csv().

To adapt this demo to another spreadsheet, you must:

@pbogden
pbogden / README.md
Last active April 26, 2019 19:23
D3 + OpenLayers

This D3 + OpenLayers example mirrors as closely as possible Mike Bostock's D3 + Leaflet example. See his example for an explanation.

Primary differences:

  1. OpenLayers uses Mercator (EPSG:4326) by default, which appears distorted (for example). It's easy to switch to "Spherical Mercator" (EPSG:900913), but then you need to be careful to convert lon/lat to the OpenLayers default x/y coordinates in meters.

  2. As in this example, the code below uses an OpenLayers Vector Layer in place of Leaflet's overlay pane. Whereas Leaflet requires repositioning only on zoom, OpenLayers needs repositioning for both zoom and pan. This makes it easier to size the SVG with OpenLayers -- it need only fit the viewport, as long as you're willing to wait for clipped features to be drawn after pan events. Fo