-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
world spec #253
Closed
Closed
world spec #253
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fcf6bd1
world spec
a14fa09
move world-map to it's own component
87cb734
fix lint errors
af730f5
assert correct coordinates
a8807b7
fix coordinate property reference
cbbf145
a semicolon is required after a class property
d6d4fa5
correct semicolon
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, {Component, PropTypes} from 'react' | ||
import d3 from 'd3' | ||
import topojson from 'topojson' | ||
import {AutoSizer} from 'react-virtualized' | ||
import ReactFauxDOM from 'react-faux-dom' | ||
|
||
import worldData from '../../data/world.json' | ||
|
||
export default class WorldMap extends Component { | ||
static propTypes = { | ||
coordinates: PropTypes.array.isRequired | ||
}; | ||
|
||
_renderMap = ({width, height}) => { | ||
const projection = d3.geo.equirectangular() | ||
.scale(height / Math.PI) | ||
.translate([width / 2, height / 2]) | ||
.precision(0.1) | ||
|
||
const path = d3.geo.path() | ||
.projection(projection) | ||
|
||
const graticule = d3.geo.graticule() | ||
|
||
const el = d3.select(ReactFauxDOM.createElement('svg')) | ||
.attr('width', width) | ||
.attr('height', height) | ||
|
||
// Fill Pattern | ||
el.append('defs') | ||
.append('pattern') | ||
.attr('id', 'gridpattern') | ||
.attr('x', 0) | ||
.attr('y', 0) | ||
.attr('width', 4) | ||
.attr('height', 4) | ||
.attr('patternUnits', 'userSpaceOnUse') | ||
.append('circle') | ||
.attr('cx', 0) | ||
.attr('cy', 0) | ||
.attr('r', 1) | ||
.attr('style', 'stroke: none; fill: rgba(255, 255, 255, 0.7)') | ||
|
||
el.append('path') | ||
.datum(graticule) | ||
.attr('class', 'graticule') | ||
.attr('d', path) | ||
|
||
el.insert('path', '.graticule') | ||
.datum(topojson.feature(worldData, worldData.objects.land)) | ||
.attr('d', path) | ||
.attr('fill', 'url(#gridpattern)') | ||
|
||
el.insert('path', '.graticule') | ||
.datum(topojson.mesh( | ||
worldData, | ||
worldData.objects.countries, | ||
(a, b) => a !== b | ||
)) | ||
.attr('d', path) | ||
.attr('fill', 'none') | ||
.attr('stroke', 'none') | ||
.attr('stroke-width', '0.5px') | ||
|
||
el.append('path') | ||
.datum({ | ||
type: 'MultiPoint', | ||
coordinates: this.props.coordinates | ||
}) | ||
.attr('d', path.pointRadius((d) => 8)) | ||
.attr('class', 'world-locations-base') | ||
|
||
el.append('path') | ||
.datum({ | ||
type: 'MultiPoint', | ||
coordinates: this.props.coordinates | ||
}) | ||
.attr('d', path.pointRadius((d) => 2)) | ||
.attr('class', 'world-locations-center') | ||
|
||
return el.node().toReact() | ||
} | ||
|
||
render () { | ||
return <AutoSizer>{this._renderMap}</AutoSizer> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {expect} from 'chai' | ||
import {render} from 'enzyme' | ||
import React from 'react' | ||
|
||
import WorldMap from '../../app/scripts/components/world-map' | ||
|
||
describe('WorldMap', () => { | ||
it('should render an svg', () => { | ||
const c = [[12, 14]] | ||
|
||
const el = render(<WorldMap coordinates={c}/>) | ||
expect(el.find('svg').length).to.equal(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {expect} from 'chai' | ||
import {shallow} from 'enzyme' | ||
import React from 'react' | ||
|
||
import World from '../../app/scripts/components/world' | ||
|
||
describe('World', () => { | ||
it('should have the correct defaults', () => { | ||
const el = shallow(<World/>) | ||
expect(el.find('WorldMap').length).to.equal(1) | ||
|
||
var inst = el.instance() | ||
expect(inst.props.peersCount).to.equal(0) | ||
expect(Object.keys(inst.props.locations).length) | ||
.to.equal(0) | ||
}) | ||
|
||
it('should set peersCount', () => { | ||
const el = shallow(<World peersCount={1337}/>) | ||
expect(el.find('.counter').node.props.children).to.equal(1337) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to think of more meaningful assertions to add here but drew a blank. The resulting output of
_renderMap
is basically all generated byd3
and I couldn't find anything else on the rendered output that could be used to assert correctness.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could assert that the point is drawn that you passed in