Skip to content

Commit acfc4e7

Browse files
committed
Merge branch 'raphael-transition' into raphael
Conflicts: Makefile d3.v2.js d3.v2.min.js src/raphael/selection.js
2 parents 6830f43 + 7195d3c commit acfc4e7

File tree

5 files changed

+306
-265
lines changed

5 files changed

+306
-265
lines changed

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ d3.raphael.js: \
162162
src/raphael/root.js \
163163
src/raphael/selection.js \
164164
src/raphael/selection-enter.js \
165-
src/raphael/axis.js \
166-
src/raphael/raphael-sizzle.js
165+
src/raphael/selection-transition.js \
166+
src/raphael/raphael-sizzle.js \
167+
src/raphael/axis.js
167168

168169
d3.behavior.js: \
169170
src/behavior/behavior.js \

d3.v2.js

+169-149
Original file line numberDiff line numberDiff line change
@@ -4957,117 +4957,28 @@ var d3_raphael_selectionPrototype = [];
49574957
* @name D3RaphaelSelection#data
49584958
*/
49594959
d3_raphael_selectionPrototype.data = function(value, key_function) {
4960-
var i = -1,
4961-
n = this.length,
4962-
group,
4963-
node;
4964-
4965-
// If no value is specified, return the first value.
4966-
if (!arguments.length) {
4967-
value = new Array(n = (group = this[0]).length);
4968-
while (++i < n) {
4969-
if (node = group[i]) {
4970-
value[i] = node.__data__;
4971-
}
4972-
}
4973-
return value;
4974-
}
4975-
4976-
function bind(group, groupData) {
4977-
var i,
4978-
n = group.length,
4979-
m = groupData.length,
4980-
n0 = Math.min(n, m),
4981-
n1 = Math.max(n, m),
4982-
updateNodes = [],
4983-
enterNodes = [],
4984-
exitNodes = [],
4985-
node,
4986-
nodeData;
4987-
4988-
if (key_function) {
4989-
var nodeByKeyValue = new d3_Map,
4990-
keyValues = [],
4991-
keyValue,
4992-
j = groupData.length;
4993-
4994-
for (i = -1; ++i < n;) {
4995-
keyValue = key_function.call(node = group[i], node.__data__, i);
4996-
if (nodeByKeyValue.has(keyValue)) {
4997-
exitNodes[j++] = node; // duplicate key
4998-
} else {
4999-
nodeByKeyValue.set(keyValue, node);
5000-
}
5001-
keyValues.push(keyValue);
5002-
}
5003-
5004-
for (i = -1; ++i < m;) {
5005-
keyValue = key_function.call(groupData, nodeData = groupData[i], i)
5006-
if (nodeByKeyValue.has(keyValue)) {
5007-
updateNodes[i] = node = nodeByKeyValue.get(keyValue);
5008-
node.__data__ = nodeData;
5009-
enterNodes[i] = exitNodes[i] = null;
5010-
} else {
5011-
enterNodes[i] = d3_selection_dataNode(nodeData);
5012-
updateNodes[i] = exitNodes[i] = null;
5013-
}
5014-
nodeByKeyValue.remove(keyValue);
5015-
}
5016-
5017-
for (i = -1; ++i < n;) {
5018-
if (nodeByKeyValue.has(keyValues[i])) {
5019-
exitNodes[i] = group[i];
5020-
}
5021-
}
5022-
} else {
5023-
for (i = -1; ++i < n0;) {
5024-
node = group[i];
5025-
nodeData = groupData[i];
5026-
if (node) {
5027-
node.__data__ = nodeData;
5028-
updateNodes[i] = node;
5029-
enterNodes[i] = exitNodes[i] = null;
5030-
} else {
5031-
enterNodes[i] = d3_selection_dataNode(nodeData);
5032-
updateNodes[i] = exitNodes[i] = null;
5033-
}
5034-
}
5035-
for (; i < m; ++i) {
5036-
enterNodes[i] = d3_selection_dataNode(groupData[i]);
5037-
updateNodes[i] = exitNodes[i] = null;
5038-
}
5039-
for (; i < n1; ++i) {
5040-
exitNodes[i] = group[i];
5041-
enterNodes[i] = updateNodes[i] = null;
5042-
}
5043-
}
5044-
5045-
enterNodes.update
5046-
= updateNodes;
4960+
// kind of a hack, but saves a lot of code duplication; sub out the
4961+
// built-in selection calls for our own for the duration of the inner call.
50474962

5048-
enterNodes.parentNode
5049-
= updateNodes.parentNode
5050-
= exitNodes.parentNode
5051-
= group.parentNode;
4963+
// save old
4964+
var old_d3_selection_enter = d3_selection_enter,
4965+
old_d3_selection = d3_selection;
50524966

5053-
enter.push(enterNodes);
5054-
update.push(updateNodes);
5055-
exit.push(exitNodes);
5056-
}
4967+
// sub in
4968+
var selection = this;
4969+
d3_selection_enter = function(elems) {
4970+
return d3_raphael_enterSelection(elems, selection.root);
4971+
};
4972+
d3_selection = function(elems) {
4973+
return d3_raphael_selection(elems, selection.root);
4974+
};
50574975

5058-
var enter = d3_raphael_enterSelection([], this.root),
5059-
update = d3_raphael_selection([], this.root),
5060-
exit = d3_raphael_selection([], this.root);
4976+
// actual call
4977+
var update = d3_selectionPrototype.data.call(this, value, key_function);
50614978

5062-
if (typeof value === "function") {
5063-
while (++i < n) {
5064-
bind(group = this[i], value.call(group, group.parentNode.__data__, i));
5065-
}
5066-
} else {
5067-
while (++i < n) {
5068-
bind(group = this[i], value);
5069-
}
5070-
}
4979+
// sub out
4980+
d3_selection_enter = old_d3_selection_enter;
4981+
d3_selection = old_d3_selection;
50714982

50724983
/**
50734984
* Returns the entering selection: placeholder nodes for each data element for which no corresponding existing DOM element was found in the current selection.
@@ -5079,7 +4990,8 @@ d3_raphael_selectionPrototype.data = function(value, key_function) {
50794990
* @function
50804991
* @name D3RaphaelUpdateSelection#enter
50814992
*/
5082-
update.enter = function() { return enter; };
4993+
var enter = update.enter;
4994+
update.enter = function() { return enter(); };
50834995

50844996
/**
50854997
* Returns the exiting selection: existing DOM elements in the current selection for which no new data element was found.
@@ -5091,7 +5003,8 @@ d3_raphael_selectionPrototype.data = function(value, key_function) {
50915003
* @function
50925004
* @name D3RaphaelUpdateSelection#exit
50935005
*/
5094-
update.exit = function() { return exit; };
5006+
var exit = update.exit;
5007+
update.exit = function() { return exit(); };
50955008
return update;
50965009
};
50975010

