Skip to content

Instantly share code, notes, and snippets.

View pnavarrc's full-sized avatar

Pablo Navarro pnavarrc

  • Act Now Coalition
  • Vancouver, Canada
  • 02:55 (UTC -07:00)
View GitHub Profile
@pnavarrc
pnavarrc / README.md
Last active March 2, 2018 11:30
SVG Linear Gradient with D3

SVG Linear Gradient with D3

This example demonstrates how to use gradients in SVG, defining the stop colors completely via CSS. The advantage of this approach is that we can use gradients in shapes without having to hardcode the stop-color attributes when defining the gradients in the SVG element.

References

@pnavarrc
pnavarrc / README.md
Last active August 29, 2015 14:05
Responsive SVG Image

Responsive SVG Image

This gist shows how to include an SVG image that adapts to the size of its container.

Whale

For this technique to work, the SVG element should have the attribute viewBox set with the image dimensions, and the attribute preserveAspectRatio="xMinYMin meet", and it shouldn't have the attributes width and height.

The container should have a width defined, as a percent or as a size in pixels.

Inserting SVG in the DOM

Inserting SVG images as DOM nodes instead of inserting them as images or objects. In this example, we load an image stored as JST templates and insert the image into the DOM, allowing to modify its style via CSS and its attributes with JavaScript.

In this gist, we change the whale color and make it move using D3.

Whale

References

@pnavarrc
pnavarrc / Makefile
Last active August 30, 2016 18:12
Square Countries
URL = http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip
ne_50m_admin_0_countries.zip:
curl -LO $(URL)
ne_50m_admin_0_countries.shp: ne_50m_admin_0_countries.zip
unzip ne_50m_admin_0_countries.zip
touch ne_50m_admin_0_countries.shp
countries.json: ne_50m_admin_0_countries.shp
@pnavarrc
pnavarrc / Makefile
Created September 8, 2014 15:41
Automatic Scaling Features with D3
URL = http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip
ne_50m_admin_0_countries.zip:
curl -LO $(URL)
ne_50m_admin_0_countries.shp: ne_50m_admin_0_countries.zip
unzip ne_50m_admin_0_countries.zip
touch ne_50m_admin_0_countries.shp
countries.json: ne_50m_admin_0_countries.shp
@pnavarrc
pnavarrc / README.md
Last active May 4, 2016 05:49
Moiré Patterns

Moiré Patterns

Moiré Patterns are patterns that results from overlapping two periodical patterns (series of straight lines, for instance). This demo allows to create Moiré patterns by changing the relative angle between the patterns, the number of bars, the bar width and the color of the bars.

Moiré Patterns

This demo uses D3 to create the patterns with SVG rectangles.

References

@pnavarrc
pnavarrc / countries.topojson
Last active September 26, 2015 12:31
Custom Raw Projection
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pnavarrc
pnavarrc / Makefile
Last active September 25, 2015 23:11
Simple Map with D3
# Download and Transform the 1:50m Country Shapefiles from Natural Earth
# http://www.naturalearthdata.com/downloads/110m-physical-vectors/
URL = http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip
# Download the zip file from the Natural Earth server
ne_110m_land.zip:
curl -LO $(URL)
# Unzip the shapefiles
@pnavarrc
pnavarrc / Makefile
Last active September 26, 2015 02:47
Map with Graticule
# Download and Transform the 1:50m Country Shapefiles from Natural Earth
# http://www.naturalearthdata.com/downloads/110m-physical-vectors/
URL = http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip
# Download the zip file from the Natural Earth server
ne_110m_land.zip:
curl -LO $(URL)
# Unzip the shapefiles
@pnavarrc
pnavarrc / Makefile
Created September 19, 2015 20:50
Maps with TopoJSON
# Download and Transform the 1:50m Country Shapefiles from Natural Earth
# http://www.naturalearthdata.com/downloads/110m-physical-vectors/
URL = http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/physical/ne_110m_land.zip
# Download the zip file from the Natural Earth server
ne_110m_land.zip:
curl -LO $(URL)
# Unzip the shapefiles