Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add cartesian clean plot step to remove old pie traces
  • Loading branch information
etpinard committed Feb 26, 2016
commit c75d8a22ef8f91c5c645846ca47886fd820342af
6 changes: 6 additions & 0 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ exports.plot = function(gd) {
if(cdPie.length) Pie.plot(gd, cdPie);
}
};

exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
if(oldFullLayout._hasPie && !newFullLayout._hasPie) {
oldFullLayout._pielayer.selectAll('g.trace').remove();
}
};
49 changes: 48 additions & 1 deletion test/jasmine/tests/plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,23 @@ describe('Test plot structure', function() {

describe('pie traces', function() {
var mock = require('@mocks/pie_simple.json');
var gd;

function countPieTraces() {
return d3.select('g.pielayer').selectAll('g.trace').size();
}

function countBarTraces() {
return d3.selectAll('g.trace.bars').size();
}

beforeEach(function(done) {
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
gd = createGraphDiv();

var mockData = Lib.extendDeep([], mock.data),
mockLayout = Lib.extendDeep({}, mock.layout);

Plotly.plot(gd, mockData, mockLayout).then(done);
});

it('has as many *slice* nodes as there are pie items', function() {
Expand All @@ -319,6 +333,39 @@ describe('Test plot structure', function() {
var testerSVG = d3.selectAll('#js-plotly-tester');
assertNamespaces(testerSVG.node());
});

it('should be able to get deleted', function(done) {
expect(countPieTraces()).toEqual(1);
expect(countSubplots()).toEqual(0);

Plotly.deleteTraces(gd, [0]).then(function() {
expect(countPieTraces()).toEqual(0);
expect(countSubplots()).toEqual(0);

done();
});
});

it('should be able to be restyled to a bar chart and back', function(done) {
expect(countPieTraces()).toEqual(1);
expect(countBarTraces()).toEqual(0);
expect(countSubplots()).toEqual(0);

Plotly.restyle(gd, 'type', 'bar').then(function() {
expect(countPieTraces()).toEqual(0);
expect(countBarTraces()).toEqual(1);
expect(countSubplots()).toEqual(1);

return Plotly.restyle(gd, 'type', 'pie');
}).then(function() {
expect(countPieTraces()).toEqual(1);
expect(countBarTraces()).toEqual(0);
expect(countSubplots()).toEqual(0);

done();
});

});
});
});

Expand Down