@@ -5371,14 +5284,31 @@ d3_raphael_selectionPrototype.datum = d3_selectionPrototype.datum;
53715284
*/
53725285
d3_raphael_selectionPrototype.remove = d3_selectionPrototype.remove;
53735286

5287+
/**
5288+
* Starts a transition selection.
5289+
*
5290+
* @return {D3RaphaelTransitionSelection} transition selection
5291+
*
5292+
* @function
5293+
* @name D3RaphaelSelection#transition
5294+
*/
5295+
d3_raphael_selectionPrototype.transition = function() {
5296+
// minor hack to sub out the dependency we want to inject.
5297+
var old_d3_transitionPrototype = d3_transitionPrototype;
5298+
d3_transitionPrototype = d3_raphael_transitionPrototype;
5299+
var transition = d3_selectionPrototype.transition.call(this);
5300+
d3_transitionPrototype = old_d3_transitionPrototype;
5301+
5302+
return transition;
5303+
};
5304+
53745305
d3_raphael_selectionPrototype.style = throw_raphael_not_supported;
53755306
d3_raphael_selectionPrototype.html = throw_raphael_not_supported;
53765307
d3_raphael_selectionPrototype.insert = throw_raphael_not_supported;
53775308
d3_raphael_selectionPrototype.filter = throw_raphael_not_supported;
53785309
d3_raphael_selectionPrototype.sort = throw_raphael_not_supported;
53795310
d3_raphael_selectionPrototype.order = throw_raphael_not_supported;
53805311
d3_raphael_selectionPrototype.on = throw_raphael_not_supported;
5381-
d3_raphael_selectionPrototype.transition = throw_raphael_not_supported;
53825312

