@captiveorigins/onetaxonomy-react 0.0.0-stage → 0.1.0-alpha.2
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/LICENSE +75 -0
- package/README.md +21 -2
- package/THIRD-PARTY-LICENSE-LUCIDE.txt +43 -0
- package/dist/Explorer.d.ts +48 -0
- package/dist/Explorer.js +395 -0
- package/dist/Lesson.d.ts +35 -0
- package/dist/Lesson.js +104 -0
- package/dist/TreeOutline.d.ts +27 -0
- package/dist/TreeOutline.js +113 -0
- package/dist/TreeView.d.ts +54 -0
- package/dist/TreeView.js +57 -0
- package/dist/drag.d.ts +26 -0
- package/dist/drag.js +85 -0
- package/dist/export.d.ts +19 -0
- package/dist/export.js +79 -0
- package/dist/icons.d.ts +76 -0
- package/dist/icons.js +74 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/styles.css +183 -0
- package/package.json +64 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Required Notice: Copyright 2026 Captive Origins (https://captiveorigins.com)
|
|
2
|
+
|
|
3
|
+
# PolyForm Noncommercial License 1.0.0
|
|
4
|
+
|
|
5
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
14
|
+
|
|
15
|
+
## Distribution License
|
|
16
|
+
|
|
17
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
18
|
+
|
|
19
|
+
## Notices
|
|
20
|
+
|
|
21
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
22
|
+
|
|
23
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
24
|
+
|
|
25
|
+
## Changes and New Works License
|
|
26
|
+
|
|
27
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
28
|
+
|
|
29
|
+
## Patent License
|
|
30
|
+
|
|
31
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
32
|
+
|
|
33
|
+
## Noncommercial Purposes
|
|
34
|
+
|
|
35
|
+
Any noncommercial purpose is a permitted purpose.
|
|
36
|
+
|
|
37
|
+
## Personal Uses
|
|
38
|
+
|
|
39
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
|
|
40
|
+
|
|
41
|
+
## Noncommercial Organizations
|
|
42
|
+
|
|
43
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
|
|
44
|
+
|
|
45
|
+
## Fair Use
|
|
46
|
+
|
|
47
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
48
|
+
|
|
49
|
+
## No Other Rights
|
|
50
|
+
|
|
51
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
52
|
+
|
|
53
|
+
## Patent Defense
|
|
54
|
+
|
|
55
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
56
|
+
|
|
57
|
+
## Violations
|
|
58
|
+
|
|
59
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
60
|
+
|
|
61
|
+
## No Liability
|
|
62
|
+
|
|
63
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
64
|
+
|
|
65
|
+
## Definitions
|
|
66
|
+
|
|
67
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
68
|
+
|
|
69
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
70
|
+
|
|
71
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
72
|
+
|
|
73
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
74
|
+
|
|
75
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @captiveorigins/onetaxonomy-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React components for OneTaxonomy: a server-renderable SVG tree, an accessible keyboard outline of the same tree, and an explorer with undo/redo. Every interaction is a view action from `@captiveorigins/onetaxonomy-core`, so the scientific data never changes and views can be saved, shared and replayed.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { createView, indexDataset } from '@captiveorigins/onetaxonomy-core'
|
|
7
|
+
import { Explorer } from '@captiveorigins/onetaxonomy-react'
|
|
8
|
+
import '@captiveorigins/onetaxonomy-react/styles.css'
|
|
9
|
+
|
|
10
|
+
const data = indexDataset(snapshot)
|
|
11
|
+
const view = createView(data, { id: 'turtles', title: 'Turtles', target: { kind: 'classification', id: 'my-classification' } })
|
|
12
|
+
|
|
13
|
+
<Explorer dataset={data} initialView={view} title="Turtles" onViewChange={save} />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- **`TreeView`**: SVG only, no effects: renders on the server. `role="img"` with a title and a description that says whether it is a classification or a phylogeny and how much is shown. Stable `ot-*` classes and `data-*` states (status, rank, collapsed, selected); extinct taxa are marked †.
|
|
17
|
+
- **`TreeOutline`**: the WAI-ARIA tree pattern: one tab stop, arrows, Right/Left to open/close, Home/End, type-ahead, Space to select, **Alt+Up/Down to reorder** (the keyboard alternative to dragging). Folded descendants are announced ("12 not shown").
|
|
18
|
+
- **`Explorer`**: toolbar (undo, redo, expand/collapse all, layout, living/extinct/unknown filter), drawing, outline and inspector (rank, status, highlights with *clade* or *group* and the hypothesis they were assessed against, flip children, show only this branch). Layouts the data can't support stay disabled with the reason. All text is replaceable through `labels`.
|
|
19
|
+
- **`useTaxonomyView`**: the headless state (view, projection, dispatch, undo/redo) for your own UI.
|
|
20
|
+
- Styles are optional (`styles.css`, CSS custom properties, dark mode, reduced motion).
|
|
21
|
+
|
|
22
|
+
Try it: `pnpm build && pnpm --filter @captiveorigins/onetaxonomy-playground build`, then open `apps/playground/dist/index.html`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lucide Icons and Contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
The following Lucide icons are derived from the Feather project:
|
|
20
|
+
|
|
21
|
+
airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out
|
|
22
|
+
|
|
23
|
+
The MIT License (MIT) (for the icons listed above)
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2013-present Cole Bemis
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type DatasetIndex, type Highlight, type Id, type LayoutKind, type Projection, type TaxonomicView, type TraitSet, type ViewAction } from '@captiveorigins/onetaxonomy-core';
|
|
2
|
+
import { type TreeLayout } from '@captiveorigins/onetaxonomy-layout';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
export type UseTaxonomyView = {
|
|
5
|
+
view: TaxonomicView;
|
|
6
|
+
projection: Projection;
|
|
7
|
+
dispatch: (action: ViewAction) => void;
|
|
8
|
+
undo: () => void;
|
|
9
|
+
redo: () => void;
|
|
10
|
+
canUndo: boolean;
|
|
11
|
+
canRedo: boolean;
|
|
12
|
+
/** The last refused action's reason (e.g. a layout the data can't support). */
|
|
13
|
+
error: string | null;
|
|
14
|
+
};
|
|
15
|
+
/** View state with undo/redo. Every change goes through the pure core reducer. */
|
|
16
|
+
export declare function useTaxonomyView(dataset: DatasetIndex, initial: TaxonomicView, { onChange }?: {
|
|
17
|
+
onChange?: (view: TaxonomicView) => void;
|
|
18
|
+
}): UseTaxonomyView;
|
|
19
|
+
/** Lays out a projection for a view's layout kind (sunburst is drawn as a rectangular outline here). */
|
|
20
|
+
export declare function layoutFor(projection: Projection, kind: LayoutKind): TreeLayout;
|
|
21
|
+
export type ExplorerLabels = Record<'undo' | 'redo' | 'expandAll' | 'collapseAll' | 'rotate' | 'layout' | 'status' | 'allStatuses' | 'outline' | 'details' | 'nothingSelected' | 'clade' | 'group' | 'hidden' | 'rank' | 'lifeStatus' | 'focus' | 'unfocus' | 'zoomIn' | 'zoomOut' | 'fit' | 'download' | 'print' | 'canvas' | 'controls' | 'dragHint' | 'propose' | 'proposalTitle' | 'proposalAuthor' | 'proposalStart' | 'proposalCancel' | 'proposalHint' | 'proposalBy' | 'proposalLeave' | 'proposalNoMoves' | 'proposalUnder' | 'proposalRoot' | 'proposalRevert' | 'proposalAccepted' | 'proposalProposed' | 'proposalMoveUnder' | 'proposalGained' | 'proposalLost' | 'proposalCompare' | 'proposalDefaultTitle' | 'overlays' | 'support' | 'extinction' | 'trait' | 'noTrait' | 'noStatedValue' | 'mixed' | 'weakSupport' | 'selection' | 'checkClade' | 'addHighlight' | 'highlightName' | 'checkAgainst' | 'clearSelection' | 'remove' | 'multiHint' | 'downloadSvg' | 'downloadPng' | 'downloadView' | 'about' | 'sources' | 'references' | 'synonyms' | 'commonNames' | 'age' | 'branchLength' | 'unmapped' | 'traits', string>;
|
|
22
|
+
export type ExplorerProps = {
|
|
23
|
+
dataset: DatasetIndex;
|
|
24
|
+
initialView: TaxonomicView;
|
|
25
|
+
title: string;
|
|
26
|
+
/** Height of the drawing area (CSS length). Default 32rem. */
|
|
27
|
+
height?: string;
|
|
28
|
+
labels?: Partial<ExplorerLabels>;
|
|
29
|
+
onViewChange?: (view: TaxonomicView) => void;
|
|
30
|
+
/** Extra content in the inspector for the selected node (e.g. a link to its page). */
|
|
31
|
+
renderDetails?: (id: Id) => ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Interactive explorer: the drawing, the accessible outline, a toolbar (undo,
|
|
35
|
+
* redo, expand/collapse, flip, layout, life-status filter) and an inspector. Every
|
|
36
|
+
* change is a view action over the pinned snapshot; the data itself never changes.
|
|
37
|
+
*/
|
|
38
|
+
export declare function Explorer({ dataset, initialView, title, height, labels: custom, onViewChange, renderDetails }: ExplorerProps): import("react").JSX.Element;
|
|
39
|
+
/** What the drawing is (classification vs phylogeny) and what each highlight is. */
|
|
40
|
+
export declare function Legend({ layout, highlights, labels: custom, trait, support, onRemoveHighlight, }: {
|
|
41
|
+
layout: TreeLayout;
|
|
42
|
+
highlights: Highlight[];
|
|
43
|
+
labels?: Partial<Pick<ExplorerLabels, 'clade' | 'group' | 'noStatedValue' | 'weakSupport' | 'mixed' | 'remove'>>;
|
|
44
|
+
/** The trait set the drawing is colored by (its states become legend entries). */
|
|
45
|
+
trait?: TraitSet | undefined;
|
|
46
|
+
support?: boolean;
|
|
47
|
+
onRemoveHighlight?: (id: Id) => void;
|
|
48
|
+
}): import("react").JSX.Element;
|
package/dist/Explorer.js
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { createHistory, describeAssessment, describeView, makeHighlight, dispatch as dispatchAction, inspectNode, nodeOverlays, acceptedTree, compareHierarchies, viewTree, serializeView, layoutProblem, projectView, redo as redoHistory, undo as undoHistory, } from '@captiveorigins/onetaxonomy-core';
|
|
4
|
+
import { radial, rectangular } from '@captiveorigins/onetaxonomy-layout';
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { dropOrder, drawnSubtree, dropTarget } from './drag.js';
|
|
7
|
+
import { citationLine, disclosureLines, downloadBlob, standaloneSvg, svgToPng } from './export.js';
|
|
8
|
+
import { Icon } from './icons.js';
|
|
9
|
+
import { TreeOutline } from './TreeOutline.js';
|
|
10
|
+
import { treeViewBox, TreeView } from './TreeView.js';
|
|
11
|
+
/** View state with undo/redo. Every change goes through the pure core reducer. */
|
|
12
|
+
export function useTaxonomyView(dataset, initial, { onChange } = {}) {
|
|
13
|
+
const [history, setHistory] = useState(() => createHistory(initial));
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const update = useCallback((next) => setHistory((h) => {
|
|
16
|
+
const n = next(h);
|
|
17
|
+
if (n !== h)
|
|
18
|
+
onChange?.(n.present);
|
|
19
|
+
return n;
|
|
20
|
+
}), [onChange]);
|
|
21
|
+
const dispatch = useCallback((action) => {
|
|
22
|
+
try {
|
|
23
|
+
// Validate outside the state updater so the error can be shown.
|
|
24
|
+
dispatchAction(history, action, dataset);
|
|
25
|
+
setError(null);
|
|
26
|
+
update((h) => dispatchAction(h, action, dataset));
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
setError(e.message);
|
|
30
|
+
}
|
|
31
|
+
}, [dataset, history, update]);
|
|
32
|
+
const projection = useMemo(() => projectView(dataset, history.present), [dataset, history.present]);
|
|
33
|
+
return {
|
|
34
|
+
view: history.present,
|
|
35
|
+
projection,
|
|
36
|
+
dispatch,
|
|
37
|
+
undo: () => update(undoHistory),
|
|
38
|
+
redo: () => update(redoHistory),
|
|
39
|
+
canUndo: history.past.length > 0,
|
|
40
|
+
canRedo: history.future.length > 0,
|
|
41
|
+
error,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Lays out a projection for a view's layout kind (sunburst is drawn as a rectangular outline here). */
|
|
45
|
+
export function layoutFor(projection, kind) {
|
|
46
|
+
if (kind === 'radial')
|
|
47
|
+
return radial(projection);
|
|
48
|
+
if (kind === 'phylogram' || kind === 'time')
|
|
49
|
+
return rectangular(projection, { scale: kind, width: 640 });
|
|
50
|
+
return rectangular(projection);
|
|
51
|
+
}
|
|
52
|
+
const LABELS = {
|
|
53
|
+
undo: 'Undo',
|
|
54
|
+
redo: 'Redo',
|
|
55
|
+
expandAll: 'Expand all',
|
|
56
|
+
collapseAll: 'Collapse all',
|
|
57
|
+
rotate: 'Flip children',
|
|
58
|
+
layout: 'Layout',
|
|
59
|
+
status: 'Show',
|
|
60
|
+
allStatuses: 'Living, extinct and unknown',
|
|
61
|
+
outline: 'Tree outline',
|
|
62
|
+
details: 'Details',
|
|
63
|
+
nothingSelected: 'Choose a taxon in the tree or the outline.',
|
|
64
|
+
clade: 'Clade',
|
|
65
|
+
group: 'Group',
|
|
66
|
+
hidden: 'not shown',
|
|
67
|
+
rank: 'Rank',
|
|
68
|
+
lifeStatus: 'Status',
|
|
69
|
+
focus: 'Show only this branch',
|
|
70
|
+
unfocus: 'Show everything',
|
|
71
|
+
zoomIn: 'Zoom in',
|
|
72
|
+
zoomOut: 'Zoom out',
|
|
73
|
+
fit: 'Fit to view',
|
|
74
|
+
download: 'Download',
|
|
75
|
+
print: 'Print',
|
|
76
|
+
canvas: 'Tree drawing: drag to pan, Ctrl or ⌘ + scroll to zoom, drag a taxon to reorder it among its siblings, double-click to fold',
|
|
77
|
+
controls: 'Drawing controls',
|
|
78
|
+
propose: 'Propose changes',
|
|
79
|
+
proposalTitle: 'Name of this proposal',
|
|
80
|
+
proposalAuthor: 'Your name',
|
|
81
|
+
proposalStart: 'Start proposing',
|
|
82
|
+
proposalCancel: 'Cancel',
|
|
83
|
+
proposalHint: 'Drag a taxon onto its new parent, or select it and choose below. The accepted data never changes.',
|
|
84
|
+
proposalBy: 'Proposed by',
|
|
85
|
+
proposalLeave: 'Leave Proposed mode',
|
|
86
|
+
proposalNoMoves: 'No moves yet.',
|
|
87
|
+
proposalUnder: 'under',
|
|
88
|
+
proposalRoot: 'the top level',
|
|
89
|
+
proposalRevert: 'Revert',
|
|
90
|
+
proposalAccepted: 'Accepted',
|
|
91
|
+
proposalProposed: 'Proposed',
|
|
92
|
+
proposalMoveUnder: 'Move under',
|
|
93
|
+
proposalGained: 'Gains',
|
|
94
|
+
proposalLost: 'Loses',
|
|
95
|
+
proposalCompare: 'Compare with the accepted arrangement',
|
|
96
|
+
proposalDefaultTitle: 'My proposal',
|
|
97
|
+
dragHint: 'Drag a taxon up or down to reorder it among its siblings; double-click a branch to fold it.',
|
|
98
|
+
overlays: 'Overlays',
|
|
99
|
+
support: 'Support values',
|
|
100
|
+
extinction: 'Extinct and fossils',
|
|
101
|
+
trait: 'Color by',
|
|
102
|
+
noTrait: 'No trait',
|
|
103
|
+
noStatedValue: 'No stated value',
|
|
104
|
+
mixed: 'Mixed states',
|
|
105
|
+
weakSupport: 'Weak support (dashed)',
|
|
106
|
+
selection: 'Selected',
|
|
107
|
+
checkClade: 'Is this a clade?',
|
|
108
|
+
addHighlight: 'Highlight',
|
|
109
|
+
highlightName: 'Name',
|
|
110
|
+
checkAgainst: 'Check against',
|
|
111
|
+
clearSelection: 'Clear selection',
|
|
112
|
+
remove: 'Remove',
|
|
113
|
+
multiHint: 'Shift-click (or Ctrl/⌘) to select several taxa and check whether they form a clade.',
|
|
114
|
+
downloadSvg: 'Drawing (SVG)',
|
|
115
|
+
downloadPng: 'Image (PNG)',
|
|
116
|
+
downloadView: 'View file (JSON)',
|
|
117
|
+
about: 'About this diagram',
|
|
118
|
+
sources: 'Sources',
|
|
119
|
+
references: 'References',
|
|
120
|
+
synonyms: 'Synonyms',
|
|
121
|
+
commonNames: 'Common names',
|
|
122
|
+
age: 'Age',
|
|
123
|
+
branchLength: 'Branch length',
|
|
124
|
+
unmapped: 'Not linked to a named taxon (a sample, population or unnamed lineage).',
|
|
125
|
+
traits: 'Traits',
|
|
126
|
+
};
|
|
127
|
+
/** Prints only this drawing: everything else on the page is hidden while printing. */
|
|
128
|
+
function printDrawing(el) {
|
|
129
|
+
if (!el)
|
|
130
|
+
return window.print();
|
|
131
|
+
el.setAttribute('data-ot-printing', '');
|
|
132
|
+
document.documentElement.setAttribute('data-ot-printing', '');
|
|
133
|
+
const done = () => {
|
|
134
|
+
el.removeAttribute('data-ot-printing');
|
|
135
|
+
document.documentElement.removeAttribute('data-ot-printing');
|
|
136
|
+
window.removeEventListener('afterprint', done);
|
|
137
|
+
};
|
|
138
|
+
window.addEventListener('afterprint', done);
|
|
139
|
+
window.print();
|
|
140
|
+
}
|
|
141
|
+
const LAYOUTS = ['rectangular', 'radial', 'phylogram', 'time'];
|
|
142
|
+
const STATUS_FILTERS = [{ value: 'all' }, { value: 'extant', statuses: ['extant'] }, { value: 'extinct', statuses: ['extinct'] }, { value: 'unknown', statuses: ['unknown'] }];
|
|
143
|
+
/**
|
|
144
|
+
* Interactive explorer: the drawing, the accessible outline, a toolbar (undo,
|
|
145
|
+
* redo, expand/collapse, flip, layout, life-status filter) and an inspector. Every
|
|
146
|
+
* change is a view action over the pinned snapshot; the data itself never changes.
|
|
147
|
+
*/
|
|
148
|
+
export function Explorer({ dataset, initialView, title, height = '32rem', labels: custom, onViewChange, renderDetails }) {
|
|
149
|
+
const labels = { ...LABELS, ...custom };
|
|
150
|
+
const t = useTaxonomyView(dataset, initialView, onViewChange ? { onChange: onViewChange } : {});
|
|
151
|
+
const { view, projection, dispatch } = t;
|
|
152
|
+
const layout = useMemo(() => layoutFor(projection, view.layout.kind), [projection, view.layout.kind]);
|
|
153
|
+
const selected = view.selected[0] ?? null;
|
|
154
|
+
const node = selected ? projection.nodes.find((n) => n.id === selected) : undefined;
|
|
155
|
+
const statusValue = STATUS_FILTERS.find((f) => JSON.stringify(f.statuses ?? null) === JSON.stringify(view.filter.status ?? null))?.value ?? 'all';
|
|
156
|
+
const hidden = (n) => `${n} ${labels.hidden}`;
|
|
157
|
+
const marks = useMemo(() => nodeOverlays(dataset, view, projection, { mixedLabel: labels.mixed }), [dataset, view, projection, labels.mixed]);
|
|
158
|
+
const disclosure = useMemo(() => describeView(dataset, view, projection), [dataset, view, projection]);
|
|
159
|
+
const details = useMemo(() => (selected && node ? inspectNode(dataset, view, selected) : null), [dataset, view, selected, node]);
|
|
160
|
+
const traits = dataset.snapshot.traits ?? [];
|
|
161
|
+
const isUnrooted = view.target.kind === 'phylogeny' && !dataset.phylogeny(view.target.id).rooted;
|
|
162
|
+
const hasSupport = projection.nodes.some((n) => n.support !== undefined);
|
|
163
|
+
const hasExtinct = projection.nodes.some((n) => n.status === 'extinct');
|
|
164
|
+
const overlays = view.overlays ?? {};
|
|
165
|
+
const setOverlays = (next) => dispatch({ type: 'setOverlays', overlays: next });
|
|
166
|
+
const choose = (id, additive = false) => dispatch({ type: 'select', nodes: additive ? (view.selected.includes(id) ? view.selected.filter((x) => x !== id) : [...view.selected, id]) : [id] });
|
|
167
|
+
// Pan and zoom (same controls as OnePedigree): the box resets when the layout or focus changes.
|
|
168
|
+
const full = useMemo(() => treeViewBox(layout), [layout]);
|
|
169
|
+
const [box, setBox] = useState(null);
|
|
170
|
+
const shown = box ?? full;
|
|
171
|
+
useEffect(() => setBox(null), [view.layout.kind, view.focus, view.target.id]);
|
|
172
|
+
const canvas = useRef(null);
|
|
173
|
+
const pointer = useRef(null);
|
|
174
|
+
const [drag, setDrag] = useState(null);
|
|
175
|
+
const [proposing, setProposing] = useState(false);
|
|
176
|
+
const proposal = view.proposal;
|
|
177
|
+
const landing = proposal && drag ? dropTarget(layout, drag.id, drag.ids, drag) : null;
|
|
178
|
+
const scale = () => {
|
|
179
|
+
const r = canvas.current?.querySelector('svg.ot-root')?.getBoundingClientRect();
|
|
180
|
+
if (!r || !r.width || !r.height)
|
|
181
|
+
return 1;
|
|
182
|
+
return Math.max(shown.width / r.width, shown.height / r.height);
|
|
183
|
+
};
|
|
184
|
+
const zoom = (factor) => {
|
|
185
|
+
const cx = shown.x + shown.width / 2;
|
|
186
|
+
const cy = shown.y + shown.height / 2;
|
|
187
|
+
setBox({ x: cx - (shown.width * factor) / 2, y: cy - (shown.height * factor) / 2, width: shown.width * factor, height: shown.height * factor });
|
|
188
|
+
};
|
|
189
|
+
const pan = (fx, fy) => setBox({ ...shown, x: shown.x + shown.width * fx, y: shown.y + shown.height * fy });
|
|
190
|
+
const allChildren = (parent) => view.order[parent] ?? viewChildren(dataset, view, parent);
|
|
191
|
+
const move = (id, direction) => {
|
|
192
|
+
const n = projection.nodes.find((x) => x.id === id);
|
|
193
|
+
if (!n?.parent)
|
|
194
|
+
return;
|
|
195
|
+
const siblings = [...allChildren(n.parent)];
|
|
196
|
+
const i = siblings.indexOf(id);
|
|
197
|
+
const j = i + direction;
|
|
198
|
+
if (i < 0 || j < 0 || j >= siblings.length)
|
|
199
|
+
return;
|
|
200
|
+
[siblings[i], siblings[j]] = [siblings[j], siblings[i]];
|
|
201
|
+
dispatch({ type: 'reorder', node: n.parent, children: siblings });
|
|
202
|
+
};
|
|
203
|
+
const onPointerDown = (e) => {
|
|
204
|
+
const target = e.target;
|
|
205
|
+
if (target.closest('button, a, select, .ot-floating'))
|
|
206
|
+
return;
|
|
207
|
+
const nodeId = target.closest('.ot-node')?.getAttribute('data-id') ?? null;
|
|
208
|
+
pointer.current = { x: e.clientX, y: e.clientY, box: shown, node: nodeId, moved: false, additive: e.shiftKey || e.ctrlKey || e.metaKey };
|
|
209
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
210
|
+
};
|
|
211
|
+
const onPointerMove = (e) => {
|
|
212
|
+
const p = pointer.current;
|
|
213
|
+
if (!p)
|
|
214
|
+
return;
|
|
215
|
+
const k = scale();
|
|
216
|
+
const dx = (e.clientX - p.x) * k;
|
|
217
|
+
const dy = (e.clientY - p.y) * k;
|
|
218
|
+
if (!p.moved && Math.hypot(e.clientX - p.x, e.clientY - p.y) < 4)
|
|
219
|
+
return;
|
|
220
|
+
p.moved = true;
|
|
221
|
+
const n = p.node ? projection.nodes.find((x) => x.id === p.node) : undefined;
|
|
222
|
+
if (n && (n.parent || proposal))
|
|
223
|
+
setDrag({ id: n.id, ids: drag?.id === n.id ? drag.ids : drawnSubtree(projection, n.id), dx, dy });
|
|
224
|
+
else
|
|
225
|
+
setBox({ ...p.box, x: p.box.x - dx, y: p.box.y - dy });
|
|
226
|
+
};
|
|
227
|
+
const onPointerUp = () => {
|
|
228
|
+
const p = pointer.current;
|
|
229
|
+
pointer.current = null;
|
|
230
|
+
if (!p)
|
|
231
|
+
return;
|
|
232
|
+
if (drag && landing) {
|
|
233
|
+
setDrag(null);
|
|
234
|
+
if (projection.nodes.find((n) => n.id === drag.id)?.parent !== landing)
|
|
235
|
+
dispatch({ type: 'proposeMove', node: drag.id, to: landing });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (drag) {
|
|
239
|
+
const parent = projection.nodes.find((n) => n.id === drag.id)?.parent;
|
|
240
|
+
const order = parent ? dropOrder(projection, layout, drag.id, drag, allChildren(parent)) : null;
|
|
241
|
+
setDrag(null);
|
|
242
|
+
if (order && parent)
|
|
243
|
+
dispatch({ type: 'reorder', node: parent, children: order });
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (!p.moved && p.node)
|
|
247
|
+
choose(p.node, p.additive);
|
|
248
|
+
};
|
|
249
|
+
const onDoubleClick = (e) => {
|
|
250
|
+
const id = e.target.closest('.ot-node')?.getAttribute('data-id');
|
|
251
|
+
const n = id ? projection.nodes.find((x) => x.id === id) : undefined;
|
|
252
|
+
if (n && !n.isTip)
|
|
253
|
+
dispatch({ type: 'toggle', node: n.id });
|
|
254
|
+
};
|
|
255
|
+
const onWheel = (e) => {
|
|
256
|
+
// Zoom only with Ctrl/⌘ (and trackpad pinch, which sets ctrlKey); plain scrolling scrolls the page.
|
|
257
|
+
if (!e.ctrlKey && !e.metaKey)
|
|
258
|
+
return;
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
zoom(e.deltaY > 0 ? 1.1 : 0.9);
|
|
261
|
+
};
|
|
262
|
+
const onKeyDown = (e) => {
|
|
263
|
+
if (e.target !== e.currentTarget)
|
|
264
|
+
return;
|
|
265
|
+
if (e.key === '+' || e.key === '=')
|
|
266
|
+
zoom(0.8);
|
|
267
|
+
else if (e.key === '-')
|
|
268
|
+
zoom(1.25);
|
|
269
|
+
else if (e.key === '0')
|
|
270
|
+
setBox(null);
|
|
271
|
+
else if (e.key.startsWith('Arrow')) {
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
pan(e.key === 'ArrowLeft' ? -0.1 : e.key === 'ArrowRight' ? 0.1 : 0, e.key === 'ArrowUp' ? -0.1 : e.key === 'ArrowDown' ? 0.1 : 0);
|
|
274
|
+
}
|
|
275
|
+
else if (e.key === 'Escape')
|
|
276
|
+
dispatch({ type: 'select', nodes: [] });
|
|
277
|
+
};
|
|
278
|
+
const exported = () => {
|
|
279
|
+
const svg = canvas.current?.querySelector('svg.ot-root');
|
|
280
|
+
return svg ? standaloneSvg(svg, disclosure, { sourcesLabel: labels.sources }) : null;
|
|
281
|
+
};
|
|
282
|
+
const [menu, setMenu] = useState(false);
|
|
283
|
+
const download = async (kind) => {
|
|
284
|
+
setMenu(false);
|
|
285
|
+
if (kind === 'view')
|
|
286
|
+
return downloadBlob(new Blob([serializeView(view)], { type: 'application/json' }), `${view.id}.onetaxonomy-view.json`);
|
|
287
|
+
const text = exported();
|
|
288
|
+
if (!text)
|
|
289
|
+
return;
|
|
290
|
+
if (kind === 'svg')
|
|
291
|
+
return downloadBlob(new Blob([text], { type: 'image/svg+xml' }), `${view.id}.svg`);
|
|
292
|
+
downloadBlob(await svgToPng(text), `${view.id}.png`);
|
|
293
|
+
};
|
|
294
|
+
return (_jsxs("div", { className: "ot-explorer", children: [_jsxs("div", { className: "ot-toolbar", role: "toolbar", "aria-label": title, children: [_jsxs("button", { type: "button", onClick: t.undo, disabled: !t.canUndo, children: [_jsx(Icon, { name: "undo" }), labels.undo] }), _jsxs("button", { type: "button", onClick: t.redo, disabled: !t.canRedo, children: [_jsx(Icon, { name: "redo" }), labels.redo] }), !proposal && !isUnrooted && (_jsxs("button", { type: "button", onClick: () => setProposing((v) => !v), "aria-expanded": proposing, children: [_jsx(Icon, { name: "grip" }), labels.propose] })), _jsx("span", { className: "ot-toolbar-gap", "aria-hidden": "true" }), _jsxs("button", { type: "button", onClick: () => dispatch({ type: 'expandAll' }), children: [_jsx(Icon, { name: "expand" }), labels.expandAll] }), _jsxs("button", { type: "button", onClick: () => dispatch({ type: 'collapseAll' }), children: [_jsx(Icon, { name: "collapse" }), labels.collapseAll] }), _jsx("span", { className: "ot-toolbar-gap", "aria-hidden": "true" }), _jsxs("label", { className: "ot-select", children: [_jsx(Icon, { name: "layout" }), _jsx("span", { children: labels.layout }), _jsx("select", { value: view.layout.kind, onChange: (e) => dispatch({ type: 'setLayout', layout: e.target.value }), children: LAYOUTS.map((k) => {
|
|
295
|
+
const problem = layoutProblem(dataset, view.target, k);
|
|
296
|
+
return (_jsx("option", { value: k, disabled: Boolean(problem), title: problem ?? undefined, children: k }, k));
|
|
297
|
+
}) })] }), _jsxs("label", { className: "ot-select", children: [_jsx(Icon, { name: "filter" }), _jsx("span", { children: labels.status }), _jsx("select", { value: statusValue, onChange: (e) => {
|
|
298
|
+
const f = STATUS_FILTERS.find((x) => x.value === e.target.value);
|
|
299
|
+
const { status: _, ...rest } = view.filter;
|
|
300
|
+
dispatch({ type: 'setFilter', filter: f.statuses ? { ...rest, status: f.statuses } : rest });
|
|
301
|
+
}, children: STATUS_FILTERS.map((f) => (_jsx("option", { value: f.value, children: f.value === 'all' ? labels.allStatuses : f.value }, f.value))) })] }), (hasSupport || hasExtinct || traits.length > 0) && _jsx("span", { className: "ot-toolbar-gap", "aria-hidden": "true" }), hasSupport && (_jsxs("button", { type: "button", "aria-pressed": Boolean(overlays.support), onClick: () => { const { support, ...rest } = overlays; setOverlays(support ? rest : { ...rest, support: {} }); }, children: [_jsx(Icon, { name: "support" }), labels.support] })), hasExtinct && (_jsxs("button", { type: "button", "aria-pressed": Boolean(overlays.extinction), onClick: () => { const { extinction, ...rest } = overlays; setOverlays(extinction ? rest : { ...rest, extinction: true }); }, children: [_jsx(Icon, { name: "fossil" }), labels.extinction] })), traits.length > 0 && (_jsxs("label", { className: "ot-select", children: [_jsx(Icon, { name: "palette" }), _jsx("span", { children: labels.trait }), _jsxs("select", { value: overlays.trait ?? '', onChange: (e) => { const { trait: _, ...rest } = overlays; setOverlays(e.target.value ? { ...rest, trait: e.target.value } : rest); }, children: [_jsx("option", { value: "", children: labels.noTrait }), traits.map((tr) => (_jsx("option", { value: tr.id, children: tr.title }, tr.id)))] })] }))] }), t.error && (_jsx("p", { className: "ot-error", role: "status", children: t.error })), _jsxs("div", { className: "ot-panes", children: [_jsxs("div", { ref: canvas, className: "ot-canvas", style: { height }, tabIndex: 0, role: "group", "aria-label": labels.canvas, "data-dragging": drag ? '' : undefined, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, onPointerCancel: () => {
|
|
302
|
+
pointer.current = null;
|
|
303
|
+
setDrag(null);
|
|
304
|
+
}, onDoubleClick: onDoubleClick, onWheel: onWheel, onKeyDown: onKeyDown, children: [_jsxs("div", { className: "ot-floating", role: "toolbar", "aria-label": labels.controls, children: [_jsx("button", { type: "button", onClick: () => zoom(0.8), "aria-label": labels.zoomIn, "data-tip": labels.zoomIn, children: _jsx(Icon, { name: "zoomIn" }) }), _jsx("button", { type: "button", onClick: () => zoom(1.25), "aria-label": labels.zoomOut, "data-tip": labels.zoomOut, children: _jsx(Icon, { name: "zoomOut" }) }), _jsx("button", { type: "button", onClick: () => setBox(null), "aria-label": labels.fit, "data-tip": labels.fit, children: _jsx(Icon, { name: "fit" }) }), _jsxs("div", { className: "ot-menu", children: [_jsx("button", { type: "button", onClick: () => setMenu((m) => !m), "aria-label": labels.download, "data-tip": labels.download, "aria-expanded": menu, "aria-haspopup": "menu", children: _jsx(Icon, { name: "download" }) }), menu && (_jsxs("div", { className: "ot-menu-list", role: "menu", onKeyDown: (e) => e.key === 'Escape' && setMenu(false), children: [_jsxs("button", { type: "button", role: "menuitem", onClick: () => download('svg'), children: [_jsx(Icon, { name: "download" }), labels.downloadSvg] }), _jsxs("button", { type: "button", role: "menuitem", onClick: () => download('png'), children: [_jsx(Icon, { name: "image" }), labels.downloadPng] }), _jsxs("button", { type: "button", role: "menuitem", onClick: () => download('view'), children: [_jsx(Icon, { name: "file" }), labels.downloadView] })] }))] }), _jsx("button", { type: "button", onClick: () => printDrawing(canvas.current), "aria-label": labels.print, "data-tip": labels.print, children: _jsx(Icon, { name: "print" }) })] }), _jsx(TreeView, { projection: projection, layout: layout, highlights: view.highlights, title: title, interactive: true, hiddenLabel: hidden, viewBox: shown, drag: drag, dropTarget: landing ?? null, overlays: marks }), proposal && (_jsxs("p", { className: "ot-proposed-badge", role: "note", children: [labels.proposalBy, " ", proposal.author, ": ", proposal.title] })), _jsx("div", { className: "ot-print-disclosure", "aria-hidden": "true", children: disclosureLines(disclosure, labels.sources).map((l, i) => (_jsx("p", { children: l }, i))) })] }), _jsxs("div", { className: "ot-side", children: [proposing && !proposal && (_jsx(ProposalStart, { labels: labels, onCancel: () => setProposing(false), onStart: (title, author) => {
|
|
305
|
+
dispatch({ type: 'startProposal', proposal: { id: `p${Date.now().toString(36)}`, title, author, created: new Date().toISOString() } });
|
|
306
|
+
setProposing(false);
|
|
307
|
+
} })), proposal && _jsx(ProposalPanel, { dataset: dataset, view: view, dispatch: dispatch, labels: labels }), _jsx(TreeOutline, { projection: projection, label: labels.outline, hiddenLabel: hidden, onToggle: (id) => dispatch({ type: 'toggle', node: id }), onSelect: (id, o) => choose(id, o?.additive), onMove: move }), _jsx("section", { className: "ot-inspector", "aria-label": labels.details, children: view.selected.length > 1 ? (_jsx(CladeCheck, { dataset: dataset, view: view, projection: projection, dispatch: dispatch, labels: labels })) : node ? (_jsxs(_Fragment, { children: [_jsx("h3", { className: "ot-inspector-title", children: node.label }), proposal && _jsx(ProposalNode, { dataset: dataset, view: view, node: node.id, projection: projection, dispatch: dispatch, labels: labels }), _jsxs("dl", { children: [node.rank && (_jsxs(_Fragment, { children: [_jsx("dt", { children: labels.rank }), _jsx("dd", { children: node.rank })] })), _jsx("dt", { children: labels.lifeStatus }), _jsx("dd", { children: node.status }), details?.age && (_jsxs(_Fragment, { children: [_jsx("dt", { children: labels.age }), _jsxs("dd", { children: [details.age.value, details.age.min !== undefined && details.age.max !== undefined ? ` (${details.age.min}–${details.age.max})` : '', " ", details.age.unit !== 'unspecified' ? details.age.unit : ''] })] })), details?.support && (_jsxs(_Fragment, { children: [_jsx("dt", { children: labels.support }), _jsxs("dd", { children: [details.support.value, details.support.method ? ` (${details.support.method})` : ''] })] })), details?.branchLength && (_jsxs(_Fragment, { children: [_jsx("dt", { children: labels.branchLength }), _jsxs("dd", { children: [details.branchLength.value, " ", details.branchLength.unit !== 'unspecified' ? details.branchLength.unit : ''] })] }))] }), details && _jsx(NodeFacts, { details: details, labels: labels }), node.hiddenDescendants > 0 && _jsx("p", { children: hidden(node.hiddenDescendants) }), _jsx(HighlightList, { highlights: view.highlights.filter((h) => node.highlights.includes(h.id)), labels: labels }), _jsxs("div", { className: "ot-inspector-actions", children: [!node.isTip && (_jsxs("button", { type: "button", onClick: () => dispatch({ type: 'rotate', node: node.id }), children: [_jsx(Icon, { name: "flip" }), labels.rotate] })), _jsxs("button", { type: "button", onClick: () => dispatch({ type: 'focus', node: view.focus === node.id ? null : node.id }), children: [_jsx(Icon, { name: view.focus === node.id ? 'unfocus' : 'focus' }), view.focus === node.id ? labels.unfocus : labels.focus] })] }), (view.target.kind === 'classification' && dataset.snapshot.phylogenies.length > 0) && _jsx(CladeCheck, { dataset: dataset, view: view, projection: projection, dispatch: dispatch, labels: labels, single: true }), renderDetails?.(node.id)] })) : (_jsxs("p", { className: "ot-hint", children: [_jsx(Icon, { name: "info" }), labels.nothingSelected, " ", labels.dragHint, " ", labels.multiHint] })) })] })] }), _jsx(Legend, { layout: layout, highlights: view.highlights, labels: labels, trait: traits.find((tr) => tr.id === overlays.trait), support: Boolean(overlays.support), onRemoveHighlight: (id) => dispatch({ type: 'removeHighlight', id }) }), proposal && proposal.moves.length > 0 && _jsx(ProposalCompare, { dataset: dataset, view: view, labels: labels, title: title }), _jsxs("details", { className: "ot-about", children: [_jsxs("summary", { children: [_jsx(Icon, { name: "book" }), labels.about] }), _jsx("ul", { children: disclosure.lines.map((l, i) => (_jsx("li", { children: l }, i))) }), disclosure.citations.length > 0 && (_jsxs(_Fragment, { children: [_jsx("h4", { children: labels.sources }), _jsx("ul", { children: disclosure.citations.map((c) => (_jsx("li", { children: citationLine(c) }, c.source))) })] }))] })] }));
|
|
308
|
+
}
|
|
309
|
+
const PALETTE = ['#cf8137', '#2f7d5c', '#91645d', '#3b6fb6', '#b9a8d9', '#d9a400'];
|
|
310
|
+
/**
|
|
311
|
+
* The clade selector: check whether the selected taxa form a clade in the hypothesis
|
|
312
|
+
* (or, for one taxon of a classification, in a chosen phylogeny), with the reason in
|
|
313
|
+
* words, then keep it as a highlight: a clade only when supported, otherwise a group.
|
|
314
|
+
*/
|
|
315
|
+
function CladeCheck({ dataset, view, projection, dispatch, labels, single = false }) {
|
|
316
|
+
const phylogenies = dataset.snapshot.phylogenies;
|
|
317
|
+
const [against, setAgainst] = useState(phylogenies[0]?.id ?? '');
|
|
318
|
+
const [name, setName] = useState('');
|
|
319
|
+
const members = view.selected;
|
|
320
|
+
const result = useMemo(() => {
|
|
321
|
+
if (view.target.kind === 'classification' && members.length !== 1)
|
|
322
|
+
return null;
|
|
323
|
+
return makeHighlight(dataset, view, { id: `h-${members.join('-')}`, label: name || members.map((m) => projection.nodes.find((n) => n.id === m)?.label ?? m).join(', '), members, ...(view.target.kind === 'classification' && against ? { hypothesis: against } : {}) });
|
|
324
|
+
}, [dataset, view, members, name, against, projection]);
|
|
325
|
+
const words = result?.assessment ? describeAssessment(dataset, result.assessment) : null;
|
|
326
|
+
const nameOf = (id) => projection.nodes.find((n) => n.id === id)?.label ?? id;
|
|
327
|
+
return (_jsxs("div", { className: "ot-clade-check", "data-status": result?.assessment?.status, children: [!single && (_jsxs(_Fragment, { children: [_jsxs("h3", { className: "ot-inspector-title", children: [labels.selection, " (", members.length, ")"] }), _jsx("p", { className: "ot-selection", children: members.map(nameOf).join(', ') })] })), view.target.kind === 'classification' && (_jsxs("label", { className: "ot-select", children: [_jsx("span", { children: labels.checkAgainst }), _jsx("select", { value: against, onChange: (e) => setAgainst(e.target.value), children: phylogenies.map((p) => (_jsx("option", { value: p.id, children: p.title }, p.id))) })] })), words && (_jsxs("div", { className: "ot-assessment-box", role: "status", children: [_jsxs("p", { children: [_jsx("strong", { children: labels.checkClade }), " ", words.headline] }), words.details.map((d, i) => (_jsx("p", { className: "ot-hint", children: d }, i)))] })), result && (_jsxs("form", { className: "ot-inspector-actions", onSubmit: (e) => {
|
|
328
|
+
e.preventDefault();
|
|
329
|
+
const id = `h${Date.now().toString(36)}`;
|
|
330
|
+
dispatch({ type: 'addHighlight', highlight: { ...result, id, color: PALETTE[view.highlights.length % PALETTE.length] } });
|
|
331
|
+
setName('');
|
|
332
|
+
}, children: [_jsxs("label", { className: "ot-select", children: [_jsx("span", { children: labels.highlightName }), _jsx("input", { value: name, onChange: (e) => setName(e.target.value), placeholder: result.label })] }), _jsxs("button", { type: "submit", children: [_jsx(Icon, { name: "palette" }), labels.addHighlight, " (", result.kind === 'clade' ? labels.clade : labels.group, ")"] })] })), !single && (_jsxs("button", { type: "button", onClick: () => dispatch({ type: 'select', nodes: [] }), children: [_jsx(Icon, { name: "close" }), labels.clearSelection] }))] }));
|
|
333
|
+
}
|
|
334
|
+
function NodeFacts({ details, labels }) {
|
|
335
|
+
const c = details.concepts.length === 1 ? details.concepts[0] : undefined;
|
|
336
|
+
const profile = c?.profile;
|
|
337
|
+
return (_jsxs("div", { className: "ot-facts", children: [details.unmapped && _jsx("p", { className: "ot-hint", children: labels.unmapped }), c?.authorship && _jsxs("p", { className: "ot-authorship", children: [c.name, " ", c.authorship] }), profile?.summary && _jsx("p", { children: profile.summary }), c && c.synonyms.length > 0 && (_jsxs("p", { children: [_jsxs("span", { className: "ot-fact-label", children: [labels.synonyms, ":"] }), " ", c.synonyms.join(', ')] })), c && c.commonNames.length > 0 && (_jsxs("p", { children: [_jsxs("span", { className: "ot-fact-label", children: [labels.commonNames, ":"] }), " ", c.commonNames.map((n) => `${n.name} (${n.locale})`).join(', ')] })), details.traits.length > 0 && (_jsxs("p", { children: [_jsxs("span", { className: "ot-fact-label", children: [labels.traits, ":"] }), " ", details.traits.map((tr) => `${tr.title}: ${tr.state}${tr.note ? ` (${tr.note})` : ''}`).join('; ')] })), details.references.length > 0 && (_jsxs("p", { children: [_jsxs("span", { className: "ot-fact-label", children: [labels.references, ":"] }), " ", details.references.join('; ')] })), details.citations.length > 0 && (_jsxs("p", { className: "ot-citations", children: [_jsxs("span", { className: "ot-fact-label", children: [labels.sources, ":"] }), " ", details.citations.map(citationLine).join('; ')] }))] }));
|
|
338
|
+
}
|
|
339
|
+
const viewChildren = (dataset, view, id) => (view.target.kind === 'classification' ? dataset.classification(view.target.id) : dataset.phylogeny(view.target.id)).children.get(id) ?? [];
|
|
340
|
+
function HighlightList({ highlights, labels, onRemove }) {
|
|
341
|
+
if (!highlights.length)
|
|
342
|
+
return null;
|
|
343
|
+
return (_jsx("ul", { className: "ot-highlights", children: highlights.map((h) => (_jsxs("li", { "data-kind": h.kind, children: [_jsx("span", { className: "ot-swatch", style: h.color ? { background: h.color } : undefined, "aria-hidden": "true" }), h.label, " \u00B7 ", h.kind === 'clade' ? labels.clade : labels.group, h.assessment?.hypothesis && (_jsxs("span", { className: "ot-assessment", children: [' ', "(", h.assessment.status, ", ", h.assessment.hypothesis.id, " v", h.assessment.hypothesis.version, ")"] })), onRemove && (_jsx("button", { type: "button", className: "ot-remove", onClick: () => onRemove(h.id), "aria-label": `${labels.remove ?? 'Remove'} ${h.label}`, title: labels.remove, children: _jsx(Icon, { name: "close", size: 12 }) }))] }, h.id))) }));
|
|
344
|
+
}
|
|
345
|
+
/** What the drawing is (classification vs phylogeny) and what each highlight is. */
|
|
346
|
+
export function Legend({ layout, highlights, labels: custom, trait, support, onRemoveHighlight, }) {
|
|
347
|
+
const labels = { clade: LABELS.clade, group: LABELS.group, noStatedValue: LABELS.noStatedValue, weakSupport: LABELS.weakSupport, mixed: LABELS.mixed, remove: LABELS.remove, ...custom };
|
|
348
|
+
return (_jsxs("div", { className: "ot-legend", children: [_jsx("p", { className: "ot-notice", children: layout.notice }), _jsx(HighlightList, { highlights: highlights, labels: labels, ...(onRemoveHighlight ? { onRemove: onRemoveHighlight } : {}) }), trait && (_jsxs("ul", { className: "ot-legend-traits", "aria-label": trait.title, children: [trait.states.map((s) => (_jsxs("li", { children: [_jsx("span", { className: "ot-swatch", "data-trait": s.id, style: s.color ? { background: s.color } : undefined, "aria-hidden": "true" }), s.label] }, s.id))), _jsxs("li", { children: [_jsx("span", { className: "ot-swatch", "data-trait": "mixed", "aria-hidden": "true" }), labels.mixed] }), _jsxs("li", { children: [_jsx("span", { className: "ot-swatch", "data-trait": "none", "aria-hidden": "true" }), labels.noStatedValue] })] })), support && _jsx("p", { className: "ot-notice", children: labels.weakSupport })] }));
|
|
349
|
+
}
|
|
350
|
+
const nodeName = (dataset, view, id, labels) => {
|
|
351
|
+
if (id === null)
|
|
352
|
+
return labels.proposalRoot;
|
|
353
|
+
if (view.target.kind === 'classification')
|
|
354
|
+
return dataset.nameOf(id) ?? id;
|
|
355
|
+
const n = dataset.phylogeny(view.target.id).node.get(id);
|
|
356
|
+
return n?.label ?? (n?.concepts?.[0] ? dataset.nameOf(n.concepts[0]) : undefined) ?? id;
|
|
357
|
+
};
|
|
358
|
+
/** Names a new proposal: a proposal always says whose it is. */
|
|
359
|
+
function ProposalStart({ labels, onStart, onCancel }) {
|
|
360
|
+
const [title, setTitle] = useState('');
|
|
361
|
+
const [author, setAuthor] = useState('');
|
|
362
|
+
return (_jsxs("form", { className: "ot-proposal", onSubmit: (e) => {
|
|
363
|
+
e.preventDefault();
|
|
364
|
+
if (author.trim())
|
|
365
|
+
onStart(title.trim() || labels.proposalDefaultTitle, author.trim());
|
|
366
|
+
}, children: [_jsx("h3", { children: labels.propose }), _jsx("p", { className: "ot-hint", children: labels.proposalHint }), _jsxs("label", { children: [labels.proposalAuthor, _jsx("input", { value: author, onChange: (e) => setAuthor(e.target.value), required: true })] }), _jsxs("label", { children: [labels.proposalTitle, _jsx("input", { value: title, onChange: (e) => setTitle(e.target.value) })] }), _jsxs("div", { className: "ot-inspector-actions", children: [_jsx("button", { type: "submit", children: labels.proposalStart }), _jsx("button", { type: "button", onClick: onCancel, children: labels.proposalCancel })] })] }));
|
|
367
|
+
}
|
|
368
|
+
/** The moves so far, each reversible (undo and redo work too). */
|
|
369
|
+
function ProposalPanel({ dataset, view, dispatch, labels }) {
|
|
370
|
+
const p = view.proposal;
|
|
371
|
+
return (_jsxs("section", { className: "ot-proposal", "aria-label": labels.propose, children: [_jsxs("h3", { children: [labels.proposalBy, " ", p.author, ": ", p.title] }), _jsx("p", { className: "ot-hint", children: labels.proposalHint }), p.moves.length ? (_jsx("ul", { children: p.moves.map((m) => (_jsxs("li", { children: [_jsxs("span", { children: [_jsx("strong", { children: nodeName(dataset, view, m.node, labels) }), " ", labels.proposalUnder, " ", nodeName(dataset, view, m.to, labels)] }), _jsx("button", { type: "button", onClick: () => dispatch({ type: 'revertMove', node: m.node }), children: labels.proposalRevert })] }, m.node))) })) : (_jsx("p", { className: "ot-hint", children: labels.proposalNoMoves })), _jsx("div", { className: "ot-inspector-actions", children: _jsx("button", { type: "button", onClick: () => dispatch({ type: 'endProposal' }), children: labels.proposalLeave }) })] }));
|
|
372
|
+
}
|
|
373
|
+
/** For the selected taxon: its accepted and proposed places, what its parent groups gain or lose, and a keyboard way to move it. */
|
|
374
|
+
function ProposalNode({ dataset, view, node, projection, dispatch, labels }) {
|
|
375
|
+
const accepted = acceptedTree(dataset, view);
|
|
376
|
+
const proposed = viewTree(dataset, view);
|
|
377
|
+
const from = accepted.parent.get(node) ?? null;
|
|
378
|
+
const to = proposed.parent.get(node) ?? null;
|
|
379
|
+
const comparison = useMemo(() => compareHierarchies(accepted, proposed), [accepted, proposed]);
|
|
380
|
+
const change = comparison.changedGroups.find((g) => g.node === node);
|
|
381
|
+
const under = new Set(drawnSubtree(projection, node));
|
|
382
|
+
const name = (id) => nodeName(dataset, view, id, labels);
|
|
383
|
+
return (_jsxs("div", { className: "ot-proposal", children: [_jsxs("p", { children: [_jsxs("strong", { children: [labels.proposalAccepted, ":"] }), " ", labels.proposalUnder, " ", name(from), _jsx("br", {}), _jsxs("strong", { children: [labels.proposalProposed, ":"] }), " ", labels.proposalUnder, " ", name(to)] }), change && change.gained.length > 0 && (_jsxs("p", { children: [_jsxs("strong", { children: [labels.proposalGained, ":"] }), " ", change.gained.map(name).join(', ')] })), change && change.lost.length > 0 && (_jsxs("p", { children: [_jsxs("strong", { children: [labels.proposalLost, ":"] }), " ", change.lost.map(name).join(', ')] })), _jsxs("label", { children: [labels.proposalMoveUnder, _jsxs("select", { value: to ?? '', onChange: (e) => dispatch({ type: 'proposeMove', node, to: e.target.value || null }), children: [view.target.kind === 'classification' && _jsx("option", { value: "", children: labels.proposalRoot }), projection.nodes
|
|
384
|
+
.filter((n) => !under.has(n.id) || n.id === to)
|
|
385
|
+
.map((n) => (_jsx("option", { value: n.id, children: n.label }, n.id)))] })] })] }));
|
|
386
|
+
}
|
|
387
|
+
/** The accepted and proposed trees side by side, same folds and filters. */
|
|
388
|
+
function ProposalCompare({ dataset, view, labels, title }) {
|
|
389
|
+
const accepted = useMemo(() => {
|
|
390
|
+
const { proposal: _p, ...rest } = view;
|
|
391
|
+
return projectView(dataset, { ...rest, order: {} });
|
|
392
|
+
}, [dataset, view]);
|
|
393
|
+
const proposed = useMemo(() => projectView(dataset, view), [dataset, view]);
|
|
394
|
+
return (_jsxs("details", { className: "ot-compare", children: [_jsx("summary", { children: labels.proposalCompare }), _jsxs("div", { className: "ot-compare-panes", children: [_jsxs("div", { children: [_jsx("h4", { children: labels.proposalAccepted }), _jsx(TreeView, { projection: accepted, layout: layoutFor(accepted, 'rectangular'), highlights: [], title: `${title}: ${labels.proposalAccepted}` })] }), _jsxs("div", { children: [_jsxs("h4", { children: [labels.proposalBy, " ", view.proposal.author] }), _jsx(TreeView, { projection: proposed, layout: layoutFor(proposed, 'rectangular'), highlights: [], title: `${title}: ${labels.proposalProposed}` })] })] })] }));
|
|
395
|
+
}
|