-
Notifications
You must be signed in to change notification settings - Fork 730
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
[geo] add package geo #105
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
027e4bb
[geo] add package geo
nschnierer b0e8368
[geo] Rename components folder to projections.
nschnierer a60ab11
[geo] Add geo mercator example to vx-demo
nschnierer b02925f
[geo] Pass centroid and index to parent component
nschnierer 6708e7c
[geo] Update readme and clean code.
nschnierer 0dfe7fd
[geo] Add pictures to readme.
nschnierer e9b8627
[geo] Using factories instead of singletons to map projections.
nschnierer ac12eb8
[geo] Remove unnecessary rests.
nschnierer 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
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,41 @@ | ||
import React from 'react'; | ||
import { GradientTealBlue, RadialGradient } from '@vx/gradient'; | ||
import { Mercator } from '@vx/geo'; | ||
import * as topojson from 'topojson-client'; | ||
import topology from '../../static/vx-geo/world-topo.json'; | ||
|
||
export default ({ width, height, events = false }) => { | ||
if (width < 10) return <div />; | ||
|
||
const world = topojson.feature(topology, topology.objects.units); | ||
|
||
return ( | ||
<svg width={width} height={height}> | ||
<RadialGradient | ||
id="geo_mercator_radial" | ||
from="#55bdd5" | ||
to="#4f3681" | ||
r={'80%'} | ||
/> | ||
<rect | ||
x={0} | ||
y={0} | ||
width={width} | ||
height={height} | ||
fill={`url(#geo_mercator_radial)`} | ||
rx={14} | ||
/> | ||
<Mercator | ||
data={world.features} | ||
scale={width / 630 * 100} | ||
translate={[width / 2, height / 2 + 50]} | ||
fill={() => '#8be4c5'} | ||
stroke={() => '#5fcfa7'} | ||
onClick={data => event => { | ||
if (!events) return; | ||
alert(`Clicked: ${data.properties.name} (${data.id})`); | ||
}} | ||
/> | ||
</svg> | ||
); | ||
}; |
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,57 @@ | ||
import React from 'react'; | ||
import Show from '../components/show'; | ||
import GeoMercator from '../components/tiles/geo-mercator'; | ||
|
||
export default () => { | ||
return ( | ||
<Show | ||
events | ||
component={GeoMercator} | ||
title="Geo Mercator" | ||
> | ||
{` | ||
import React from 'react'; | ||
import { GradientTealBlue, RadialGradient } from '@vx/gradient'; | ||
import { Mercator } from '@vx/geo'; | ||
import * as topojson from 'topojson-client'; | ||
import topology from '../../static/vx-geo/world-topo.json'; | ||
|
||
export default ({ width, height, events = false }) => { | ||
if (width < 10) return <div />; | ||
|
||
const world = topojson.feature(topology, topology.objects.units); | ||
|
||
return ( | ||
<svg width={width} height={height}> | ||
<RadialGradient | ||
id="geo_mercator_radial" | ||
from="#55bdd5" | ||
to="#4f3681" | ||
r={'80%'} | ||
/> | ||
<rect | ||
x={0} | ||
y={0} | ||
width={width} | ||
height={height} | ||
fill={\`url(#geo_mercator_radial)\`} | ||
rx={14} | ||
/> | ||
<Mercator | ||
data={world.features} | ||
scale={width / 630 * 100} | ||
translate={[width / 2, height / 2 + 50]} | ||
fill={() => '#8be4c5'} | ||
stroke={() => '#5fcfa7'} | ||
onClick={data => event => { | ||
if (!events) return; | ||
alert(\`Clicked: \${data.properties.name} (\${data.id})\`); | ||
}} | ||
/> | ||
</svg> | ||
); | ||
}; | ||
`} | ||
</Show> | ||
); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,19 @@ | ||
{ | ||
"presets": ["es2015", "react", "stage-0"], | ||
"plugins": [], | ||
"env": { | ||
"development": { | ||
"plugins": [ | ||
["react-transform", { | ||
"transforms": [{ | ||
"transform": "react-transform-hmr", | ||
"imports": ["react"], | ||
"locals": ["module"] | ||
}] | ||
}], | ||
"transform-runtime", | ||
"transform-decorators-legacy" | ||
] | ||
} | ||
} | ||
} |
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 @@ | ||
include node_modules/react-fatigue-dev/Makefile |
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,99 @@ | ||
# @vx/geo | ||
|
||
``` | ||
npm install --save @vx/geo | ||
``` | ||
|
||
Draw GeoJSON/TopoJSON features with different projections using d3-geo and react to render it. | ||
|
||
## `<Mercator />` | ||
The spherical Mercator projection. Many online street mapping services use a variant of the spherical Mercator projection (OpenStreetMap, Bing Maps, Google Maps, ...). | ||
|
||
### Example | ||
|
||
<img width="500" src="https://user-images.githubusercontent.com/3831579/28503643-0fb53628-700b-11e7-824c-293f5df0caf5.png" alt="vx-geo-mercator"> | ||
|
||
```js | ||
<Mercator | ||
data={myData} | ||
scale={myScale} | ||
translate={[width / 2, height / 2]} | ||
fill={(feature) => '#aaaaaa'} | ||
onClick={data => event => { | ||
alert(`Clicked!`); | ||
}} | ||
/> | ||
``` | ||
|
||
### Properties | ||
|
||
| Name | Default | Type | Description | | ||
|:--------------- |:------------------- |:-------- |:----------------------------------------------------------------------------------------------------------- | | ||
| data | | object | GeoJSON/TopoJSON features. | | ||
| projectionFunc | | function | Returns projection function. | | ||
| clipAngle | | number | Sets the projection’s clipping circle radius. | | ||
| clipExtent | | array | Sets the projection’s viewport clip extent. | | ||
| scale | | number | Sets the projection’s scale. | | ||
| translate | [480, 250] | array | Sets the projection’s translation offset. | | ||
| center | [0, 0] | array | Sets the projection’s center. | | ||
| rotate | | array | Sets the projection’s three-axis rotation. | | ||
| precision | | number | Sets the threshold for the projection’s adaptive resampling. | | ||
| fitExtent | | array | Sets the projection’s scale and translate. [extend, object] | | ||
| fitSize | | array | A convenience method for fitExtent. [size, object] | | ||
| centroid | | function | Get centroid of path. | | ||
| className | `vx-mercator` | string | The class name for the `path` element. | | ||
|
||
|
||
## `<Orthographic />` | ||
|
||
The orthographic projection. | ||
|
||
### Example | ||
|
||
<img width="200" src="https://user-images.githubusercontent.com/3831579/28503686-bfb776f8-700b-11e7-942d-8c3124f1f618.png" alt="vx-geo-mercator"> | ||
|
||
```js | ||
<Orthographic | ||
data={myData} | ||
scale={myScale} | ||
translate={[width / 2, height / 2]} | ||
fill={(feature) => '#aaaaaa'} | ||
onClick={data => event => { | ||
alert(`Clicked!`); | ||
}} | ||
/> | ||
``` | ||
|
||
### Properties | ||
Same properties as Mercator. | ||
|
||
| Name | Default | Type | Description | | ||
|:--------------- |:------------------- |:-------- |:----------------------------------------------------------------------------------------------------------- | | ||
| className | `vx-orthographic` | string | The class name for the `path` element. | | ||
|
||
## `<Albers />` | ||
|
||
The albers projection. | ||
|
||
### Example | ||
|
||
<img width="250" src="https://user-images.githubusercontent.com/3831579/28503693-d27ed9fc-700b-11e7-9e0a-e6b54a4a9b83.png" alt="vx-geo-mercator"> | ||
|
||
```js | ||
<Albers | ||
data={myData} | ||
scale={myScale} | ||
translate={[width / 2, height / 2]} | ||
fill={(feature) => '#aaaaaa'} | ||
onClick={data => event => { | ||
alert(`Clicked!`); | ||
}} | ||
/> | ||
``` | ||
|
||
### Properties | ||
Same properties as Mercator. | ||
|
||
| Name | Default | Type | Description | | ||
|:--------------- |:------------------- |:-------- |:----------------------------------------------------------------------------------------------------------- | | ||
| className | `vx-albers` | string | The class name for the `path` element. | |
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,53 @@ | ||
{ | ||
"name": "@vx/geo", | ||
"version": "0.0.132", | ||
"description": "vx geo", | ||
"main": "build/index.js", | ||
"scripts": { | ||
"build": "make build SRC=./src", | ||
"prepublish": "make build SRC=./src", | ||
"test": "jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hshoff/vx.git" | ||
}, | ||
"keywords": [ | ||
"vx", | ||
"react", | ||
"d3", | ||
"visualizations", | ||
"charts", | ||
"geo" | ||
], | ||
"author": "@nschnierer", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/hshoff/vx/issues" | ||
}, | ||
"homepage": "https://github.com/hshoff/vx#readme", | ||
"dependencies": { | ||
"@vx/group": "0.0.127", | ||
"classnames": "^2.2.5", | ||
"d3-geo": "^1.6.4", | ||
"prop-types": "^15.5.10" | ||
}, | ||
"devDependencies": { | ||
"babel-jest": "^20.0.3", | ||
"enzyme": "^2.9.1", | ||
"jest": "^20.0.4", | ||
"react": "^15.0.0 || 15.x", | ||
"react-addons-test-utils": "^15.6.0", | ||
"react-fatigue-dev": "github:tj/react-fatigue-dev", | ||
"react-test-renderer": "^15.6.1", | ||
"react-tools": "^0.13.3", | ||
"regenerator-runtime": "^0.10.5", | ||
"topojson-client": "^3.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.0.0 || 15.x" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,3 @@ | ||
export { default as Albers } from './projections/Albers'; | ||
export { default as Mercator } from './projections/Mercator'; | ||
export { default as Orthographic } from './projections/Orthographic'; |
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,6 @@ | ||
import React from 'react'; | ||
import Projection from './Projection'; | ||
|
||
export default function Albers({ ...restProps }) { | ||
return <Projection projection="albers" {...restProps} />; | ||
} |
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 @@ | ||
// TODO: Add graticule component. |
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,6 @@ | ||
import React from 'react'; | ||
import Projection from './Projection'; | ||
|
||
export default function Mercator({ ...restProps }) { | ||
return <Projection projection="mercator" {...restProps} />; | ||
} |
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,6 @@ | ||
import React from 'react'; | ||
import Projection from './Projection'; | ||
|
||
export default function Orthographic({ ...restProps }) { | ||
return <Projection projection="orthographic" {...restProps} />; | ||
} |
Oops, something went wrong.
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.
should have caught this in the first review but this is an unnecessary rest here.
let's go with:
and we'll need to update the other projections. this isn't a blocker. happy to change this after a merge.
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.
Ugh... Solved it. @hshoff