Skip to content

Commit

Permalink
pretransition event
Browse files Browse the repository at this point in the history
closes #806
  • Loading branch information
gordonwoodhull committed Jun 1, 2015
1 parent f1f3adc commit b85d842
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 14 deletions.
7 changes: 6 additions & 1 deletion dc.js

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

2 changes: 1 addition & 1 deletion dc.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dc.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dc.min.js.map

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion spec/base-mixin-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ describe("dc.baseMixin", function () {
});

describe('renderlets', function () {
var firstRenderlet, secondRenderlet, thirdRenderlet;
var firstRenderlet, secondRenderlet, thirdRenderlet,
pretransition;
beforeEach(function () {
var expectedCallbackSignature = function (callbackChart) {
expect(callbackChart).toBe(chart);
};
firstRenderlet = jasmine.createSpy().and.callFake(expectedCallbackSignature);
secondRenderlet = jasmine.createSpy().and.callFake(expectedCallbackSignature);
thirdRenderlet = jasmine.createSpy().and.callFake(expectedCallbackSignature);
pretransition = jasmine.createSpy().and.callFake(expectedCallbackSignature);
chart.renderlet(firstRenderlet); // still testing renderlet event-namespace generation here
chart.renderlet(secondRenderlet);
chart.on('renderlet.third', thirdRenderlet);
chart.on('pretransition.pret', pretransition);
});

it('should not execute a renderlet until after the render transitions', function() {
Expand All @@ -54,6 +57,18 @@ describe("dc.baseMixin", function () {
expect(firstRenderlet).toHaveBeenCalled();
});

it('should execute pretransition event before the render transitions', function() {
chart.render();
expect(pretransition).toHaveBeenCalled();
flushAllD3Transitions();
});

it('should execute pretransition event before the redraw transitions', function() {
chart.redraw();
expect(pretransition).toHaveBeenCalled();
flushAllD3Transitions();
});

it('should execute each renderlet after a render', function () {
chart.render();
flushAllD3Transitions();
Expand Down
7 changes: 6 additions & 1 deletion src/base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ dc.baseMixin = function (_chart) {
'postRedraw',
'filtered',
'zoomed',
'renderlet');
'renderlet',
'pretransition');

var _legend;

Expand Down Expand Up @@ -476,6 +477,7 @@ dc.baseMixin = function (_chart) {
};

_chart._activateRenderlets = function (event) {
_listeners.pretransition(_chart);
if (_chart.transitionDuration() > 0 && _svg) {
_svg.transition().duration(_chart.transitionDuration())
.each('end', function () {
Expand Down Expand Up @@ -1107,6 +1109,9 @@ dc.baseMixin = function (_chart) {
This listener function will be invoked after transitions after redraw and render. Replaces the
deprecated `.renderlet()` method.
#### .on('pretransition', function(chart, filter){...})
Like `.on('renderlet', ...)` but the event is fired before transitions start.
#### .on('preRender', function(chart){...})
This listener function will be invoked before chart rendering.
Expand Down
3 changes: 3 additions & 0 deletions web/docs/api-latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ All dc chart instance supports the following listeners.
This listener function will be invoked after transitions after redraw and render. Replaces the
deprecated `.renderlet()` method.
#### .on('pretransition', function(chart, filter){...})
Like `.on('renderlet', ...)` but the event is fired before transitions start.
#### .on('preRender', function(chart){...})
This listener function will be invoked before chart rendering.
Expand Down
2 changes: 2 additions & 0 deletions web/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ <h4 id="-options-optionsobject-">.options(optionsObject)</h4>
<h4 id="-on-renderlet-function-chart-filter-">.on(‘renderlet’, function(chart, filter){…})</h4>
<p>This listener function will be invoked after transitions after redraw and render. Replaces the
deprecated <code>.renderlet()</code> method.</p>
<h4 id="-on-pretransition-function-chart-filter-">.on(‘pretransition’, function(chart, filter){…})</h4>
<p>Like <code>.on(&#39;renderlet&#39;, ...)</code> but the event is fired before transitions start.</p>
<h4 id="-on-prerender-function-chart-">.on(‘preRender’, function(chart){…})</h4>
<p>This listener function will be invoked before chart rendering.</p>
<h4 id="-on-postrender-function-chart-">.on(‘postRender’, function(chart){…})</h4>
Expand Down
7 changes: 6 additions & 1 deletion web/js/dc.js

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

2 changes: 1 addition & 1 deletion web/js/dc.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions web/js/dc.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/js/dc.min.js.map

Large diffs are not rendered by default.

0 comments on commit b85d842

Please sign in to comment.