Skip to content

Commit c672387

Browse files
revert(RouteDetails): remove color; remove headsign buttons
1 parent d5080c9 commit c672387

File tree

5 files changed

+72
-102
lines changed

5 files changed

+72
-102
lines changed

i18n/en-US.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ components:
3939
RouteDetails:
4040
operatedBy: "Operated by {agencyName}"
4141
moreDetails: "More Details"
42-
stopsTo: "Stops To"
42+
stopsTo: "Towards"
43+
selectADirection: "Select a direction..."
4344
RouteViewer:
4445
allAgencies: All Agencies
4546
allModes: All Modes # Note to translator: This text is width-constrained.

lib/components/viewers/route-details.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
3-
import { Button } from 'react-bootstrap'
43
import { connect } from 'react-redux'
5-
import { FormattedMessage } from 'react-intl'
4+
import { FormattedMessage, injectIntl } from 'react-intl'
65

76
import Icon from '../util/icon'
87
import { extractHeadsignFromPattern, getColorAndNameFromRoute } from '../../util/viewer'
@@ -63,7 +62,9 @@ class RouteDetails extends Component {
6362
* If a headsign link is clicked, set that pattern in redux state so that the
6463
* view can adjust
6564
*/
66-
_headSignButtonClicked = (id) => {
65+
_headSignButtonClicked = (e) => {
66+
const { target } = e
67+
const { value: id } = target
6768
const { route, setViewedRoute } = this.props
6869
setViewedRoute({ patternId: id, routeId: route.id })
6970
};
@@ -77,12 +78,11 @@ class RouteDetails extends Component {
7778
};
7879

7980
render () {
80-
const { className, operator, pattern, route, setHoveredStop } = this.props
81+
const { intl, operator, pattern, route, setHoveredStop, viewedRoute } = this.props
8182
const { agency, patterns, url } = route
8283

8384
const {
84-
backgroundColor: routeColor,
85-
color: textColor
85+
backgroundColor: routeColor
8686
} = getColorAndNameFromRoute(operator, route)
8787

8888
const headsigns =
@@ -131,9 +131,10 @@ class RouteDetails extends Component {
131131
return bVehicleCount - aVehicleCount
132132
})
133133

134+
// if no pattern is set, we are in the routeRow
134135
return (
135-
<Container backgroundColor={routeColor} textColor={textColor}>
136-
<RouteNameContainer className={className} textColor={textColor}>
136+
<Container full={pattern != null}>
137+
<RouteNameContainer>
137138
<LogoLinkContainer>
138139
{agency && <FormattedMessage
139140
id='components.RouteDetails.operatedBy'
@@ -142,26 +143,37 @@ class RouteDetails extends Component {
142143
}}
143144
/>}
144145
{url && (
145-
<MoreDetailsLink color={textColor} href={url} target='_blank'>
146+
<MoreDetailsLink href={url} target='_blank'>
146147
<Icon type='link' />
147148
<FormattedMessage id='components.RouteDetails.moreDetails' />
148149
</MoreDetailsLink>
149150
)}
150151
</LogoLinkContainer>
151152
</RouteNameContainer>
152-
<PatternContainer color={routeColor} textColor={textColor}>
153-
<h4><FormattedMessage id='components.RouteDetails.stopsTo' /></h4>
153+
<PatternContainer>
154+
<h4>
155+
<label htmlFor='headsign-selector' id='headsign-selector-label'>
156+
<FormattedMessage id='components.RouteDetails.stopsTo' />
157+
</label>
158+
</h4>
154159
{headsigns &&
155-
headsigns.map((h) => (
156-
<Button
157-
bsStyle='link'
158-
className={h.id === pattern?.id ? 'active' : ''}
160+
<select
161+
id='headsign-selector'
162+
name='headsigns'
163+
onBlur={this._headSignButtonClicked}
164+
onChange={this._headSignButtonClicked}
165+
value={viewedRoute.patternId}
166+
>
167+
{!viewedRoute.patternId && <option>{intl.formatMessage({id: 'components.RouteDetails.selectADirection'})}</option>}
168+
{headsigns.map((h) => (
169+
<option
159170
key={h.id}
160-
onClick={() => this._headSignButtonClicked(h.id)}
171+
value={h.id}
161172
>
162173
{h.headsign}
163-
</Button>
174+
</option>
164175
))}
176+
</select>}
165177
</PatternContainer>
166178
{pattern && (
167179
<StopContainer
@@ -200,4 +212,4 @@ const mapDispatchToProps = {
200212
setViewedStop
201213
}
202214

203-
export default connect(mapStateToProps, mapDispatchToProps)(RouteDetails)
215+
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(RouteDetails))

lib/components/viewers/route-viewer.js

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Label, Button } from 'react-bootstrap'
55
import { VelocityTransitionGroup } from 'velocity-react'
66
import { connect } from 'react-redux'
77
import styled from 'styled-components'
8-
import tinycolor from 'tinycolor2'
98
import { FormattedMessage, injectIntl } from 'react-intl'
109

1110
import Icon from '../util/icon'
@@ -141,17 +140,12 @@ class RouteViewer extends Component {
141140
route,
142141
transitOperators
143142
) || {}
144-
const { backgroundColor, color } = getColorAndNameFromRoute(
145-
operator,
146-
route
147-
)
148143

149144
return (
150145
<div className='route-viewer'>
151146
{/* Header Block */}
152147
<div
153148
className='route-viewer-header'
154-
style={{ backgroundColor, color }}
155149
>
156150
{/* Always show back button, as we don't write a route anymore */}
157151
<div className='back-button-container'>
@@ -166,11 +160,10 @@ class RouteViewer extends Component {
166160
<ModeIcon
167161
aria-label={getModeFromRoute(route)}
168162
mode={getModeFromRoute(route)}
169-
style={{ fill: color }}
170163
width={22}
171164
/>
172165
)}
173-
<strong>{route.shortName}</strong>
166+
<RouteName operator={operator} route={route} />
174167
</div>
175168
</div>
176169
<RouteDetails
@@ -301,7 +294,7 @@ class RouteViewer extends Component {
301294
}
302295

303296
const StyledRouteRow = styled.div`
304-
background-color: ${props => props.isActive ? props.routeColor : 'white'};
297+
background-color: white;
305298
border-bottom: 1px solid gray;
306299
`
307300

@@ -311,20 +304,6 @@ const RouteRowButton = styled(Button)`
311304
padding: 6px;
312305
width: 100%;
313306
transition: all ease-in-out 0.1s;
314-
315-
&:hover {
316-
background-color: ${(props) =>
317-
!props.isActive && tinycolor(props.routeColor)
318-
.lighten(50)
319-
.toHexString()};
320-
border-radius: 0;
321-
}
322-
323-
&:active:focus,
324-
&:active:hover {
325-
background-color: ${(props) => props.routeColor};
326-
border-radius: 0;
327-
}
328307
`
329308

330309
const RouteRowElement = styled.span``
@@ -358,6 +337,22 @@ const RouteNameElement = styled(Label)`
358337
text-overflow: ellipsis;
359338
`
360339

340+
const RouteName = ({operator, route}) => {
341+
const { backgroundColor, color, longName } = getColorAndNameFromRoute(
342+
operator,
343+
route
344+
)
345+
return (
346+
<RouteNameElement
347+
backgroundColor={backgroundColor}
348+
color={color}
349+
title={`${route.shortName} ${longName}`}
350+
>
351+
<b>{route.shortName}</b> {longName}
352+
</RouteNameElement>
353+
)
354+
}
355+
361356
class RouteRow extends PureComponent {
362357
static contextType = ComponentContext
363358

@@ -405,22 +400,15 @@ class RouteRow extends PureComponent {
405400
const { intl, isActive, operator, route } = this.props
406401
const { ModeIcon } = this.context
407402

408-
const { backgroundColor, color, longName, potentiallyUnreadableBackgroundColor } = getColorAndNameFromRoute(
409-
operator,
410-
route
411-
)
412-
413403
return (
414404
<StyledRouteRow
415405
isActive={isActive}
416406
ref={this.activeRef}
417-
routeColor={backgroundColor}
418407
>
419408
<RouteRowButton
420409
className='clear-button-formatting'
421410
isActive={isActive}
422411
onClick={this._onClick}
423-
routeColor={potentiallyUnreadableBackgroundColor}
424412
>
425413
<RouteRowElement>
426414
{operator && operator.logo && (
@@ -440,19 +428,13 @@ class RouteRow extends PureComponent {
440428
aria-label={getModeFromRoute(route)}
441429
height={22}
442430
mode={getModeFromRoute(route)}
443-
style={{ fill: isActive && color }}
444431
width={22}
445432
/>
446433
</ModeIconElement>
447-
<RouteNameElement
448-
backgroundColor={
449-
isActive ? backgroundColor : potentiallyUnreadableBackgroundColor
450-
}
451-
color={color}
452-
title={`${route.shortName} ${longName}`}
453-
>
454-
<b>{route.shortName}</b> {longName}
455-
</RouteNameElement>
434+
<RouteName
435+
operator={operator}
436+
route={route}
437+
/>
456438
</RouteRowButton>
457439
<VelocityTransitionGroup
458440
enter={{ animation: 'slideDown' }}

lib/components/viewers/styled.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
11
import styled from 'styled-components'
22

3-
/** Converts text color (either black or white) to rgb */
4-
const textHexToRgb = (color) => (color === '#ffffff' ? '255,255,255' : '0,0,0')
5-
63
/** Route Details */
74
export const Container = styled.div`
8-
background-color: ${(props) => props.backgroundColor};
9-
color: ${(props) => props.textColor};
105
overflow-y: hidden;
116
height: 100%;
7+
background-color: ${props => props.full ? '#ddd' : 'inherit'}
128
`
9+
1310
export const RouteNameContainer = styled.div`
1411
padding: 8px;
15-
color: ${props => props.textColor};
12+
background-color: inherit;
1613
`
1714
export const LogoLinkContainer = styled.div`
1815
display: flex;
1916
align-items: center;
2017
justify-content: space-between;
2118
`
2219
export const MoreDetailsLink = styled.a`
23-
color: ${(props) => props.color};
24-
background-color: rgba(${(props) => textHexToRgb(props.color)},0.1);
20+
color: #333;
21+
background-color: rgba(0,0,0,0.1);
2522
padding: 5px;
2623
display: block;
2724
border-radius: 5px;
2825
transition: 0.1s all ease-in-out;
2926
3027
&:hover {
31-
background-color: rgba(255,255,255,0.8);
32-
color: #333;
28+
background-color: rgba(0,0,0,0.8);
29+
color: #eee;
3330
}
3431
}
3532
`
3633
export const PatternContainer = styled.div`
37-
background-color: ${(props) => props.routeColor};
38-
color: ${(props) => props.textColor};
34+
background-color: inherit;
35+
color: inherit;
3936
display: flex;
4037
justify-content: flex-start;
4138
align-items: baseline;
4239
gap: 16px;
43-
padding: 0 8px;
40+
padding: 0 8px 8px;
4441
margin: 0;
4542
4643
overflow-x: scroll;
@@ -49,19 +46,6 @@ export const PatternContainer = styled.div`
4946
margin-bottom: 0px;
5047
white-space: nowrap;
5148
}
52-
53-
button {
54-
color: inherit;
55-
border-bottom: 3px solid ${(props) => props.textColor};
56-
}
57-
58-
button:hover, button:focus, button:visited {
59-
text-decoration: none;
60-
}
61-
button:hover, button:focus, button.active {
62-
color: ${(props) => props.color};
63-
background-color: ${(props) => props.textColor};
64-
}
6549
}
6650
`
6751

@@ -114,4 +98,9 @@ export const Stop = styled.a`
11498
stop's bar connects the previous bar with the current one */
11599
top: -37px;
116100
}
101+
102+
/* hide the first line between blobs */
103+
&:first-of-type::after {
104+
background: transparent;
105+
}
117106
`

lib/util/viewer.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -288,35 +288,21 @@ function getCleanRouteLongName ({ longNameSplitter, route }) {
288288
*/
289289
export function getColorAndNameFromRoute (operator, route) {
290290
const {defaultRouteColor, defaultRouteTextColor, longNameSplitter} = operator || {}
291-
const potentiallyUnreadableBackgroundColor = `#${defaultRouteColor || route.color || 'ffffff'}`
291+
const backgroundColor = `#${defaultRouteColor || route.color || 'ffffff'}`
292292
// NOTE: text color is not a part of short response route object, so there
293293
// is no way to determine from OTP what the text color should be if the
294294
// background color is, say, black. Instead, determine the appropriate
295295
// contrast color and use that if no text color is available.
296-
const contrastColor = getContrastYIQ(potentiallyUnreadableBackgroundColor)
296+
const contrastColor = getContrastYIQ(backgroundColor)
297297
const color = `#${defaultRouteTextColor || route.textColor || contrastColor}`
298298
// Default long name is empty string (long name is an optional GTFS value).
299299
const longName = getCleanRouteLongName({ longNameSplitter, route })
300300

301301
// Choose a color that the text color will look good against
302-
let backgroundColor = potentiallyUnreadableBackgroundColor
303-
if (
304-
!tinycolor.isReadable(
305-
tinycolor(potentiallyUnreadableBackgroundColor),
306-
tinycolor(color),
307-
// Buses are likely to have less care put into their color selection
308-
{level: route.mode === 'BUS' ? 'AAA' : 'AA'}
309-
)
310-
) {
311-
backgroundColor = tinycolor(potentiallyUnreadableBackgroundColor)
312-
.desaturate(40)
313-
.toHexString()
314-
}
315302

316303
return {
317304
backgroundColor,
318305
color,
319-
longName,
320-
potentiallyUnreadableBackgroundColor
306+
longName
321307
}
322308
}

0 commit comments

Comments
 (0)