Skip to content

Instantly share code, notes, and snippets.

// XXX YOU ARE NOT MEANT TO EDIT THIS FILE
// XXX YOU ARE NOT MEANT TO EDIT THIS FILE
// XXX YOU ARE NOT MEANT TO EDIT THIS FILE
let key_func = function(d){ return d.id }
// https://bost.ocks.org/mike/chart/
// XXX meant to be used with datum(), not data()
// i.e. selection should just be a single g
@zischwartz
zischwartz / README.md
Created January 4, 2018 19:16 — forked from mbostock/README.md
Local Variables

It’s often desirable when using D3 to define local behavior, that is, behavior that is specific to an individual element, rather than the same for all elements in a selection. The simplest example of this is passing a function to selection.attr to compute an attribute value for each element.

But what happens if your local behavior is more complicated? What if you want multiple operations (multiple attributes, or elements) to have local behavior, but still share local state between them? For instance, when rendering small multiples of time-series data, you might want the same x-scale for all charts but distinct y-scales to compare the relative (not absolute) performance of each metric.

There are several ways to do this in D3:

  1. Make the y-scale global, but set the domain on the y-scale before use. (Example.)

  2. Use selection.each to create a local con

@zischwartz
zischwartz / index.html
Last active February 22, 2018 15:52
Example descriptionwefawioejfoijwaef joiaj
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<div class="content">
<span id="greet">Hello</span>
</div>
<script type="text/javascript" src="index.js"></script>
let cards = [0,1,2,3,4]
@zischwartz
zischwartz / .block
Last active January 30, 2018 16:18
d3 raise()/order problem
license: mit
@zischwartz
zischwartz / .block
Created December 13, 2017 17:21
fresh block
license: mit
@zischwartz
zischwartz / .block
Created November 15, 2017 14:17
Local Variables
license: mit
@zischwartz
zischwartz / .block
Created November 13, 2017 20:47
Circle Dragging I
license: gpl-3.0
function make_graph(data){
var svg = d3.select("svg")
// hackily just remove everything from last time.
// a more sophisticated version would transition nicely
svg.selectAll("*").remove()
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom;
@zischwartz
zischwartz / rgb_to_lab.swift
Created March 23, 2016 19:54
Convert RGB to L*ab color space in Swift
//http://stackoverflow.com/a/24201042/83859
infix operator ^^ { }
func ^^ (radix: Double, power: Double) -> Double {
return Double(pow(Double(radix), Double(power)))
}
//Based on https://github.com/d3/d3-color/blob/master/src/lab.js