chrono-phylo-tree 1.2.2 → 1.3.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.
- package/README.md +172 -81
- package/dist/chrono-phylo-tree.es.js +458 -419
- package/dist/chrono-phylo-tree.umd.js +10 -10
- package/dist/classes/Species.d.ts +25 -5
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,10 @@ You can test and explore the functionality of the chrono-phylo-tree library by v
|
|
|
12
12
|
|
|
13
13
|
### Updates
|
|
14
14
|
|
|
15
|
+
**1.3.0**
|
|
16
|
+
|
|
17
|
+
- Inputs changed to interface type
|
|
18
|
+
|
|
15
19
|
**1.0.12**
|
|
16
20
|
|
|
17
21
|
- New functions for Species class.
|
|
@@ -91,17 +95,61 @@ import { Species, PhTree } from "chrono-phylo-tree";
|
|
|
91
95
|
You can create species and construct a phylogenetic tree as follows:
|
|
92
96
|
|
|
93
97
|
```typescript
|
|
94
|
-
const root = new Species(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
const root = new Species({
|
|
99
|
+
name: "Hominoidea",
|
|
100
|
+
apparition: -25e6,
|
|
101
|
+
duration: 6e6,
|
|
102
|
+
});
|
|
103
|
+
root.addDescendant({
|
|
104
|
+
name: "Hilobates",
|
|
105
|
+
afterApparition: 6e6,
|
|
106
|
+
duration: 19e6,
|
|
107
|
+
});
|
|
108
|
+
const child0 = root.addDescendant({
|
|
109
|
+
name: "Hominidae",
|
|
110
|
+
afterApparition: 6e6,
|
|
111
|
+
duration: 6e6,
|
|
112
|
+
});
|
|
113
|
+
child0.addDescendant({
|
|
114
|
+
name: "Pongo",
|
|
115
|
+
afterApparition: 6e6,
|
|
116
|
+
duration: 13e6,
|
|
117
|
+
});
|
|
118
|
+
const child1 = child0.addDescendant({
|
|
119
|
+
name: "Homininae",
|
|
120
|
+
afterApparition: 6e6,
|
|
121
|
+
duration: 5e6,
|
|
122
|
+
});
|
|
123
|
+
child1.addDescendant({
|
|
124
|
+
name: "Gorilla",
|
|
125
|
+
afterApparition: 5e6,
|
|
126
|
+
duration: 8e6,
|
|
127
|
+
});
|
|
128
|
+
const child2 = child1.addDescendant({
|
|
129
|
+
name: "Hominini",
|
|
130
|
+
afterApparition: 5e6,
|
|
131
|
+
duration: 2e6,
|
|
132
|
+
});
|
|
133
|
+
const child3 = child2.addDescendant({
|
|
134
|
+
name: "Pan",
|
|
135
|
+
afterApparition: 2e6,
|
|
136
|
+
duration: 3e6,
|
|
137
|
+
});
|
|
138
|
+
child3.addDescendant({
|
|
139
|
+
name: "Pan Troglodytes",
|
|
140
|
+
afterApparition: 3e6,
|
|
141
|
+
duration: 3e6,
|
|
142
|
+
});
|
|
143
|
+
child3.addDescendant({
|
|
144
|
+
name: "Pan Paniscus",
|
|
145
|
+
afterApparition: 3e6,
|
|
146
|
+
duration: 3e6,
|
|
147
|
+
});
|
|
148
|
+
child2.addDescendant({
|
|
149
|
+
name: "Homo",
|
|
150
|
+
afterApparition: 2e6,
|
|
151
|
+
duration: 6e6,
|
|
152
|
+
});
|
|
105
153
|
```
|
|
106
154
|
|
|
107
155
|
## Rendering the Tree in a React Component
|
|
@@ -112,62 +160,76 @@ If using chrono-phylo-tree in a React project, you can render the tree as follow
|
|
|
112
160
|
import React from "react";
|
|
113
161
|
import { Species, PhTree } from "chrono-phylo-tree";
|
|
114
162
|
|
|
115
|
-
const root = new Species(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
6e6,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
child2.addDescendant(
|
|
156
|
-
"
|
|
157
|
-
2e6,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
const root = new Species({
|
|
164
|
+
name: "Hominoidea",
|
|
165
|
+
apparition: -25e6,
|
|
166
|
+
duration: 6e6,
|
|
167
|
+
});
|
|
168
|
+
root.addDescendant({
|
|
169
|
+
name: "Hilobates",
|
|
170
|
+
afterApparition: 6e6,
|
|
171
|
+
duration: 19e6,
|
|
172
|
+
image:
|
|
173
|
+
"https://upload.wikimedia.org/wikipedia/commons/4/40/Hylobaes_lar_Canarias.jpg",
|
|
174
|
+
});
|
|
175
|
+
const child0 = root.addDescendant({
|
|
176
|
+
name: "Hominidae",
|
|
177
|
+
afterApparition: 6e6,
|
|
178
|
+
duration: 6e6,
|
|
179
|
+
});
|
|
180
|
+
child0.addDescendant({
|
|
181
|
+
name: "Pongo",
|
|
182
|
+
afterApparition: 6e6,
|
|
183
|
+
duration: 13e6,
|
|
184
|
+
image:
|
|
185
|
+
"https://upload.wikimedia.org/wikipedia/commons/6/65/Pongo_tapanuliensis.jpg",
|
|
186
|
+
});
|
|
187
|
+
const child1 = child0.addDescendant({
|
|
188
|
+
name: "Homininae",
|
|
189
|
+
afterApparition: 6e6,
|
|
190
|
+
duration: 5e6,
|
|
191
|
+
});
|
|
192
|
+
child1.addDescendant({
|
|
193
|
+
name: "Gorilla",
|
|
194
|
+
afterApparition: 5e6,
|
|
195
|
+
duration: 8e6,
|
|
196
|
+
image: "https://gorillas-world.com/wp-content/uploads/anatomia.jpg",
|
|
197
|
+
});
|
|
198
|
+
const child2 = child1.addDescendant({
|
|
199
|
+
name: "Hominini",
|
|
200
|
+
afterApparition: 5e6,
|
|
201
|
+
duration: 2e6,
|
|
202
|
+
});
|
|
203
|
+
const child3 = child2.addDescendant({
|
|
204
|
+
name: "Pan",
|
|
205
|
+
afterApparition: 2e6,
|
|
206
|
+
duration: 3e6,
|
|
207
|
+
});
|
|
208
|
+
child3.addDescendant({
|
|
209
|
+
name: "Pan Troglodytes",
|
|
210
|
+
afterApparition: 3e6,
|
|
211
|
+
duration: 3e6,
|
|
212
|
+
image:
|
|
213
|
+
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR-v4-d4R9AUgsHdG42VPYuYj_d4OMRHKasUQ&s",
|
|
214
|
+
});
|
|
215
|
+
child3.addDescendant({
|
|
216
|
+
name: "Pan Paniscus",
|
|
217
|
+
afterApparition: 3e6,
|
|
218
|
+
duration: 3e6,
|
|
219
|
+
image:
|
|
220
|
+
"https://upload.wikimedia.org/wikipedia/commons/e/e2/Apeldoorn_Apenheul_zoo_Bonobo.jpg",
|
|
221
|
+
});
|
|
222
|
+
child2.addDescendant({
|
|
223
|
+
name: "Homo",
|
|
224
|
+
afterApparition: 2e6,
|
|
225
|
+
duration: 6e6,
|
|
226
|
+
image:
|
|
227
|
+
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7XK_e3HG0jhOticytH1Dn3tzBEZyRyWc5Mg&s",
|
|
228
|
+
});
|
|
162
229
|
|
|
163
230
|
const App = () => {
|
|
164
231
|
return (
|
|
165
|
-
<PhTree
|
|
166
|
-
commonAncestor={ancestor}
|
|
167
|
-
width={1000}
|
|
168
|
-
height={500}
|
|
169
|
-
stroke="black"
|
|
170
|
-
/>
|
|
232
|
+
<PhTree commonAncestor={root} width={1000} height={500} stroke="black" />
|
|
171
233
|
);
|
|
172
234
|
};
|
|
173
235
|
|
|
@@ -178,7 +240,8 @@ export default App;
|
|
|
178
240
|
|
|
179
241
|
```typescript
|
|
180
242
|
interface SpeciesJSON {
|
|
181
|
-
|
|
243
|
+
id?: string | number;
|
|
244
|
+
name?: string;
|
|
182
245
|
apparition?: number;
|
|
183
246
|
duration?: number;
|
|
184
247
|
description?: string;
|
|
@@ -208,19 +271,32 @@ The `Species` class represents a species in a phylogenetic tree, with properties
|
|
|
208
271
|
#### Constructor
|
|
209
272
|
|
|
210
273
|
```typescript
|
|
211
|
-
|
|
212
|
-
|
|
274
|
+
interface ConstructorProps {
|
|
275
|
+
id?: string | number;
|
|
276
|
+
name?: string;
|
|
277
|
+
apparition?: number;
|
|
278
|
+
duration?: number;
|
|
279
|
+
ancestor?: Species;
|
|
280
|
+
descendants?: Species[];
|
|
281
|
+
description?: string;
|
|
282
|
+
image?: string;
|
|
283
|
+
}
|
|
284
|
+
...
|
|
285
|
+
constructor({
|
|
286
|
+
id,
|
|
287
|
+
name = "",
|
|
213
288
|
apparition = 0,
|
|
214
289
|
duration = 0,
|
|
215
|
-
ancestor
|
|
216
|
-
descendants
|
|
217
|
-
description
|
|
218
|
-
image
|
|
219
|
-
)
|
|
290
|
+
ancestor,
|
|
291
|
+
descendants = [],
|
|
292
|
+
description,
|
|
293
|
+
image
|
|
294
|
+
}: ConstructorProps)
|
|
220
295
|
```
|
|
221
296
|
|
|
222
297
|
Initializes a new instance of the `Species` class.
|
|
223
298
|
|
|
299
|
+
- **id**: Id of the species.
|
|
224
300
|
- **name**: The name of the species.
|
|
225
301
|
- **apparition**: The time at which the species appears.
|
|
226
302
|
- **duration**: The duration for which the species exists.
|
|
@@ -288,18 +364,25 @@ Links the current species to multiple descendants. The method attempts to link e
|
|
|
288
364
|
#### addDescendant
|
|
289
365
|
|
|
290
366
|
```typescript
|
|
291
|
-
|
|
367
|
+
interface DescendantProps extends Omit<Omit<Omit<ConstructorProps, "apparition">, "ancestor">, "descendants"> {
|
|
368
|
+
afterApparition?: number;
|
|
369
|
+
copy?: boolean;
|
|
370
|
+
}
|
|
371
|
+
...
|
|
372
|
+
addDescendant({
|
|
373
|
+
id,
|
|
292
374
|
name = '',
|
|
293
375
|
afterApparition = 0,
|
|
294
376
|
duration = 0,
|
|
295
|
-
description
|
|
296
|
-
image
|
|
377
|
+
description,
|
|
378
|
+
image,
|
|
297
379
|
copy = false
|
|
298
|
-
): Species
|
|
380
|
+
}: DescendantProps): Species
|
|
299
381
|
```
|
|
300
382
|
|
|
301
383
|
Adds a descendant to the current species.
|
|
302
384
|
|
|
385
|
+
- **id**: Id of the descendant.
|
|
303
386
|
- **name**: The name of the descendant.
|
|
304
387
|
- **afterApparition**: The time after the ancestor's appearance when the descendant appears.
|
|
305
388
|
- **duration**: The duration for which the descendant exists.
|
|
@@ -319,19 +402,26 @@ Removes a descendant from the current species.
|
|
|
319
402
|
#### addAncestor
|
|
320
403
|
|
|
321
404
|
```typescript
|
|
322
|
-
|
|
405
|
+
interface AncestorProps extends Omit<DescendantProps, "afterApparition"> {
|
|
406
|
+
previousApparition?: number;
|
|
407
|
+
display?: boolean;
|
|
408
|
+
}
|
|
409
|
+
...
|
|
410
|
+
addAncestor({
|
|
411
|
+
id,
|
|
323
412
|
name = '',
|
|
324
413
|
previousApparition = 0,
|
|
325
414
|
duration = 0,
|
|
326
|
-
description
|
|
327
|
-
image
|
|
415
|
+
description,
|
|
416
|
+
image,
|
|
328
417
|
display = true,
|
|
329
418
|
copy = false
|
|
330
|
-
): Species
|
|
419
|
+
}: AncestorProps): Species
|
|
331
420
|
```
|
|
332
421
|
|
|
333
422
|
Adds an ancestor to the current species.
|
|
334
423
|
|
|
424
|
+
- **id**: Id of the ancestor.
|
|
335
425
|
- **name**: The name of the ancestor.
|
|
336
426
|
- **previousApparition**: The time before the current species' appearance when the ancestor appears.
|
|
337
427
|
- **duration**: The duration for which the ancestor exists.
|
|
@@ -450,7 +540,8 @@ static fromJSON(json: SpeciesJSON, ancestor?: Species): Species
|
|
|
450
540
|
Creates a species instance from a JSON object.
|
|
451
541
|
|
|
452
542
|
- **json**: The JSON object representing the species. The structure of the JSON object should follow the format below:
|
|
453
|
-
- **
|
|
543
|
+
- **id**: (string, number, optional) The id of the species.
|
|
544
|
+
- **name**: (string, optional) The name of the species.
|
|
454
545
|
- **apparition**: (number, optional) The time when the species first appeared. This is only required if the species has no ancestor.
|
|
455
546
|
- **afterApparition**: (number, optional) The time after the ancestor's apparition when this species appeared. This is required if the species has an ancestor.
|
|
456
547
|
- **duration**: (number) The duration for which the species existed.
|