10000 Sanitize orphan subplot logic and 'last trace' deletion by etpinard · Pull Request #268 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content
8000

Sanitize orphan subplot logic and 'last trace' deletion #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
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
add cartesian clean plot step to remove old pie traces
  • Loading branch information
etpinard committed Feb 23, 2016
commit 245f8a44193724da7ac82ee2d73e707f62132a67
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
0