Skip to content

Commit 0d38cf7

Browse files
committed
rename Plots getSubplotIdsInData -> findSubplotIds
1 parent c75d8a2 commit 0d38cf7

File tree

4 files changed

+55
-43
lines changed

4 files changed

+55
-43
lines changed

src/plots/geo/layout/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var supplyGeoAxisLayoutDefaults = require('./axis_defaults');
1717

1818

1919
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
20-
var geos = Plots.getSubplotIdsInData(fullData, 'geo'),
20+
var geos = Plots.findSubplotIds(fullData, 'geo'),
2121
geosLength = geos.length;
2222

2323
var geoLayoutIn, geoLayoutOut;

src/plots/gl3d/layout/defaults.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ var supplyGl3dAxisLayoutDefaults = require('./axis_defaults');
1818
module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
1919
if(!layoutOut._hasGL3D) return;
2020

21-
var scenes = Plots.getSubplotIdsInData(fullData, 'gl3d');
22-
23-
// Get number of scenes to compute default scene domain
24-
var scenesLength = scenes.length;
21+
var scenes = Plots.findSubplotIds(fullData, 'gl3d'),
22+
scenesLength = scenes.length;
2523

2624
var sceneLayoutIn, sceneLayoutOut;
2725

src/plots/plots.js

+34-15
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,40 @@ plots.registerSubplot = function(_module) {
140140
subplotsRegistry[plotType] = _module;
141141
};
142142

143-
// TODO separate the 'find subplot' step (which looks in layout)
144-
// from the 'get subplot ids' step (which looks in fullLayout._plots)
143+
/**
144+
* Find subplot ids in data.
145+
* Meant to be used in the defaults step.
146+
*
147+
* Use plots.getSubplotIds to grab the current
148+
* subplot ids later on in Plotly.plot.
149+
*
150+
* @param {array} data plotly data array
151+
* (intended to be _fullData, but does not have to be).
152+
* @param {string} type subplot type to look for.
153+
*
154+
* @return {array} list of subplot ids (strings).
155+
* N.B. these ids possibly un-ordered.
156+
*
157+
* TODO incorporate cartesian/gl2d axis finders in this paradigm.
158+
*/
159+
plots.findSubplotIds = function findSubplotIds(data, type) {
160+
var subplotIds = [];
161+
162+
if(plots.subplotsRegistry[type] === undefined) return subplotIds;
163+
164+
var attr = plots.subplotsRegistry[type].attr;
165+
166+
for(var i = 0; i < data.length; i++) {
167+
var trace = data[i];
168+
169+
if(plots.traceIs(trace, type) && subplotIds.indexOf(trace[attr]) === -1) {
170+
subplotIds.push(trace[attr]);
171+
}
172+
}
173+
174+
return subplotIds;
175+
};
176+
145177
plots.getSubplotIds = function getSubplotIds(layout, type) {
146178
if(plots.subplotsRegistry[type] === undefined) return [];
147179

@@ -165,19 +197,6 @@ plots.getSubplotIds = function getSubplotIds(layout, type) {
165197
return subplotIds;
166198
};
167199

168-
plots.getSubplotIdsInData = function getSubplotsInData(data, type) {
169-
if(plots.subplotsRegistry[type] === undefined) return [];
170-
171-
var attr = plots.subplotsRegistry[type].attr,
172-
subplotIds = [],
173-
trace;
174-
175-
for (var i = 0; i < data.length; i++) {
176-
trace = data[i];
177-
if(Plotly.Plots.traceIs(trace, type) && subplotIds.indexOf(trace[attr])===-1) {
178-
subplotIds.push(trace[attr]);
179-
}
180-
}
181200

182201
return subplotIds;
183202
};

test/jasmine/tests/plots_test.js

+18-23
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,26 @@ describe('Test Plots', function() {
145145
});
146146
});
147147

148-
describe('Plots.getSubplotIdsInData', function() {
149-
var getSubplotIdsInData = Plots.getSubplotIdsInData;
150-
151-
var ids, data;
152-
153-
it('it should return scene ids', function() {
154-
data = [
155-
{
156-
type: 'scatter3d',
157-
scene: 'scene'
158-
},
159-
{
160-
type: 'surface',
161-
scene: 'scene2'
162-
},
163-
{
164-
type: 'choropleth',
165-
geo: 'geo'
166-
}
167-
];
168-
169-
ids = getSubplotIdsInData(data, 'geo');
148+
describe('Plots.findSubplotIds', function() {
149+
var findSubplotIds = Plots.findSubplotIds;
150+
var ids;
151+
152+
it('should return subplots ids found in the data', function() {
153+
var data = [{
154+
type: 'scatter3d',
155+
scene: 'scene'
156+
}, {
157+
type: 'surface',
158+
scene: 'scene2'
159+
}, {
160+
type: 'choropleth',
161+
geo: 'geo'
162+
}];
163+
164+
ids = findSubplotIds(data, 'geo');
170165
expect(ids).toEqual(['geo']);
171166

172-
ids = getSubplotIdsInData(data, 'gl3d');
167+
ids = findSubplotIds(data, 'gl3d');
173168
expect(ids).toEqual(['scene', 'scene2']);
174169
});
175170

0 commit comments

Comments
 (0)