diff --git a/lib/actions/map.js b/lib/actions/map.js
index f3ec18447..26cbcbcef 100644
--- a/lib/actions/map.js
+++ b/lib/actions/map.js
@@ -109,7 +109,7 @@ export function switchLocations () {
}
}
-export const showLegDiagram = createAction('SHOW_LEG_DIAGRAM')
+export const setLegDiagram = createAction('SET_LEG_DIAGRAM')
export const setElevationPoint = createAction('SET_ELEVATION_POINT')
diff --git a/lib/components/map/elevation-point-marker.js b/lib/components/map/elevation-point-marker.js
index 5013b1a8e..893ff5cce 100644
--- a/lib/components/map/elevation-point-marker.js
+++ b/lib/components/map/elevation-point-marker.js
@@ -13,7 +13,6 @@ import { CircleMarker } from 'react-leaflet'
class ElevationPointMarker extends Component {
render () {
const { diagramLeg, elevationPoint, showElevationProfile } = this.props
-
// Compute the elevation point marker, if activeLeg and elevation profile is enabled.
let elevationPointMarker = null
if (showElevationProfile && diagramLeg && elevationPoint) {
diff --git a/lib/components/map/leg-diagram.js b/lib/components/map/leg-diagram.js
index 917d1f3bf..893ae3c7d 100644
--- a/lib/components/map/leg-diagram.js
+++ b/lib/components/map/leg-diagram.js
@@ -6,7 +6,7 @@ import { Button } from 'react-bootstrap'
import { connect } from 'react-redux'
import ReactResizeDetector from 'react-resize-detector'
-import { setElevationPoint, showLegDiagram } from '../../actions/map'
+import { setElevationPoint, setLegDiagram } from '../../actions/map'
const { getElevationProfile, getTextWidth, legElevationAtDistance } = coreUtils.itinerary
@@ -23,7 +23,7 @@ const METERS_TO_FEET = 3.28084
class LegDiagram extends Component {
static propTypes = {
elevationPoint: PropTypes.number,
- showLegDiagram: PropTypes.func,
+ setLegDiagram: PropTypes.func,
setElevationPoint: PropTypes.func
}
@@ -67,7 +67,7 @@ class LegDiagram extends Component {
}
_onCloseButtonClick = () => {
- this.props.showLegDiagram(null)
+ this.props.setLegDiagram(null)
this.props.setElevationPoint(null)
}
@@ -383,7 +383,7 @@ const mapStateToProps = (state, ownProps) => {
}
const mapDispatchToProps = {
- showLegDiagram,
+ setLegDiagram,
setElevationPoint
}
diff --git a/lib/components/narrative/leg-diagram-preview.js b/lib/components/narrative/leg-diagram-preview.js
index fd624d807..7a1c52bbf 100644
--- a/lib/components/narrative/leg-diagram-preview.js
+++ b/lib/components/narrative/leg-diagram-preview.js
@@ -1,105 +1,7 @@
-import coreUtils from '@opentripplanner/core-utils'
-import PropTypes from 'prop-types'
-import React, {Component} from 'react'
+import LegDiagramPreviewLayout from '@opentripplanner/itinerary-body/lib/AccessLegBody/leg-diagram-preview'
import { connect } from 'react-redux'
-import ReactResizeDetector from 'react-resize-detector'
-import { showLegDiagram } from '../../actions/map'
-
-const METERS_TO_FEET = 3.28084
-
-class LegDiagramPreview extends Component {
- static propTypes = {
- leg: PropTypes.object
- }
-
- constructor (props) {
- super(props)
- this.state = { width: null }
- }
-
- _onResize = (width, height) => {
- if (width > 0) {
- this.setState({ width })
- }
- }
-
- /**
- * Determine if the diagram currently visible is for this leg (based on start
- * time).
- */
- _isActive = () => {
- const { diagramVisible, leg } = this.props
- return diagramVisible && diagramVisible.startTime === leg.startTime
- }
-
- _onExpandClick = () => {
- const { leg, showLegDiagram } = this.props
- if (this._isActive()) showLegDiagram(null)
- else showLegDiagram(leg)
- }
-
- /** Round elevation to whole number and add symbol. */
- _formatElevation = (elev) => Math.round(elev) + `'`
-
- render () {
- const { leg, showElevationProfile } = this.props
- if (!showElevationProfile) return null
- const profile = coreUtils.itinerary.getElevationProfile(leg.steps)
- // Don't show for very short legs
- if (leg.distance < 500 || leg.mode === 'CAR') return null
-
- return (
-
- {/* The preview elevation SVG */}
-
-
- Elevation chart{' '}
- ↑{this._formatElevation(profile.gain * METERS_TO_FEET)}{' '}
- ↓{this._formatElevation(-profile.loss * METERS_TO_FEET)}
-
- {profile.points.length > 0
- ? generateSvg(profile, this.state.width)
- : 'No elevation data available.'
- }
-
-
-
- )
- }
-}
-
-function generateSvg (profile, width) {
- const height = 30
- let { minElev, maxElev, points: ptArr, traversed } = profile
- // Pad the min-max range by 25m on either side
- minElev -= 25
- maxElev += 25
-
- // Transform the point array and store it as an SVG-ready string
- const pts = ptArr.map(pt => {
- const x = (pt[0] / traversed) * width
- const y = height - height * (pt[1] - minElev) / (maxElev - minElev)
- return x + ',' + y
- }).join(' ')
-
- // Render the SVG
- return (
-
- )
-}
+import { setLegDiagram } from '../../actions/map'
// Connect to the redux store
@@ -111,7 +13,7 @@ const mapStateToProps = (state, ownProps) => {
}
const mapDispatchToProps = {
- showLegDiagram
+ setLegDiagram
}
-export default connect(mapStateToProps, mapDispatchToProps)(LegDiagramPreview)
+export default connect(mapStateToProps, mapDispatchToProps)(LegDiagramPreviewLayout)
diff --git a/lib/components/narrative/line-itin/connected-itinerary-body.js b/lib/components/narrative/line-itin/connected-itinerary-body.js
index aa316bddb..974fd10c0 100644
--- a/lib/components/narrative/line-itin/connected-itinerary-body.js
+++ b/lib/components/narrative/line-itin/connected-itinerary-body.js
@@ -9,7 +9,7 @@ import React, { Component } from 'react'
import { connect } from 'react-redux'
import styled from 'styled-components'
-import { showLegDiagram } from '../../../actions/map'
+import { setLegDiagram } from '../../../actions/map'
import { setViewedTrip } from '../../../actions/ui'
import TransitLegSubheader from './connected-transit-leg-subheader'
import RealtimeTimeColumn from './realtime-time-column'
@@ -42,7 +42,8 @@ class ConnectedItineraryBody extends Component {
LegIcon,
setActiveLeg,
setViewedTrip,
- showLegDiagram,
+ showElevationProfile,
+ setLegDiagram,
timeOptions
} = this.props
@@ -57,10 +58,10 @@ class ConnectedItineraryBody extends Component {
PlaceName={PlaceName}
RouteDescription={RouteDescription}
setActiveLeg={setActiveLeg}
- setLegDiagram={showLegDiagram}
+ setLegDiagram={setLegDiagram}
setViewedTrip={setViewedTrip}
showAgencyInfo
- showElevationProfile
+ showElevationProfile={showElevationProfile}
showLegIcon
showMapButtonColumn={false}
showRouteFares={config.itinerary && config.itinerary.showRouteFares}
@@ -91,7 +92,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = {
setViewedTrip,
- showLegDiagram
+ setLegDiagram
}
export default connect(mapStateToProps, mapDispatchToProps)(
diff --git a/lib/index.js b/lib/index.js
index 8c513a2c8..620c87193 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -14,7 +14,6 @@ import OsmBaseLayer from './components/map/osm-base-layer'
import TileOverlay from './components/map/tile-overlay'
import ItineraryCarousel from './components/narrative/itinerary-carousel'
-import LegDiagramPreview from './components/narrative/leg-diagram-preview'
import NarrativeItineraries from './components/narrative/narrative-itineraries'
import NarrativeItinerary from './components/narrative/narrative-itinerary'
import NarrativeRoutingResults from './components/narrative/narrative-routing-results'
@@ -71,7 +70,6 @@ export {
TileOverlay,
// narrative components
- LegDiagramPreview,
LineItinerary,
NarrativeItineraries,
NarrativeItinerary,
diff --git a/lib/reducers/create-otp-reducer.js b/lib/reducers/create-otp-reducer.js
index 0b5c6218d..3ab796977 100644
--- a/lib/reducers/create-otp-reducer.js
+++ b/lib/reducers/create-otp-reducer.js
@@ -576,7 +576,7 @@ function createOtpReducer (config, initialQuery) {
}
}
})
- case 'SHOW_LEG_DIAGRAM':
+ case 'SET_LEG_DIAGRAM':
return update(state, {
ui: {
diagramLeg: { $set: action.payload }
diff --git a/package.json b/package.json
index e816419cf..af3ec60b0 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
},
"homepage": "https://github.com/opentripplanner/otp-react-redux#readme",
"dependencies": {
- "@opentripplanner/base-map": "^1.0.1",
+ "@opentripplanner/base-map": "^1.0.2",
"@opentripplanner/core-utils": "^1.2.1",
"@opentripplanner/endpoints-overlay": "^1.0.1",
"@opentripplanner/from-to-location-picker": "^1.0.1",
diff --git a/yarn.lock b/yarn.lock
index 78bbf2c4e..4ad4b8b1a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1253,12 +1253,12 @@
universal-user-agent "^3.0.0"
url-template "^2.0.8"
-"@opentripplanner/base-map@^1.0.1":
- version "1.0.1"
- resolved "https://registry.yarnpkg.com/@opentripplanner/base-map/-/base-map-1.0.1.tgz#cef7f9fc181d1cb414aa3f11cddef3a8040ac3fa"
- integrity sha512-/5versYgxFzaIEekvknmdzAc7ssTTLGaI8Ag+yZefEcio+M+JQNrRKIHfsj0d6x6hfodnTSG+fzaJ/GfklTFAA==
+"@opentripplanner/base-map@^1.0.2":
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/@opentripplanner/base-map/-/base-map-1.0.2.tgz#039dfdb11116ebb5d330a859f5ee33cfa6b8d768"
+ integrity sha512-QkNDJrZqGgiafO8fxJhnOFPWcpUIsDszlBZIh8q0B3ztFRPZeQA8cFX/c429PhXXmCbpYx5JkerhnxMKz140XA==
dependencies:
- "@opentripplanner/core-utils" "^1.2.0"
+ "@opentripplanner/core-utils" "^2.1.0"
prop-types "^15.7.2"
"@opentripplanner/core-utils@^1.2.0", "@opentripplanner/core-utils@^1.2.1":