• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Snippets and conventions for d3

This repo is no longer being updated!

Template code lives at d3-init

Library code merged into d3-jetpack

d3-starterkit

Snippets and conventions for starting a new d3 project without a fuss. Includes d3, lodash, d3-jetpack, some handy css and a few convenience functions. Short example and longer blog post.

This branch uses d3 verison 4, see the d3v3 branch to use with d3 version 3.

selection.dataAppend

Instead of making an empty selection, binding data to it, taking the enter selection and appending elements as separate steps:

var circles = svg.selectAll('circle')
    .data(data)
    .enter()
    .append('circle')

Use dataAppend:

var circles = svg.dataAppend(data, 'circle')

selection.selectAppend

Select or append a single element. Always returning the selection:

var g = svg.selectAll('g')
    .data([null])
    .call(function(sel) {
      sel.enter().append('g')
    })

Use selectAppend:

var g = el.selectAppend('g')

d3.attachTooltip

Attaches a light weight tooltip that prints out all of an objects properties on mouseover. No more > d3.select($0).datum()! Assumes that a <div class='tooltip'></div> and the tooltip css exist on the page – see index for an example.

circles.call(d3.attachTooltip)

For formated tooltips, update the html of the tooltip on mouseover:

circles
    .call(d3.attachTooltip)
    .on('mouseover', function(d){
      d3.select('.tooltip').html(template(d)) })

If your fancy tooltip requires lots of markup, using a template might be easier than building a complex html tree with d3.

d3.conventions

d3.conventions() appends an svg element with a g element according to the margin convention to the page and returns an object with the following properties:

totalWidth, totalHeight, margin: size of the svg and its margins

width, height: size of svg inside of margins.

parentSel: d3.selection of the element the svg was appended to. Defaults to d3.select("body"), but like every other returned value, can be specified by passing in an object: d3.conventions({parentSel: d3.select("#graph-container"), totalHeight: 1300}) appends an svg to #graph-container with a height of 1300.

svg: g element translated to make room for the margins

x: Linear scale with a range of [0, width]

y: Linear scale with a range of [height, 0]

xAxis: Axis with scale set to x and orient to "bottom"

yAxis: Axis with scale set to y and orient to "left"

drawAxis: Call to append axis group elements to the svg after configuring the domain. Not configurable.

More Repositories

1

graph-scroll

scrollers > steppers
HTML
509
star
2

roadtolarissa

JavaScript
182
star
3

swoopy-drag

Artisanal label placement for d3 graphics
HTML
120
star
4

hot-server

live-server with hot reloading
JavaScript
99
star
5

gistsnap

snapshot thumbnails for blocks.roadtolarissa.com
JavaScript
34
star
6

reddit-comment-visualizer

downloads and displays user's reddit comments
JavaScript
31
star
7

kindle-tracker

JavaScript
28
star
8

meteors

interactive map of 500 years of witnessed meteor impacts
JavaScript
24
star
9

d3-init

blocks template
CSS
18
star
10

tornado-tuners

interactive map of tornados
JavaScript
18
star
11

d3-jetpack-module

JavaScript
16
star
12

talks

CSS
13
star
13

doc2txt

google doc -> .md
JavaScript
11
star
14

film-strips

JavaScript
8
star
15

unemployment

unemployment rates by gender, race, age, and education
JavaScript
7
star
16

BizarreSierpinskiTriangle

JavaScript
7
star
17

whalewords

word frequency in Moby Dick with d3.js
JavaScript
7
star
18

gistclone

clones a gist or bl.ock.org url
JavaScript
6
star
19

nbadraft

how effective are higher picks in the nba?
JavaScript
5
star
20

connect4-ai

JavaScript
5
star
21

scraping

HTML
4
star
22

scrape-stl

scrape-stl
JavaScript
4
star
23

d3-force-container

constrain particles to an area for forceSimulation in d3v4
JavaScript
4
star
24

deportions

JavaScript
3
star
25

stringline-status

JavaScript
3
star
26

comp-geo

JavaScript
2
star
27

whitehouse-petitions

scrapes and analyses White House petitions
Python
2
star
28

chicago-crime-crossfilter

JavaScript
2
star
29

typing

Lyric Typing Game
JavaScript
2
star
30

learning

HTML
2
star
31

d3-rectangleForce

1
star
32

box-scores

scrapes nba box scores
JavaScript
1
star
33

news-block

filter out sticky banners, pivots to video and newsletter nags
1
star
34

hello-arcadia

Clojure
1
star
35

sound-shapes

JavaScript
1
star
36

nycdatascience

JavaScript
1
star
37

subway-parse

JavaScript
1
star
38

hangout-boardgames

play board games on google hangout
JavaScript
1
star
39

shader-school

JavaScript
1
star
40

webpack-hmr

JavaScript
1
star
41

webgl-workshop

JavaScript
1
star