canon-atlas 0.1.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.
@@ -0,0 +1,38 @@
1
+ /* Pure label helpers, shared verbatim by the browser page (inlined as a plain
2
+ script, where the module guard below is skipped) and the gate suite (loaded
3
+ with require). Kept dependency-free and side-effect-free on purpose. */
4
+
5
+ var AtlasLabels = (function () {
6
+ /* A long title drawn in full is a banner across the sky. Cut on the last word
7
+ boundary that still leaves a readable name, hard otherwise, and never
8
+ through the middle of a surrogate pair. The panel and the search text keep
9
+ the whole title. */
10
+ function truncateLabel(s) {
11
+ if (s.length <= 46) return s;
12
+ var sp = s.lastIndexOf(" ", 44);
13
+ var cut = sp > 24 ? sp : 44;
14
+ var cc = s.charCodeAt(cut - 1);
15
+ if (cc >= 0xd800 && cc <= 0xdbff) cut--;
16
+ return s.slice(0, cut) + "…";
17
+ }
18
+
19
+ /* Label level of detail. Every node earns a zoom at which its label becomes
20
+ eligible, ranked once and never recomputed: the biggest documents (by
21
+ degree, the size the eye sees) keep their names at any distance, the rest
22
+ arrive as you close in, so the fit view reads as a sky rather than a wall
23
+ of text. Rank breaks ties, and carries corpora whose degrees are flat. */
24
+ function assignTiers(nodes) {
25
+ var real = nodes.filter(function (n) { return n.exists; })
26
+ .sort(function (a, b) { return ((b.degree || 0) - (a.degree || 0)) || (b.rank - a.rank); });
27
+ var near = 8 + Math.round(real.length * 0.2);
28
+ var mid = near + Math.round(real.length * 0.4);
29
+ nodes.forEach(function (n) { n._minK = 1.7; });
30
+ real.forEach(function (n, i) {
31
+ n._minK = i < 8 ? 0 : i < near ? 0.75 : i < mid ? 1.2 : 1.7;
32
+ });
33
+ }
34
+
35
+ return { truncateLabel: truncateLabel, assignTiers: assignTiers };
36
+ })();
37
+
38
+ if (typeof module !== "undefined") module.exports = AtlasLabels;