ui Module
Web-based UI for interactive population simulation.
Overview
The ui subpackage provides launch(), Dashboard, and visualization
utilities for interactive population simulation and data exploration.
Requires nicegui.
Complete Module Reference
natal.ui
NATAL UI Module
Provides user interface components for visualizing and controlling simulations.
Requires nicegui to be installed (pip install nicegui).
PopulationDashboard
A real-time dashboard for controlling and visualizing a NATAL population.
Initialize the population dashboard.
Sets up chart data structures, allele frequency tracking, observation panel, and UI state flags for the simulation control interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
BasePopulation[Any]
|
The simulation population instance to monitor and control. |
required |
Raises:
| Type | Description |
|---|---|
ImportError
|
If NiceGUI is not installed. |
Source code in src/natal/ui/dashboard_population.py
refresh_ui
Update reactive UI elements.
Source code in src/natal/ui/dashboard_population.py
reset_simulation
Reset the population and UI state.
Source code in src/natal/ui/dashboard_population.py
show_export_dialog
Open a dialog to let the user select what to export.
Source code in src/natal/ui/dashboard_population.py
export_data
handle_chart_click
Handle click on chart points to inspect history.
Source code in src/natal/ui/dashboard_population.py
handle_tick_input
Handle manual tick input.
Source code in src/natal/ui/dashboard_population.py
handle_chart_zoom
Handle Highcharts 'selection' event to update view window.
Source code in src/natal/ui/dashboard_population.py
inspect_tick
Handle click on chart points to inspect history.
Source code in src/natal/ui/dashboard_population.py
build_layout
Construct the NiceGUI layout.
Source code in src/natal/ui/dashboard_population.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 | |
reset_zoom
Reset zoom on both charts.
Source code in src/natal/ui/dashboard_population.py
SpatialDashboard
Real-time dashboard for a SpatialPopulation.
Initialize the spatial dashboard.
Source code in src/natal/ui/spatial_dashboard.py
refresh_ui
Refresh all reactive UI elements.
Source code in src/natal/ui/spatial_dashboard.py
show_export_dialog
Open export dialog for spatial data.
Source code in src/natal/ui/spatial_dashboard.py
reset_simulation
Reset the spatial simulation and the dashboard session history.
Source code in src/natal/ui/spatial_dashboard.py
build_layout
Construct the NiceGUI layout.
Source code in src/natal/ui/spatial_dashboard.py
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 | |
launch
Launch either the population or spatial dashboard.
Source code in src/natal/ui/dashboard.py
launch_population
launch_population(population: BasePopulation[Any], port: int = 8080, title: str = 'NATAL Dashboard')
Launch the embedded dashboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
BasePopulation[Any]
|
The population object to visualize. |
required |
port
|
int
|
Web server port. |
8080
|
title
|
str
|
The title of the dashboard. |
'NATAL Dashboard'
|
Source code in src/natal/ui/dashboard_population.py
launch_spatial
launch_spatial(population: SpatialPopulation, port: int = 8080, title: str = 'NATAL Spatial Dashboard') -> None
Launch the embedded spatial dashboard.
Source code in src/natal/ui/spatial_dashboard.py
get_allele_color
Determine a display color for an allele based on naming conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allele_name
|
str
|
The name of the allele. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hex color string (e.g., "#ff0000"). |
Source code in src/natal/ui/visualization.py
render_cell_svg
Generate an SVG string representing a cell's genotype.
Draws a cell circle containing chromosome bars. Can render both diploid Genotypes and HaploidGenotypes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Any
|
Genotype or HaploidGenotype instance. |
required |
species_def
|
Species
|
Species instance defining the chromosome structure. |
required |
size
|
int
|
Width/Height of the SVG in pixels. |
100
|
Returns:
| Type | Description |
|---|---|
str
|
String containing the SVG XML. |