Skip to content

Commit

Permalink
Merge tag '2.0.0-beta.11' into develop
Browse files Browse the repository at this point in the history
2.0.0 beta 11
  • Loading branch information
gordonwoodhull committed Jun 1, 2015
2 parents d18f09b + dcd69ff commit 55f8b5c
Show file tree
Hide file tree
Showing 33 changed files with 152 additions and 74 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ Mihai Hodorogea <mihaihodorogea@gmail.com>
Enrico Spinielli <enrico.spinielli+github@gmail.com>
Timothy Ruhle <timothy.ruhle@gmail.com>
Shobhit Gupta <shobhitg@vmware.com>
Alan Kavanagh <akavanagh208@gmail.com>
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* Front page stable version automatically read from GitHub, by Enrico Spinielli ([#865](https://github.com/dc-js/dc.js/pull/865))

# 2.0 Series
## 2.0.0 beta 11
* pretransition event ([#806](https://github.com/dc-js/dc.js/issues/806))
* replace `.renderlet(...)` with `.on("renderlet", ...)` in test and examples, by Alan Kavanagh ([#906](https://github.com/dc-js/dc.js/issues/906) / ([#917](https://github.com/dc-js/dc.js/pull/917))

## 2.0.0 beta 10
* component package manager support, by Shobhit Gupta ([#860](https://github.com/dc-js/dc.js/pull/860))
* add sourcemaps (*.map) to distributions ([#866](https://github.com/dc-js/dc.js/issues/866))
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dcjs",
"version": "2.0.0-beta.10",
"version": "2.1.0-dev",
"main": ["dc.js", "dc.css"],
"keywords": [
"visualization",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dc.js",
"repository": "dc-js/dc.js",
"description": "Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js",
"version": "2.0.0-beta.10",
"version": "2.1.0-dev",
"keywords": [
"visualization",
"svg",
Expand Down
19 changes: 12 additions & 7 deletions 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.

2 changes: 1 addition & 1 deletion spec/bar-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('dc.barChart', function() {
describe('with a custom click handler', function() {
beforeEach(function() {
chart.brushOn(false)
.renderlet(function(_chart) {
.on('renderlet', function(_chart) {
_chart.selectAll("rect.bar").on("click", _chart.onClick);
})
.render();
Expand Down
67 changes: 56 additions & 11 deletions spec/base-mixin-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe("dc.baseMixin", function () {
var chart, dimension, group, addFilterHandler, removeFilterHandler, hasFilterHandler, resetFilterHandler;
var id, chart, dimension, group, addFilterHandler, removeFilterHandler, hasFilterHandler, resetFilterHandler;

beforeEach(function () {
var data = crossfilter(loadDateFixture());
Expand All @@ -14,8 +14,12 @@ describe("dc.baseMixin", function () {
.options({
dimension: dimension,
group: group,
transitionDuration: 0
transitionDuration: 100
});
id = 'base-chart';
appendChartID(id);
chart.anchor('#' + id)
.resetSvg(); // so that renderlets can fire
addFilterHandler = chart.addFilterHandler();
hasFilterHandler = chart.hasFilterHandler();
removeFilterHandler = chart.removeFilterHandler();
Expand All @@ -24,51 +28,85 @@ describe("dc.baseMixin", function () {

describe('renderlets', function () {
var firstRenderlet, secondRenderlet, thirdRenderlet,
third = 'renderlet.third';
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);
chart.renderlet(firstRenderlet);
pretransition = jasmine.createSpy().and.callFake(expectedCallbackSignature);
chart.renderlet(firstRenderlet); // still testing renderlet event-namespace generation here
chart.renderlet(secondRenderlet);
chart.on(third, thirdRenderlet);
chart.on('renderlet.third', thirdRenderlet);
chart.on('pretransition.pret', pretransition);
});

it('should not execute a renderlet until after the render transitions', function() {
chart.render();
expect(firstRenderlet).not.toHaveBeenCalled();
flushAllD3Transitions();
expect(firstRenderlet).toHaveBeenCalled();
});

it('should not execute a renderlet until after the redraw transitions', function() {
chart.redraw();
expect(firstRenderlet).not.toHaveBeenCalled();
flushAllD3Transitions();
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();
expect(firstRenderlet).toHaveBeenCalled();
expect(secondRenderlet).toHaveBeenCalled();
});

it('should execute each renderlet after a redraw', function () {
chart.redraw();
flushAllD3Transitions();
expect(firstRenderlet).toHaveBeenCalled();
expect(secondRenderlet).toHaveBeenCalled();
});

it('should execute a named renderlet after a render', function () {
chart.render();
flushAllD3Transitions();
expect(thirdRenderlet).toHaveBeenCalled();
});

it('should execute a named renderlet after a redraw', function () {
chart.redraw();
flushAllD3Transitions();
expect(thirdRenderlet).toHaveBeenCalled();
});

it('should remove a named renderlet expect no call after a redraw', function () {
chart.on(third);
chart.on('renderlet.third');
chart.redraw();
flushAllD3Transitions();
expect(secondRenderlet).toHaveBeenCalled();
expect(thirdRenderlet).not.toHaveBeenCalled();
});

it('should remove a named renderlet and expect no call after a redraw', function () {
chart.on(third);
chart.on('renderlet.third');
chart.render();
flushAllD3Transitions();
expect(secondRenderlet).toHaveBeenCalled();
expect(thirdRenderlet).not.toHaveBeenCalled();
});
Expand All @@ -87,14 +125,17 @@ describe("dc.baseMixin", function () {

chart.on('preRender', preRenderSpy);
chart.on('postRender', postRenderSpy);
chart.render();
});

it('should execute the preRender callback', function () {
chart.render();
flushAllD3Transitions();
expect(preRenderSpy).toHaveBeenCalled();
});

it('should execute the postRender callback', function () {
chart.render();
flushAllD3Transitions();
expect(postRenderSpy).toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -168,14 +209,18 @@ describe("dc.baseMixin", function () {

chart.on("preRedraw", preRedrawSpy);
chart.on("postRedraw", postRedrawSpy);
chart.redraw();
});

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

it('should execute the postRedraw callback', function () {
it('should execute the postRedraw callback after transitions', function () {
chart.redraw();
expect(postRedrawSpy).not.toHaveBeenCalled();
flushAllD3Transitions();
expect(postRedrawSpy).toHaveBeenCalled();
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/bubble-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('dc.bubbleChart', function() {
chart.selectAll("circle").attr("fill", "red");
});
renderlet.and.callThrough();
chart.renderlet(renderlet);
chart.on("renderlet", renderlet);
});

it('is invoked with render', function () {
Expand Down
2 changes: 1 addition & 1 deletion spec/composite-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('dc.compositeChart', function() {

describe('subchart renderlets', function () {
beforeEach(function () {
chart.children()[0].renderlet(function(chart) {
chart.children()[0].on("renderlet", function(chart) {
chart.selectAll('rect.bar').attr('width', function(d) {
return 10;
});
Expand Down
2 changes: 1 addition & 1 deletion spec/coordinate-grid-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('dc.coordinateGridChart', function() {

describe('renderlets', function () {
beforeEach(function () {
chart.renderlet(function (chart) {
chart.on("renderlet", function (chart) {
chart.selectAll("path").attr("fill", "red");
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/data-grid-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('dc.dataGrid', function() {
chart.selectAll(".dc-grid-label").text("changed");
});
derlet.and.callThrough();
chart.renderlet(derlet);
chart.on("renderlet", derlet);
});
it('custom renderlet should be invoked with render', function() {
chart.render();
Expand Down
2 changes: 1 addition & 1 deletion spec/data-table-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('dc.dataTable', function() {
chart.selectAll("td.dc-table-label").text("changed");
});
derlet.and.callThrough();
chart.renderlet(derlet);
chart.on("renderlet", derlet);
});
it('custom renderlet should be invoked with render', function() {
chart.render();
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/spec-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ function makeDate(year, month, day) {
throw new Error("makeDate takes year, month, day");
return new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
}

// http://stackoverflow.com/questions/20068497/d3-transition-in-unit-testing
function flushAllD3Transitions() {
var now = Date.now;
Date.now = function() { return Infinity; };
d3.timer.flush();
Date.now = now;
}
2 changes: 1 addition & 1 deletion spec/pie-chart-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ describe('dc.pieChart', function() {
var chart;
beforeEach(function() {
chart = buildChart("chart-renderlet");
chart.renderlet(function() {
chart.on("renderlet", function() {
chart.selectAll("path").attr("fill", "red");
});
});
Expand Down
15 changes: 10 additions & 5 deletions 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 @@ -980,15 +982,15 @@ dc.baseMixin = function (_chart) {
#### .renderlet(renderletFunction)
A renderlet is similar to an event listener on rendering event. Multiple renderlets can be added
to an individual chart. Each time a chart is rerendered or redrawn the renderlets are invoked
right after the chart finishes its own drawing routine, giving you a way to modify the svg
right after the chart finishes its transitions, giving you a way to modify the svg
elements. Renderlet functions take the chart instance as the only input parameter and you can
use the dc API or use raw d3 to achieve pretty much any effect.
@Deprecated - Use [Listeners](#Listeners) with a 'renderlet' prefix
Generates a random key for the renderlet, which makes it hard for removal.
Generates a random key for the renderlet, which makes it hard to remove.
```js
// renderlet function
chart.renderlet(function(chart){
// do this instead of .renderlet(function(chart) { ... })
chart.on("renderlet", function(chart){
// mix of dc API and d3 manipulation
chart.select('g.y').style('display', 'none');
// its a closure so you can also access other chart variable available in the closure scope
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
2 changes: 1 addition & 1 deletion src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ dc.coordinateGridMixin = function (_chart) {
to null, then the zoom will be reset. _For focus to work elasticX has to be turned off;
otherwise focus will be ignored._
```js
chart.renderlet(function(chart){
chart.on('renderlet', function(chart) {
// smooth the rendering through event throttling
dc.events.trigger(function(){
// focus some other chart to the range selected by user on this chart
Expand Down
2 changes: 1 addition & 1 deletion src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function allows the library to smooth out the rendering by throttling events and
the most recent event.
```js
chart.renderlet(function(chart){
chart.on('renderlet', function(chart) {
// smooth the rendering through event throttling
dc.events.trigger(function(){
// focus some other chart to the range selected by user on this chart
Expand Down
Loading

0 comments on commit 55f8b5c

Please sign in to comment.