Skip to content

Commit de50756

Browse files
committed
lib: generalize filterVisible utils
- so that all array containers (not just gd.data) can use it.
1 parent 8745a22 commit de50756

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/lib/filter_visible.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99

1010
'use strict';
1111

12-
module.exports = function filterVisible(dataIn) {
13-
var dataOut = [];
12+
/** Filter out object items with visible !== true
13+
* insider array container.
14+
*
15+
* @param {array of objects} container
16+
* @return {array of objects} of length <= container
17+
*
18+
*/
19+
module.exports = function filterVisible(container) {
20+
var out = [];
1421

15-
for(var i = 0; i < dataIn.length; i++) {
16-
var trace = dataIn[i];
22+
for(var i = 0; i < container.length; i++) {
23+
var item = container[i];
1724

18-
if(trace.visible === true) dataOut.push(trace);
25+
if(item.visible === true) out.push(item);
1926
}
2027

21-
return dataOut;
28+
return out;
2229
};

src/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ lib.error = loggersModule.error;
7676
lib.notifier = require('./notifier');
7777

7878
lib.filterUnique = require('./filter_unique');
79+
lib.filterVisible = require('./filter_visible');
80+
7981

8082
/**
8183
* swap x and y of the same attribute in container cont

src/plots/ternary/ternary.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var Drawing = require('../../components/drawing');
1919
var setConvert = require('../cartesian/set_convert');
2020
var extendFlat = require('../../lib/extend').extendFlat;
2121
var Axes = require('../cartesian/axes');
22-
var filterVisible = require('../../lib/filter_visible');
2322
var dragElement = require('../../components/dragelement');
2423
var Titles = require('../../components/titles');
2524
var prepSelect = require('../cartesian/select');
@@ -94,7 +93,7 @@ proto.plot = function(ternaryData, fullLayout) {
9493
var moduleData = traceHash[moduleNames[i]];
9594
var _module = moduleData[0]._module;
9695

97-
_module.plot(_this, filterVisible(moduleData), ternaryLayout);
96+
_module.plot(_this, Lib.filterVisible(moduleData), ternaryLayout);
9897
}
9998

10099
_this.traceHash = traceHash;

0 commit comments

Comments
 (0)