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
Showing
7 changed files
with
107,539 additions
and
101,209 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# D3 World map | ||
|
||
**Install** | ||
- d3 - `https://d3js.org/d3.v7.min.js` | ||
- topojson - `https://unpkg.com/topojson@3` | ||
|
||
```js scripts=d3,topojson | ||
//hide | ||
const svg = d3.create("svg"); | ||
svg.attr("width", "100%") | ||
svg.attr("height", "500px") | ||
|
||
const projection = d3.geoNaturalEarth1(); | ||
const pathGenerator = d3.geoPath().projection(projection); | ||
|
||
svg.append('path') | ||
.style("fill", "#4242e4") | ||
.attr('d', pathGenerator({type: 'Sphere'})); | ||
|
||
|
||
d3.json('https://unpkg.com/world-atlas@1.1.4/world/110m.json') | ||
.then(data => { | ||
const countries = topojson.feature(data, data.objects.countries); | ||
svg.selectAll('path').data(countries.features) | ||
.enter().append('path') | ||
.style("fill", "lightgreen") | ||
.style("stroke", "black") | ||
.style("stroke-opacity", "0.1") | ||
.attr('d', pathGenerator); | ||
print(svg.node().outerHTML) | ||
}); | ||
``` |
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,17 @@ | ||
|
||
## Install react | ||
`npm i -S react` | ||
`npm i -S react-dom` | ||
|
||
```js | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const LikeButton = (props) => { | ||
return <h1>{props.name}</h1>; | ||
} | ||
ReactDOM.render(<LikeButton | ||
name="Hello from React!" /> | ||
, htmlEl); | ||
``` | ||
|
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,61 @@ | ||
# ThreeGlobe World map | ||
|
||
**Install** | ||
- three - `https://unpkg.com/three@0.145.0/build/three.js` | ||
- threeControls - `https://unpkg.com/three/examples/js/controls/TrackballControls.js` | ||
- threeGlobe - `https://unpkg.com/three-globe@2.24.8/dist/three-globe.min.js` | ||
|
||
```js scripts=three,threeControls,threeGlobe | ||
//hide | ||
// Gen random data | ||
const N = 300; | ||
const gData = [...Array(N).keys()].map(() => ({ | ||
lat: (Math.random() - 0.5) * 180, | ||
lng: (Math.random() - 0.5) * 360, | ||
size: Math.random() / 3, | ||
color: ['red', 'white', 'blue', 'green'][Math.round(Math.random() * 3)] | ||
})); | ||
|
||
const Globe = new ThreeGlobe() | ||
.globeImageUrl('https://unpkg.com/three-globe/example/img/earth-dark.jpg') | ||
.bumpImageUrl('https://unpkg.com/three-globe/example/img/earth-topology.png') | ||
.pointsData(gData) | ||
.pointAltitude('size') | ||
.pointColor('color'); | ||
|
||
setTimeout(() => { | ||
gData.forEach(d => d.size = Math.random()); | ||
Globe.pointsData(gData); | ||
}, 4000); | ||
|
||
// Setup renderer | ||
const renderer = new THREE.WebGLRenderer(); | ||
renderer.setSize(500, 500); | ||
htmlEl.appendChild(renderer.domElement); | ||
|
||
// Setup scene | ||
const scene = new THREE.Scene(); | ||
scene.add(Globe); | ||
scene.add(new THREE.AmbientLight(0xbbbbbb)); | ||
scene.add(new THREE.DirectionalLight(0xffffff, 0.6)); | ||
|
||
// Setup camera | ||
const camera = new THREE.PerspectiveCamera(); | ||
camera.aspect = 500/500; | ||
camera.updateProjectionMatrix(); | ||
camera.position.z = 500; | ||
|
||
// Add camera controls | ||
const tbControls = new THREE.TrackballControls(camera, renderer.domElement); | ||
tbControls.minDistance = 101; | ||
tbControls.rotateSpeed = 5; | ||
tbControls.zoomSpeed = 0.8; | ||
|
||
// Kick-off renderer | ||
(function animate() { // IIFE | ||
// Frame cycle | ||
tbControls.update(); | ||
renderer.render(scene, camera); | ||
requestAnimationFrame(animate); | ||
})(); | ||
``` |
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.