@@ -2,6 +2,7 @@ import Color from 'color'
2
2
import React from 'react'
3
3
import toCapitalCase from 'lodash.capitalize'
4
4
import toSpaceCase from 'lodash.lowercase'
5
+ import unique from 'lodash.uniq'
5
6
6
7
import DeepEqual from './deep-equal'
7
8
import Icon from './icon'
@@ -164,13 +165,6 @@ function findRouteForPattern ({id, patterns, routes}) {
164
165
return routes . find ( ( r ) => r . route_id === patterns . find ( ( p ) => p . pattern_id === id ) . route_id )
165
166
}
166
167
167
- function unique ( a ) {
168
- return a . reduce ( function ( n , e ) {
169
- if ( n . indexOf ( e ) === - 1 ) n . push ( e )
170
- return n
171
- } , [ ] )
172
- }
173
-
174
168
const typeToIcon = {
175
169
0 : 'subway' ,
176
170
1 : 'subway' ,
@@ -196,23 +190,28 @@ function showAccess (keys, base) {
196
190
}
197
191
198
192
function AccessDiffPercentage ( {
199
- diff
193
+ newAccess,
194
+ originalAccess
200
195
} ) {
201
- if ( diff > 0 ) return < span className = 'pull-right increase' > < strong > { diff } </ strong > %< Icon type = 'level-up' /> </ span >
202
- else if ( diff < 0 ) return < span className = 'pull-right decrease' > < strong > { diff * - 1 } </ strong > %< Icon className = 'fa-rotate-180' type = 'level-up' /> </ span >
203
- else return < span />
196
+ const actualDiff = newAccess - originalAccess
197
+ const nume = actualDiff > 0
198
+ ? newAccess - originalAccess
199
+ : originalAccess - newAccess
200
+ const diff = parseInt ( ( nume / originalAccess * 100 ) . toFixed ( 1 ) )
201
+ if ( diff === 0 ) return < span />
202
+ else if ( actualDiff > 0 ) return < span className = 'pull-right increase' > < strong > { diff } </ strong > %< Icon type = 'level-up' /> </ span >
203
+ else return < span className = 'pull-right decrease' > < strong > { diff * - 1 } </ strong > %< Icon className = 'fa-rotate-180' type = 'level-up' /> </ span >
204
204
}
205
205
206
206
function showDiff ( keys , base , comparison ) {
207
207
return (
208
208
< div className = 'CardAccess' >
209
209
< div className = 'heading' > Access to</ div >
210
210
{ keys . map ( ( key , i ) => {
211
- const diff = parseInt ( ( ( base [ key ] - comparison [ key ] ) / base [ key ] * 100 ) . toFixed ( 1 ) )
212
211
return (
213
212
< div className = 'Metric' key = { key } >
214
213
< MetricIcon name = { key } /> < strong > { ( base [ key ] | 0 ) . toLocaleString ( ) } </ strong > { toSpaceCase ( key ) }
215
- < AccessDiffPercentage diff = { diff } />
214
+ < AccessDiffPercentage newAccess = { base [ key ] } originalAccess = { comparison [ key ] } />
216
215
</ div >
217
216
)
218
217
} ) }
0 commit comments