@grunwaldlab/heat-tree 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # heat-tree
2
+
3
+ A self-contained widget for phylogenetic and taxonomic tree visualization with categorical and continuous variables associated with nodes and tips.
4
+
5
+ ![](docs/images/example_screenshot.png)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install heat-tree
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - Interactive phylogenetic and taxonomic tree visualization
16
+ - Support for both rectangular and circular layouts
17
+ - Metadata visualization through color, size, and text styling
18
+ - Tree manipulation: collapse/expand/hide/reveal subtrees and roots
19
+ - Automatic and manual zoom/pan controls
20
+ - Export to SVG and PNG formats
21
+ - Responsive design with mobile support
22
+ - Minimal dependencies (D3.js only)
23
+ - Minimal configuration required
24
+
25
+ ## Quick Start
26
+
27
+ ```javascript
28
+ import { heatTree } from 'heat-tree';
29
+
30
+ const newickString = "(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);";
31
+
32
+ heatTree(
33
+ {
34
+ trees: [
35
+ {
36
+ name: 'My Tree',
37
+ newick: newickString
38
+ }
39
+ ]
40
+ },
41
+ '#container'
42
+ );
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### Basic Usage
48
+
49
+ The `heatTree` function creates an interactive tree visualization in a specified container element.
50
+
51
+ ```javascript
52
+ heatTree(treesConfig, containerSelector, options);
53
+ ```
54
+
55
+ **Parameters:**
56
+
57
+ - `treesConfig` (Object): Configuration object containing tree data
58
+ - `trees` (Array): Array of tree objects, each with:
59
+ - `newick` (string, required): Newick format tree string
60
+ - `name` (string, optional): Display name for the tree
61
+ - `metadata` (Array|Object, optional): Metadata tables (see Metadata section)
62
+ - `aesthetics` (Object, optional): Initial aesthetic mappings (see Aesthetics section)
63
+
64
+ - `containerSelector` (string): CSS selector for the container element (e.g., `'#my-tree'`)
65
+
66
+ - `options` (Object, optional): Configuration options (see Options section)
67
+
68
+ You can also pass just a container selector to create an empty visualization:
69
+
70
+ ```javascript
71
+ heatTree('#container', options);
72
+ ```
73
+
74
+ ### Adding Metadata
75
+
76
+ Metadata can be associated with tree nodes to control visual properties:
77
+
78
+ ```javascript
79
+ const metadata = `node_id\tabundance\tsource
80
+ A\t145\tfarm
81
+ B\t892\tnursery
82
+ C\t234\tcity`;
83
+
84
+ heatTree(
85
+ {
86
+ trees: [
87
+ {
88
+ name: 'My Tree',
89
+ newick: newickString,
90
+ metadata: [
91
+ {
92
+ name: 'Sample Data',
93
+ data: metadata
94
+ }
95
+ ]
96
+ }
97
+ ]
98
+ },
99
+ '#container'
100
+ );
101
+ ```
102
+
103
+ Metadata tables should be tab-separated or comma-separated text with a `node_id` column that corresponds to node IDs in the newick string.
104
+
105
+ ### Default Aesthetic Mappings
106
+
107
+ Although the metadata columns used to color/size tree parts can be set interactively, they can also be defined when the widget first loads:
108
+
109
+ ```javascript
110
+ heatTree(
111
+ {
112
+ trees: [
113
+ {
114
+ name: 'My Tree',
115
+ newick: newickString,
116
+ metadata: [{ name: 'Data', data: metadata }],
117
+ aesthetics: {
118
+ tipLabelColor: 'source', // Color tips by 'source' column
119
+ tipLabelSize: 'abundance', // Size tips by 'abundance' column
120
+ tipLabelStyle: 'font_style' // Style tips by 'font_style' column
121
+ }
122
+ }
123
+ ]
124
+ },
125
+ '#container'
126
+ );
127
+ ```
128
+
129
+ **Available Aesthetics:**
130
+
131
+ - `tipLabelText`: Text content for tip labels
132
+ - `tipLabelColor`: Color of tip labels (supports categorical and continuous data)
133
+ - `tipLabelSize`: Size of tip labels (continuous data)
134
+ - `tipLabelFont`: Font family for tip labels
135
+ - `tipLabelStyle`: Font style for tip labels (normal, bold, italic, bold italic)
136
+
137
+ ## Default Options
138
+
139
+ Configure the visualization behavior and appearance:
140
+
141
+ ### Layout Options
142
+
143
+ - `layout` (string): Tree layout type
144
+ - `'rectangular'` (default): Traditional phylogenetic tree layout
145
+ - `'circular'`: Radial/circular tree layout
146
+
147
+ ### Zoom and Pan Options
148
+
149
+ - `manualZoomAndPanEnabled` (boolean): Enable/disable manual zoom and pan
150
+ - `true` (default): Manual controls enabled
151
+ - `false`: Manual controls disabled
152
+
153
+ - `autoZoom` (string): Automatic zoom behavior when tree changes
154
+ - `'Default'` (default): Adaptive behavior based on tree and layout
155
+ - `'Both'`: Zoom to fit both width and height
156
+ - `'X'`: Zoom to fit width only
157
+ - `'Y'`: Zoom to fit height only
158
+ - `'None'`: No automatic zooming
159
+
160
+ - `autoPan` (string): Automatic pan behavior when tree changes
161
+ - `'Default'` (default): Adaptive behavior based on tree and layout
162
+ - `'Both'`: Pan to center or minimize unused space in both dimensions
163
+ - `'X'`: Pan horizontally only
164
+ - `'Y'`: Pan vertically only
165
+ - `'None'`: No automatic panning
166
+
167
+ ### Tree Scaling Options
168
+
169
+ - `branchLengthScale` (number): Scale factor for branch lengths
170
+ - Range: 0.01 to 100
171
+ - Default: 1
172
+
173
+ - `treeHeightScale` (number): Scale factor for tree height (spacing between tips)
174
+ - Range: 0.1 to 10
175
+ - Default: 1
176
+
177
+ ### Visual Options
178
+
179
+ - `buttonSize` (number): Size of control buttons in pixels
180
+ - Default: 25
181
+
182
+ - `transitionDuration` (number): Duration of animations in milliseconds
183
+ - Default: 500
184
+
185
+ ### Example with Options
186
+
187
+ ```javascript
188
+ heatTree(
189
+ {
190
+ trees: [
191
+ {
192
+ name: 'My Tree',
193
+ newick: newickString,
194
+ metadata: [{ name: 'Data', data: metadata }],
195
+ aesthetics: {
196
+ tipLabelColor: 'source'
197
+ }
198
+ }
199
+ ]
200
+ },
201
+ '#container',
202
+ {
203
+ layout: 'circular',
204
+ branchLengthScale: 1.5,
205
+ treeHeightScale: 2,
206
+ autoZoom: 'Both',
207
+ autoPan: 'Both',
208
+ manualZoomAndPanEnabled: true,
209
+ transitionDuration: 750
210
+ }
211
+ );
212
+ ```
213
+
214
+ ## Multiple Trees
215
+
216
+ The widget can be initialized with multiple trees:
217
+
218
+ ```javascript
219
+ heatTree(
220
+ {
221
+ trees: [
222
+ {
223
+ name: 'Tree 1',
224
+ newick: newickString1,
225
+ metadata: [{ name: 'Data 1', data: metadata1 }]
226
+ },
227
+ {
228
+ name: 'Tree 2',
229
+ newick: newickString2,
230
+ metadata: [{ name: 'Data 2', data: metadata2 }]
231
+ }
232
+ ]
233
+ },
234
+ '#container'
235
+ );
236
+ ```
237
+
238
+ Use the toolbar's "Data" tab to switch between loaded trees.
239
+
240
+ ## Dependencies
241
+
242
+ - [D3.js](https://d3js.org/) v7.9.0
243
+
244
+ ## License
245
+
246
+ MIT
247
+
248
+ ## Contributing
249
+
250
+ Contributions are welcome! Please visit the [GitHub repository](https://github.com/grunwaldlab/heat-tree) to report issues or submit pull requests.