Skip to content

Commit

Permalink
Add animate attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranajit Banerjee committed Apr 4, 2017
1 parent 8226ec6 commit 4482f2f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
21 changes: 12 additions & 9 deletions build/d3-scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Scroller.prototype.attr = function (key, value) {
}
};

Scroller.prototype.drawSelf = function () {
Scroller.prototype.drawSelf = function (animate) {
var self = this,
selection = this.attr('selection'),
btnConfig = this.attr('buttons'),
Expand Down Expand Up @@ -303,23 +303,24 @@ Scroller.prototype.drawSelf = function () {
self.attr('handle').width = endX - startX;
self.emit('change');
};
hue(hueTarget, true);
hue(hueTarget, animate);
return this;
};

Scroller.prototype.draw = function () {
return this.drawSelf()
.drawButtons();
Scroller.prototype.draw = function (animate) {
return this.drawSelf(animate)
.drawButtons(animate);
};

Scroller.prototype.drawButtons = function () {
Scroller.prototype.drawButtons = function (animate) {
var self = this,
selection = this.attr('selection'),
height = this.attr('height'),
btnWidth = this.attr('buttons').width,
width = this.attr('width'),
margin = this.attr('margin'),
leftMargin = margin.left,
duration = this.attr('animate'),
translate = function (x, y) {
return 'translate(' + x + COMMA + y + ')';
},
Expand All @@ -344,9 +345,11 @@ Scroller.prototype.drawButtons = function () {
self.emit('slide', x + handleConf.width / 2);
});

selection
.selectAll('.buttonGroup g')
.attr('transform', function (d, index) {
selection = selection
.selectAll('.buttonGroup g');

animate && (selection = selection.transition().duration(duration));
selection.attr('transform', function (d, index) {
return index ? translate(width - margin.right - btnWidth, 0) : translate(2 * leftMargin, 0);
})
.each(function (d, index) {
Expand Down
2 changes: 1 addition & 1 deletion build/d3-scroller.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions src/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Scroller.prototype.attr = function (key, value) {
}
};

Scroller.prototype.drawSelf = function () {
Scroller.prototype.drawSelf = function (animate) {
var self = this,
selection = this.attr('selection'),
btnConfig = this.attr('buttons'),
Expand Down Expand Up @@ -215,23 +215,24 @@ Scroller.prototype.drawSelf = function () {
self.attr('handle').width = endX - startX;
self.emit('change');
};
hue(hueTarget, true);
hue(hueTarget, animate);
return this;
};

Scroller.prototype.draw = function () {
return this.drawSelf()
.drawButtons();
Scroller.prototype.draw = function (animate) {
return this.drawSelf(animate)
.drawButtons(animate);
};

Scroller.prototype.drawButtons = function () {
Scroller.prototype.drawButtons = function (animate) {
var self = this,
selection = this.attr('selection'),
height = this.attr('height'),
btnWidth = this.attr('buttons').width,
width = this.attr('width'),
margin = this.attr('margin'),
leftMargin = margin.left,
duration = this.attr('animate'),
translate = function (x, y) {
return 'translate(' + x + COMMA + y + ')';
},
Expand All @@ -256,9 +257,11 @@ Scroller.prototype.drawButtons = function () {
self.emit('slide', x + handleConf.width / 2);
});

selection
.selectAll('.buttonGroup g')
.attr('transform', function (d, index) {
selection = selection
.selectAll('.buttonGroup g');

animate && (selection = selection.transition().duration(duration));
selection.attr('transform', function (d, index) {
return index ? translate(width - margin.right - btnWidth, 0) : translate(2 * leftMargin, 0);
})
.each(function (d, index) {
Expand Down

0 comments on commit 4482f2f

Please sign in to comment.