Skip to content

Commit

Permalink
Update to 2.4.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 19, 2011
1 parent a62be8e commit 16f193d
Show file tree
Hide file tree
Showing 32 changed files with 153 additions and 192 deletions.
5 changes: 0 additions & 5 deletions _includes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ EX_FILES = \
../data/morley.csv \
../ex/cluster.js \
../ex/cluster.css \
../ex/calendar.js \
../ex/calendar.css \
../ex/chord.css \
../ex/chord.js \
Expand Down Expand Up @@ -95,10 +94,6 @@ $(SRC_FILES):
@rm -rf $@
git cat-file blob master:$(subst ../,,$@) > $@

../ex/calendar.js:
@rm -rf $@
git cat-file blob master:examples/calendar/calendar.js > $@

../ex/calendar.css:
@rm -rf $@
git cat-file blob master:examples/calendar/calendar.css > $@
Expand Down
6 changes: 3 additions & 3 deletions _includes/cartogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ d3.json("../data/us-states.json", function(json) {
.selectAll("path")
.data(json.features)
.enter().append("svg:path")
.attr("d", path)
.attr("transform", function(d) {
var centroid = path.centroid(d),
x = centroid[0],
Expand All @@ -44,8 +45,7 @@ d3.json("../data/us-states.json", function(json) {
+ "translate(" + -x + "," + -y + ")";
})
.style("stroke-width", function(d) {
return 1 / Math.sqrt(data[+d.id] * 5);
})
.attr("d", path);
return 1 / Math.sqrt(data[+d.id] * 5 || 1);
});

});
88 changes: 46 additions & 42 deletions _includes/dji.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
var w = 960,
pw = 14,
z = ~~((w - pw * 2) / 53),
ph = z >> 1,
h = z * 7;

var vis = d3.select("#chart")
.selectAll("svg")
var m = [19, 20, 20, 19], // top right bottom left margin
w = 960 - m[1] - m[3], // width
h = 136 - m[0] - m[2], // height
z = 17; // cell size

var day = d3.time.format("%w"),
week = d3.time.format("%U"),
percent = d3.format(".1%"),
format = d3.time.format("%Y-%m-%d");

var color = d3.scale.quantize()
.domain([-.05, .05])
.range(d3.range(9));

var svg = d3.select("#chart").selectAll("svg")
.data(d3.range(1990, 2011))
.enter().append("svg:svg")
.attr("width", w)
.attr("height", h + ph * 2)
.attr("width", w + m[1] + m[3])
.attr("height", h + m[0] + m[2])
.attr("class", "RdYlGn")
.append("svg:g")
.attr("transform", "translate(" + pw + "," + ph + ")");
.attr("transform", "translate(" + (m[3] + (w - z * 53) / 2) + "," + (m[0] + (h - z * 7) / 2) + ")");

vis.append("svg:text")
.attr("transform", "translate(-6," + h / 2 + ")rotate(-90)")
svg.append("svg:text")
.attr("transform", "translate(-6," + z * 3.5 + ")rotate(-90)")
.attr("text-anchor", "middle")
.text(function(d) { return d; });
.text(String);

vis.selectAll("rect.day")
.data(calendar.dates)
var rect = svg.selectAll("rect.day")
.data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("svg:rect")
.attr("x", function(d) { return d.week * z; })
.attr("y", function(d) { return d.day * z; })
.attr("class", "day")
.attr("width", z)
.attr("height", z);
.attr("height", z)
.attr("x", function(d) { return week(d) * z; })
.attr("y", function(d) { return day(d) * z; });

vis.selectAll("path.month")
.data(calendar.months)
svg.selectAll("path.month")
.data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("svg:path")
.attr("class", "month")
.attr("d", function(d) {
return "M" + (d.firstWeek + 1) * z + "," + d.firstDay * z
+ "H" + d.firstWeek * z
+ "V" + 7 * z
+ "H" + d.lastWeek * z
+ "V" + (d.lastDay + 1) * z
+ "H" + (d.lastWeek + 1) * z
+ "V" + 0
+ "H" + (d.firstWeek + 1) * z
+ "Z";
});
.attr("d", monthPath);

