forked from uber-archive/vis-academy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Xiaoji Chen
committed
Oct 2, 2017
1 parent
98627e9
commit 6cdf890
Showing
35 changed files
with
418 additions
and
584 deletions.
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
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
45 changes: 16 additions & 29 deletions
45
src/demos/custom-layers/1-combination-layer/src/taxi-layer.js
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 |
---|---|---|
@@ -1,47 +1,34 @@ | ||
import DeckGL, {CompositeLayer, ScatterplotLayer, ArcLayer} from 'deck.gl'; | ||
|
||
const defaultProps = { | ||
radiusScale: 40, | ||
pickupColor: [255, 0, 0], | ||
dropoffColor: [0, 0, 255], | ||
getPickupLocation: d => d.pickup, | ||
getDropoffLocation: d => d.dropoff | ||
}; | ||
|
||
export default class TaxiLayer extends CompositeLayer { | ||
|
||
renderLayers() { | ||
const {id, data, pickupColor, dropoffColor, radiusScale, getPickupLocation, getDropoffLocation} = this.props; | ||
|
||
return [ | ||
new ScatterplotLayer({ | ||
id: `${id}-pickup`, | ||
data, | ||
getPosition: getPickupLocation, | ||
getColor: d => pickupColor, | ||
radiusScale | ||
id: `${this.props.id}-pickup`, | ||
data: this.props.data, | ||
getPosition: this.props.getPickupLocation, | ||
getColor: d => this.props.pickupColor, | ||
radiusScale: 40 | ||
}), | ||
new ScatterplotLayer({ | ||
id: `${id}-dropoff`, | ||
data, | ||
getPosition: getDropoffLocation, | ||
getColor: d => dropoffColor, | ||
radiusScale | ||
id: `${this.props.id}-dropoff`, | ||
data: this.props.data, | ||
getPosition: this.props.getDropoffLocation, | ||
getColor: d => this.props.dropoffColor, | ||
radiusScale: 40 | ||
}), | ||
new ArcLayer({ | ||
id: `${id}-arc`, | ||
data, | ||
id: `${this.props.id}-arc`, | ||
data: this.props.data, | ||
opacity: 0.3, | ||
getSourcePosition: getPickupLocation, | ||
getTargetPosition: getDropoffLocation, | ||
getSourceColor: d => pickupColor, | ||
getTargetColor: d => dropoffColor, | ||
getSourcePosition: this.props.getPickupLocation, | ||
getTargetPosition: this.props.getDropoffLocation, | ||
getSourceColor: d => this.props.pickupColor, | ||
getTargetColor: d => this.props.dropoffColor, | ||
strokeWidth: 2 | ||
}) | ||
]; | ||
} | ||
|
||
} | ||
|
||
TaxiLayer.layerName = 'TaxiLayer'; | ||
TaxiLayer.defaultProps = defaultProps; |
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
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,31 @@ | ||
import turf from '@turf/helpers'; | ||
import clustersKmeans from '@turf/clusters-kmeans'; | ||
|
||
/** | ||
* Clusters points | ||
* @param data {array} - source data | ||
* @param accessors {object} - key to accessor mapping. | ||
* keys will be used to add results back to the datum. | ||
* accessor should return a [longitude, latitude] pair. | ||
*/ | ||
export function clusterPoints(data, accessors) { | ||
const clusteredData = data.map(d => ({...d})); | ||
|
||
const allPoints = []; | ||
|
||
data.forEach((d, index) => { | ||
for (const key in accessors) { | ||
const p = turf.point(accessors[key](d), {index, key}); | ||
allPoints.push(p); | ||
} | ||
}); | ||
|
||
// Calculate clusters using K-means: https://en.wikipedia.org/wiki/K-means_clustering) | ||
clustersKmeans(turf.featureCollection(allPoints)).features | ||
.forEach(p => { | ||
const {index, key, centroid} = p.properties; | ||
clusteredData[index][key] = centroid; | ||
}); | ||
|
||
return clusteredData; | ||
} |
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
45 changes: 16 additions & 29 deletions
45
src/demos/custom-layers/2-adaptor-layer/src/taxi-layer.js
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 |
---|---|---|
@@ -1,47 +1,34 @@ | ||
import DeckGL, {CompositeLayer, ScatterplotLayer, ArcLayer} from 'deck.gl'; | ||
|
||
const defaultProps = { | ||
radiusScale: 40, | ||
pickupColor: [255, 0, 0], | ||
dropoffColor: [0, 0, 255], | ||
getPickupLocation: d => d.pickup, | ||
getDropoffLocation: d => d.dropoff | ||
}; | ||
|
||
export default class TaxiLayer extends CompositeLayer { | ||
|
||
renderLayers() { | ||
const {id, data, pickupColor, dropoffColor, radiusScale, getPickupLocation, getDropoffLocation} = this.props; | ||
|
||
return [ | ||
new ScatterplotLayer({ | ||
id: `${id}-pickup`, | ||
data, | ||
getPosition: getPickupLocation, | ||
getColor: d => pickupColor, | ||
radiusScale | ||
id: `${this.props.id}-pickup`, | ||
data: this.props.data, | ||
getPosition: this.props.getPickupLocation, | ||
getColor: d => this.props.pickupColor, | ||
radiusScale: 40 | ||
}), | ||
new ScatterplotLayer({ | ||
id: `${id}-dropoff`, | ||
data, | ||
getPosition: getDropoffLocation, | ||
getColor: d => dropoffColor, | ||
radiusScale | ||
id: `${this.props.id}-dropoff`, | ||
data: this.props.data, | ||
getPosition: this.props.getDropoffLocation, | ||
getColor: d => this.props.dropoffColor, | ||
radiusScale: 40 | ||
}), | ||
new ArcLayer({ | ||
id: `${id}-arc`, | ||
data, | ||
id: `${this.props.id}-arc`, | ||
data: this.props.data, | ||
opacity: 0.3, | ||
getSourcePosition: getPickupLocation, | ||
getTargetPosition: getDropoffLocation, | ||
getSourceColor: d => pickupColor, | ||
getTargetColor: d => dropoffColor, | ||
getSourcePosition: this.props.getPickupLocation, | ||
getTargetPosition: this.props.getDropoffLocation, | ||
getSourceColor: d => this.props.pickupColor, | ||
getTargetColor: d => this.props.dropoffColor, | ||
strokeWidth: 2 | ||
}) | ||
]; | ||
} | ||
|
||
} | ||
|
||
TaxiLayer.layerName = 'TaxiLayer'; | ||
TaxiLayer.defaultProps = defaultProps; |
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
Oops, something went wrong.