Skip to content

Instantly share code, notes, and snippets.

@Andrew-Reid
Andrew-Reid / index.html
Last active April 5, 2024 20:46
~ 20 000 Simultaneous Canvas Transitions
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Canvas, Lots of Transitions</title>
<script src='https://d3js.org/d3.v4.min.js' type='text/javascript'></script>
</head>
@Andrew-Reid
Andrew-Reid / d3-cluster.js
Last active December 8, 2023 02:48
D3 Marker Clustering
// https://d3js.org/d3-force/ Version 1.1.0. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-quadtree'), require('d3-collection'), require('d3-dispatch'), require('d3-timer')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-quadtree', 'd3-collection', 'd3-dispatch', 'd3-timer'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,global.d3));
}(this, (function (exports,d3Quadtree,d3Collection,d3Dispatch,d3Timer) { 'use strict';
var constant = function(x) {
return function() {
@Andrew-Reid
Andrew-Reid / index.html
Last active October 17, 2023 02:42
~20 000 Simultaneous SVG Transitions
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SVG Lots of Transitions</title>
<script src='https://d3js.org/d3.v4.min.js' type='text/javascript'></script>
</head>
@Andrew-Reid
Andrew-Reid / customers.csv
Last active August 12, 2023 22:47
Map Data Sources - Alternating CSVs - Load on Demand
customers long lat
Ann -157 21
Bob 178 -18
Cathy 120 15
Dan 105 21
Carlos -82 23
Maria -80 26
Edna -75 10
Jaun -80 8.5
Al 141 43
@Andrew-Reid
Andrew-Reid / index.html
Last active January 11, 2023 14:09
Flow Map
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<script src="http://d3js.org/d3.v4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script>
<script src="https://d3js.org/d3-geo-projection.v1.min.js"></script>
<style>
.route {
@Andrew-Reid
Andrew-Reid / index.html
Last active October 9, 2022 11:10
Nested Enter/Update/Exit with id
<html>
<head>
<script src="https://d3js.org/d3.v4.js"></script>
</head>
<body>
<script>
// starter data:
var data = [
{id:0, children: d3.range(10)},
@Andrew-Reid
Andrew-Reid / index.html
Created March 15, 2021 03:43
Key function
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
</head>
<body>
<script>
var svg = d3.select("body")
.append("svg")
.attr("width", 960)
@Andrew-Reid
Andrew-Reid / data.csv
Last active April 26, 2020 22:07
Grouped Bar Chart Toggle Series
State Under 5 Years 5 to 13 Years 14 to 17 Years 18 to 24 Years 25 to 44 Years 45 to 64 Years 65 Years and Over
CA 2704659 4499890 2159981 3853788 10604510 8819342 4114496
TX 2027307 3277946 1420518 2454721 7017731 5656528 2472223
NY 1208495 2141490 1058031 1999120 5355235 5120254 2607672
FL 1140516 1938695 925060 1607297 4782119 4746856 3187797
IL 894368 1558919 725973 1311479 3596343 3239173 1575308
PA 737462 1345341 679201 1203944 3157759 3414001 1910571
@Andrew-Reid
Andrew-Reid / index.html
Last active April 16, 2020 17:25
d3v4 Multiple Pie Charts on Map - Data from CSV
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
svg {
background: #9ecae1;
}
.mesh {
fill:none;
@Andrew-Reid
Andrew-Reid / data.json
Last active April 7, 2020 04:42
Grouped Force Layout
{
"nodes": [
{"id": "Myriel", "group": 1},
{"id": "Napoleon", "group": 1},
{"id": "Mlle.Baptistine", "group": 1},
{"id": "Mme.Magloire", "group": 1},
{"id": "CountessdeLo", "group": 1},
{"id": "Geborand", "group": 1},
{"id": "Champtercier", "group": 1},
{"id": "Cravatte", "group": 1},