@@ -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,17 @@ 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+ console . error ( `The color value ${ rgbaValue } isn't properly formatted to convert the alpha value.` ) ;
526+ return rgbaValue ;
527+ }
528+
529+ rgbaArray [ 3 ] = `${ alpha } )` ;
530+ return rgbaArray . join ( ) ;
503531 } ;
504532
505533 render ( ) {
@@ -531,30 +559,58 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
531559 return (
532560 < React . Fragment >
533561 < Collapsible
534- trigger = { this . props . t ( 'transit:accessibilityComparison:Legend ' ) }
562+ trigger = { this . props . t ( 'transit:accessibilityComparison:Colors ' ) }
535563 open = { true }
536564 transitionTime = { 100 }
537565 >
566+ { mode === 'scenarios' && (
567+ < div className = "tr__form-section" >
568+ { this . props . t ( 'transit:accessibilityComparison:ScenarioLocation' ) } :
569+ < span style = { { color : this . state . intersectionLocationColor } } > ◉</ span >
570+ </ div >
571+ ) }
538572 < 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' } ) }
573+ { this . props . t (
574+ ` transit:accessibilityComparison: ${ mode === 'scenarios' ? 'Scenario' : 'Location' } IntersectionPolygon`
575+ ) }
542576 :
543- < span style = { { color : AccessibilityComparisonConstants . MAP_1_COLOR } } > ◉</ span >
577+ < span style = { { color : this . state . intersectionPolygonColor } } > ◉</ span >
544578 </ div >
579+ { mode === 'locations' && (
580+ < div className = "tr__form-section" >
581+ { this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '1' } ) } :
582+
583+ < span style = { { color : this . state . comparisonLocation1Color } } > ◉</ span >
584+ </ div >
585+ ) }
545586 < div className = "tr__form-section" >
546587 { mode === 'scenarios'
547- ? this . props . t ( 'transit:transitComparison:ScenarioN' , { scenarioNumber : '2' } )
548- : this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '2' } ) }
588+ ? this . props . t ( 'transit:accessibilityComparison:ScenarioNPolygon' , {
589+ scenarioNumber : '1'
590+ } )
591+ : this . props . t ( 'transit:accessibilityComparison:LocationNPolygon' , {
592+ locationNumber : '1'
593+ } ) }
549594 :
550- < span style = { { color : AccessibilityComparisonConstants . MAP_2_COLOR } } > ◉</ span >
595+ < span style = { { color : this . state . comparisonPolygon1Color } } > ◉</ span >
551596 </ div >
597+ { mode === 'locations' && (
598+ < div className = "tr__form-section" >
599+ { this . props . t ( 'transit:accessibilityComparison:LocationN' , { locationNumber : '2' } ) } :
600+
601+ < span style = { { color : this . state . comparisonLocation2Color } } > ◉</ span >
602+ </ div >
603+ ) }
552604 < div className = "tr__form-section" >
553- { this . props . t (
554- `transit:accessibilityComparison:${ mode === 'scenarios' ? 'Scenario' : 'Location' } Intersection`
555- ) }
605+ { mode === 'scenarios'
606+ ? this . props . t ( 'transit:accessibilityComparison:ScenarioNPolygon' , {
607+ scenarioNumber : '2'
608+ } )
609+ : this . props . t ( 'transit:accessibilityComparison:LocationNPolygon' , {
610+ locationNumber : '2'
611+ } ) }
556612 :
557- < span style = { { color : AccessibilityComparisonConstants . INTERSECTION_COLOR } } > ◉</ span >
613+ < span style = { { color : this . state . comparisonPolygon2Color } } > ◉</ span >
558614 </ div >
559615 </ Collapsible >
560616
@@ -951,6 +1007,8 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
9511007 < AccessibilityComparisonStatsComponent
9521008 accessibilityPolygons = { this . state . currentPolygons }
9531009 mode = { mode }
1010+ color1 = { this . changeAlphaValue ( this . state . comparisonPolygon1Color , 1 ) }
1011+ color2 = { this . changeAlphaValue ( this . state . comparisonPolygon2Color , 1 ) }
9541012 />
9551013 </ React . Fragment >
9561014 ) }
@@ -968,8 +1026,8 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
9681026 const value = comparisonModes [ index ] ;
9691027 this . onValueChange ( 'selectedMode' , { value } ) ;
9701028 if ( value === 'scenarios' ) {
971- routing . updatePointColor ( AccessibilityComparisonConstants . INTERSECTION_COLOR ) ;
972- alternateRouting . updatePointColor ( AccessibilityComparisonConstants . INTERSECTION_COLOR ) ;
1029+ routing . updatePointColor ( this . state . intersectionLocationColor ) ;
1030+ alternateRouting . updatePointColor ( this . state . intersectionLocationColor ) ;
9731031 if ( routing . hasLocation ( ) ) {
9741032 alternateRouting . setLocation (
9751033 routing . attributes . locationGeojson ! . geometry . coordinates
@@ -983,8 +1041,8 @@ class AccessibilityComparisonForm extends ChangeEventsForm<AccessibilityComparis
9831041 ) ;
9841042 }
9851043 } else if ( value === 'locations' ) {
986- routing . updatePointColor ( AccessibilityComparisonConstants . MAP_1_COLOR ) ;
987- alternateRouting . updatePointColor ( AccessibilityComparisonConstants . MAP_2_COLOR ) ;
1044+ routing . updatePointColor ( this . state . comparisonLocation1Color ) ;
1045+ alternateRouting . updatePointColor ( this . state . comparisonLocation2Color ) ;
9881046 alternateRouting . attributes . scenarioId = routing . attributes . scenarioId ;
9891047 if ( routing . hasLocation ( ) ) {
9901048 alternateRouting . setLocation (
0 commit comments