UNPKG

dimple-js

Version:

Dimple is an object-oriented API allowing you to create flexible axis-based charts using [d3.js](http://d3js.org "d3.js").

28 lines (26 loc) 1.2 kB
// Copyright: 2015 AlignAlytics // License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt" // Source: /src/methods/filterData.js // Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple#wiki-filterData dimple.filterData = function (data, field, filterValues) { var returnData = data; if (field !== null && filterValues !== null) { // Build an array from a single filter value or use the array if (filterValues !== null && filterValues !== undefined) { filterValues = [].concat(filterValues); } // The data to return returnData = []; // Iterate all the data data.forEach(function (d) { // If an invalid field is passed, just pass the data if (d[field] === null) { returnData.push(d); } else { if (filterValues.indexOf([].concat(d[field]).join("/")) > -1) { returnData.push(d); } } }, this); } // Return the filtered data return returnData; };