Skip to content

Commit

Permalink
Refactor examples imports
Browse files Browse the repository at this point in the history
  • Loading branch information
vasturiano committed Dec 13, 2024
1 parent 3f16c69 commit 9a558ec
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 55 deletions.
11 changes: 5 additions & 6 deletions example/airline-routes/highlight-links.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3-dsv"></script>
<script src="//unpkg.com/index-array-by"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
<script type="module">
import { csvParseRows } from 'https://esm.sh/d3-dsv';
import indexBy from 'https://esm.sh/index-array-by';

const COUNTRY = 'Portugal';
const MAP_CENTER = { lat: 37.6, lng: -16.6, altitude: 0.4 };
Expand Down Expand Up @@ -47,9 +46,9 @@

Promise.all([
fetch('https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat').then(res => res.text())
.then(d => d3.csvParseRows(d, airportParse)),
.then(d => csvParseRows(d, airportParse)),
fetch('https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat').then(res => res.text())
.then(d => d3.csvParseRows(d, routeParse))
.then(d => csvParseRows(d, routeParse))
]).then(([airports, routes]) => {

const filteredAirports = airports.filter(d => d.country === COUNTRY);
Expand Down
11 changes: 5 additions & 6 deletions example/airline-routes/us-international-outbound.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3-dsv"></script>
<script src="//unpkg.com/index-array-by"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
<script type="module">
import { csvParseRows } from 'https://esm.sh/d3-dsv';
import indexBy from 'https://esm.sh/index-array-by';

const COUNTRY = 'United States';
const OPACITY = 0.22;
Expand Down Expand Up @@ -45,9 +44,9 @@

Promise.all([
fetch('https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat').then(res => res.text())
.then(d => d3.csvParseRows(d, airportParse)),
.then(d => csvParseRows(d, airportParse)),
fetch('https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat').then(res => res.text())
.then(d => d3.csvParseRows(d, routeParse))
.then(d => csvParseRows(d, routeParse))
]).then(([airports, routes]) => {

const byIata = indexBy(airports, 'iata', false);
Expand Down
9 changes: 5 additions & 4 deletions example/choropleth-countries/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
const colorScale = d3.scaleSequentialSqrt(d3.interpolateYlOrRd);
<script type="module">
import { scaleSequentialSqrt } from 'https://esm.sh/d3-scale';
import { interpolateYlOrRd } from 'https://esm.sh/d3-scale-chromatic';

const colorScale = scaleSequentialSqrt(interpolateYlOrRd);

// GDP per capita (avoiding countries with small pop)
const getVal = feat => feat.properties.GDP_MD_EST / Math.max(1e5, feat.properties.POP_EST);
Expand Down
2 changes: 1 addition & 1 deletion example/clouds/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="globeViz"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import * as THREE from 'https://esm.sh/three';

const world = new Globe(document.getElementById('globeViz'), { animateIn: false })
.globeImageUrl('//unpkg.com/three-globe/example/img/earth-blue-marble.jpg')
Expand Down
2 changes: 1 addition & 1 deletion example/custom-globe-styling/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="globeViz"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import * as THREE from 'https://esm.sh/three';

const world = new Globe(document.getElementById('globeViz'))
.globeImageUrl('//unpkg.com/three-globe/example/img/earth-blue-marble.jpg')
Expand Down
2 changes: 1 addition & 1 deletion example/custom-layer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="globeViz"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import * as THREE from 'https://esm.sh/three';

// Gen random data
const N = 300;
Expand Down
8 changes: 4 additions & 4 deletions example/earthquakes/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
const weightColor = d3.scaleLinear()
<script type="module">
import { scaleLinear } from 'https://esm.sh/d3-scale';

const weightColor = scaleLinear()
.domain([0, 60])
.range(['lightblue', 'darkred'])
.clamp(true);
Expand Down
7 changes: 3 additions & 4 deletions example/hollow-globe/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/topojson-client"></script>

<script src="//unpkg.com/globe.gl"></script>
<!-- <script src="../../dist/globe.gl.js"></script>-->
</head>
Expand All @@ -11,7 +9,8 @@
<div id="globeViz"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import { MeshLambertMaterial, DoubleSide } from 'https://esm.sh/three';
import * as topojson from 'https://esm.sh/topojson-client';

const world = new Globe(document.getElementById('globeViz'))
.backgroundColor('rgba(0,0,0,0)')
Expand All @@ -22,7 +21,7 @@
.then(landTopo => {
world
.polygonsData(topojson.feature(landTopo, landTopo.objects.land).features)
.polygonCapMaterial(new THREE.MeshLambertMaterial({ color: 'darkslategrey', side: THREE.DoubleSide }))
.polygonCapMaterial(new MeshLambertMaterial({ color: 'darkslategrey', side: DoubleSide }))
.polygonSideColor(() => 'rgba(0,0,0,0)');
});
</script>
Expand Down
9 changes: 4 additions & 5 deletions example/moon-landing-sites/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3-array"></script>
<script src="//unpkg.com/d3-scale"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
const colorScale = d3.scaleOrdinal(['orangered', 'mediumblue', 'darkgreen', 'yellow']);
<script type="module">
import { scaleOrdinal } from 'https://esm.sh/d3-scale';

const colorScale = scaleOrdinal(['orangered', 'mediumblue', 'darkgreen', 'yellow']);

const labelsTopOrientation = new Set(['Apollo 12', 'Luna 2', 'Luna 20', 'Luna 21', 'Luna 24', 'LCROSS Probe']); // avoid label collisions

Expand Down
8 changes: 4 additions & 4 deletions example/population-heatmap/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3-dsv"></script>

<script src="//unpkg.com/globe.gl"></script>
<!-- <script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
<script type="module">
import { csvParse } from 'https://esm.sh/d3-dsv';

const world = new Globe(document.getElementById('globeViz'))
.globeImageUrl('//unpkg.com/three-globe/example/img/earth-night.jpg')
.heatmapPointLat('lat')
Expand All @@ -21,7 +21,7 @@
.enablePointerInteraction(false);

fetch('../datasets/world_population.csv').then(res => res.text())
.then(csv => d3.csvParse(csv, ({ lat, lng, pop }) => ({ lat: +lat, lng: +lng, pop: +pop })))
.then(csv => csvParse(csv, ({ lat, lng, pop }) => ({ lat: +lat, lng: +lng, pop: +pop })))
.then(data => world.heatmapsData([data]));
</script>
</body>
5 changes: 2 additions & 3 deletions example/satellites/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
}
</style>

<script src="//unpkg.com/satellite.js/dist/satellite.min.js"></script>

<script src="//unpkg.com/globe.gl"></script>
<!-- <script src="../../dist/globe.gl.js"></script>-->
</head>
Expand All @@ -26,7 +24,8 @@
<div id="time-log"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import * as satellite from 'https://esm.sh/satellite.js';
import * as THREE from 'https://esm.sh/three';

const EARTH_RADIUS_KM = 6371; // km
const SAT_SIZE = 100; // km
Expand Down
7 changes: 3 additions & 4 deletions example/solar-terminator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@

<script src="//unpkg.com/globe.gl"></script>
<!-- <script src="../../dist/globe.gl.js"></script>-->

<script src="//unpkg.com/solar-calculator"></script>
</head>

<body>
<div id="globeViz"></div>
<div id="time"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import { MeshLambertMaterial } from 'https://esm.sh/three';
import * as solar from 'https://esm.sh/solar-calculator';

const VELOCITY = 9; // minutes per frame

Expand All @@ -48,7 +47,7 @@
.tileWidth(180)
.tileHeight(180)
.tileUseGlobeProjection(false)
.tileMaterial(() => new THREE.MeshLambertMaterial({ color: '#ffff00', opacity: 0.3, transparent: true }))
.tileMaterial(() => new MeshLambertMaterial({ color: '#ffff00', opacity: 0.3, transparent: true }))
.tilesTransitionDuration(0);

// animate time of day
Expand Down
2 changes: 1 addition & 1 deletion example/tiles/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div id="globeViz"></div>

<script type="module">
import * as THREE from '//unpkg.com/three/build/three.module.js';
import * as THREE from 'https://esm.sh/three';

const TILE_MARGIN = 0.35; // degrees

Expand Down
11 changes: 6 additions & 5 deletions example/volcanoes/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3"></script>
<script src="//unpkg.com/[email protected]/dist/polished.js"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
const catColor = d3.scaleOrdinal(d3.schemeCategory10.map(col => polished.transparentize(0.2, col)));
<script type="module">
import { scaleOrdinal } from 'https://esm.sh/d3-scale';
import { schemeCategory10 } from 'https://esm.sh/d3-scale-chromatic';
import { transparentize } from 'https://esm.sh/polished';

const catColor = scaleOrdinal(schemeCategory10.map(col => transparentize(0.2, col)));

const getAlt = d => d.elevation * 5e-5;

Expand Down
13 changes: 7 additions & 6 deletions example/world-population/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<head>
<style> body { margin: 0; } </style>

<script src="//unpkg.com/d3"></script>
<script src="//unpkg.com/d3-dsv"></script>

<script src="//unpkg.com/globe.gl"></script>
<!--<script src="../../dist/globe.gl.js"></script>-->
</head>

<body>
<div id="globeViz"></div>

<script>
const weightColor = d3.scaleSequentialSqrt(d3.interpolateYlOrRd)
<script type="module">
import { csvParse } from 'https://esm.sh/d3-dsv';
import { scaleSequentialSqrt } from 'https://esm.sh/d3-scale';
import { interpolateYlOrRd } from 'https://esm.sh/d3-scale-chromatic';

const weightColor = scaleSequentialSqrt(interpolateYlOrRd)
.domain([0, 1e7]);

const world = new Globe(document.getElementById('globeViz'))
Expand All @@ -28,7 +29,7 @@
.enablePointerInteraction(false); // performance improvement

fetch('../datasets/world_population.csv').then(res => res.text())
.then(csv => d3.csvParse(csv, ({ lat, lng, pop }) => ({ lat: +lat, lng: +lng, pop: +pop })))
.then(csv => csvParse(csv, ({ lat, lng, pop }) => ({ lat: +lat, lng: +lng, pop: +pop })))
.then(data => world.hexBinPointsData(data));

// Add auto-rotation
Expand Down

0 comments on commit 9a558ec

Please sign in to comment.