forked from strongriley/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add various new examples. Update to 1.11.
- Loading branch information
Showing
49 changed files
with
1,333 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var w = 120, | ||
h = 500, | ||
m = [10, 50, 20, 50], // top right bottom left | ||
min = Infinity, | ||
max = -Infinity; | ||
|
||
var chart = d3.chart.box() | ||
.whiskers(iqr(1.5)) | ||
.width(w - m[1] - m[3]) | ||
.height(h - m[0] - m[2]); | ||
|
||
d3.csv("morley.csv", function(csv) { | ||
var data = []; | ||
|
||
csv.forEach(function(x) { | ||
var e = ~~x.Expt - 1, | ||
r = ~~x.Run - 1, | ||
s = ~~x.Speed, | ||
d = data[e]; | ||
if (!d) d = data[e] = [s]; | ||
else d.push(s); | ||
if (s > max) max = s; | ||
if (s < min) min = s; | ||
}); | ||
|
||
chart.domain([min, max]); | ||
|
||
var vis = d3.select("#chart").selectAll("svg") | ||
.data(data) | ||
.enter().append("svg:svg") | ||
.attr("class", "box") | ||
.attr("width", w) | ||
.attr("height", h) | ||
.append("svg:g") | ||
.attr("transform", "translate(" + m[3] + "," + m[0] + ")") | ||
.call(chart); | ||
|
||
chart.duration(1000); | ||
window.transition = function() { | ||
vis.map(randomize).call(chart); | ||
}; | ||
}); | ||
|
||
function randomize(d) { | ||
if (!d.randomizer) d.randomizer = randomizer(d); | ||
return d.map(d.randomizer); | ||
} | ||
|
||
function randomizer(d) { | ||
var k = d3.max(d) * .02; | ||
return function(d) { | ||
return Math.max(min, Math.min(max, d + k * (Math.random() - .5))); | ||
}; | ||
} | ||
|
||
// Returns a function to compute the interquartile range. | ||
function iqr(k) { | ||
return function(d, i) { | ||
var q1 = d.quartiles[0], | ||
q3 = d.quartiles[2], | ||
iqr = (q3 - q1) * k, | ||
i = -1, | ||
j = d.length; | ||
while (d[++i] < q1 - iqr); | ||
while (d[--j] > q3 + iqr); | ||
return [i, j]; | ||
}; | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var w = 960, | ||
h = 2200; | ||
|
||
var cluster = d3.layout.cluster() | ||
.size([h, w - 160]) | ||
.sort(null) | ||
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; }); | ||
|
||
var diagonal = d3.svg.diagonal() | ||
.projection(function(d) { return [d.y, d.x]; }); | ||
|
||
var vis = d3.select("#chart").append("svg:svg") | ||
.attr("width", w) | ||
.attr("height", h) | ||
.append("svg:g") | ||
.attr("transform", "translate(40, 0)"); | ||
|
||
d3.json("flare.json", function(json) { | ||
var nodes = cluster(d3.entries(json)[0]); | ||
|
||
var link = vis.selectAll("path.link") | ||
.data(cluster.links(nodes)) | ||
.enter().append("svg:path") | ||
.attr("class", "link") | ||
.attr("d", diagonal); | ||
|
||
var node = vis.selectAll("g.node") | ||
.data(nodes) | ||
.enter().append("svg:g") | ||
.attr("class", "node") | ||
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; }) | ||
|
||
node.append("svg:circle") | ||
.attr("r", 4.5); | ||
|
||
node.append("svg:text") | ||
.attr("dx", function(d) { return d.children ? -8 : 8; }) | ||
.attr("dy", 3) | ||
.attr("text-anchor", function(d) { return d.children ? "end" : "start"; }) | ||
.text(function(d) { return d.data.key; }); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var w = 960, | ||
h = 960, | ||
format = d3.format(",d"); | ||
|
||
var pack = d3.layout.pack() | ||
.size([w - 4, h - 4]) | ||
.children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null; }); | ||
|
||
var vis = d3.select("#chart").append("svg:svg") | ||
.attr("width", w) | ||
.attr("height", h) | ||
.attr("class", "pack") | ||
.append("svg:g") | ||
.attr("transform", "translate(2, 2)"); | ||
|
||
d3.json("flare.json", function(json) { | ||
var node = vis.data(d3.entries(json)).selectAll("g.node") | ||
.data(pack) | ||
.enter().append("svg:g") | ||
.attr("class", function(d) { return d.children ? "node" : "leaf node"; }) | ||
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); | ||
|
||
node.append("svg:title") | ||
.text(function(d) { return d.data.key + (d.children ? "" : ": " + format(d.value)); }); | ||
|
||
node.append("svg:circle") | ||
.attr("r", function(d) { return d.r; }); | ||
|
||
node.filter(function(d) { return !d.children; }).append("svg:text") | ||
.attr("text-anchor", "middle") | ||
.attr("dy", ".3em") | ||
.text(function(d) { return d.data.key.substring(0, d.r / 3); }); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.