d3.csv("dji.csv", function(csv) {
var data = d3.nest()
.key(function(d) { return d.Date; })
.rollup(function(d) { return (d[0].Close - d[0].Open) / d[0].Open; })
.map(csv);
.key(function(d) { return d.Date; })
.rollup(function(d) { return (d[0].Close - d[0].Open) / d[0].Open; })
.map(csv);

var color = d3.scale.quantize()
.domain([-.05, .05])
.range(d3.range(9));

vis.selectAll("rect.day")
.attr("class", function(d) { return "day q" + color(data[d.Date]) + "-9"; })
rect
.attr("class", function(d) { return "day q" + color(data[format(d)]) + "-9"; })
.append("svg:title")
.text(function(d) { return d.Date + ": " + (data[d.Date] * 100).toFixed(1) + "%"; });
.text(function(d) { return format(d) + ": " + percent(data[format(d)]); });
});

function monthPath(t0) {
var t1 = new Date(t0.getUTCFullYear(), t0.getUTCMonth() + 1, 0),
d0 = +day(t0), w0 = +week(t0),
d1 = +day(t1), w1 = +week(t1);
return "M" + (w0 + 1) * z + "," + d0 * z
+ "H" + w0 * z + "V" + 7 * z
+ "H" + w1 * z + "V" + (d1 + 1) * z
+ "H" + (w1 + 1) * z + "V" + 0
+ "H" + (w0 + 1) * z + "Z";
}
2 changes: 1 addition & 1 deletion _layouts/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>d3.js{% if page.title %} ~ {{ page.title }}{% endif %}</title>
<script type="text/javascript" src="../d3.js?2.4.2"></script>
<script type="text/javascript" src="../d3.js?2.4.4"></script>
<style type="text/css">

@import url("../style.css?1.10.0");
Expand Down
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>d3.js{% if page.title %} ~ {{ page.title }}{% endif %}</title>
<script type="text/javascript" src="d3.js?2.4.2"></script>
<script type="text/javascript" src="d3.js?2.4.4"></script>
<style type="text/css">

@import url("style.css?1.10.0");
Expand Down
2 changes: 1 addition & 1 deletion _layouts/ex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>d3.js{% if page.title %} ~ {{ page.title }}{% endif %}</title>
<script type="text/javascript" src="../d3.js?2.4.2"></script>
<script type="text/javascript" src="../d3.js?2.4.4"></script>
<style type="text/css">

@import url("../style.css?1.10.0");
Expand Down
2 changes: 1 addition & 1 deletion _layouts/tutorial.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>d3.js{% if page.title %} ~ {{ page.title }}{% endif %}</title>
<script type="text/javascript" src="../d3.js?2.4.2"></script>
<script type="text/javascript" src="../d3.js?2.4.4"></script>
<style type="text/css">

@import url("../style.css?1.10.0");
Expand Down
21 changes: 11 additions & 10 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
d3 = {version: "2.4.2"}; // semver
d3 = {version: "2.4.4"}; // semver
var d3_array = d3_arraySlice; // conversion for NodeLists

function d3_arrayCopy(pseudoarray) {
Expand Down Expand Up @@ -1824,7 +1824,7 @@ d3_selectionPrototype.transition = function() {
}
}

return d3_transition(subgroups, d3_transitionInheritId || ++d3_transitionId);
return d3_transition(subgroups, d3_transitionInheritId || ++d3_transitionId, Date.now());
};
var d3_selectionRoot = d3_selection([[document]]);

