This examples demonstrates how to use D3's brush component to implement focus + context zooming. Click and drag in the small chart below to pan or zoom.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns pas.tree | |
(:use [clojure.pprint :only [pprint]])) | |
(def reg-cntry-list | |
{"America" ["USA" "Canada" "Mexico" "Venezuala" "Brazil" "Argentina" "Cuba"] | |
"Asia" ["India" "Pakistan" "Singapore" "China" "Japan" "Sri Lanka" "Malaysia"] | |
"Europe" ["UK" "Germany" "France" "Italy" "Belgium" "Turkey" "Finland"] | |
"Middle East" ["Saudi Arabia" "Bahrain" "UAE" "Kuwait" "Yemen" "Qatar" "Iraq"] | |
"Africa" ["Libya" "Tanzania" "South Africa" "Kenya" "Ethiopia" "Morocco" "Zimbabwe"]}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def my-data {"Jay" | |
{"clojure" | |
{:name "Jay", :language "clojure", :enjoys true}, | |
"ruby" | |
{:name "Jay", :language "ruby", :enjoys true}} | |
"Jon" | |
{"java" | |
{:name "Jon", :language "java", :enjoys true}}} ) | |
(defn nth-vals* [a i m] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Use pyments to output syntax highlighted PNG files of Python code" | |
# http://paste.pocoo.org/show/402065/ | |
import glob | |
import re | |
import sys | |
import os | |
from pygments import highlight | |
from pygments.lexers import PythonLexer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Provides python-like string interpolation. | |
* It supports value interpolation either by keys of a dictionary or | |
* by index of an array. | |
* | |
* Examples:: | |
* | |
* interpolate("Hello %s.", ["World"]) == "Hello World." | |
* interpolate("Hello %(name)s.", {name: "World"}) == "Hello World." | |
* interpolate("Hello %%.", {name: "World"}) == "Hello %." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Code from http://peteriserins.com/2011/12/23/sat-in-clojure-core-logic.html | |
(defn and-rewrite [expr] | |
`(conde | |
(~(goalify (second expr)) | |
~(goalify (second (rest expr)))))) | |
(defn or-rewrite [expr] | |
`(conde | |
(~(goalify (second expr))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro with-private-fns [[ns fns] & tests] | |
"Refers private fns from ns and runs tests in context." | |
`(let ~(reduce #(conj %1 %2 `(ns-resolve '~ns '~%2)) [] fns) | |
~@tests)) | |
(with-private-fns [org.foo.bar [fn1 fn2]] | |
(deftest test-fn1..) | |
(deftest test-fn2..)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; From: http://clj-me.cgrand.net/2011/08/19/conways-game-of-life/ | |
(defn neighbours [[x y]] | |
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])] | |
[(+ dx x) (+ dy y)])) | |
(defn step [cells] | |
(set (for [[loc n] (frequencies (mapcat neighbours cells)) | |
:when (or (= n 3) (and (= n 2) (cells loc)))] | |
loc))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create_time_series(ystart) { | |
var start = new Date(1990, 0, 1); | |
var year = 1000 * 60 * 60 * 24 * 365; | |
return d3.range(0, 20, .02).map(function(x) { | |
return { | |
x: new Date(start.getTime() + year * x), | |
y: (ystart + .1 * (Math.sin(x * 2 * Math.PI)) | |
+ Math.random() * .1) * Math.pow(1.18, x) | |
+ Math.random() * .1}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label | value | |
---|---|---|
one | 25 | |
two | 50 | |
three | 78 | |
four | 44 | |
five | 23 | |
six | 90 | |
seven | 25 | |
eight | 16 | |
nine | 34 |
OlderNewer