Skip to content

Commit

Permalink
Remove features during the animation loop for the d3 renderer.
Browse files Browse the repository at this point in the history
Drawing features was moved inside a requestAnimationFrame.  Removing features also needs to be there or the dynamicData example doesn't work.
  • Loading branch information
manthey committed Jun 3, 2016
1 parent 36b8077 commit 0c00e1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion examples/dynamicData/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ $(function () {
.draw();
});

map.draw();
});
17 changes: 14 additions & 3 deletions src/d3/d3Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var d3Renderer = function (arg) {
m_transform = {dx: 0, dy: 0, rx: 0, ry: 0, rotation: 0},
m_renderAnimFrameRef = null,
m_renderIds = {},
m_removeIds = {},
m_svg = null,
m_defs = null;

Expand Down Expand Up @@ -431,6 +432,8 @@ var d3Renderer = function (arg) {
m_svg = undefined;
m_defs.remove();
m_defs = undefined;
m_renderIds = {};
m_removeIds = {};
s_exit();
};

Expand Down Expand Up @@ -512,10 +515,16 @@ var d3Renderer = function (arg) {
};

this._renderFrame = function () {
var id;
for (id in m_removeIds) {
m_this.select(id).remove();
m_defs.selectAll('.' + id).remove();
}
m_removeIds = {};
var ids = m_renderIds;
m_renderIds = {};
m_renderAnimFrameRef = null;
for (var id in ids) {
for (id in ids) {
if (ids.hasOwnProperty(id)) {
m_this._renderFeature(id);
}
Expand Down Expand Up @@ -563,8 +572,10 @@ var d3Renderer = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this._removeFeature = function (id) {
m_this.select(id).remove();
m_defs.selectAll('.' + id).remove();
m_removeIds[id] = true;
if (m_renderAnimFrameRef === null) {
m_renderAnimFrameRef = window.requestAnimationFrame(m_this._renderFrame);
}
delete m_features[id];
if (m_renderIds[id]) {
delete m_renderIds[id];
Expand Down
2 changes: 2 additions & 0 deletions tests/cases/d3PointFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('d3 point feature', function () {
var selection;

layer.deleteFeature(feature2).draw();
stepAnimationFrame();

selection = layer.node().find('circle');
expect(selection.length).toBe(4);
Expand All @@ -71,6 +72,7 @@ describe('d3 point feature', function () {

layer.clear().draw();
map.draw();
stepAnimationFrame();

selection = layer.node().find('circle');
expect(selection.length).toBe(0);
Expand Down

0 comments on commit 0c00e1d

Please sign in to comment.