Skip to content

Instantly share code, notes, and snippets.

View adg29's full-sized avatar
📱

Alan Garcia adg29

📱
View GitHub Profile
@adg29
adg29 / conditionalwrap.js
Created September 25, 2020 22:43 — forked from kitze/conditionalwrap.js
one-line React component for conditionally wrapping children
import React from 'react';
const ConditionalWrap = ({condition, wrap, children}) => condition ? wrap(children) : children;
const Header = ({shouldLinkToHome}) => (
<div>
<ConditionalWrap
condition={shouldLinkToHome}
wrap={children => <a href="/">{children}</a>}
>
@adg29
adg29 / README.md
Created September 21, 2016 19:13 — forked from veltman/README.md
Smoother polygon transitions

Smooth transitioning US tour in the same vein as this example. Steps:

  1. Compares both shapes and adds evenly-spaced points to whichever polygon has fewer so that both have the same number of points
  2. Picks the winding of the first polygon that minimizes the sum of the squared distances between point pairs

Some possible improvements:

  • Adding additional points to both shapes first such that every segment longer than a certain distance is bisected
  • Tweaking the placement of added points with simulated annealing
  • Using a cost function that factors in self-intersections at the halfway mark in addition to distance traveled
@adg29
adg29 / README.md
Last active July 26, 2016 15:29 — forked from monfera/.block
circinus

Playing with reusing d3.geo for plotting. Subsequent example: http://bl.ocks.org/monfera/11085004

Mike Bostock and Jason Davies have added cool geo features, some of which can be of interest for regular data plotting too (most of which not covered in this example):

  1. The use of projections to easily change between Cartesian, polar, spiral, etc. plots
  • d3.geo supports spherical projections; this example projects a sphere-bound spiral
  1. Traditional, but data-intensive plots can benefit from adaptive resampling and line simplification
@adg29
adg29 / README.md
Created April 21, 2016 17:32 — forked from dmachat/README.md
Map click + updateChoropleth bug
@adg29
adg29 / README.md
Created March 15, 2016 19:47 — forked from bycoffe/README.md
Town/county map using d3 and TopoJSON

This is a demonstration of how to create a combination town/county map from a shapefile using TopoJSON and d3.js.

It includes a simplified version of the code used for the Massachusetts special Senate election results on The Huffington Post.

Get the data

Download a shapefile of Massachusetts towns from the state's GIS site:

wget http://wsgw.mass.gov/data/gispub/shape/census2000/towns/census2000towns_poly.exe
@adg29
adg29 / index.html
Last active September 1, 2015 17:33 — forked from sconnelley/index.html
Fitting D3 map inside a viewport and constrain panning.
<!DOCTYPE html>
<html lang="en">
<head>
<title>d3 geo map</title>
<meta charset="utf-8">
<style>
svg {
border: 1px solid #ccc;
}
@adg29
adg29 / d3.geo.voronoi.js
Last active August 29, 2015 14:27 — forked from fitnr/d3.geo.voronoi.js
US Urban Areas Voronoi
(function() {
var π = Math.PI,
degrees = 180 / π,
radians = π / 180,
ε = 1e-15,
circle = d3.geo.circle().angle(90);
d3.geo.voronoi = function(points, triangles) {
if (arguments.length < 2) triangles = d3.geo.delaunay(points);
@adg29
adg29 / README.md
Last active April 27, 2017 17:50 — forked from mbostock/.block
TopoJSON Resources

Some of these files are from the us-atlas:

  • us.json - make topo/us-10m.json
  • us-congress-113.json - make topo/us-congress-10m.json

Others are from the world-atlas:

  • world-50m.json - make topo/world-50m.json
  • world-110m.json - make topo/world-110m.json
@adg29
adg29 / README.md
Last active April 27, 2017 17:51 — forked from amrit/README.md
US State Emissions Choropleth

US State Emissions Choropleth

@adg29
adg29 / README.md
Last active April 27, 2017 18:01 — forked from mbostock/.block
U.S. Counties TopoJSON

A demo of TopoJSON on a U.S. counties shapefile from the U.S. census bureau. The same TopoJSON file can also be used to show states.