53835313
function d3_raphael_enterSelection(groups, d3_raphael_root) {
53845314
d3_arraySubclass(groups, d3_raphael_enterSelectionPrototype);
@@ -5455,6 +5385,134 @@ d3_raphael_enterSelectionPrototype.insert = throw_raphael_not_supported;
54555385

54565386

54575387

5388+
var d3_raphael_transitionPrototype = [];
5389+
5390+
/**
5391+
* Specifies an attribute to be animated.
5392+
*
5393+
* @see <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-attr">d3.selection.attr()</a>
5394+
* @param {String} name property name
5395+
* @param value property value
5396+
* @return {D3RaphaelTransitionSelection} this
5397+
*
5398+
* @function
5399+
* @name D3RaphaelTransitionSelection#attr
5400+
*/
5401+
d3_raphael_transitionPrototype.attr = d3_transitionPrototype.attr;
5402+
5403+
d3_raphael_transitionPrototype.attrTween = function(name, tween) {
5404+
function attrTween(d, i) {
5405+
var f = tween.call(this, d, i, this.attr(name));
5406+
return f === d3_transitionRemove
5407+
? (this.attr(name, null), null)
5408+
: f && function(t) { this.attr(name, f(t)); };
5409+
}
5410+
5411+
return this.tween('attr.' + name, attrTween);
5412+
};
5413+
5414+
/**
5415+
* Specifies an amount of time to delay before transitioning.
5416+
*
5417+
* @see <a href="https://github.com/mbostock/d3/wiki/Transition#wiki-delay">transition.delay()</a>
5418+
* @param value delay in ms
5419+
* @return {D3RaphaelTransitionSelection} this
5420+
*
5421+
* @function
5422+
* @name D3RaphaelTransitionSelection#delay
5423+
*/
5424+
d3_raphael_transitionPrototype.delay = d3_transitionPrototype.duration;
5425+
5426+
/**
5427+
* Specifies a duration for the transition.
5428+
*
5429+
* @see <a href="https://github.com/mbostock/d3/wiki/Transition#wiki-duration">transition.duration()</a>
5430+
* @param value length in ms
5431+
* @return {D3RaphaelTransitionSelection} this
5432+
*
5433+
* @function
5434+
* @name D3RaphaelTransitionSelection#duration
5435+
*/
5436+
d3_raphael_transitionPrototype.duration = d3_transitionPrototype.duration;
5437+
5438+
/**
5439+
* Specifies a transition easing function.
5440+
*
5441+
* @see <a href="https://github.com/mbostock/d3/wiki/Transition#wiki-ease">transition.ease()</a>
5442+
* @param value string or function
5443+
* @return {D3RaphaelTransitionSelection} this
5444+
*
5445+
* @function
5446+
* @name D3RaphaelTransitionSelection#ease
5447+
*/
5448+
d3_raphael_transitionPrototype.duration = d3_transitionPrototype.duration;
5449+
5450+
/**
5451+
* Sets the text content when the transition begins.
5452+
*
5453+
* @see <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-text">d3.selection.text()</a>
5454+
* @param value property value
5455+
* @return {D3RaphaelTransitionSelection} this
5456+
*
5457+
* @function
5458+
* @name D3RaphaelTransitionSelection#text
5459+
*/
5460+
d3_raphael_transitionPrototype.text = d3_raphael_selectionPrototype.text;
5461+
5462+
/**
5463+
* Removes elements after transitions are completed.
5464+
*
5465+
* @see <a href="https://github.com/mbostock/d3/wiki/Transition#wiki-remove">transition.remove()</a>
5466+
* @return {D3RaphaelTransitionSelection} this
5467+
*
5468+
* @function
5469+
* @name D3RaphaelTransitionSelection#remove
5470+
*/
5471+
d3_raphael_transitionPrototype.remove = d3_transitionPrototype.remove;
5472+
5473+
d3_raphael_transitionPrototype.style = throw_raphael_not_supported;
5474+
d3_raphael_transitionPrototype.styleTween = throw_raphael_not_supported;
5475+
d3_raphael_transitionPrototype.select = throw_raphael_not_supported;
5476+
d3_raphael_transitionPrototype.selectAll = throw_raphael_not_supported;
5477+
5478+
// Prefer Sizzle, if available
5479+
if (typeof Sizzle === "function") {
5480+
5481+
// lookup to translate dom nodes to raphael objs
5482+
var d3_raphael_obj_from_dom = function(domElems, d3_paper) {
5483+
// don't do a paper.getById for every elem because that's n^2.
5484+
// traverse the linked list ourselves. still m+n, but oh well.
5485+
5486+
var elemCount = domElems.length;
5487+
5488+
// but first build an index of ids we're looking for
5489+
var domElemIndex = {};
5490+
for (var i = -1; ++i < elemCount;) {
5491+
var domElem = domElems[i];
5492+
domElemIndex[domElem.raphaelid] = true;
5493+
}
5494+
5495+
var raphaelElems = [];
5496+
var bot = d3_paper.paper.bottom;
5497+
while (bot && (raphaelElems.length < elemCount)) {
5498+
if (domElemIndex[bot.id]) {
5499+
raphaelElems.push(bot);
5500+
}
5501+
bot = bot.next;
5502+
}
5503+
return raphaelElems;
5504+
};
5505+
5506+
// override root functions
5507+
D3RaphaelRoot.prototype.select = function(s) {
5508+
return d3_raphael_selection([d3_raphael_obj_from_dom(Sizzle(s, this.paper.canvas)[0], this)], this);
5509+
};
5510+
D3RaphaelRoot.prototype.selectAll = function(s) {
5511+
return d3_raphael_selection([d3_raphael_obj_from_dom(Sizzle.uniqueSort(Sizzle(s, this.paper.canvas)), this)], this);
5512+
};
5513+
5514+
}
5515+
54585516
/**
54595517
* Constructs a Raphael axis renderer function.
54605518
*
@@ -5731,45 +5789,7 @@ d3.raphael.axis = function() {
57315789
}
57325790

57335791
return axis;
5734-
};// Prefer Sizzle, if available
5735-
if (typeof Sizzle === "function") {
5736-
5737-
// lookup to translate dom nodes to raphael objs
5738-
var d3_raphael_obj_from_dom = function(domElems, d3_paper) {
5739-
// don't do a paper.getById for every elem because that's n^2.
5740-
// traverse the linked list ourselves. still m+n, but oh well.
5741-
5742-
var elemCount = domElems.length;
5743-
5744-
// but first build an index of ids we're looking for
5745-
var domElemIndex = {};
5746-
for (var i = -1; ++i < elemCount;) {
5747-
var domElem = domElems[i];
5748-
domElemIndex[domElem.raphaelid] = true;
5749-
}
5750-
5751-
var raphaelElems = [];
5752-
var bot = d3_paper.paper.bottom;
5753-
while (bot && (raphaelElems.length < elemCount)) {
5754-
if (domElemIndex[bot.id]) {
5755-
raphaelElems.push(bot);
5756-
}
5757-
bot = bot.next;
5758-
}
5759-
return raphaelElems;
5760-
};
5761-
5762-
// override root functions
5763-
D3RaphaelRoot.prototype.select = function(s) {
5764-
return d3_raphael_selection([d3_raphael_obj_from_dom(Sizzle(s, this.paper.canvas)[0], this)], this);
5765-
};
5766-
D3RaphaelRoot.prototype.selectAll = function(s) {
5767-
return d3_raphael_selection([d3_raphael_obj_from_dom(Sizzle.uniqueSort(Sizzle(s, this.paper.canvas)), this)], this);
5768-
};
5769-
5770-
}
5771-
5772-
d3.behavior = {};
5792+
};d3.behavior = {};
57735793
// TODO Track touch points by identifier.
57745794

57755795
d3.behavior.drag = function() {

d3.v2.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)