Skip to content
This repository has been archived by the owner on Apr 8, 2018. It is now read-only.

Commit

Permalink
Patched transition-style
Browse files Browse the repository at this point in the history
  • Loading branch information
mhemesath committed Mar 13, 2013
1 parent 9f4dd13 commit ed4807c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ r2d3.core.js: \
lib/d3/src/core/transition-selectAll.js \
lib/d3/src/core/transition-filter.js \
lib/d3/src/core/transition-attr.js \
lib/d3/src/core/transition-style.js \
src/core/transition-style.js \
lib/d3/src/core/transition-text.js \
lib/d3/src/core/transition-remove.js \
lib/d3/src/core/transition-delay.js \
Expand Down
2 changes: 1 addition & 1 deletion examples/d3_examples/parallel/parallel.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<!--[if gte IE 9]><!-->
<script src="../../../lib/d3/d3.v2.js"></script>
<!--<![endif]-->
<script type="text/javascript">
<style type="text/css">

svg {
Expand Down Expand Up @@ -46,6 +45,7 @@
</style>
</head>
<body>
<script type="text/javascript">

var margin = {top: 30, right: 10, bottom: 10, left: 10},
width = 960 - margin.right - margin.left,
Expand Down
12 changes: 9 additions & 3 deletions r2d3.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10374,10 +10374,10 @@ d3_transitionPrototype.style = function(name, value, priority) {
d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, window.getComputedStyle(this, null).getPropertyValue(name));
var f = tween.call(this, d, i, this.getCurrentStyle()[name]);
return f === d3_tweenRemove
? (this.style.removeProperty(name), null)
: f && function(t) { this.style.setProperty(name, f(t), priority); };
? (this.removeStyleProperty(name), null)
: f && function(t) { this.setStyleProperty(name, f(t), priority); };
});
};
d3_transitionPrototype.text = function(value) {
Expand Down Expand Up @@ -13158,13 +13158,19 @@ R2D3Element.prototype.removeStyleProperty = function(name) {
this.updateProperty(name);
}

R2D3Element.prototype.getCurrentStyle = function() {
return this.domNode.currentStyle;
}




//=====================================
// DOM APIs
//=====================================



R2D3Element.prototype.appendChild = function(node) {
if (node.r2d3) {
// TODO: Reposition raphael paper node
Expand Down
33 changes: 11 additions & 22 deletions r2d3.v2.min.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/core/transition-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
d3_transitionPrototype.style = function(name, value, priority) {
var n = arguments.length;
if (n < 3) {

// For style(object) or style(object, string), the object specifies the
// names and values of the attributes to set or remove. The values may be
// functions that are evaluated for each element. The optional string
// specifies the priority.
if (typeof name !== "string") {
if (n < 2) value = "";
for (priority in name) this.styleTween(priority, d3_tweenByName(name[priority], priority), value);
return this;
}

// For style(string, string) or style(string, function), use the default
// priority. The priority is ignored for style(string, null).
priority = "";
}

// Otherwise, a name, value and priority are specified, and handled as below.
return this.styleTween(name, d3_tweenByName(value, name), priority);
};

d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
var f = tween.call(this, d, i, this.getCurrentStyle()[name]);
return f === d3_tweenRemove
? (this.removeStyleProperty(name), null)
: f && function(t) { this.setStyleProperty(name, f(t), priority); };
});
};
6 changes: 6 additions & 0 deletions src/raphael/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,19 @@ R2D3Element.prototype.removeStyleProperty = function(name) {
this.updateProperty(name);
}

R2D3Element.prototype.getCurrentStyle = function() {
return this.domNode.currentStyle;
}




//=====================================
// DOM APIs
//=====================================



R2D3Element.prototype.appendChild = function(node) {
if (node.r2d3) {
// TODO: Reposition raphael paper node
Expand Down
13 changes: 1 addition & 12 deletions tests/core/group-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,4 @@ test('insert on group with matching element', function() {
circle = g.insert('circle', 'rect');

equal(g.selectAll('circle').length, 1);
});


test('inherit styles from group', function() {
var svg = d3.select('#group').append('svg'),
g = svg.append('g');

g.style('fill', '#ffffff');
var rect = g.append('rect');
equal(rect.node().attr('fill'), '#ffffff');

})
});

0 comments on commit ed4807c

Please sign in to comment.