8000 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

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
Next Next commit
ensure that Plots.getSubplotIds returns an ordered list of ids
  • Loading branch information
etpinard committed Feb 19, 2016
commit ef7f50120788d9ee0273b5161c37989ae1d0bc09
31 changes: 23 additions & 8 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,19 @@ plots.findSubplotIds = function findSubplotIds(data, layout, type) {
return subplotIds;
};

/**
* Get the ids of the current subplots.
*
* @param {object} layout plotly full layout object.
* @param {string} type subplot type to look for.
*
* @return {array} list of ordered subplot ids (strings).
*
*/
plots.getSubplotIds = function getSubplotIds(layout, type) {
if(plots.subplotsRegistry[type] === undefined) return [];
var _module = plots.subplotsRegistry[type];

if(_module === undefined) return [];

// layout must be 'fullLayout' here
if(type === 'cartesian' && !layout._hasCartesian) return [];
Expand All @@ -196,19 +207,23 @@ plots.getSubplotIds = function getSubplotIds(layout, type) {
return Object.keys(layout._plots);
}

var idRegex = plots.subplotsRegistry[type].idRegex,
var idRegex = _module.idRegex,
layoutKeys = Object.keys(layout),
subplotIds = [],
layoutKey;
subplotIds = [];

for(var i = 0; i < layoutKeys.length; i++) {
layoutKey = layoutKeys[i];
var layoutKey = layoutKeys[i];

if(idRegex.test(layoutKey)) subplotIds.push(layoutKey);
}

return subplotIds;
};

// order the ids
var idLen = _module.idRoot.length;
subplotIds.sort(function(a, b) {
var aNum = +(a.substr(idLen) || 1),
bNum = +(b.substr(idLen) || 1);
return aNum - bNum;
});

return subplotIds;
};
Expand Down
28 changes: 23 additions & 5 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ describe('Test Plots', function() {

describe('Plots.getSubplotIds', function() {
var getSubplotIds = Plots.getSubplotIds;
var layout;

it('returns scene ids', function() {
layout = {
scene: {},
it('returns scene ids in order', function() {
var layout = {
scene2: {},
scene: {},
scene3: {}
};

Expand All @@ -116,13 +115,32 @@ describe('Test Plots', function() {

expect(getSubplotIds(layout, 'cartesian'))
.toEqual([]);
expect(getSubplotIds(layout, 'geo'))
.toEqual([]);
expect(getSubplotIds(layout, 'no-valid-subplot-type'))
.toEqual([]);
});

it('returns geo ids in order', function() {
var layout = {
geo2: {},
geo: {},
geo3: {}
};

expect(getSubplotIds(layout, 'geo'))
.toEqual(['geo', 'geo2', 'geo3']);

expect(getSubplotIds(layout, 'cartesian'))
.toEqual([]);
expect(getSubplotIds(layout, 'gl3d'))
.toEqual([]);
expect(getSubplotIds(layout, 'no-valid-subplot-type'))
.toEqual([]);
});

it('returns cartesian ids', function() {
layout = {
var layout = {
_plots: { xy: {}, x2y2: {} }
};

Expand Down
0