@figtreejs/core 0.0.1-beta.0 → 0.0.1-beta.1

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.
@@ -1,5 +1,3 @@
1
- // export function layout (tree:ImmutableTree,node?:NodeRef):Map<NodeRef,FunctionalVertex>{
2
-
3
1
  import type { ImmutableTree, NodeRef } from "../../evo";
4
2
  import { preOrderIterator, tipIterator } from "../../evo";
5
3
  import type { NodeLabelType } from "../types";
@@ -18,6 +16,13 @@ type data = {
18
16
  number: number;
19
17
  };
20
18
 
19
+ /**
20
+ * The radial (unrooted) layout
21
+ * @param tree
22
+ * @param options {spread: number} - increases this increases the space between tips
23
+ * @returns (node)=>FunctionalVertex
24
+ */
25
+
21
26
  export function radialLayout(
22
27
  tree: ImmutableTree,
23
28
  options: { spread?: number } = {},
@@ -59,21 +64,20 @@ export function radialLayout(
59
64
  dx = Math.cos(branchAngle);
60
65
  dy = Math.sin(branchAngle);
61
66
  }
67
+
68
+ const nTheta = normalizeAngle(branchAngle);
62
69
  const vertex = {
63
70
  x,
64
71
  y,
65
72
  layoutClass: layoutClass.Radial,
66
- theta: branchAngle,
73
+ theta: nTheta,
67
74
  nodeLabel: {
68
75
  dxFactor: dx,
69
76
  dyFactor: dy,
70
77
  alignmentBaseline: "middle",
71
78
  textAnchor:
72
- normalizeAngle(branchAngle) > Math.PI / 2 &&
73
- normalizeAngle(branchAngle) < (3 * Math.PI) / 2
74
- ? "end"
75
- : "start",
76
- rotation: 0, // textSafeDegrees(normalizeAngle(branchAngle))
79
+ nTheta > Math.PI / 2 && nTheta < (3 * Math.PI) / 2 ? "end" : " start",
80
+ rotation: textSafeDegrees(nTheta) * 2, // why is this magic 2 needed?
77
81
  } as NodeLabelType,
78
82
  };
79
83
 
@@ -130,9 +134,9 @@ export function textSafeDegrees(radians: number) {
130
134
  //trial and error - must be a better way
131
135
  if (d > 90 && d < 270) {
132
136
  return (d - 180) / 2;
133
- } else if (d > 0 && d < 88) {
137
+ } else if (d > 0 && d < 90) {
134
138
  return d / 2;
135
- } else if (d < 360 && d > 272) {
139
+ } else if (d < 360 && d > 270) {
136
140
  return (360 + d) / 2;
137
141
  } else {
138
142
  return d;
@@ -5,6 +5,13 @@ import type { NodeLabelType, FunctionalVertex } from "../types";
5
5
  import { layoutClass } from "../types";
6
6
  import { unNullify } from "../../utils/maybe";
7
7
 
8
+ /**
9
+ * This is the base class for layouts that place the parent nodes at the mean of their children.
10
+ * It forms the basis of the polar and rectangular layouts.
11
+ * The difference between the two is handled by the scaling functions.
12
+ * @param lc - layoutClass rectangular / polar
13
+ * @returns
14
+ */
8
15
  export function baseLayout(lc: layoutClass) {
9
16
  function layout(tree: ImmutableTree): (node: NodeRef) => FunctionalVertex {
10
17
  const map = new Map<NodeRef, FunctionalVertex>();
@@ -1,76 +1,3 @@
1
- import type { layoutOptions } from "../components/figtree/figtree-types";
2
- //TODO make tree
3
-
4
- // TODO caching
5
-
6
- //
7
- export interface Label {
8
- x: number;
9
- y: number;
10
- alignmentBaseline: string;
11
- textAnchor: string;
12
- rotation: number;
13
- alignedPos?: { x: number; y: number };
14
- }
15
- export interface Vertex {
16
- number: number;
17
- x: number;
18
- y: number;
19
- hidden: boolean | undefined;
20
- labelHidden: boolean | undefined;
21
- level: number;
22
- branch?: {
23
- d: string;
24
- label: Label;
25
- };
26
- theta?: number; //angle
27
- r?: number; //radius
28
- nodeLabel: Label;
29
- }
30
-
31
- export interface ArbitraryVertex {
32
- hidden: boolean;
33
- labelHidden: boolean;
34
- number: number;
35
- x: number;
36
- y: number;
37
- level: number;
38
- theta?: number; //angle
39
- pathPoints: { x: number; y: number }[];
40
- nodeLabel: {
41
- dx: number;
42
- dy: number;
43
- alignmentBaseline: string;
44
- textAnchor: string;
45
- rotation?: number;
46
- };
47
- }
48
-
49
- //ids match node ids
50
- export interface Vertices {
51
- type: "Rectangular" | "Polar" | "Radial";
52
- vertices: Vertex[];
53
- origin?: { x: number; y: number }; // used by polar layout to denote the position of the root (or stem) which can change
54
- theta?: [number, number]; // used by polar layout to denote the range of angles
55
- axisLength?: number; // provided by layouts that support axis
56
- }
57
-
58
- export interface ArbitraryVertices {
59
- vertices: ArbitraryVertex[];
60
- extent: { x: [number, number]; y: [number, number] };
61
- }
62
-
63
- export interface internalLayoutOptions extends layoutOptions {
64
- // all layout options plus width and height of drawable area
65
- width?: number;
66
- height?: number;
67
- }
68
-
69
- export interface CartoonData {
70
- cartooned: boolean;
71
- collapseFactor: number;
72
- }
73
-
74
1
  export const defaultInternalLayoutOptions = {
75
2
  width: 1000,
76
3
  height: 1000,