chrono-phylo-tree 1.0.16 → 1.1.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/eslint.config.js +28 -0
- package/global.d.ts +26 -0
- package/index.html +13 -0
- package/package.json +2 -7
- package/src/App.css +131 -0
- package/src/App.tsx +149 -0
- package/src/assets/react.svg +1 -0
- package/src/classes/Species.tsx +267 -0
- package/src/components/HoverDescription.tsx +27 -0
- package/src/components/LanguageSelector.tsx +29 -0
- package/src/components/Menu.tsx +348 -0
- package/src/components/NavBar.tsx +234 -0
- package/src/components/PhTree.tsx +362 -0
- package/src/index.css +68 -0
- package/src/index.ts +4 -0
- package/src/main.tsx +10 -0
- package/src/types.d.ts +9 -0
- package/src/utils/between.tsx +3 -0
- package/src/utils/example.tsx +73 -0
- package/src/utils/hexToRGBA.tsx +12 -0
- package/src/utils/scientificNotation.tsx +20 -0
- package/src/utils/setFromJson.tsx +40 -0
- package/src/utils/translate.tsx +68 -0
- package/src/utils/updateSpecies.tsx +129 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.app.json +26 -0
- package/tsconfig.json +17 -0
- package/tsconfig.node.json +24 -0
- package/vite.config.ts +34 -0
- package/dist/App.d.ts +0 -3
- package/dist/App.d.ts.map +0 -1
- package/dist/chrono-phylo-tree.js +0 -1111
- package/dist/chrono-phylo-tree.umd.cjs +0 -15
- package/dist/classes/Species.d.ts +0 -35
- package/dist/classes/Species.d.ts.map +0 -1
- package/dist/components/HoverDescription.d.ts +0 -15
- package/dist/components/HoverDescription.d.ts.map +0 -1
- package/dist/components/LanguageSelector.d.ts +0 -9
- package/dist/components/LanguageSelector.d.ts.map +0 -1
- package/dist/components/Menu.d.ts +0 -15
- package/dist/components/Menu.d.ts.map +0 -1
- package/dist/components/NavBar.d.ts +0 -33
- package/dist/components/NavBar.d.ts.map +0 -1
- package/dist/components/PhTree.d.ts +0 -31
- package/dist/components/PhTree.d.ts.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/utils/between.d.ts +0 -2
- package/dist/utils/between.d.ts.map +0 -1
- package/dist/utils/example.d.ts +0 -3
- package/dist/utils/example.d.ts.map +0 -1
- package/dist/utils/hexToRGBA.d.ts +0 -2
- package/dist/utils/hexToRGBA.d.ts.map +0 -1
- package/dist/utils/scientificNotation.d.ts +0 -2
- package/dist/utils/scientificNotation.d.ts.map +0 -1
- package/dist/utils/setFromJson.d.ts +0 -3
- package/dist/utils/setFromJson.d.ts.map +0 -1
- package/dist/utils/translate.d.ts +0 -4
- package/dist/utils/translate.d.ts.map +0 -1
- package/dist/utils/updateSpecies.d.ts +0 -7
- package/dist/utils/updateSpecies.d.ts.map +0 -1
- /package/{dist → public}/logo.png +0 -0
- /package/{dist → public}/translate.csv +0 -0
- /package/{dist → public}/vite.svg +0 -0
package/eslint.config.js
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
import js from '@eslint/js'
|
2
|
+
import globals from 'globals'
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
5
|
+
import tseslint from 'typescript-eslint'
|
6
|
+
|
7
|
+
export default tseslint.config(
|
8
|
+
{ ignores: ['dist'] },
|
9
|
+
{
|
10
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
12
|
+
languageOptions: {
|
13
|
+
ecmaVersion: 2020,
|
14
|
+
globals: globals.browser,
|
15
|
+
},
|
16
|
+
plugins: {
|
17
|
+
'react-hooks': reactHooks,
|
18
|
+
'react-refresh': reactRefresh,
|
19
|
+
},
|
20
|
+
rules: {
|
21
|
+
...reactHooks.configs.recommended.rules,
|
22
|
+
'react-refresh/only-export-components': [
|
23
|
+
'warn',
|
24
|
+
{ allowConstantExport: true },
|
25
|
+
],
|
26
|
+
},
|
27
|
+
},
|
28
|
+
)
|
package/global.d.ts
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
interface SaveFilePickerOptions {
|
2
|
+
suggestedName?: string;
|
3
|
+
types?: Array<{
|
4
|
+
description: string;
|
5
|
+
accept: { [mimeType: string]: string[] };
|
6
|
+
}>;
|
7
|
+
}
|
8
|
+
|
9
|
+
interface FileSystemCreateWritableOptions {
|
10
|
+
keepExistingData?: boolean;
|
11
|
+
}
|
12
|
+
|
13
|
+
interface FileSystemFileHandle {
|
14
|
+
createWritable: (options?: FileSystemCreateWritableOptions) => Promise<FileSystemWritableFileStream>;
|
15
|
+
}
|
16
|
+
|
17
|
+
interface FileSystemWritableFileStream extends WritableStream {
|
18
|
+
seek(position: number): Promise<void>;
|
19
|
+
truncate(size: number): Promise<void>;
|
20
|
+
write(data: FileSystemWriteChunkType): Promise<void>;
|
21
|
+
close: () => Promise<void>;
|
22
|
+
}
|
23
|
+
|
24
|
+
interface Window {
|
25
|
+
showSaveFilePicker?: (options?: SaveFilePickerOptions) => Promise<FileSystemFileHandle>;
|
26
|
+
}
|
package/index.html
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8" />
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/logo.png" />
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7
|
+
<title id="title">Árbol Cronofilogenético</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div id="root"></div>
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
12
|
+
</body>
|
13
|
+
</html>
|
package/package.json
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "chrono-phylo-tree",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.1.1",
|
4
4
|
"description": "A React-based phylogenetic tree visualization library",
|
5
5
|
"type": "module",
|
6
|
-
"main": "
|
7
|
-
"module": "dist/index.d.ts",
|
8
|
-
"types": "dist/index.d.ts",
|
9
|
-
"files": [
|
10
|
-
"dist"
|
11
|
-
],
|
6
|
+
"main": "src/index.ts",
|
12
7
|
"scripts": {
|
13
8
|
"dev": "vite",
|
14
9
|
"build": "tsc -b && vite build",
|
package/src/App.css
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
@import "tailwindcss";
|
2
|
+
|
3
|
+
@tailwindcss base;
|
4
|
+
@tailwindcss component;
|
5
|
+
@tailwindcss utilities;
|
6
|
+
|
7
|
+
#root {
|
8
|
+
max-width: 1280px;
|
9
|
+
margin: 0 auto;
|
10
|
+
padding: 2rem;
|
11
|
+
text-align: center;
|
12
|
+
}
|
13
|
+
|
14
|
+
.logo {
|
15
|
+
height: 6em;
|
16
|
+
padding: 1.5em;
|
17
|
+
will-change: filter;
|
18
|
+
transition: filter 300ms;
|
19
|
+
}
|
20
|
+
.logo:hover {
|
21
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
22
|
+
}
|
23
|
+
.logo.react:hover {
|
24
|
+
filter: drop-shadow(0 0 2em #61dafbaa);
|
25
|
+
}
|
26
|
+
|
27
|
+
@keyframes logo-spin {
|
28
|
+
from {
|
29
|
+
transform: rotate(0deg);
|
30
|
+
}
|
31
|
+
to {
|
32
|
+
transform: rotate(360deg);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
@media (prefers-reduced-motion: no-preference) {
|
37
|
+
a:nth-of-type(2) .logo {
|
38
|
+
animation: logo-spin infinite 20s linear;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
.card {
|
43
|
+
padding: 2em;
|
44
|
+
}
|
45
|
+
|
46
|
+
.read-the-docs {
|
47
|
+
color: #888;
|
48
|
+
}
|
49
|
+
|
50
|
+
input:not([type="file"]) {
|
51
|
+
text-rendering: auto;
|
52
|
+
color: fieldtext;
|
53
|
+
letter-spacing: normal;
|
54
|
+
word-spacing: normal;
|
55
|
+
line-height: normal;
|
56
|
+
text-transform: none;
|
57
|
+
text-indent: 0px;
|
58
|
+
text-shadow: none;
|
59
|
+
display: inline-block;
|
60
|
+
text-align: start;
|
61
|
+
appearance: auto;
|
62
|
+
-webkit-rtl-ordering: logical;
|
63
|
+
cursor: text;
|
64
|
+
background-color: field;
|
65
|
+
margin: 0em;
|
66
|
+
padding: 1px 0px;
|
67
|
+
border-width: 2px;
|
68
|
+
border-style: inset;
|
69
|
+
border-color: light-dark(rgb(118, 118, 118), rgb(133, 133, 133));
|
70
|
+
border-image: initial;
|
71
|
+
padding-block: 1px;
|
72
|
+
padding-inline: 2px;
|
73
|
+
}
|
74
|
+
|
75
|
+
input:not([type="image" i], [type="range" i], [type="checkbox" i], [type="radio" i]) {
|
76
|
+
overflow-clip-margin: 0px !important;
|
77
|
+
overflow: clip !important;
|
78
|
+
}
|
79
|
+
|
80
|
+
input[type="text" i],
|
81
|
+
input[type="number" i] {
|
82
|
+
margin-left: 4px;
|
83
|
+
margin-right: 4px;
|
84
|
+
padding-block: 1px;
|
85
|
+
padding-inline: 2px;
|
86
|
+
background-color: field;
|
87
|
+
}
|
88
|
+
|
89
|
+
input[type="range" i] {
|
90
|
+
appearance: auto;
|
91
|
+
cursor: default;
|
92
|
+
color: light-dark(rgb(16, 16, 16), rgb(255, 255, 255));
|
93
|
+
padding: initial;
|
94
|
+
border: initial;
|
95
|
+
margin: 2px;
|
96
|
+
}
|
97
|
+
|
98
|
+
input[type="file"]::file-selector-button{
|
99
|
+
background-color: #6b6b6b;
|
100
|
+
padding-left: 4px;
|
101
|
+
padding-right: 4px;
|
102
|
+
border-radius: 0.25rem;
|
103
|
+
}
|
104
|
+
|
105
|
+
textarea {
|
106
|
+
font-family: monospace;
|
107
|
+
text-rendering: auto;
|
108
|
+
color: fieldtext;
|
109
|
+
letter-spacing: normal;
|
110
|
+
word-spacing: normal;
|
111
|
+
line-height: normal;
|
112
|
+
text-transform: none;
|
113
|
+
text-indent: 0px;
|
114
|
+
text-shadow: none;
|
115
|
+
display: inline-block;
|
116
|
+
text-align: start;
|
117
|
+
appearance: auto;
|
118
|
+
-webkit-rtl-ordering: logical;
|
119
|
+
resize: -internal-textarea-auto;
|
120
|
+
cursor: text;
|
121
|
+
overflow-wrap: break-word;
|
122
|
+
background-color: field;
|
123
|
+
column-count: initial !important;
|
124
|
+
margin: 0em;
|
125
|
+
border-width: 1px;
|
126
|
+
border-style: solid;
|
127
|
+
border-color: light-dark(rgb(118, 118, 118), rgb(133, 133, 133));
|
128
|
+
border-image: initial;
|
129
|
+
padding: 2px;
|
130
|
+
white-space: pre-wrap;
|
131
|
+
}
|
package/src/App.tsx
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
import { useEffect, useState } from 'react'
|
2
|
+
import './App.css'
|
3
|
+
import { PhTree } from './components/PhTree'
|
4
|
+
import { Species } from './classes/Species'
|
5
|
+
import { between } from './utils/between';
|
6
|
+
import { codeTextAlt, getLanguageOptions } from './utils/translate';
|
7
|
+
import { Menu } from './components/Menu';
|
8
|
+
import { NavBar } from './components/NavBar';
|
9
|
+
import { scientificNotation } from './utils/scientificNotation';
|
10
|
+
import { hexToRGBA } from './utils/hexToRGBA';
|
11
|
+
import { example } from './utils/example';
|
12
|
+
import { createAncestor, createDescendant, deleteAncestor, deleteSpecies, saveSpecies } from './utils/updateSpecies';
|
13
|
+
import { setFromJson } from './utils/setFromJson';
|
14
|
+
import { HoverDescription } from './components/HoverDescription';
|
15
|
+
|
16
|
+
function App() {
|
17
|
+
const [scale, setScale] = useState(1);
|
18
|
+
const [species, setSpecies] = useState<Species | undefined>(undefined);
|
19
|
+
const [speciesList, setSpeciesList] = useState<Species[]>([]);
|
20
|
+
const [lineColor, setLineColor] = useState("#7F7F7F");
|
21
|
+
const [presentTime, setPresentTime] = useState<number>(1);
|
22
|
+
const [presentTimeBoolean, setPresentTimeBoolean] = useState(true);
|
23
|
+
const [chronoScale, setChronoScale] = useState(true);
|
24
|
+
const [language, setLanguage] = useState("spanish");
|
25
|
+
const [hoverPosition, setHoverPosition] = useState({x: 0, y: 0});
|
26
|
+
const [showHover, setShowHover] = useState(false);
|
27
|
+
const [showImages, setShowImages] = useState(true);
|
28
|
+
const languages = getLanguageOptions();
|
29
|
+
const minScale = 1e-12;
|
30
|
+
const offset = {x: 0, y: -50}
|
31
|
+
|
32
|
+
useEffect(() => {
|
33
|
+
const title = document.getElementById("title");
|
34
|
+
if(title) {
|
35
|
+
codeTextAlt("ttl", language).then((ttl) => title.textContent = ttl);
|
36
|
+
}
|
37
|
+
}, [language]);
|
38
|
+
const showScaleNumber = false;
|
39
|
+
|
40
|
+
const showExample = () => {
|
41
|
+
setSpecies(() =>{
|
42
|
+
if(presentTimeBoolean){
|
43
|
+
setPresentTime(example.absoluteExtinction());
|
44
|
+
}
|
45
|
+
setScale(example.absoluteDuration());
|
46
|
+
return example;
|
47
|
+
});
|
48
|
+
};
|
49
|
+
|
50
|
+
const changePresentTime = (n: number) => {
|
51
|
+
setPresentTime(n);
|
52
|
+
setScale(between(scale, 1, maxScale(n)));
|
53
|
+
};
|
54
|
+
|
55
|
+
const maxScale = (n: number) => species ? Math.min(species.absoluteDuration(), presentTimeBoolean ? n - species.apparition : species.absoluteDuration()) : 1
|
56
|
+
|
57
|
+
const createEmptySpecies = async () => {
|
58
|
+
setSpecies(new Species(await codeTextAlt("nvbtn01", language), 0, 1));
|
59
|
+
setScale(1);
|
60
|
+
setPresentTime(1);
|
61
|
+
};
|
62
|
+
|
63
|
+
const deleteAllSpecies = async () => {
|
64
|
+
if(!species) return;
|
65
|
+
if(!confirm(await codeTextAlt("cnfrm01" + (species.descendants.length > 0 ? "_0" : ""), language, [species.name]))) return;
|
66
|
+
setSpecies(undefined);
|
67
|
+
};
|
68
|
+
|
69
|
+
const handleMouseMove = (x: number, y: number) => {
|
70
|
+
setHoverPosition({
|
71
|
+
x: x,
|
72
|
+
y: y,
|
73
|
+
});
|
74
|
+
};
|
75
|
+
|
76
|
+
//document.addEventListener("mousemove", handleMouseMove);
|
77
|
+
|
78
|
+
return (
|
79
|
+
<>
|
80
|
+
<NavBar
|
81
|
+
species={species}
|
82
|
+
color={hexToRGBA(lineColor, 0.5)}
|
83
|
+
lineColor={lineColor}
|
84
|
+
setLineColor={setLineColor}
|
85
|
+
language={language}
|
86
|
+
languages={languages}
|
87
|
+
setLanguage={setLanguage}
|
88
|
+
minScale={minScale}
|
89
|
+
maxScale={maxScale(presentTime)}
|
90
|
+
scale={scale}
|
91
|
+
setScale={setScale}
|
92
|
+
chronoScale={chronoScale}
|
93
|
+
setChronoScale={setChronoScale}
|
94
|
+
showScaleNumber={showScaleNumber}
|
95
|
+
showHover={showHover}
|
96
|
+
setShowHover={setShowHover}
|
97
|
+
showImages={showImages}
|
98
|
+
setShowImages={setShowImages}
|
99
|
+
presentTime={presentTime}
|
100
|
+
setPresentTime={setPresentTime}
|
101
|
+
setFromJson={setFromJson(setSpecies, setScale, setPresentTime, presentTimeBoolean)}
|
102
|
+
presentTimeBoolean={presentTimeBoolean}
|
103
|
+
setPresentTimeBoolean={setPresentTimeBoolean}
|
104
|
+
changePresentTime={changePresentTime}
|
105
|
+
deleteAllSpecies={deleteAllSpecies}
|
106
|
+
createEmptySpecies={createEmptySpecies}
|
107
|
+
showExample={showExample}
|
108
|
+
/>
|
109
|
+
{species && <div className="h-155 sm:h-65"/>}
|
110
|
+
{species && <PhTree
|
111
|
+
commonAncestor={species}
|
112
|
+
width={window.screen.width * (species?.absoluteDuration() ?? 0) / scale - 64}
|
113
|
+
height={50}
|
114
|
+
stroke={lineColor}
|
115
|
+
format={scientificNotation}
|
116
|
+
chronoScale={chronoScale}
|
117
|
+
showImages={showImages}
|
118
|
+
presentTime={presentTimeBoolean ? presentTime : undefined}
|
119
|
+
padding={1}
|
120
|
+
handleMouseMove={handleMouseMove}
|
121
|
+
>
|
122
|
+
{(sp, showMenu, toggleShowMenu, hoverSpecies) => species &&
|
123
|
+
<>
|
124
|
+
{showMenu && sp && <Menu
|
125
|
+
species={sp}
|
126
|
+
language={language}
|
127
|
+
open={showMenu}
|
128
|
+
onClose={() => toggleShowMenu(sp)}
|
129
|
+
saveSpecies={saveSpecies(setSpecies, language)}
|
130
|
+
createDescendant={createDescendant(setSpecies, language, presentTimeBoolean, setPresentTime, setScale)}
|
131
|
+
createAncestor={createAncestor(setSpecies, language, presentTimeBoolean, setPresentTime, setScale)}
|
132
|
+
deleteAncestor={deleteAncestor(sp, setSpecies, setScale, language)}
|
133
|
+
deleteSpecies={deleteSpecies(sp, setSpecies, language)}
|
134
|
+
/>}
|
135
|
+
{showHover && hoverSpecies && hoverSpecies.description &&
|
136
|
+
<HoverDescription
|
137
|
+
hoverPosition={hoverPosition}
|
138
|
+
hoverSpecies={hoverSpecies}
|
139
|
+
offset={offset}
|
140
|
+
/>
|
141
|
+
}
|
142
|
+
</>
|
143
|
+
}
|
144
|
+
</PhTree>}
|
145
|
+
</>
|
146
|
+
)
|
147
|
+
}
|
148
|
+
|
149
|
+
export default App
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
@@ -0,0 +1,267 @@
|
|
1
|
+
import { sortArray } from "multiple-sorting-array";
|
2
|
+
import { SpeciesJSON } from "../types";
|
3
|
+
|
4
|
+
export class Species {
|
5
|
+
name = "";
|
6
|
+
apparition = 0;
|
7
|
+
duration = 0;
|
8
|
+
ancestor?: Species = undefined;
|
9
|
+
descendants: Species[] = [];
|
10
|
+
description?: string = undefined;
|
11
|
+
display = true;
|
12
|
+
image?: string = undefined;
|
13
|
+
|
14
|
+
private onPosition(ret = true) {
|
15
|
+
if(!ret) return ret;
|
16
|
+
return this.firstAncestor().stepsUntil(this)! % 2 === 0;
|
17
|
+
}
|
18
|
+
|
19
|
+
constructor(
|
20
|
+
name = '',
|
21
|
+
apparition = 0,
|
22
|
+
duration = 0,
|
23
|
+
ancestor: Species | undefined = undefined,
|
24
|
+
descendants: Species[] = [],
|
25
|
+
description: string | undefined = undefined,
|
26
|
+
image: string | undefined = undefined,
|
27
|
+
) {
|
28
|
+
if(duration <= 0){
|
29
|
+
throw new Error("The duration of the species must be greater than 0");
|
30
|
+
}
|
31
|
+
this.name = name;
|
32
|
+
this.apparition = apparition;
|
33
|
+
this.duration = duration;
|
34
|
+
this.ancestor = ancestor;
|
35
|
+
this.descendants = descendants;
|
36
|
+
this.description = description === "" ? undefined : description;
|
37
|
+
this.image = image === "" ? undefined : image;
|
38
|
+
}
|
39
|
+
|
40
|
+
copy() : Species {
|
41
|
+
const fa = this.firstAncestor();
|
42
|
+
const n = fa.allDescendants(false).indexOf(this)
|
43
|
+
const sp = Species.fromJSON(fa.toJSON());
|
44
|
+
return sp.allDescendants(false)[n];
|
45
|
+
}
|
46
|
+
|
47
|
+
unlinkAncestor(): [Species, Species] | undefined {
|
48
|
+
if(!this.ancestor) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
this.ancestor.descendants = this.ancestor.descendants.filter((d) => d !== this);
|
52
|
+
const exAncestor = this.ancestor;
|
53
|
+
this.ancestor = undefined;
|
54
|
+
return [exAncestor.firstAncestor(), this];
|
55
|
+
}
|
56
|
+
|
57
|
+
unlinkDescendant(descendant: Species): [Species, Species] | undefined {
|
58
|
+
if(!this.descendants.includes(descendant)) {
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
this.descendants = this.descendants.filter((d) => d !== descendant);
|
62
|
+
descendant.ancestor = undefined;
|
63
|
+
return [this.firstAncestor(), descendant];
|
64
|
+
}
|
65
|
+
|
66
|
+
linkAncestor(ancestor: Species) {
|
67
|
+
if(this.ancestor === ancestor && ancestor.descendants.includes(this)) {
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
if(ancestor.apparition > this.apparition) {
|
71
|
+
throw new Error(`The ancestor's apparition (${ancestor.apparition}) must be before or equal the descendant's apparition (${this.apparition})`);
|
72
|
+
}
|
73
|
+
if(ancestor.extinction() < this.apparition) {
|
74
|
+
throw new Error(`The ancestor's extinction (${ancestor.extinction()}) must be after or equal the descendant's apparition (${this.apparition})`);
|
75
|
+
}
|
76
|
+
if(this.ancestor !== ancestor) {
|
77
|
+
this.unlinkAncestor();
|
78
|
+
}
|
79
|
+
this.ancestor = ancestor;
|
80
|
+
ancestor.descendants.push(this);
|
81
|
+
}
|
82
|
+
|
83
|
+
linkDescendant(descendant: Species) {
|
84
|
+
if(descendant.ancestor === this && this.descendants.includes(descendant)) {
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
if(descendant.apparition < this.apparition) {
|
88
|
+
throw new Error(`The descendant's apparition (${descendant.apparition}) must be after or equal the ancestor's apparition (${this.apparition})`);
|
89
|
+
}
|
90
|
+
if(descendant.extinction() > this.extinction()) {
|
91
|
+
throw new Error(`The descendant's extinction (${descendant.extinction()}) must be before or equal the ancestor's extinction (${this.extinction()})`);
|
92
|
+
}
|
93
|
+
if(this.descendants.includes(descendant)) {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
if(descendant.ancestor) {
|
97
|
+
descendant.unlinkAncestor();
|
98
|
+
}
|
99
|
+
this.descendants.push(descendant);
|
100
|
+
descendant.ancestor = this;
|
101
|
+
}
|
102
|
+
|
103
|
+
linkDescendants(descendants: Species[]) {
|
104
|
+
for(const desc of descendants) {
|
105
|
+
try {
|
106
|
+
this.linkDescendant(desc);
|
107
|
+
} catch (error) {
|
108
|
+
console.error(`Error linking descendant ${desc.name} to ancestor ${this.name}:`, error);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
addDescendant(
|
114
|
+
name = '',
|
115
|
+
afterApparition = 0,
|
116
|
+
duration = 0,
|
117
|
+
description: string | undefined = undefined,
|
118
|
+
image: string | undefined = undefined,
|
119
|
+
copy = false
|
120
|
+
) {
|
121
|
+
if(afterApparition < 0 || afterApparition > this.duration) {
|
122
|
+
throw new Error(`The apparition of the descendant must be between the apparition (${this.apparition}) and the extinction (${this.extinction()}) of the ancestor`);
|
123
|
+
}
|
124
|
+
const sp = copy ? this.copy() : this;
|
125
|
+
const desc = new Species(
|
126
|
+
name,
|
127
|
+
sp.apparition + Math.max(afterApparition, 0),
|
128
|
+
Math.max(duration, 0),
|
129
|
+
undefined,
|
130
|
+
[],
|
131
|
+
description,
|
132
|
+
image
|
133
|
+
);
|
134
|
+
desc.linkAncestor(sp);
|
135
|
+
return copy ? sp : desc;
|
136
|
+
}
|
137
|
+
|
138
|
+
removeDescendant(desc: Species) {
|
139
|
+
this.descendants = this.descendants.filter((d) => d !== desc);
|
140
|
+
}
|
141
|
+
|
142
|
+
addAncestor(
|
143
|
+
name = '',
|
144
|
+
previousApparition = 0,
|
145
|
+
duration = 0,
|
146
|
+
description: string | undefined = undefined,
|
147
|
+
image: string | undefined = undefined,
|
148
|
+
display = true,
|
149
|
+
copy = false
|
150
|
+
) {
|
151
|
+
if(previousApparition < 0) {
|
152
|
+
throw new Error(`The apparition of the ancestor must be before or equal the apparition (${this.apparition}) of the descendant`);
|
153
|
+
}
|
154
|
+
if(duration < previousApparition){
|
155
|
+
throw new Error(`The extiction of the ancestor must be after or equal the apparition (${this.apparition}) of the descendant`);
|
156
|
+
}
|
157
|
+
const sp = copy ? this.copy() : this;
|
158
|
+
const anc = new Species(
|
159
|
+
name,
|
160
|
+
sp.apparition - Math.max(previousApparition, 0),
|
161
|
+
duration,
|
162
|
+
undefined,
|
163
|
+
[],
|
164
|
+
description,
|
165
|
+
image
|
166
|
+
);
|
167
|
+
anc.display = display;
|
168
|
+
sp.linkAncestor(anc);
|
169
|
+
return copy ? sp : anc;
|
170
|
+
}
|
171
|
+
|
172
|
+
extinction() {
|
173
|
+
return this.apparition + this.duration;
|
174
|
+
}
|
175
|
+
|
176
|
+
absoluteExtinction(): number {
|
177
|
+
return this.descendants.length > 0
|
178
|
+
? Math.max(...this.allDescendants(false).map((desc) => desc.extinction()))
|
179
|
+
: this.extinction();
|
180
|
+
}
|
181
|
+
|
182
|
+
absoluteDuration() {
|
183
|
+
return this.absoluteExtinction() - this.apparition;
|
184
|
+
}
|
185
|
+
|
186
|
+
firstAncestor(includeNotDisplay = false): Species {
|
187
|
+
return this.ancestor ? ((this.ancestor.display || includeNotDisplay) ? this.ancestor.firstAncestor() : this) : this;
|
188
|
+
}
|
189
|
+
|
190
|
+
cousinsExtinction() {
|
191
|
+
return this.firstAncestor().absoluteExtinction();
|
192
|
+
}
|
193
|
+
|
194
|
+
allDescendants(sort = true): Species[] {
|
195
|
+
const desc = sort ? sortArray(this.descendants, s => -s.apparition, s => -s.absoluteExtinction()) : this.descendants;
|
196
|
+
if (desc.length === 0) {
|
197
|
+
return [this];
|
198
|
+
}
|
199
|
+
const limitDesc = desc.filter(desc => desc.apparition >= this.extinction());
|
200
|
+
const prevDesc = desc.filter(desc => limitDesc.indexOf(desc) === -1);
|
201
|
+
const halfFunc = this.onPosition(sort) ? Math.ceil : Math.floor;
|
202
|
+
const half = halfFunc(limitDesc.length / 2);
|
203
|
+
const lim0 = limitDesc.slice(0, half);
|
204
|
+
const lim1 = limitDesc.slice(half);
|
205
|
+
return lim0.flatMap((d) => d.allDescendants(sort)).concat([this]).concat(lim1.flatMap((d) => d.allDescendants(sort))).concat(prevDesc.flatMap((d) => d.allDescendants(sort)));
|
206
|
+
}
|
207
|
+
|
208
|
+
stepsChain(desc: Species, includeNotDisplay = false): Species[] {
|
209
|
+
if(!this.allDescendants(false).includes(desc)) {
|
210
|
+
return [];
|
211
|
+
}
|
212
|
+
return [this as Species].concat(this.descendants.find(d => d.allDescendants(false).includes(desc))?.stepsChain(desc) ?? []).filter(d => d.display || includeNotDisplay);
|
213
|
+
}
|
214
|
+
|
215
|
+
stepsUntil(desc: Species, includeNotDisplay = false): number | undefined {
|
216
|
+
if(!this.allDescendants(false).includes(desc)) {
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
return this.stepsChain(desc, includeNotDisplay).length - 1;
|
220
|
+
}
|
221
|
+
|
222
|
+
stepsUntilLastDescendant(icludeNotDisplay = false): number{
|
223
|
+
if(this.descendants.length === 0) {
|
224
|
+
return 0;
|
225
|
+
}
|
226
|
+
return Math.max(...this.allDescendants(false).filter(d => d.descendants.length === 0).map(d => this.stepsUntil(d, icludeNotDisplay) ?? 0));
|
227
|
+
}
|
228
|
+
|
229
|
+
toJSON(): SpeciesJSON {
|
230
|
+
return {
|
231
|
+
name: this.name,
|
232
|
+
apparition: !this.ancestor ? this.apparition : undefined,
|
233
|
+
afterApparition: this.ancestor ? this.apparition - this.ancestor.apparition : undefined,
|
234
|
+
description: this.description,
|
235
|
+
duration: this.duration,
|
236
|
+
descendants: this.descendants.length > 0 ? this.descendants.map((desc) => desc.toJSON()) : undefined,
|
237
|
+
image: this.image,
|
238
|
+
};
|
239
|
+
}
|
240
|
+
|
241
|
+
async saveJSON(filename: string | undefined = undefined) {
|
242
|
+
try{
|
243
|
+
const jsonString = JSON.stringify(this.toJSON(), null, 2);
|
244
|
+
const blob = new Blob([jsonString], { type: 'application/json' });
|
245
|
+
const url = URL.createObjectURL(blob);
|
246
|
+
const a = document.createElement('a');
|
247
|
+
a.href = url;
|
248
|
+
a.download = filename ?? `${this.name}.json`;
|
249
|
+
a.click();
|
250
|
+
URL.revokeObjectURL(url);
|
251
|
+
} catch(errror) {
|
252
|
+
console.error("Error saving file:", errror);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
static fromJSON(json: SpeciesJSON, ancestor?: Species): Species {
|
257
|
+
const afterApparition = json.afterApparition ?? 0;
|
258
|
+
const apparition = ancestor ? ancestor.apparition : json.apparition ?? 0;
|
259
|
+
const sp = new Species(json.name ?? "", apparition + afterApparition, json.duration ?? 0, ancestor, [], json.description, json.image);
|
260
|
+
if(json.descendants) {
|
261
|
+
for (const desc of json.descendants) {
|
262
|
+
sp.descendants.push(Species.fromJSON(desc, sp));
|
263
|
+
}
|
264
|
+
}
|
265
|
+
return sp
|
266
|
+
}
|
267
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Species } from "../classes/Species";
|
2
|
+
import { scientificNotation } from "../utils/scientificNotation";
|
3
|
+
|
4
|
+
export const HoverDescription = ({
|
5
|
+
hoverPosition,
|
6
|
+
hoverSpecies,
|
7
|
+
offset = { x: 0, y: 50 }
|
8
|
+
} : HoverDescriptionProps) => {
|
9
|
+
return (
|
10
|
+
<nav
|
11
|
+
style={{
|
12
|
+
left: hoverPosition.x + offset.x,
|
13
|
+
top: hoverPosition.y - offset.y,
|
14
|
+
}}
|
15
|
+
className="absolute bg-gray-500 p-2.5"
|
16
|
+
>
|
17
|
+
<p>{hoverSpecies.name} ({scientificNotation(hoverSpecies.apparition)} — {scientificNotation(hoverSpecies.extinction())}):</p>
|
18
|
+
<p>{hoverSpecies.description}</p>
|
19
|
+
</nav>
|
20
|
+
);
|
21
|
+
};
|
22
|
+
|
23
|
+
interface HoverDescriptionProps {
|
24
|
+
hoverPosition: { x: number; y: number };
|
25
|
+
hoverSpecies: Species;
|
26
|
+
offset?: { x: number; y: number };
|
27
|
+
}
|