Skip to content

Instantly share code, notes, and snippets.

View seliopou's full-sized avatar
💭
I may be slow to respond.

Spiros Eliopoulos seliopou

💭
I may be slow to respond.
View GitHub Profile

Instead of adding methods to d3.selection, make a transform its own object that you can define independently of a selection. So this...

d3.selectAll("g.label")
  .translate(function(d) { return [20,d.x*10]})
  .rotate(40)
  .scale(function(d) {return [d.size,2]})

... would turn into this:

@seliopou
seliopou / d3-transform-chaining.md
Last active December 15, 2015 16:09
A discussion of the API behavior of d3-transform.

d3-transform chaining

An unnecessarily thorough analysis

The Methods of d3.selection

When you look at the behavior of the methods on a d3.selection, they fall into one of two categories:

  • those that create a new selection, e.g., .filter(), .exit(), .enter(), .append(), etc.; and
  • those that mutate the existing selection, e.g., .attr(), .style(), on(), etc.

Question: Are these categories disjoint and exhaustive?

@seliopou
seliopou / gist:5623971
Created May 21, 2013 23:02
how to do that thing
var g = svg.selectAll('g')
.data(/* the data */)
g.enter().append('circle')
g.selectAll('circle')
.attr('r', function(d) { /* radius */ })
@seliopou
seliopou / Permutation.hs
Created July 17, 2013 16:10
Random Code, Permutations, and unsafePerformIO
module Permutation
( permute -- :: RandomGen g => [a] -> g -> ([a], g)
, permuteST -- :: RandomGen g => [a] -> g -> ST s ([a], g)
, permuteIO -- :: [a] -> IO [a]
, unsafePermute -- :: [a] -> [a]
) where
import Control.Monad ( foldM )
-- N.B. Unsafe operations have been deprecated in the original module and have
-- been moved to Control.Monad.ST.Unsafe.
@seliopou
seliopou / static-voronoi.html
Last active August 29, 2015 13:57
Static Voronoi diagram example
<!DOCTYPE html>
<meta charset="utf-8">
<style>
/* taken from: http://bl.ocks.org/mbostock/4060366 */
path {
stroke: #fff;
}
@seliopou
seliopou / Video.elm
Created May 13, 2014 00:42
An example of using elm-d3 to embed a video.
-- This is how you embed a video in your Elm program using elm-d3. From the
-- root directory of the elm-d3 project, compile it using something like the
-- following command:
--
-- elm --make --src-dir=src `./scripts/build-flags` /path/to/Video.elm
--
-- Of course, replace /path/to/Video.elm with the path to this module.
--
module Video where
@seliopou
seliopou / FileInput.elm
Last active August 29, 2015 14:01
An example of using elm-d3 to create a form with a file input.
-- This is how you create a form that supports file upload, and drag-n-drop.
-- From the root directory of the elm-d3 project, compile it using something
-- like the following command:
--
-- elm --make --src-dir=src `./scripts/build-flags` /path/to/FileInput.elm
--
-- Of course, replace /path/to/FileInput.elm with the path to this module.
--
module FileInput where
@seliopou
seliopou / _.md
Last active August 29, 2015 14:05
test
@seliopou
seliopou / _.md
Last active August 29, 2015 14:05
Tributary inlet
@seliopou
seliopou / _.md
Last active August 29, 2015 14:05
Scale Solar System