@@ -13,32 +13,25 @@ var d3 = require('d3');
13
13
14
14
// flattenUniqueSort :: String -> Function -> [[String]] -> [String]
15
15
function flattenUniqueSort ( axisLetter , sortFunction , data ) {
16
-
17
16
// Bisection based insertion sort of distinct values for logarithmic time complexity.
18
17
// Can't use a hashmap, which is O(1), because ES5 maps coerce keys to strings. If it ever becomes a bottleneck,
19
18
// code can be separated: a hashmap (JS object) based version if all values encountered are strings; and
20
19
// downgrading to this O(log(n)) array on the first encounter of a non-string value.
21
20
22
21
var categoryArray = [ ] ;
23
-
24
22
var traceLines = data . map ( function ( d ) { return d [ axisLetter ] ; } ) ;
25
-
26
- var i , j , tracePoints , category , insertionIndex ;
27
-
28
23
var bisector = d3 . bisector ( sortFunction ) . left ;
29
24
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 ] || [ ] ;
35
27
36
- category = tracePoints [ j ] ;
28
+ for ( var j = 0 ; j < tracePoints . length ; j ++ ) {
29
+ var category = tracePoints [ j ] ;
37
30
38
31
// skip loop: ignore null and undefined categories
39
32
if ( category === null || category === undefined ) continue ;
40
33
41
- insertionIndex = bisector ( categoryArray , category ) ;
34
+ var insertionIndex = bisector ( categoryArray , category ) ;
42
35
43
36
// skip loop on already encountered values
44
37
if ( insertionIndex < categoryArray . length && categoryArray [ insertionIndex ] === category ) continue ;
0 commit comments