chrono-phylo-tree 1.0.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.
Files changed (2) hide show
  1. package/README.md +659 -0
  2. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,659 @@
1
+ # chrono-phylo-tree Documentation
2
+
3
+ ## Overview
4
+
5
+ The **chrono-phylo-tree** is a JavaScript/TypeScript library designed to visualize and manage phylogenetic trees. Phylogenetic trees are diagrams that represent evolutionary relationships among species, where each node represents a species, and branches represent the evolutionary lineage, it can also be used in speculative evolution projects.
6
+
7
+ This documentation provides a detailed explanation of the core components and classes used in the application, including the `Species` class, which represents individual species in the tree, and the `PhTree` and `Menu` components, which handle the visualization and user interaction with the tree.
8
+
9
+ ### Key Features
10
+
11
+ - **Species Management**: The `Species` class allows you to define species, manage their ancestors and descendants, and calculate properties such as extinction time and duration.
12
+ - **Interactive Tree Visualization**: The `PhTree` component renders the phylogenetic tree as an SVG, allowing users to interact with the tree by toggling the visibility of species and accessing detailed information.
13
+ - **User-Friendly Interface**: The `Menu` component provides a modal interface for editing species attributes, adding new descendants or ancestors, and deleting species.
14
+ - **Localization Support**: The application supports multiple languages, making it accessible to a global audience.
15
+
16
+ ### How It Works
17
+
18
+ 1. **Species Representation**: Each species is represented by an instance of the `Species` class, which stores its name, appearance time, duration, ancestor, descendants, and other attributes.
19
+ 2. **Tree Rendering**: The `PhTree` component takes a common ancestor species as input and recursively renders the tree structure using SVG elements. It supports dynamic resizing, padding, and customizable stroke colors.
20
+ 3. **User Interaction**: Users can interact with the tree by clicking on species nodes to open the `Menu` component, where they can edit species data, add new species, or delete existing ones.
21
+ 4. **Data Persistence**: The application allows users to save the phylogenetic tree as a JSON file, ensuring that the data can be easily stored and reloaded.
22
+
23
+ This documentation will guide you through the properties, methods, and usage of each component, helping you understand how to build, modify, and interact with phylogenetic trees using this application.
24
+
25
+ ## Installation
26
+
27
+ You can install chrono-phylo-tree via npm:
28
+
29
+ ```bash
30
+ npm install chrono-phylo-tree
31
+ ```
32
+
33
+ or using yarn:
34
+
35
+ ```bash
36
+ npm install chrono-phylo-tree
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### Importing the Library
42
+
43
+ In a JavaScript or TypeScript project, import the necessary modules:
44
+
45
+ ```typescript
46
+ import { Species, PhTree } from "chrono-phylo-tree";
47
+ ```
48
+
49
+ ## Creating a Phylogenetic Tree
50
+
51
+ You can create species and construct a phylogenetic tree as follows:
52
+
53
+ ```typescript
54
+ const root = new Species("Hominoidea", -25e6, 6e6);
55
+ root.addDescendant("Hilobates", 6e6, 19e6);
56
+ const child0 = root.addDescendant("Hominidae", 6e6, 6e6);
57
+ child0.addDescendant("Pongo", 6e6, 13e6);
58
+ const child1 = child0.addDescendant("Homininae", 6e6, 5e6);
59
+ child1.addDescendant("Gorilla", 5e6, 8e6);
60
+ const child2 = child1.addDescendant("Hominini", 5e6, 2e6);
61
+ const child3 = child2.addDescendant("Pan", 2e6, 3e6);
62
+ child3.addDescendant("Pan Troglodytes", 3e6, 3e6);
63
+ child3.addDescendant("Pan Paniscus", 3e6, 3e6);
64
+ child2.addDescendant("Homo", 2e6, 6e6);
65
+ ```
66
+
67
+ ## Rendering the Tree in a React Component
68
+
69
+ If using chrono-phylo-tree in a React project, you can render the tree as follows:
70
+
71
+ ```typescript
72
+ import React from "react";
73
+ import { Species, PhTree } from "chrono-phylo-tree";
74
+
75
+ const root = new Species("Hominoidea", -25e6, 6e6);
76
+ root.addDescendant("Hilobates", 6e6, 19e6);
77
+ const child0 = root.addDescendant("Hominidae", 6e6, 6e6);
78
+ child0.addDescendant("Pongo", 6e6, 13e6);
79
+ const child1 = child0.addDescendant("Homininae", 6e6, 5e6);
80
+ child1.addDescendant("Gorilla", 5e6, 8e6);
81
+ const child2 = child1.addDescendant("Hominini", 5e6, 2e6);
82
+ const child3 = child2.addDescendant("Pan", 2e6, 3e6);
83
+ child3.addDescendant("Pan Troglodytes", 3e6, 3e6);
84
+ child3.addDescendant("Pan Paniscus", 3e6, 3e6);
85
+ child2.addDescendant("Homo", 2e6, 6e6);
86
+
87
+ const App = () => {
88
+ return (
89
+ <PhTree
90
+ commonAncestor={ancestor}
91
+ width={1000}
92
+ height={500}
93
+ stroke="black"
94
+ />
95
+ );
96
+ };
97
+
98
+ export default App;
99
+ ```
100
+
101
+ ## Species Class
102
+
103
+ The `Species` class represents a species in a phylogenetic tree, with properties and methods to manage its ancestors, descendants, and other attributes.
104
+
105
+ ### Properties
106
+
107
+ - **name**: `string`The name of the species.
108
+ - **apparition**: `number`The time at which the species appears in the timeline.
109
+ - **duration**: `number`The duration for which the species exists.
110
+ - **ancestor**: `Species | undefined`The ancestor species from which this species descends. It is `undefined` if this species has no ancestor.
111
+ - **descendants**: `Species[]`An array of species that descend from this species.
112
+ - **description**: `string | undefined`An optional description of the species.
113
+ - **display**: `boolean`
114
+ A flag indicating whether the species should be displayed. Default is `true`
115
+
116
+ ### Methods
117
+
118
+ #### Constructor
119
+
120
+ ```typescript
121
+ constructor(
122
+ name = '',
123
+ apparition = 0,
124
+ duration = 0,
125
+ ancestor?: Species,
126
+ descendants: Species[] = [],
127
+ description: string | undefined = undefined
128
+ )
129
+ ```
130
+
131
+ Initializes a new instance of the `Species` class.
132
+
133
+ - **name**: The name of the species.
134
+ - **apparition**: The time at which the species appears.
135
+ - **duration**: The duration for which the species exists.
136
+ - **ancestor**: The ancestor of the species.
137
+ - **descendants**: An array of descendant species.
138
+ - **description**: An optional description of the species.
139
+
140
+ #### copy
141
+
142
+ ```typescript
143
+ copy(): Species
144
+ ```
145
+
146
+ Creates a deep copy of the current species and its descendants.
147
+
148
+ #### addDescendant
149
+
150
+ ```typescript
151
+ addDescendant(
152
+ name = '',
153
+ afterApparition = 0,
154
+ duration = 0,
155
+ description: string | undefined = undefined,
156
+ copy = false
157
+ ): Species
158
+ ```
159
+
160
+ Adds a descendant to the current species.
161
+
162
+ - **name**: The name of the descendant.
163
+ - **afterApparition**: The time after the ancestor's appearance when the descendant appears.
164
+ - **duration**: The duration for which the descendant exists.
165
+ - **description**: An optional description of the descendant.
166
+ - **copy**: If `true`, the current species is copied before adding the descendant.
167
+
168
+ #### removeDescendant
169
+
170
+ ```typescript
171
+ removeDescendant(desc: Species): void
172
+ ```
173
+
174
+ Removes a descendant from the current species.
175
+
176
+ - **desc**: The descendant species to remove.
177
+
178
+ #### addAncestor
179
+
180
+ ```typescript
181
+ addAncestor(
182
+ name = '',
183
+ previousApparition = 0,
184
+ duration = 0,
185
+ description: string | undefined = undefined,
186
+ display = true,
187
+ copy = false
188
+ ): Species
189
+ ```
190
+
191
+ Adds an ancestor to the current species.
192
+
193
+ - **name**: The name of the ancestor.
194
+ - **previousApparition**: The time before the current species' appearance when the ancestor appears.
195
+ - **duration**: The duration for which the ancestor exists.
196
+ - **description**: An optional description of the ancestor.
197
+ - **display**: A flag indicating whether the ancestor should be displayed.
198
+ - **copy**: If `true`, the current species is copied before adding the ancestor.
199
+
200
+ #### extinction
201
+
202
+ ```typescript
203
+ extinction(): number
204
+ ```
205
+
206
+ Returns the time at which the species goes extinct.
207
+
208
+ #### absoluteExtinction
209
+
210
+ ```typescript
211
+ absoluteExtinction(): number
212
+ ```
213
+
214
+ Returns the time at which the species goes extinct, considering its descendants.
215
+
216
+ #### absoluteDuration
217
+
218
+ ```typescript
219
+ absoluteDuration(): number
220
+ ```
221
+
222
+ Returns the duration of the species, considering its descendants.
223
+
224
+ #### firstAncestor
225
+
226
+ ```typescript
227
+ firstAncestor(includeNotDisplay = false): Species
228
+ ```
229
+
230
+ Returns the first ancestor of the species.
231
+
232
+ - **includeNotDisplay**: If `true`, includes ancestors that are not displayed.
233
+
234
+ #### cousinsExtinction
235
+
236
+ ```typescript
237
+ cousinsExtinction(): number
238
+ ```
239
+
240
+ Returns the extinction time of the species' cousins.
241
+
242
+ #### allDescendants
243
+
244
+ ```typescript
245
+ allDescendants(): Species[]
246
+ ```
247
+
248
+ Returns an array of all descendants of the species, sorted by appearance time.
249
+
250
+ #### toJSON
251
+
252
+ ```typescript
253
+ toJSON(): any
254
+ ```
255
+
256
+ Converts the species and its descendants to a JSON object.
257
+
258
+ #### saveJSON
259
+
260
+ ```typescript
261
+ saveJSON(filename: string | undefined = undefined): Promise<void>
262
+ ```
263
+
264
+ Saves the species and its descendants as a JSON file.
265
+
266
+ - **filename**: The name of the file to save. If not provided, the species name is used.
267
+
268
+ #### fromJSON
269
+
270
+ ```typescript
271
+ static fromJSON(json: any, ancestor?: Species): Species
272
+ ```
273
+
274
+ Creates a species instance from a JSON object.
275
+
276
+ - **json**: The JSON object representing the species. The structure of the JSON object should follow the format below:
277
+ - **name**: (string) The name of the species.
278
+ - **apparition**: (number, optional) The time when the species first appeared. This is only required if the species has no ancestor.
279
+ - **afterApparition**: (number, optional) The time after the ancestor's apparition when this species appeared. This is required if the species has an ancestor.
280
+ - **duration**: (number) The duration for which the species existed.
281
+ - **description**: (string, optional) A description of the species.
282
+ - **descendants**: (array, optional) An array of JSON objects representing the descendant species. Each descendant follows the same structure as described here.
283
+ - **ancestor**: (Species, optional) The ancestor species, if any. This is used to calculate the apparition time of the current species based on the ancestor's apparition time.
284
+
285
+ ### Example JSON Structure
286
+
287
+ Here is an example of a JSON object representing a species and its descendants:
288
+
289
+ ```json
290
+ {
291
+ "name": "Hominoidea",
292
+ "apparition": -25000000,
293
+ "duration": 6000000,
294
+ "descendants": [
295
+ {
296
+ "name": "Hilobates",
297
+ "afterApparition": 6000000,
298
+ "duration": 19000000
299
+ },
300
+ {
301
+ "name": "Hominidae",
302
+ "afterApparition": 6000000,
303
+ "duration": 6000000,
304
+ "descendants": [
305
+ {
306
+ "name": "Pongo",
307
+ "afterApparition": 6000000,
308
+ "duration": 13000000
309
+ },
310
+ {
311
+ "name": "Homininae",
312
+ "afterApparition": 6000000,
313
+ "duration": 5000000,
314
+ "descendants": [
315
+ {
316
+ "name": "Gorilla",
317
+ "afterApparition": 5000000,
318
+ "duration": 8000000
319
+ },
320
+ {
321
+ "name": "Hominini",
322
+ "afterApparition": 5000000,
323
+ "duration": 2000000,
324
+ "descendants": [
325
+ {
326
+ "name": "Pan",
327
+ "afterApparition": 2000000,
328
+ "duration": 3000000,
329
+ "descendants": [
330
+ {
331
+ "name": "Pan Troglodytes",
332
+ "afterApparition": 3000000,
333
+ "duration": 3000000
334
+ },
335
+ {
336
+ "name": "Pan Paniscus",
337
+ "afterApparition": 3000000,
338
+ "duration": 3000000
339
+ }
340
+ ]
341
+ },
342
+ {
343
+ "name": "Homo",
344
+ "afterApparition": 2000000,
345
+ "duration": 6000000
346
+ }
347
+ ]
348
+ }
349
+ ]
350
+ }
351
+ ]
352
+ }
353
+ ]
354
+ }
355
+ ```
356
+
357
+ In this example:
358
+
359
+ - The root species is "Hominoidea", which appeared 25 million years ago and existed for 6 million years.
360
+
361
+ - It has two descendants: "Hilobates" and "Hominidae".
362
+
363
+ - "Hominidae" further has descendants like "Pongo" and "Homininae", and so on.
364
+
365
+ This structure allows for a hierarchical representation of species and their evolutionary relationships.
366
+
367
+ ## PhTree Component
368
+
369
+ The `PhTree` component is a React-based visualization tool designed to display phylogenetic trees. It allows users to interact with the tree, toggle the visibility of descendants, and access detailed information about each species through a menu.
370
+
371
+ ### Features
372
+
373
+ - **Interactive Tree Visualization**: Displays a phylogenetic tree with interactive nodes representing species.
374
+ - **Toggle Descendants**: Users can show or hide the descendants of any species in the tree.
375
+ - **Species Information**: Clicking on a species node opens a menu with detailed information and options to modify the species.
376
+ - **Customizable Appearance**: Supports customization of tree dimensions, padding, stroke color, and number formatting.
377
+ - **Time-Based Filtering**: Optionally filters the displayed species based on a specified present time.
378
+
379
+ ### Properties
380
+
381
+ The `PhTree` component accepts the following props:
382
+
383
+ - **commonAncestor**: `Species`The root species of the phylogenetic tree.
384
+ - **width**: `number` (optional, default: `1000`)The width of the SVG canvas.
385
+ - **height**: `number` (optional, default: `50`)The height per descendant of the SVG canvas.
386
+ - **padding**: `number` (optional, default: `0`)The padding around the tree.
387
+ - **stroke**: `string` (optional, default: `"grey"`)The stroke color for the tree lines.
388
+ - **format**: `(n: number) => string` (optional, default: `(n) => n.toString()`)A function to format the display of time values.
389
+ - **presentTime**: `number` (optional)The current time to highlight in the tree.
390
+ - **children**:`(species: Species, showMenu: boolean,toggleShowMenu: (species: Species) => void) => React.ReactNode` (optional) Render prop to customize the menu content.
391
+
392
+ ### State
393
+
394
+ - **showMenu**: `boolean`Controls the visibility of the `Menu` component.
395
+ - **species**: `Species | undefined`The currently selected species for which the menu is displayed.
396
+ - **showDesc**: `Map<Species, boolean>`A map to track the visibility of descendants for each species.
397
+
398
+ ## Methods
399
+
400
+ - **toggleShowMenu**: `(species: Species) => void`Toggles the visibility of the menu for a given species.
401
+ - **toggleShowDesc**: `(species: Species) => void`
402
+ Toggles the visibility of descendants for a given species, if `false`, its `descendants` won't be displayed and the `line` will extend until its `absoluteExtinction()`.
403
+
404
+ ### Rendering
405
+
406
+ The component renders an SVG element that contains the phylogenetic tree. It uses the `DrawTree` component to recursively draw the tree structure. The `children` render prop is conditionally rendered based on the `showMenu` state.
407
+
408
+ ### Customization
409
+
410
+ The `PhTree` component can be customized using the various props it accepts. Additionally, the `children` render prop allows for further customization of the menu content displayed when a species node is clicked.
411
+
412
+ ## Menu Component
413
+
414
+ The `Menu` component provides a user interface to edit and manage species data. It allows users to modify species attributes, add descendants or ancestors, and delete species.
415
+
416
+ ### Properties
417
+
418
+ - **species**: `Species`The species for which the menu is displayed.
419
+ - **language**: `string` (optional)The language code for localization.
420
+ - **open**: `boolean` (optional)Controls the visibility of the menu.
421
+ - **onClose**: `() => void` (optional)A callback function to close the menu.
422
+ - **saveSpecies**: `(s: Species, name: string, apparition: number, duration: number, description?: string) => void` (optional)A callback function to save species data.
423
+ - **createDescendant**: `(s: Species, name: string, afterApparition: number, duration: number, description: string) => void` (optional)A callback function to create a new descendant species.
424
+ - **createAncestor**: `(s: Species, name: string, previousApparition: number, duration: number, description: string) => void` (optional)A callback function to create a new ancestor species.
425
+ - **deleteAncestor**: `() => void` (optional)A callback function to delete an ancestor species.
426
+ - **deleteSpecies**: `() => void` (optional)
427
+ A callback function to delete a species.
428
+
429
+ ### State
430
+
431
+ - **name**: `string`The name of the species.
432
+ - **apparition**: `number`The appearance time of the species.
433
+ - **duration**: `number`The duration of the species.
434
+ - **description**: `string | undefined`The description of the species.
435
+ - **addDescendant**: `boolean`Controls the visibility of the descendant addition form.
436
+ - **addAncestor**: `boolean`
437
+ Controls the visibility of the ancestor addition form.
438
+
439
+ ### Methods
440
+
441
+ - **toggleAddDescendant**: `() => void`Toggles the visibility of the descendant addition form.
442
+ - **toggleAddAncestor**: `() => void`Toggles the visibility of the ancestor addition form.
443
+ - **uniqueDescendant**: `(s: Species) => boolean`
444
+ Checks if the species is the only descendant of its ancestor.
445
+
446
+ ### Rendering
447
+
448
+ The component renders a modal form with fields to edit species attributes. It conditionally renders forms to add descendants or ancestors based on the state. The form includes buttons to save changes, delete species, and close the menu.
449
+
450
+ ## Translation Functions
451
+
452
+ The application supports localization through a CSV file (`translate.csv`) that contains translation strings for different languages. The `translate.tsx` file provides functions to fetch and use these translations dynamically.
453
+
454
+ ### CSV File Structure (`translate.csv`)
455
+
456
+ The `translate.csv` file is structured as follows:
457
+
458
+ - **Columns**:
459
+
460
+ - `code`: A unique identifier for each translation string.
461
+ - `spanish`: The translation in Spanish.
462
+ - `english`: The translation in English.
463
+
464
+ - **Rows**:
465
+
466
+ - Each row represents a translation string, identified by its `code`.
467
+ - The first row with the `code` value `"lan"` contains the language names (e.g., `"Español"` for Spanish, `"English"` for English).
468
+
469
+ #### Example CSV Content
470
+
471
+ ```csv
472
+ code;spanish;english
473
+ lan;Español;English
474
+ ttl;Árbol Cronofilogenético;Chronophylogenetic Tree
475
+ nvlbl00;Escala;Scale
476
+ nvlbl01;Presente;Present
477
+ nvlbl02;Color;Color
478
+ nvlbl03;Repositorio;Repository
479
+ nvlbl04;Importar JSON;Import JSON
480
+ nvbtn00;Crear especie vacía;Create empty species
481
+ nvbtn00_0;Eliminar todas las especies;Delete all species
482
+ nvbtn01;Ejemplo;Example
483
+ nvbtn02;Descargar JSON;Download JSON
484
+ nvlbl05;Idioma;Language
485
+ splbl00;Nombre;Name
486
+ splbl01;Aparición;Apparition
487
+ splbl02;Duración;Duration
488
+ splbl03;Descripción;Description
489
+ spbtn00;Guardar;Save
490
+ spbtn01;Eliminar;Delete
491
+ spbtn02;Crear descendiente;Create descendant
492
+ spbtn03;Crear ancestro;Create ancestor
493
+ spbtn04;Quitar Ancestro;Remove Ancestor
494
+ spbtn04_0;Quitar Ancestros;Remove Ancestors
495
+ spbtn05;Cancelar;Cancel
496
+ cdbtn00;Crear;Create
497
+ cnfrm00;¿Estás seguro de que deseas quitar al ancestro de {0}?;Are you sure you want to remove the {0}'s ancestor?
498
+ cnfrm00_0;¿Estás seguro de que deseas quitar a los ancestros de {0}?;Are you sure you want to remove the {0}'s ancestors?
499
+ cnfrm01;¿Estás seguro de que deseas eliminar la especie {0}?;Are you sure you want to remove the {0} species?
500
+ cnfrm01_0;¿Estás seguro de que deseas eliminar la especie {0} junto a sus descendientes?;Are you sure you want to remove the {0} species along with its descendants?
501
+ ```
502
+
503
+ ### How It Works
504
+
505
+ 1. **Translation Lookup**:
506
+
507
+ - The `codeText` and `codeTextAlt` functions in `translate.tsx` fetch the translation data from the CSV file.
508
+ - They search for the row with the matching `code` and retrieve the translation for the specified language.
509
+ - If the translation contains placeholders (e.g., `{0}`), they are replaced with the provided arguments.
510
+
511
+ 2. **Language Options**:
512
+
513
+ - The `getLanguageOptions` function retrieves the available languages from the CSV file by looking for the row with the `code` value `"lan"`.
514
+ - It returns a map of language codes (e.g., `"spanish"`, `"english"`) to their corresponding language names (e.g., `"Español"`, `"English"`).
515
+
516
+ 3. **Dynamic Translation**:
517
+
518
+ - The application uses the `codeText` function to dynamically translate UI elements based on the selected language.
519
+ - For example, buttons, labels, and confirmation messages are translated using the `code` values defined in the CSV file.
520
+
521
+ #### `codeText`
522
+
523
+ ```typescript
524
+ export const codeText = (code: string, language: string, arg: string[] = [], filePath: string = "/translate.csv"): string
525
+ ```
526
+
527
+ Retrieves a translated string based on a given code and language. It also supports string interpolation using placeholders (`{0}`, `{1}`, etc.).
528
+
529
+ **Parameters**
530
+
531
+ - **code**: `string`
532
+ The code that identifies the translation string in the CSV file.
533
+ - **language**: `string`
534
+ The language code (e.g., `"spanish"`, `"english"`) for which the translation is requested.
535
+ - **arg**: `string[]` (optional, default: `[]`)
536
+ An array of arguments to replace placeholders in the translated string.
537
+ - **filePath**: `string` (optional, default: `"/translate.csv"`)
538
+ The path to the CSV file containing the translation data.
539
+
540
+ **Returns**
541
+
542
+ - **`string`**: The translated string with placeholders replaced by the provided arguments. If the translation is not found, the function returns the original `code`.
543
+
544
+ #### `codeTextAlt`
545
+
546
+ ```typescript
547
+ export const codeTextAlt = async (code: string, language: string, arg: string[] = [], filePath: string = "/translate.csv"): Promise<string>
548
+ ```
549
+
550
+ An asynchronous version of codeText. It fetches the translation data from the CSV file and retrieves the translated string.
551
+
552
+ **Parameters**
553
+
554
+ - **code**: `string`
555
+ The code that identifies the translation string in the CSV file.
556
+ - **language**: `string`
557
+ The language code (e.g., `"spanish"`, `"english"`) for which the translation is requested.
558
+ - **arg**: `string[]` (optional, default: `[]`)
559
+ An array of arguments to replace placeholders in the translated string.
560
+ - **filePath**: `string` (optional, default: `"/translate.csv"`)
561
+ The path to the CSV file containing the translation data.
562
+
563
+ **Returns**
564
+
565
+ - **`Promise<string>`**: A promise that resolves to the translated string with placeholders replaced by the provided arguments. If the translation is not found, the function returns the original `code`.
566
+
567
+ #### `getLanguageOptions`
568
+
569
+ ```typescript
570
+ export const getLanguageOptions = (filePath: string = "/translate.csv"): Map<string, string>
571
+ ```
572
+
573
+ Retrieves a map of available language options from the CSV file. The language options are stored in a row with the code `"lan"`.
574
+
575
+ **Parameters**
576
+
577
+ - **filePath**: string (optional, default: "/translate.csv")
578
+ The path to the CSV file containing the translation data.
579
+
580
+ **Returns**
581
+
582
+ - **`Map<string, string>`**: A map where the keys are language codes (e.g., "spanish", "english") and the values are the corresponding language names (e.g., "Español", "English").
583
+
584
+ ### Example Usage
585
+
586
+ #### Fetching a Translated String
587
+
588
+ **`codeText`**
589
+
590
+ ```typescript
591
+ const greeting = codeText("greeting", "spanish", ["Juan"]); //Example row: greeting; Hola, {0}; Hello, {0}
592
+ console.log(greeting); // Output: "Hola, Juan"
593
+ ```
594
+
595
+ **`codeTextAlt`**
596
+
597
+ ```typescript
598
+ const greeting = await codeTextAlt("greeting", "spanish", ["Juan"]); //Example row: greeting; Hola, {0}; Hello, {0}
599
+ console.log(greeting); // Output: "Hola, Juan"
600
+ ```
601
+
602
+ #### Fetching Language Options
603
+
604
+ ```typescript
605
+ const languageOptions = getLanguageOptions();
606
+ console.log(languageOptions.get("spanish")); // Output: "Español"
607
+ ```
608
+
609
+ ### Adding New Languages
610
+
611
+ To add support for a new language (e.g., French):
612
+
613
+ 1. Add a new column to the CSV file (e.g., `french`).
614
+ 2. Populate the new column with translations for each `code`.
615
+ 3. Update the `getLanguageOptions` function to include the new language in the language options map.
616
+
617
+ #### Example CSV Update for French
618
+
619
+ ```csv
620
+ code;spanish;english;french
621
+ lan;Español;English;Français
622
+ nvlbl00;Escala;Scale;Échelle
623
+ nvlbl01;Presente;Present;Présent
624
+ ...
625
+ ```
626
+
627
+ ### Supported Translation Codes
628
+
629
+ Below is a list of some of the translation codes used in the application:
630
+
631
+ | Code | Spanish | English |
632
+ | ----------- | ------------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
633
+ | `ttl` | Árbol Cronofilogenético | Chronophylogenetic Tree |
634
+ | `nvlbl00` | Escala | Scale |
635
+ | `nvlbl01` | Presente | Present |
636
+ | `nvlbl02` | Color | Color |
637
+ | `nvlbl03` | Repositorio | Repository |
638
+ | `nvlbl04` | Importar JSON | Import JSON |
639
+ | `nvbtn00` | Crear especie vacía | Create empty species |
640
+ | `nvbtn00_0` | Eliminar todas las especies | Delete all species |
641
+ | `nvbtn01` | Ejemplo | Example |
642
+ | `nvbtn02` | Descargar JSON | Download JSON |
643
+ | `nvlbl05` | Idioma | Language |
644
+ | `splbl00` | Nombre | Name |
645
+ | `splbl01` | Aparición | Apparition |
646
+ | `splbl02` | Duración | Duration |
647
+ | `splbl03` | Descripción | Description |
648
+ | `spbtn00` | Guardar | Save |
649
+ | `spbtn01` | Eliminar | Delete |
650
+ | `spbtn02` | Crear descendiente | Create descendant |
651
+ | `spbtn03` | Crear ancestro | Create ancestor |
652
+ | `spbtn04` | Quitar Ancestro | Remove Ancestor |
653
+ | `spbtn04_0` | Quitar Ancestros | Remove Ancestors |
654
+ | `spbtn05` | Cancelar | Cancel |
655
+ | `cdbtn00` | Crear | Create |
656
+ | `cnfrm00` | ¿Estás seguro de que deseas quitar al ancestro de {0}? | Are you sure you want to remove the {0}'s ancestor? |
657
+ | `cnfrm00_0` | ¿Estás seguro de que deseas quitar a los ancestros de {0}? | Are you sure you want to remove the {0}'s ancestors? |
658
+ | `cnfrm01` | ¿Estás seguro de que deseas eliminar la especie {0}? | Are you sure you want to remove the {0} species? |
659
+ | `cnfrm01_0` | ¿Estás seguro de que deseas eliminar la especie {0} junto a sus descendientes? | Are you sure you want to remove the {0} species along with its descendants? |
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "chrono-phylo-tree",
3
+ "version": "1.0.1",
4
+ "description": "A React-based phylogenetic tree visualization library",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "dev": "vite",
14
+ "build": "tsc -b && vite build",
15
+ "lint": "eslint .",
16
+ "preview": "vite preview"
17
+ },
18
+ "dependencies": {
19
+ "papaparse": "^5.5.2",
20
+ "react": "^19.0.0",
21
+ "react-dom": "^19.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@eslint/js": "^9.19.0",
25
+ "@types/papaparse": "^5.3.15",
26
+ "@types/react": "^19.0.8",
27
+ "@types/react-dom": "^19.0.3",
28
+ "@vitejs/plugin-react": "^4.3.4",
29
+ "eslint": "^9.19.0",
30
+ "eslint-plugin-react-hooks": "^5.0.0",
31
+ "eslint-plugin-react-refresh": "^0.4.18",
32
+ "globals": "^15.14.0",
33
+ "typescript": "~5.7.2",
34
+ "typescript-eslint": "^8.21.0",
35
+ "vite": "^6.0.11"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/LUCHER4321/Phylo_Tree"
40
+ },
41
+ "keywords": ["phylogenetic", "tree", "visualization", "react"],
42
+ "author": "LUCHER4321"
43
+ }