@@ -50,7 +50,6 @@ import {
5050 minutesToSeconds
5151} from 'chaire-lib-common/lib/utils/DateTimeUtils' ;
5252import AccessibilityComparisonStatsComponent from './AccessibilityComparisonStatsComponent' ;
53- import * as AccessibilityComparisonConstants from './accessibilityComparisonConstants' ;
5453import { comparisonModes } from './comparisonModes' ;
5554import AccessibilityMapCoordinatesComponent from '../accessibilityMap/widgets/AccessibilityMapCoordinateComponent' ;
5655import TimeOfTripComponent from '../transitRouting/widgets/TimeOfTripComponent' ;
@@ -90,6 +89,12 @@ interface TransitRoutingFormState extends ChangeEventsState<TransitAccessibility
9089 contextMenuRoot : Root | undefined ;
9190 alternateScenario1Id ?: string ;
9291 alternateScenario2Id ?: string ;
92+ intersectionLocationColor : string ;
93+ intersectionPolygonColor : string ;
94+ comparisonLocation1Color : string ;
95+ comparisonPolygon1Color : string ;
96+ comparisonLocation2Color : string ;
97+ comparisonPolygon2Color : string ;
9398}
9499
95100class AccessibilityComparisonForm extends ChangeEventsForm < AccessibilityComparisonFormProps , TransitRoutingFormState > {
@@ -123,14 +128,28 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
123128 alternateScenario1Id : '' ,
124129 alternateScenario2Id : '' ,
125130 contextMenu : null ,
126- contextMenuRoot : undefined
131+ contextMenuRoot : undefined ,
132+ intersectionLocationColor : Preferences . get (
133+ 'transit.routing.transitAccessibilityMap.intersectionLocationColor'
134+ ) ,
135+ intersectionPolygonColor : Preferences . get (
136+ 'transit.routing.transitAccessibilityMap.intersectionPolygonColor'
137+ ) ,
138+ comparisonLocation1Color : Preferences . get (
139+ 'transit.routing.transitAccessibilityMap.comparisonLocation1Color'
140+ ) ,
141+ comparisonPolygon1Color : Preferences . get ( 'transit.routing.transitAccessibilityMap.comparisonPolygon1Color' ) ,
142+ comparisonLocation2Color : Preferences . get (
143+ 'transit.routing.transitAccessibilityMap.comparisonLocation2Color'
144+ ) ,
145+ comparisonPolygon2Color : Preferences . get ( 'transit.routing.transitAccessibilityMap.comparisonPolygon2Color' )
127146 } ;
128147
129148 this . displayMap = this . displayMap . bind ( this ) ;
130149 this . calculateRouting = this . calculateRouting . bind ( this ) ;
131150 this . onScenarioCollectionUpdate = this . onScenarioCollectionUpdate . bind ( this ) ;
132151
133- routingEngine . updatePointColor ( AccessibilityComparisonConstants . INTERSECTION_COLOR ) ;
152+ routingEngine . updatePointColor ( this . state . intersectionLocationColor ) ;
134153 if ( routingEngine . hasLocation ( ) ) {
135154 ( serviceLocator . eventManager as EventManager ) . emitEvent < MapUpdateLayerEventType > ( 'map.updateLayer' , {
136155 layerName : 'accessibilityMapPoints' ,
@@ -175,17 +194,17 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
175194
176195 const numberOfPolygons = routing . attributes . numberOfPolygons as number ;
177196
178- const colors = {
179- intersectionColor : this . convertToRGBA ( AccessibilityComparisonConstants . INTERSECTION_COLOR , 0.6 ) ,
180- scenario1Minus2Color : this . convertToRGBA ( AccessibilityComparisonConstants . MAP_1_COLOR , 0.6 ) ,
181- scenario2Minus1Color : this . convertToRGBA ( AccessibilityComparisonConstants . MAP_2_COLOR , 0.6 )
197+ const polygonColors = {
198+ intersectionColor : this . state . intersectionPolygonColor ,
199+ scenario1Minus2Color : this . state . comparisonPolygon1Color ,
200+ scenario2Minus1Color : this . state . comparisonPolygon2Color
182201 } ;
183202
184203 const mapComparison = await calculateAccessibilityMapComparison (
185204 currentResult1 . polygons ,
186205 currentResult2 . polygons ,
187206 numberOfPolygons ,
188- colors
207+ polygonColors
189208 ) ;
190209
191210 const finalMap : TransitAccessibilityMapWithPolygonAndTimeResult [ ] = [ ] ;
@@ -498,8 +517,16 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
498517 } ;
499518 }
500519
501- private convertToRGBA = ( rgbValue : string , alpha : number ) => {
502- return rgbValue . replace ( ')' , `, ${ alpha } )` ) . replace ( 'rgb' , 'rgba' ) ;
520+ // Takes in a color string of the rgba format and returns a new one with the same rgb values but the inputed alpha value.
521+ // Necessary for the stats component. We want to pass the polygons colors as props to color some text in the results table, but the colors for those are transparent, while we want to text to be opaque.
522+ private changeAlphaValue = ( rgbaValue : string , alpha : number ) => {
523+ const rgbaArray = rgbaValue . split ( ',' ) ;
524+ if ( rgbaArray . length !== 4 ) {
525+ return rgbaValue ;
526+ }
527+
528+ rgbaArray [ 3 ] = `${ alpha } )` ;
529+ return rgbaArray . join ( ) ;
503530 } ;
504531
505532 render ( ) {
@@ -531,30 +558,58 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
531558 return (
532559 < React . Fragment >
533560 < Collapsible
534- trigger = { this . props . t ( 'transit:accessibilityComparison:Legend ' ) }
561+ trigger = { this . props . t ( 'transit:accessibilityComparison:Colors ' ) }
535562 open = { true }
536563 transitionTime = { 100 }
537564 >
565+ { mode === 'scenarios' && (
566+ < div className = "tr__form-section" >
567+ { this . props . t ( 'transit:accessibilityComparison:ScenarioLocation' ) } :
568+ < span style = { { color : this . state . intersectionLocationColor } } > ◉</ span >
569+ </ div >
570+ ) }
538571 < div className = "tr__form-section" >
539- { mode === 'scenarios'
540- ? this . props . t ( ' transit:transitComparison:ScenarioN' , { scenarioNumber : '1' } )
541- : this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '1' } ) }
572+ { this . props . t (
573+ ` transit:accessibilityComparison: ${ mode === 'scenarios' ? 'Scenario' : 'Location' } IntersectionPolygon`
574+ ) }
542575 :
543- < span style = { { color : AccessibilityComparisonConstants . MAP_1_COLOR } } > ◉</ span >
576+ < span style = { { color : this . state . intersectionPolygonColor } } > ◉</ span >
544577 </ div >
578+ { mode === 'locations' && (
579+ < div className = "tr__form-section" >
580+ { this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '1' } ) } :
581+
582+ < span style = { { color : this . state . comparisonLocation1Color } } > ◉</ span >
583+ </ div >
584+ ) }
545585 < div className = "tr__form-section" >
546586 { mode === 'scenarios'
547- ? this . props . t ( 'transit:transitComparison:ScenarioN' , { scenarioNumber : '2' } )
548- : this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '2' } ) }
587+ ? this . props . t ( 'transit:accessibilityComparison:ScenarioNPolygon' , {
588+ scenarioNumber : '1'
589+ } )
590+ : this . props . t ( 'transit:accessibilityComparison:LocationNPolygon' , {
591+ locationNumber : '1'
592+ } ) }
549593 :
550- < span style = { { color : AccessibilityComparisonConstants . MAP_2_COLOR } } > ◉</ span >
594+ < span style = { { color : this . state . comparisonPolygon1Color } } > ◉</ span >
551595 </ div >
596+ { mode === 'locations' && (
597+ < div className = "tr__form-section" >
598+ { this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '2' } ) } :
599+
600+ < span style = { { color : this . state . comparisonLocation2Color } } > ◉</ span >
601+ </ div >
602+ ) }
552603 < div className = "tr__form-section" >
553- { this . props . t (
554- `transit:accessibilityComparison:${ mode === 'scenarios' ? 'Scenario' : 'Location' } Intersection`
555- ) }
604+ { mode === 'scenarios'
605+ ? this . props . t ( 'transit:accessibilityComparison:ScenarioNPolygon' , {
606+ scenarioNumber : '2'
607+ } )
608+ : this . props . t ( 'transit:accessibilityComparison:LocationNPolygon' , {
609+ locationNumber : '2'
610+ } ) }
556611 :
557- < span style = { { color : AccessibilityComparisonConstants . INTERSECTION_COLOR } } > ◉</ span >
612+ < span style = { { color : this . state . comparisonPolygon2Color } } > ◉</ span >
558613 </ div >
559614 </ Collapsible >
560615
@@ -951,6 +1006,8 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
9511006 < AccessibilityComparisonStatsComponent
9521007 accessibilityPolygons = { this . state . currentPolygons }
9531008 mode = { mode }
1009+ color1 = { this . changeAlphaValue ( this . state . comparisonPolygon1Color , 1 ) }
1010+ color2 = { this . changeAlphaValue ( this . state . comparisonPolygon2Color , 1 ) }
9541011 />
9551012 </ React . Fragment >
9561013 ) }
@@ -968,8 +1025,8 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
9681025 const value = comparisonModes [ index ] ;
9691026 this . onValueChange ( 'selectedMode' , { value } ) ;
9701027 if ( value === 'scenarios' ) {
971- routing . updatePointColor ( AccessibilityComparisonConstants . INTERSECTION_COLOR ) ;
972- alternateRouting . updatePointColor ( AccessibilityComparisonConstants . INTERSECTION_COLOR ) ;
1028+ routing . updatePointColor ( this . state . intersectionLocationColor ) ;
1029+ alternateRouting . updatePointColor ( this . state . intersectionLocationColor ) ;
9731030 if ( routing . hasLocation ( ) ) {
9741031 alternateRouting . setLocation (
9751032 routing . attributes . locationGeojson ! . geometry . coordinates
@@ -983,8 +1040,8 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
9831040 ) ;
9841041 }
9851042 } else if ( value === 'locations' ) {
986- routing . updatePointColor ( AccessibilityComparisonConstants . MAP_1_COLOR ) ;
987- alternateRouting . updatePointColor ( AccessibilityComparisonConstants . MAP_2_COLOR ) ;
1043+ routing . updatePointColor ( this . state . comparisonLocation1Color ) ;
1044+ alternateRouting . updatePointColor ( this . state . comparisonLocation2Color ) ;
9881045 alternateRouting . attributes . scenarioId = routing . attributes . scenarioId ;
9891046 if ( routing . hasLocation ( ) ) {
9901047 alternateRouting . setLocation (
0 commit comments