celestial-chart 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/LICENSE +13 -0
- package/NOTICE.md +41 -0
- package/README.md +192 -0
- package/build/celestial.cjs +15354 -0
- package/build/celestial.js +15330 -0
- package/build/celestial.min.js +7 -0
- package/build/celestial.mjs +15333 -0
- package/celestial.css +111 -0
- package/images/dtpick.png +0 -0
- package/lib/geo-zoom.js +116 -0
- package/package.json +89 -0
- package/src/add.js +46 -0
- package/src/canvas.js +269 -0
- package/src/celestial.js +1177 -0
- package/src/config.js +537 -0
- package/src/core.js +14 -0
- package/src/d3.js +28 -0
- package/src/datetimepicker.js +233 -0
- package/src/form.js +837 -0
- package/src/get.js +210 -0
- package/src/global.js +4 -0
- package/src/horizontal.js +98 -0
- package/src/index.js +8 -0
- package/src/kepler.js +481 -0
- package/src/location.js +359 -0
- package/src/moon.js +522 -0
- package/src/projection.js +205 -0
- package/src/svg.js +879 -0
- package/src/timezones.js +71 -0
- package/src/transform.js +94 -0
- package/src/util.js +275 -0
- package/types/celestial.d.ts +545 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// The projections' raw functions are resolved by name, so the two packages are
|
|
2
|
+
// imported as namespaces here — this is the only place in the library where the
|
|
3
|
+
// access is dynamic.
|
|
4
|
+
import * as d3geo from "d3-geo";
|
|
5
|
+
import * as d3geoproj from "d3-geo-projection";
|
|
6
|
+
import * as d3 from "./d3.js";
|
|
7
|
+
import { projections } from "./config.js";
|
|
8
|
+
import { Celestial } from "./core.js";
|
|
9
|
+
import { has } from "./util.js";
|
|
10
|
+
|
|
11
|
+
// d3 v3 used the form `d3.geo.<name>.raw`; in v7 that is `d3.geo<Name>Raw`, and
|
|
12
|
+
// a few projections were renamed as well. The exceptions are listed here —
|
|
13
|
+
// anything not in the table follows the naming convention.
|
|
14
|
+
var RAW_RENAMES = {
|
|
15
|
+
"naturalEarth": "geoNaturalEarth1Raw" // a v3 plugin Natural Earth I-et adott
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// A few projections' raw functions interpret their argument differently in v4.
|
|
19
|
+
// The values in config.js are calibrated for v3, so they are adapted here.
|
|
20
|
+
var ARG_ADAPT = {
|
|
21
|
+
// The first thing v4's twoPointEquidistantRaw does is `z0 *= 2`. v3 used the
|
|
22
|
+
// argument directly, so it has to be halved to get the same projection.
|
|
23
|
+
"twoPointEquidistant": function (z) { return z / 2; }
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Two projections lost their raw function in d3-geo-projection v4, although the
|
|
27
|
+
// v3 plugin had them. The formulas are taken from there unchanged — and
|
|
28
|
+
// test/projections.test.mjs measures them against the v3 output to 1e-10.
|
|
29
|
+
var LOCAL_RAW = {
|
|
30
|
+
"hatano": (function () {
|
|
31
|
+
var eps = 1e-6, halfPi = Math.PI / 2;
|
|
32
|
+
function hatano(l, f) {
|
|
33
|
+
var c = Math.sin(f) * (f < 0 ? 2.43763 : 2.67595);
|
|
34
|
+
for (var i = 0, d; i < 20; i++) {
|
|
35
|
+
f -= d = (f + Math.sin(f) - c) / (1 + Math.cos(f));
|
|
36
|
+
if (Math.abs(d) < eps) break;
|
|
37
|
+
}
|
|
38
|
+
return [0.85 * l * Math.cos(f *= 0.5), Math.sin(f) * (f < 0 ? 1.93052 : 1.75859)];
|
|
39
|
+
}
|
|
40
|
+
hatano.invert = function (x, y) {
|
|
41
|
+
var t = Math.abs(t = y * (y < 0 ? 0.5179951515653813 : 0.5686373742600607)) > 1 - eps
|
|
42
|
+
? (t > 0 ? halfPi : -halfPi) : Math.asin(t);
|
|
43
|
+
return [1.1764705882352942 * x / Math.cos(t),
|
|
44
|
+
Math.abs(t = ((t += t) + Math.sin(t)) * (y < 0 ? 0.4102345310814193 : 0.3736990601468637)) > 1 - eps
|
|
45
|
+
? (t > 0 ? halfPi : -halfPi) : Math.asin(t)];
|
|
46
|
+
};
|
|
47
|
+
return hatano;
|
|
48
|
+
})(),
|
|
49
|
+
// v4's healpixRaw RESCALED the projection (v3 did `point[0] /= 2`, v4 does
|
|
50
|
+
// `point[0] *= 4/tau` and `point[1] /= h`) — and differently for x and y, so
|
|
51
|
+
// the aspect ratio changed too. The scale/ratio values in config.js are
|
|
52
|
+
// calibrated for v3, so the v3 version is carried forward. Collignon and the
|
|
53
|
+
// cylindrical equal-area projection come from v4.
|
|
54
|
+
"healpix": function (h) {
|
|
55
|
+
var lambert = d3geoproj.geoCylindricalEqualAreaRaw(0),
|
|
56
|
+
collignon = d3geoproj.geoCollignonRaw,
|
|
57
|
+
pi = Math.PI, halfPi = pi / 2,
|
|
58
|
+
healpixParallel = 41 + 48 / 36 + 37 / 3600,
|
|
59
|
+
f0 = healpixParallel * pi / 180,
|
|
60
|
+
dx0 = 2 * pi,
|
|
61
|
+
dx1 = collignon(pi, f0)[0] - collignon(-pi, f0)[0],
|
|
62
|
+
y0 = lambert(0, f0)[1],
|
|
63
|
+
y1 = collignon(0, f0)[1],
|
|
64
|
+
dy1 = collignon(0, halfPi)[1] - y1,
|
|
65
|
+
k = 2 * pi / h;
|
|
66
|
+
|
|
67
|
+
function forward(l, f) {
|
|
68
|
+
var point, f2 = Math.abs(f);
|
|
69
|
+
if (f2 > f0) {
|
|
70
|
+
var i = Math.min(h - 1, Math.max(0, Math.floor((l + pi) / k)));
|
|
71
|
+
l += pi * (h - 1) / h - i * k;
|
|
72
|
+
point = collignon(l, f2);
|
|
73
|
+
point[0] = point[0] * dx0 / dx1 - dx0 * (h - 1) / (2 * h) + i * dx0 / h;
|
|
74
|
+
point[1] = y0 + (point[1] - y1) * 4 * dy1 / dx0;
|
|
75
|
+
if (f < 0) point[1] = -point[1];
|
|
76
|
+
} else {
|
|
77
|
+
point = lambert(l, f);
|
|
78
|
+
}
|
|
79
|
+
point[0] /= 2;
|
|
80
|
+
return point;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
forward.invert = function (x, y) {
|
|
84
|
+
x *= 2;
|
|
85
|
+
var y2 = Math.abs(y);
|
|
86
|
+
if (y2 > y0) {
|
|
87
|
+
var i = Math.min(h - 1, Math.max(0, Math.floor((x + pi) / k)));
|
|
88
|
+
x = (x + pi * (h - 1) / h - i * k) * dx1 / dx0;
|
|
89
|
+
var point = collignon.invert(x, 0.25 * (y2 - y0) * dx0 / dy1 + y1);
|
|
90
|
+
point[0] -= pi * (h - 1) / h - i * k;
|
|
91
|
+
if (y < 0) point[1] = -point[1];
|
|
92
|
+
return point;
|
|
93
|
+
}
|
|
94
|
+
return lambert.invert(x, y);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return forward;
|
|
98
|
+
},
|
|
99
|
+
"wagner7": (function () {
|
|
100
|
+
function wagner7(l, f) {
|
|
101
|
+
var s = 0.90631 * Math.sin(f),
|
|
102
|
+
c0 = Math.sqrt(1 - s * s),
|
|
103
|
+
c1 = Math.sqrt(2 / (1 + c0 * Math.cos(l /= 3)));
|
|
104
|
+
return [2.66723 * c0 * c1 * Math.sin(l), 1.24104 * s * c1];
|
|
105
|
+
}
|
|
106
|
+
wagner7.invert = function (x, y) {
|
|
107
|
+
var t1 = x / 2.66723, t2 = y / 1.24104,
|
|
108
|
+
p = Math.sqrt(t1 * t1 + t2 * t2),
|
|
109
|
+
c = 2 * Math.asin(Math.max(-1, Math.min(1, p / 2)));
|
|
110
|
+
return [3 * Math.atan2(x * Math.tan(c), 2.66723 * p),
|
|
111
|
+
p && Math.asin(Math.max(-1, Math.min(1, y * Math.sin(c) / (1.24104 * 0.90631 * p))))];
|
|
112
|
+
};
|
|
113
|
+
return wagner7;
|
|
114
|
+
})()
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Resolves a projection's raw function from its name, including the argument
|
|
118
|
+
// adaptation. Exported because the tests measure this against the pinned v3
|
|
119
|
+
// output.
|
|
120
|
+
function rawProjection(name_, arg) {
|
|
121
|
+
var raw = has(LOCAL_RAW, name_) ? LOCAL_RAW[name_]
|
|
122
|
+
: (function () {
|
|
123
|
+
var key_ = RAW_RENAMES[name_] || ("geo" + name_.charAt(0).toUpperCase() + name_.slice(1) + "Raw");
|
|
124
|
+
return d3geoproj[key_] || d3geo[key_];
|
|
125
|
+
})();
|
|
126
|
+
if (!raw || arg === undefined || arg === null) return raw;
|
|
127
|
+
return raw(has(ARG_ADAPT, name_) ? ARG_ADAPT[name_](arg) : arg);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//Flipped projection generated on the fly
|
|
131
|
+
Celestial.projection = function(projection) {
|
|
132
|
+
var p, raw, forward;
|
|
133
|
+
|
|
134
|
+
if (!has(projections, projection)) { throw new Error("Projection not supported: " + projection); }
|
|
135
|
+
p = projections[projection];
|
|
136
|
+
|
|
137
|
+
raw = rawProjection(projection, p.arg);
|
|
138
|
+
if (!raw) { throw new Error("Projection not supported: " + projection); }
|
|
139
|
+
|
|
140
|
+
// We look at the sky mirrored: from the outside in, not from the inside out.
|
|
141
|
+
// The v3 code did this by wrapping the raw function — `raw(-lambda, phi)` — and
|
|
142
|
+
// ezt tartjuk meg.
|
|
143
|
+
//
|
|
144
|
+
// v7's reflectX(true) would be the obvious choice, and for 65 projections it
|
|
145
|
+
// gives exactly the same result. But not for all of them: for `wiechel` it
|
|
146
|
+
// differs by 795 pixels, because there the sign of lambda matters INSIDE the
|
|
147
|
+
// formula too (`atan2(sin lambda * cos phi, -sin phi)`), not only in the
|
|
148
|
+
// x coordinate of the result. Wrapping is unaffected by this.
|
|
149
|
+
forward = function (l, f) { return raw(-l, f); };
|
|
150
|
+
forward.invert = function (x, y) {
|
|
151
|
+
var coord = raw.invert && raw.invert(x, y);
|
|
152
|
+
if (coord) coord[0] = -coord[0];
|
|
153
|
+
return coord;
|
|
154
|
+
};
|
|
155
|
+
return d3.geoProjection(forward);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
function projectionTween(a, b) {
|
|
160
|
+
var prj = d3.geoProjection(raw).scale(1),
|
|
161
|
+
center = prj.center,
|
|
162
|
+
translate = prj.translate,
|
|
163
|
+
α;
|
|
164
|
+
|
|
165
|
+
function raw(λ, φ) {
|
|
166
|
+
var pa = a([λ *= 180 / Math.PI, φ *= 180 / Math.PI]), pb = b([λ, φ]);
|
|
167
|
+
return [(1 - α) * pa[0] + α * pb[0], (α - 1) * pa[1] - α * pb[1]];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
prj.alpha = function(_) {
|
|
171
|
+
if (!arguments.length) return α;
|
|
172
|
+
α = +_;
|
|
173
|
+
var ca = a.center(), cb = b.center(),
|
|
174
|
+
ta = a.translate(), tb = b.translate();
|
|
175
|
+
|
|
176
|
+
center([(1 - α) * ca[0] + α * cb[0], (1 - α) * ca[1] + α * cb[1]]);
|
|
177
|
+
translate([(1 - α) * ta[0] + α * tb[0], (1 - α) * ta[1] + α * tb[1]]);
|
|
178
|
+
return prj;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
delete prj.translate;
|
|
182
|
+
delete prj.center;
|
|
183
|
+
return prj.alpha(0);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var eulerAngles = {
|
|
187
|
+
"equatorial": [0.0, 0.0, 0.0],
|
|
188
|
+
"ecliptic": [0.0, 0.0, 23.4393],
|
|
189
|
+
"galactic": [93.5949, 28.9362, -58.5988],
|
|
190
|
+
"supergalactic": [137.3100, 59.5283, 57.7303]
|
|
191
|
+
// "mars": [97.5,23.5,29]
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
var poles = {
|
|
195
|
+
"equatorial": [0.0, 90.0],
|
|
196
|
+
"ecliptic": [-90.0, 66.5607],
|
|
197
|
+
"galactic": [-167.1405, 27.1283],
|
|
198
|
+
"supergalactic": [-76.2458, 15.7089]
|
|
199
|
+
// "mars": [-42.3186, 52.8865]
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
Celestial.eulerAngles = function () { return eulerAngles; };
|
|
203
|
+
Celestial.poles = function () { return poles; };
|
|
204
|
+
|
|
205
|
+
export { eulerAngles, poles, projectionTween, rawProjection };
|