Expand All @@ -1844,16 +1844,17 @@ d3.selectAll = function(selector) {
? d3_selectionRoot.selectAll(selector)
: d3_selection([d3_array(selector)]); // assume node[]
};
function d3_transition(groups, id) {
function d3_transition(groups, id, time) {
d3_arraySubclass(groups, d3_transitionPrototype);

var tweens = {},
event = d3.dispatch("start", "end"),
ease = d3_transitionEase,
then = Date.now();
ease = d3_transitionEase;

groups.id = id;

groups.time = time;

groups.tween = function(name, tween) {
if (arguments.length < 2) return tweens[name];
if (tween == null) delete tweens[name];
Expand Down Expand Up @@ -1883,7 +1884,7 @@ function d3_transition(groups, id) {

++lock.count;

delay <= elapsed ? start(elapsed) : d3.timer(start, delay, then);
delay <= elapsed ? start(elapsed) : d3.timer(start, delay, time);

function start(elapsed) {
if (lock.active > id) return stop();
Expand All @@ -1896,7 +1897,7 @@ function d3_transition(groups, id) {
}

event.start.dispatch.call(node, d, i);
if (!tick(elapsed)) d3.timer(tick, 0, then);
if (!tick(elapsed)) d3.timer(tick, 0, time);
return 1;
}

Expand Down Expand Up @@ -1926,7 +1927,7 @@ function d3_transition(groups, id) {
}
});
return 1;
}, 0, then);
}, 0, time);

return groups;
}
Expand Down Expand Up @@ -1987,7 +1988,7 @@ d3_transitionPrototype.select = function(selector) {
}
}

return d3_transition(subgroups, this.id).ease(this.ease());
return d3_transition(subgroups, this.id, this.time).ease(this.ease());
};
d3_transitionPrototype.selectAll = function(selector) {
var subgroups = [],
Expand All @@ -2009,7 +2010,7 @@ d3_transitionPrototype.selectAll = function(selector) {
}
}

return d3_transition(subgroups, this.id).ease(this.ease());
return d3_transition(subgroups, this.id, this.time).ease(this.ease());
};
d3_transitionPrototype.attr = function(name, value) {
return this.attrTween(name, d3_transitionTween(value));
Expand Down
4 changes: 2 additions & 2 deletions d3.min.js

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions d3.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,22 @@ function d3_time_year(d) {
return new d3_time(d.getFullYear(), 0, 1);
}

function d3_time_daysElapsed(d0, d1) {
return ~~((d1 - d0) / 864e5 - (d1.getTimezoneOffset() - d0.getTimezoneOffset()) / 1440);
}

function d3_time_dayOfYear(d) {
return d3_time_zfill3(1 + ~~((d - d3_time_year(d)) / 864e5));
return d3_time_zfill3(1 + d3_time_daysElapsed(d3_time_year(d), d));
}

function d3_time_weekNumberSunday(d) {
var d0 = d3_time_year(d);
return d3_time_zfill2(~~(((d - d0) / 864e5 + d0.getDay()) / 7));
return d3_time_zfill2(~~((d3_time_daysElapsed(d0, d) + d0.getDay()) / 7));
}

function d3_time_weekNumberMonday(d) {
var d0 = d3_time_year(d);
return d3_time_zfill2(~~(((d - d0) / 864e5 + (d0.getDay() + 6) % 7) / 7));
return d3_time_zfill2(~~((d3_time_daysElapsed(d0, d) + (d0.getDay() + 6) % 7) / 7));
}

// TODO table of time zone offset names?
Expand All @@ -328,9 +332,14 @@ d3.time.format.utc = function(template) {
var local = d3.time.format(template);

function format(date) {
var utc = new d3_time_format_utc();
utc._ = date;
return local(utc);
try {
d3_time = d3_time_format_utc;
var utc = new d3_time();
utc._ = date;
return local(utc);
} finally {
d3_time = Date;
}
}

format.parse = function(string) {
Expand Down
Loading

0 comments on commit 16f193d

Please sign in to comment.