Skip to content

Commit efd47e1

Browse files
committed
Add daylight toggle to timezones to show day/night across world
1 parent c2d0673 commit efd47e1

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

packages/layerchart/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"prismjs": "^1.29.0",
5959
"rehype-slug": "^6.0.0",
6060
"shapefile": "^0.6.6",
61+
"solar-calculator": "^0.3.0",
6162
"svelte": "^4.2.8",
6263
"svelte-check": "^3.6.3",
6364
"svelte-json-tree": "^2.2.0",

packages/layerchart/src/routes/docs/examples/Timezones/+page.svelte

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
geoEquirectangular,
77
geoMercator,
88
geoNaturalEarth1,
9-
geoOrthographic,
109
} from 'd3-geo';
1110
import { extent } from 'd3-array';
1211
import { scaleSequential } from 'd3-scale';
1312
import { interpolateRdBu } from 'd3-scale-chromatic';
1413
import { feature } from 'topojson-client';
14+
import { century, equationOfTime, declination } from 'solar-calculator';
1515
1616
import { Field, SelectField, Switch, timerStore } from 'svelte-ux';
1717
@@ -24,10 +24,13 @@
2424
import TooltipItem from '$lib/components/TooltipItem.svelte';
2525
import ClipPath from '$lib/components/ClipPath.svelte';
2626
import Graticule from '$lib/components/Graticule.svelte';
27+
import GeoCircle from '$lib/components/GeoCircle.svelte';
28+
import { antipode } from '$lib/utils/geo.js';
2729
2830
export let data;
2931
3032
let enableClip = false;
33+
let showDaylight = false;
3134
3235
let projection = geoNaturalEarth1;
3336
const projections = [
@@ -69,9 +72,15 @@
6972
7073
return result;
7174
}
75+
76+
const now = new Date();
77+
const day = new Date(+now).setUTCHours(0, 0, 0, 0);
78+
const t = century(now);
79+
const longitude = ((day - now) / 864e5) * 360 - 180;
80+
const sun = [longitude - equationOfTime(t) / 4, declination(t)];
7281
</script>
7382

74-
<div class="grid grid-cols-[1fr,auto,2fr] gap-2 my-2">
83+
<div class="grid grid-cols-[1fr,auto,auto,2fr] gap-2 my-2">
7584
<SelectField
7685
label="Projections"
7786
options={projections}
@@ -80,9 +89,14 @@
8089
toggleIcon={null}
8190
stepper
8291
/>
92+
8393
<Field label="Clip" let:id>
8494
<Switch bind:checked={enableClip} {id} size="md" />
8595
</Field>
96+
97+
<Field label="Daylight" let:id>
98+
<Switch bind:checked={showDaylight} {id} size="md" />
99+
</Field>
86100
</div>
87101

88102
<h1>Examples</h1>
@@ -101,7 +115,7 @@
101115
let:tooltip
102116
>
103117
<Svg>
104-
<GeoPath geojson={{ type: 'Sphere' }} class="_fill-surface-200 stroke-surface-content/30" />
118+
<GeoPath geojson={{ type: 'Sphere' }} class="stroke-surface-content/30" />
105119
<Graticule class="stroke-surface-content/20" />
106120

107121
<GeoPath {geojson} id="clip" />
@@ -122,6 +136,10 @@
122136
class="stroke-gray-900/10 fill-gray-900/20 pointer-events-none"
123137
/>
124138
{/each}
139+
140+
{#if showDaylight}
141+
<GeoCircle center={antipode(sun)} class="stroke-none fill-black/50 pointer-events-none" />
142+
{/if}
125143
</Svg>
126144

127145
<Tooltip let:data>

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)