@@ -13,32 +13,25 @@ var d3 = require('d3');
1313
1414// flattenUniqueSort :: String -> Function -> [[String]] -> [String]
1515function flattenUniqueSort ( axisLetter , sortFunction , data ) {
16-
1716 // Bisection based insertion sort of distinct values for logarithmic time complexity.
1817 // Can't use a hashmap, which is O(1), because ES5 maps coerce keys to strings. If it ever becomes a bottleneck,
1918 // code can be separated: a hashmap (JS object) based version if all values encountered are strings; and
2019 // downgrading to this O(log(n)) array on the first encounter of a non-string value.
2120
2221 var categoryArray = [ ] ;
23-
2422 var traceLines = data . map ( function ( d ) { return d [ axisLetter ] ; } ) ;
25-
26- var i , j , tracePoints , category , insertionIndex ;
27-
2823 var bisector = d3 . bisector ( sortFunction ) . left ;
2924
30- for ( i = 0 ; i < traceLines . length ; i ++ ) {
31-
32- tracePoints = traceLines [ i ] ;
33-
34- for ( j = 0 ; j < tracePoints . length ; j ++ ) {
25+ for ( var i = 0 ; i < traceLines . length ; i ++ ) {
26+ var tracePoints = traceLines [ i ] || [ ] ;
3527
36- category = tracePoints [ j ] ;
28+ for ( var j = 0 ; j < tracePoints . length ; j ++ ) {
29+ var category = tracePoints [ j ] ;
3730
3831 // skip loop: ignore null and undefined categories
3932 if ( category === null || category === undefined ) continue ;
4033
41- insertionIndex = bisector ( categoryArray , category ) ;
34+ var insertionIndex = bisector ( categoryArray , category ) ;
4235
4336 // skip loop on already encountered values
4437 if ( insertionIndex < categoryArray . length && categoryArray [ insertionIndex ] === category ) continue ;
0 commit comments