@@ -17,6 +17,8 @@ exports.builder = function (yargs) {
17
17
18
18
yargs . describe ( 'activity' , 'Filter movements to specified activity' ) ;
19
19
20
+ yargs . describe ( 'filter' , 'Only render cities containing the given string' ) ;
21
+
20
22
yargs . describe ( 'min-points' , '(advanced) Minimum number of points for clustering' )
21
23
. number ( 'min-points' )
22
24
. default ( 'min-points' , 4 ) ;
@@ -34,14 +36,24 @@ exports.handler = function (options) {
34
36
segments = _ . filter ( segments , [ 'activity' , options . activity ] ) ;
35
37
36
38
const controlPoints = clusterLocations ( segments , options ) ;
37
- const sortedControlPoints = _ . chain ( controlPoints )
39
+ let clusters = _ . chain ( controlPoints )
38
40
. sortBy ( points => - points . length )
39
- . take ( options . limit )
41
+ . map ( points => ( {
42
+ label : lookupLabel ( points ) ,
43
+ controlPoints : points
44
+ } ) )
40
45
. value ( ) ;
41
46
47
+ if ( options . filter )
48
+ clusters = _ . filter ( clusters , c => {
49
+ return ( c . label || '' ) . toLowerCase ( ) . indexOf ( options . filter . toLowerCase ( ) ) > - 1 ;
50
+ } ) ;
51
+
52
+ clusters = _ . take ( clusters , options . limit ) ;
53
+
42
54
const context = utils . createD3n ( options ) ;
43
55
44
- _ . each ( sortedControlPoints , ( cluster , index , clusters ) => {
56
+ _ . each ( clusters , ( cluster , index , clusters ) => {
45
57
const square = computeSquareDimensions ( index , clusters . length , options ) ;
46
58
drawMapAtSquare ( context , square , cluster , segments , options ) ;
47
59
} ) ;
@@ -89,11 +101,11 @@ function computeSquareDimensions(index, count, options) {
89
101
} ;
90
102
}
91
103
92
- function drawMapAtSquare ( context , square , controlPoints , segments , options ) {
104
+ function drawMapAtSquare ( context , square , cluster , segments , options ) {
93
105
94
106
const moves = _ . filter ( segments , [ 'type' , 'move' ] ) ;
95
107
96
- const projection = createProjection ( context , controlPoints , square . size , square . size ) ;
108
+ const projection = createProjection ( context , cluster . controlPoints , square . size , square . size ) ;
97
109
const geopath = context . d3 . geoPath ( )
98
110
. projection ( projection ) ;
99
111
@@ -112,8 +124,6 @@ function drawMapAtSquare(context, square, controlPoints, segments, options) {
112
124
. attr ( 'width' , square . size )
113
125
. attr ( 'fill' , backgroundColor ) ;
114
126
115
- const label = lookupLabel ( controlPoints ) ;
116
-
117
127
const pointToCoord = point => [ point . lon , point . lat ] ;
118
128
_ . each ( moves , move => {
119
129
@@ -130,7 +140,7 @@ function drawMapAtSquare(context, square, controlPoints, segments, options) {
130
140
. attr ( 'd' , geopath ) ;
131
141
} ) ;
132
142
133
- const fontSize = square . size * 0.05 ;
143
+ const fontSize = Math . min ( square . size * 0.05 , 16 ) ;
134
144
context . svg . append ( 'text' )
135
145
. attr ( 'text-anchor' , 'start' )
136
146
. attr ( 'font-family' , 'sans-serif' )
@@ -139,7 +149,7 @@ function drawMapAtSquare(context, square, controlPoints, segments, options) {
139
149
. attr ( 'font-size' , fontSize )
140
150
. attr ( 'x' , square . x + fontSize * 0.5 )
141
151
. attr ( 'y' , square . y + square . size - fontSize * 0.5 )
142
- . text ( label ) ;
152
+ . text ( cluster . label ) ;
143
153
144
154
}
145
155
0 commit comments