Skip to content

Commit

Permalink
🔀 Merge pull request #146 from alexlee-dev/feature/ship-indicator
Browse files Browse the repository at this point in the history
✨ Ship Indicator
  • Loading branch information
Alex Lee committed Sep 22, 2019
2 parents 2f73659 + f9febbe commit 5c9a7b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cypress/integration/Map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ describe('Map', () => {
it('Should indicate the Home Planet.', () => {
cy.get('body').contains('(Home Planet)')
})

it('Should indicate the ship current location.', () => {
cy.get('body').contains('(YOUR_SHIP)')
})
})
19 changes: 16 additions & 3 deletions src/components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const addEventsToNodes = svg => {
})
}

const Map = ({ planets }) => {
const Map = ({ planets, ship }) => {
console.log({ ship })
const drawChart = () => {
const height = d3.select('#map-root').property('clientHeight')
const width = d3.select('#map-root').property('clientWidth')
Expand All @@ -101,6 +102,8 @@ const Map = ({ planets }) => {
.attr('x', ({ x }) => x + radius + 2)
.attr('y', ({ y }) => y - 10)

shipInd.attr('x', ({ x }) => x + radius + 2).attr('y', ({ y }) => y + 30)

//update link positions
//simply tells one end of the line to follow one node around
//and the other end of the line to follow the other node around
Expand Down Expand Up @@ -160,6 +163,15 @@ const Map = ({ planets }) => {
.attr('y', ({ y }) => y)
.style('font-size', '10px')

const shipInd = svg
.select(`#${ship.location.name}`)
.append('text')
.text('(YOUR_SHIP)')
.attr('id', 'ship-ind')
.attr('x', ({ x }) => x)
.attr('y', ({ y }) => y)
.style('font-size', '10px')

addEventsToNodes(svg)
}

Expand All @@ -172,9 +184,10 @@ const Map = ({ planets }) => {
}

Map.propTypes = {
planets: PropTypes.array.isRequired
planets: PropTypes.array.isRequired,
ship: PropTypes.object.isRequired
}

const mapStateToProps = ({ world }) => ({ planets: world.planets })
const mapStateToProps = ({ ship, world }) => ({ planets: world.planets, ship })

export default connect(mapStateToProps)(Map)

0 comments on commit 5c9a7b3

Please sign in to comment.