matterviz 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. package/dist/EmptyState.svelte +10 -2
  2. package/dist/FilePicker.svelte +154 -96
  3. package/dist/Icon.svelte +20 -14
  4. package/dist/MillerIndexInput.svelte +27 -21
  5. package/dist/api/optimade.js +6 -6
  6. package/dist/app.css +216 -178
  7. package/dist/brillouin/BrillouinZone.svelte +299 -198
  8. package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
  9. package/dist/brillouin/BrillouinZoneControls.svelte +32 -5
  10. package/dist/brillouin/BrillouinZoneExportPane.svelte +74 -55
  11. package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
  12. package/dist/brillouin/BrillouinZoneInfoPane.svelte +99 -68
  13. package/dist/brillouin/BrillouinZoneScene.svelte +277 -165
  14. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -1
  15. package/dist/brillouin/BrillouinZoneTooltip.svelte +17 -7
  16. package/dist/brillouin/compute.js +11 -6
  17. package/dist/chempot-diagram/ChemPotDiagram.svelte +327 -0
  18. package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +13 -0
  19. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +847 -0
  20. package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +16 -0
  21. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +3194 -0
  22. package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +16 -0
  23. package/dist/chempot-diagram/ChemPotScene3D.svelte +11 -0
  24. package/dist/chempot-diagram/ChemPotScene3D.svelte.d.ts +7 -0
  25. package/dist/chempot-diagram/async-compute.svelte.d.ts +3 -0
  26. package/dist/chempot-diagram/async-compute.svelte.js +77 -0
  27. package/dist/chempot-diagram/chempot-worker.d.ts +1 -0
  28. package/dist/chempot-diagram/chempot-worker.js +11 -0
  29. package/dist/chempot-diagram/color.d.ts +10 -0
  30. package/dist/chempot-diagram/color.js +32 -0
  31. package/dist/chempot-diagram/compute.d.ts +48 -0
  32. package/dist/chempot-diagram/compute.js +812 -0
  33. package/dist/chempot-diagram/index.d.ts +6 -0
  34. package/dist/chempot-diagram/index.js +6 -0
  35. package/dist/chempot-diagram/pointer.d.ts +16 -0
  36. package/dist/chempot-diagram/pointer.js +40 -0
  37. package/dist/chempot-diagram/temperature.d.ts +15 -0
  38. package/dist/chempot-diagram/temperature.js +36 -0
  39. package/dist/chempot-diagram/types.d.ts +86 -0
  40. package/dist/chempot-diagram/types.js +28 -0
  41. package/dist/colors/index.d.ts +3 -1
  42. package/dist/colors/index.js +9 -3
  43. package/dist/composition/BarChart.svelte +141 -77
  44. package/dist/composition/BubbleChart.svelte +107 -52
  45. package/dist/composition/Composition.svelte +100 -79
  46. package/dist/composition/Formula.svelte +108 -62
  47. package/dist/composition/FormulaFilter.svelte +973 -353
  48. package/dist/composition/FormulaFilter.svelte.d.ts +35 -1
  49. package/dist/composition/PieChart.svelte +199 -99
  50. package/dist/composition/PieChart.svelte.d.ts +1 -1
  51. package/dist/composition/format.d.ts +5 -0
  52. package/dist/composition/format.js +20 -3
  53. package/dist/composition/parse.js +14 -9
  54. package/dist/convex-hull/ConvexHull.svelte +93 -38
  55. package/dist/convex-hull/ConvexHull2D.svelte +551 -393
  56. package/dist/convex-hull/ConvexHull3D.svelte +1303 -825
  57. package/dist/convex-hull/ConvexHull4D.svelte +1012 -686
  58. package/dist/convex-hull/ConvexHullControls.svelte +115 -28
  59. package/dist/convex-hull/ConvexHullInfoPane.svelte +29 -3
  60. package/dist/convex-hull/ConvexHullStats.svelte +821 -249
  61. package/dist/convex-hull/ConvexHullStats.svelte.d.ts +6 -1
  62. package/dist/convex-hull/ConvexHullTooltip.svelte +41 -16
  63. package/dist/convex-hull/GasPressureControls.svelte +104 -61
  64. package/dist/convex-hull/StructurePopup.svelte +25 -4
  65. package/dist/convex-hull/TemperatureSlider.svelte +45 -25
  66. package/dist/convex-hull/barycentric-coords.js +13 -7
  67. package/dist/convex-hull/demo-temperature.d.ts +6 -0
  68. package/dist/convex-hull/demo-temperature.js +40 -0
  69. package/dist/convex-hull/gas-thermodynamics.js +17 -12
  70. package/dist/convex-hull/helpers.d.ts +10 -1
  71. package/dist/convex-hull/helpers.js +79 -38
  72. package/dist/convex-hull/index.d.ts +1 -0
  73. package/dist/convex-hull/index.js +1 -0
  74. package/dist/convex-hull/thermodynamics.d.ts +8 -21
  75. package/dist/convex-hull/thermodynamics.js +163 -69
  76. package/dist/convex-hull/types.d.ts +12 -12
  77. package/dist/convex-hull/types.js +0 -12
  78. package/dist/coordination/CoordinationBarPlot.svelte +232 -176
  79. package/dist/element/BohrAtom.svelte +56 -13
  80. package/dist/element/ElementHeading.svelte +7 -2
  81. package/dist/element/ElementPhoto.svelte +15 -9
  82. package/dist/element/ElementStats.svelte +10 -4
  83. package/dist/element/ElementTile.svelte +137 -73
  84. package/dist/element/Nucleus.svelte +39 -11
  85. package/dist/element/data.js +2 -14
  86. package/dist/element/data.json.gz +0 -0
  87. package/dist/element/types.d.ts +1 -0
  88. package/dist/feedback/ClickFeedback.svelte +16 -5
  89. package/dist/feedback/DragOverlay.svelte +10 -2
  90. package/dist/feedback/Spinner.svelte +4 -2
  91. package/dist/feedback/StatusMessage.svelte +8 -2
  92. package/dist/fermi-surface/FermiSlice.svelte +118 -88
  93. package/dist/fermi-surface/FermiSurface.svelte +336 -239
  94. package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
  95. package/dist/fermi-surface/FermiSurfaceControls.svelte +113 -46
  96. package/dist/fermi-surface/FermiSurfaceScene.svelte +536 -343
  97. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +1 -1
  98. package/dist/fermi-surface/FermiSurfaceTooltip.svelte +14 -5
  99. package/dist/fermi-surface/compute.js +16 -20
  100. package/dist/fermi-surface/parse.js +37 -33
  101. package/dist/fermi-surface/symmetry.js +2 -7
  102. package/dist/fermi-surface/types.d.ts +3 -5
  103. package/dist/heatmap-matrix/HeatmapMatrix.svelte +1527 -0
  104. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +110 -0
  105. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +225 -0
  106. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +30 -0
  107. package/dist/heatmap-matrix/index.d.ts +53 -0
  108. package/dist/heatmap-matrix/index.js +100 -0
  109. package/dist/heatmap-matrix/shared.d.ts +2 -0
  110. package/dist/heatmap-matrix/shared.js +4 -0
  111. package/dist/icons.d.ts +111 -0
  112. package/dist/icons.js +158 -0
  113. package/dist/index.d.ts +5 -2
  114. package/dist/index.js +5 -2
  115. package/dist/io/decompress.js +1 -1
  116. package/dist/io/export.d.ts +3 -0
  117. package/dist/io/export.js +138 -140
  118. package/dist/io/file-drop.d.ts +7 -0
  119. package/dist/io/file-drop.js +43 -0
  120. package/dist/io/index.d.ts +2 -2
  121. package/dist/io/index.js +2 -112
  122. package/dist/io/is-binary.js +2 -3
  123. package/dist/io/types.d.ts +1 -0
  124. package/dist/io/url-drop.d.ts +2 -0
  125. package/dist/io/url-drop.js +117 -0
  126. package/dist/isosurface/Isosurface.svelte +220 -110
  127. package/dist/isosurface/IsosurfaceControls.svelte +65 -28
  128. package/dist/isosurface/parse.js +104 -56
  129. package/dist/isosurface/slice.d.ts +2 -1
  130. package/dist/isosurface/slice.js +8 -13
  131. package/dist/isosurface/types.d.ts +14 -1
  132. package/dist/isosurface/types.js +152 -5
  133. package/dist/labels.d.ts +2 -1
  134. package/dist/labels.js +12 -8
  135. package/dist/layout/FullscreenToggle.svelte +11 -2
  136. package/dist/layout/InfoCard.svelte +38 -6
  137. package/dist/layout/InfoTag.svelte +125 -94
  138. package/dist/layout/PropertyFilter.svelte +82 -37
  139. package/dist/layout/SettingsSection.svelte +85 -55
  140. package/dist/layout/SubpageGrid.svelte +82 -0
  141. package/dist/layout/SubpageGrid.svelte.d.ts +14 -0
  142. package/dist/layout/index.d.ts +1 -0
  143. package/dist/layout/index.js +1 -0
  144. package/dist/layout/json-tree/JsonNode.svelte +266 -223
  145. package/dist/layout/json-tree/JsonTree.svelte +516 -429
  146. package/dist/layout/json-tree/JsonTree.svelte.d.ts +1 -1
  147. package/dist/layout/json-tree/JsonValue.svelte +281 -173
  148. package/dist/layout/json-tree/types.d.ts +10 -2
  149. package/dist/layout/json-tree/utils.d.ts +2 -0
  150. package/dist/layout/json-tree/utils.js +37 -2
  151. package/dist/marching-cubes.js +25 -2
  152. package/dist/math.d.ts +20 -17
  153. package/dist/math.js +474 -57
  154. package/dist/overlays/ContextMenu.svelte +66 -40
  155. package/dist/overlays/DraggablePane.svelte +331 -154
  156. package/dist/overlays/DraggablePane.svelte.d.ts +2 -0
  157. package/dist/periodic-table/PeriodicTable.svelte +278 -145
  158. package/dist/periodic-table/PeriodicTableControls.svelte +178 -128
  159. package/dist/periodic-table/PropertySelect.svelte +25 -7
  160. package/dist/periodic-table/TableInset.svelte +8 -3
  161. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +559 -267
  162. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +6 -2
  163. package/dist/phase-diagram/PhaseDiagramControls.svelte +131 -51
  164. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +3 -2
  165. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +126 -0
  166. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +15 -0
  167. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +160 -110
  168. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +8 -1
  169. package/dist/phase-diagram/PhaseDiagramTooltip.svelte +217 -86
  170. package/dist/phase-diagram/PhaseDiagramTooltip.svelte.d.ts +6 -3
  171. package/dist/phase-diagram/TdbInfoPanel.svelte +28 -4
  172. package/dist/phase-diagram/build-diagram.js +9 -9
  173. package/dist/phase-diagram/colors.js +1 -3
  174. package/dist/phase-diagram/index.d.ts +2 -0
  175. package/dist/phase-diagram/index.js +2 -0
  176. package/dist/phase-diagram/parse.js +10 -9
  177. package/dist/phase-diagram/svg-to-diagram.d.ts +2 -0
  178. package/dist/phase-diagram/svg-to-diagram.js +869 -0
  179. package/dist/phase-diagram/types.d.ts +10 -0
  180. package/dist/phase-diagram/utils.d.ts +8 -4
  181. package/dist/phase-diagram/utils.js +219 -74
  182. package/dist/plot/AxisLabel.svelte +51 -0
  183. package/dist/plot/AxisLabel.svelte.d.ts +16 -0
  184. package/dist/plot/BarPlot.svelte +1461 -768
  185. package/dist/plot/BarPlot.svelte.d.ts +3 -3
  186. package/dist/plot/BarPlotControls.svelte +33 -6
  187. package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
  188. package/dist/plot/ColorBar.svelte +533 -383
  189. package/dist/plot/ColorBar.svelte.d.ts +1 -1
  190. package/dist/plot/ColorScaleSelect.svelte +28 -7
  191. package/dist/plot/ElementScatter.svelte +38 -16
  192. package/dist/plot/FillArea.svelte +152 -92
  193. package/dist/plot/Histogram.svelte +1162 -709
  194. package/dist/plot/Histogram.svelte.d.ts +1 -1
  195. package/dist/plot/HistogramControls.svelte +81 -18
  196. package/dist/plot/HistogramControls.svelte.d.ts +6 -2
  197. package/dist/plot/InteractiveAxisLabel.svelte +34 -11
  198. package/dist/plot/InteractiveAxisLabel.svelte.d.ts +1 -1
  199. package/dist/plot/Line.svelte +63 -28
  200. package/dist/plot/PlotControls.svelte +221 -96
  201. package/dist/plot/PlotControls.svelte.d.ts +1 -1
  202. package/dist/plot/PlotLegend.svelte +174 -91
  203. package/dist/plot/PlotTooltip.svelte +45 -6
  204. package/dist/plot/PortalSelect.svelte +175 -146
  205. package/dist/plot/ReferenceLine.svelte +77 -22
  206. package/dist/plot/ReferenceLine.svelte.d.ts +1 -0
  207. package/dist/plot/ReferenceLine3D.svelte +132 -107
  208. package/dist/plot/ReferencePlane.svelte +146 -123
  209. package/dist/plot/ScatterPlot.svelte +1880 -1156
  210. package/dist/plot/ScatterPlot.svelte.d.ts +3 -3
  211. package/dist/plot/ScatterPlot3D.svelte +256 -131
  212. package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
  213. package/dist/plot/ScatterPlot3DControls.svelte +300 -297
  214. package/dist/plot/ScatterPlot3DControls.svelte.d.ts +2 -1
  215. package/dist/plot/ScatterPlot3DScene.svelte +608 -406
  216. package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
  217. package/dist/plot/ScatterPlotControls.svelte +150 -70
  218. package/dist/plot/ScatterPlotControls.svelte.d.ts +1 -1
  219. package/dist/plot/ScatterPoint.svelte +98 -26
  220. package/dist/plot/ScatterPoint.svelte.d.ts +1 -0
  221. package/dist/plot/SpacegroupBarPlot.svelte +142 -85
  222. package/dist/plot/Surface3D.svelte +159 -108
  223. package/dist/plot/ZeroLines.svelte +96 -0
  224. package/dist/plot/ZeroLines.svelte.d.ts +32 -0
  225. package/dist/plot/ZoomRect.svelte +23 -0
  226. package/dist/plot/ZoomRect.svelte.d.ts +8 -0
  227. package/dist/plot/axis-utils.d.ts +1 -1
  228. package/dist/plot/axis-utils.js +1 -3
  229. package/dist/plot/data-cleaning.js +12 -28
  230. package/dist/plot/data-transform.js +2 -1
  231. package/dist/plot/fill-utils.js +2 -0
  232. package/dist/plot/index.d.ts +6 -2
  233. package/dist/plot/index.js +6 -2
  234. package/dist/plot/interactions.d.ts +8 -10
  235. package/dist/plot/interactions.js +2 -3
  236. package/dist/plot/layout.d.ts +11 -2
  237. package/dist/plot/layout.js +44 -17
  238. package/dist/plot/reference-line.d.ts +5 -22
  239. package/dist/plot/reference-line.js +12 -84
  240. package/dist/plot/scales.js +24 -36
  241. package/dist/plot/types.d.ts +53 -40
  242. package/dist/plot/types.js +12 -7
  243. package/dist/plot/utils/label-placement.d.ts +32 -15
  244. package/dist/plot/utils/label-placement.js +227 -63
  245. package/dist/plot/utils/series-visibility.js +2 -3
  246. package/dist/plot/utils.d.ts +1 -0
  247. package/dist/plot/utils.js +14 -0
  248. package/dist/rdf/RdfPlot.svelte +173 -132
  249. package/dist/rdf/calc-rdf.js +4 -5
  250. package/dist/sanitize.d.ts +4 -0
  251. package/dist/sanitize.js +107 -0
  252. package/dist/settings.d.ts +21 -6
  253. package/dist/settings.js +63 -19
  254. package/dist/spectral/Bands.svelte +963 -412
  255. package/dist/spectral/Bands.svelte.d.ts +22 -2
  256. package/dist/spectral/BandsAndDos.svelte +90 -49
  257. package/dist/spectral/BrillouinBandsDos.svelte +151 -93
  258. package/dist/spectral/Dos.svelte +389 -258
  259. package/dist/spectral/helpers.d.ts +23 -1
  260. package/dist/spectral/helpers.js +119 -51
  261. package/dist/spectral/types.d.ts +2 -0
  262. package/dist/state.svelte.d.ts +1 -1
  263. package/dist/state.svelte.js +3 -2
  264. package/dist/structure/Arrow.svelte +59 -20
  265. package/dist/structure/AtomLegend.svelte +231 -129
  266. package/dist/structure/AtomLegend.svelte.d.ts +1 -1
  267. package/dist/structure/Bond.svelte +73 -47
  268. package/dist/structure/CanvasTooltip.svelte +10 -2
  269. package/dist/structure/CellSelect.svelte +148 -51
  270. package/dist/structure/Cylinder.svelte +33 -17
  271. package/dist/structure/Lattice.svelte +88 -33
  272. package/dist/structure/Structure.svelte +1077 -821
  273. package/dist/structure/Structure.svelte.d.ts +1 -1
  274. package/dist/structure/StructureControls.svelte +373 -139
  275. package/dist/structure/StructureControls.svelte.d.ts +1 -1
  276. package/dist/structure/StructureExportPane.svelte +124 -89
  277. package/dist/structure/StructureExportPane.svelte.d.ts +1 -1
  278. package/dist/structure/StructureInfoPane.svelte +304 -231
  279. package/dist/structure/StructureScene.svelte +919 -445
  280. package/dist/structure/StructureScene.svelte.d.ts +16 -7
  281. package/dist/structure/atom-properties.d.ts +6 -2
  282. package/dist/structure/atom-properties.js +42 -29
  283. package/dist/structure/bonding.js +6 -7
  284. package/dist/structure/export.js +22 -34
  285. package/dist/structure/ferrox-wasm-types.d.ts +3 -2
  286. package/dist/structure/ferrox-wasm-types.js +0 -3
  287. package/dist/structure/ferrox-wasm.d.ts +3 -2
  288. package/dist/structure/ferrox-wasm.js +2 -3
  289. package/dist/structure/index.d.ts +16 -0
  290. package/dist/structure/index.js +88 -6
  291. package/dist/structure/measure.d.ts +2 -2
  292. package/dist/structure/measure.js +4 -44
  293. package/dist/structure/parse.js +130 -155
  294. package/dist/structure/partial-occupancy.d.ts +25 -0
  295. package/dist/structure/partial-occupancy.js +99 -0
  296. package/dist/structure/pbc.d.ts +1 -0
  297. package/dist/structure/pbc.js +16 -6
  298. package/dist/structure/supercell.d.ts +2 -2
  299. package/dist/structure/supercell.js +12 -22
  300. package/dist/structure/validation.js +5 -3
  301. package/dist/symmetry/SymmetryStats.svelte +94 -37
  302. package/dist/symmetry/WyckoffTable.svelte +42 -14
  303. package/dist/symmetry/cell-transform.js +5 -3
  304. package/dist/symmetry/index.d.ts +7 -4
  305. package/dist/symmetry/index.js +87 -21
  306. package/dist/symmetry/spacegroups.js +148 -148
  307. package/dist/table/HeatmapTable.svelte +1112 -516
  308. package/dist/table/HeatmapTable.svelte.d.ts +12 -1
  309. package/dist/table/ToggleMenu.svelte +125 -90
  310. package/dist/table/index.d.ts +2 -0
  311. package/dist/table/index.js +2 -4
  312. package/dist/theme/ThemeControl.svelte +21 -12
  313. package/dist/time.js +4 -1
  314. package/dist/tooltip/TooltipContent.svelte +33 -8
  315. package/dist/trajectory/Trajectory.svelte +889 -687
  316. package/dist/trajectory/TrajectoryError.svelte +14 -3
  317. package/dist/trajectory/TrajectoryExportPane.svelte +148 -90
  318. package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +1 -1
  319. package/dist/trajectory/TrajectoryInfoPane.svelte +272 -143
  320. package/dist/trajectory/constants.d.ts +6 -0
  321. package/dist/trajectory/constants.js +7 -0
  322. package/dist/trajectory/extract.js +13 -31
  323. package/dist/trajectory/format-detect.d.ts +9 -0
  324. package/dist/trajectory/format-detect.js +76 -0
  325. package/dist/trajectory/frame-reader.d.ts +17 -0
  326. package/dist/trajectory/frame-reader.js +332 -0
  327. package/dist/trajectory/helpers.d.ts +14 -0
  328. package/dist/trajectory/helpers.js +172 -0
  329. package/dist/trajectory/index.d.ts +1 -0
  330. package/dist/trajectory/index.js +23 -14
  331. package/dist/trajectory/parse/ase.d.ts +2 -0
  332. package/dist/trajectory/parse/ase.js +77 -0
  333. package/dist/trajectory/parse/hdf5.d.ts +2 -0
  334. package/dist/trajectory/parse/hdf5.js +129 -0
  335. package/dist/trajectory/parse/index.d.ts +12 -0
  336. package/dist/trajectory/parse/index.js +299 -0
  337. package/dist/trajectory/parse/lammps.d.ts +5 -0
  338. package/dist/trajectory/parse/lammps.js +179 -0
  339. package/dist/trajectory/parse/vasp.d.ts +2 -0
  340. package/dist/trajectory/parse/vasp.js +68 -0
  341. package/dist/trajectory/parse/xyz.d.ts +2 -0
  342. package/dist/trajectory/parse/xyz.js +110 -0
  343. package/dist/trajectory/plotting.js +13 -8
  344. package/dist/trajectory/types.d.ts +11 -0
  345. package/dist/trajectory/types.js +1 -0
  346. package/dist/utils.d.ts +3 -0
  347. package/dist/utils.js +17 -0
  348. package/dist/xrd/XrdPlot.svelte +337 -245
  349. package/dist/xrd/broadening.js +14 -9
  350. package/dist/xrd/calc-xrd.js +12 -19
  351. package/dist/xrd/parse.d.ts +1 -1
  352. package/dist/xrd/parse.js +17 -17
  353. package/package.json +103 -101
  354. package/readme.md +4 -4
  355. package/dist/trajectory/parse.d.ts +0 -42
  356. package/dist/trajectory/parse.js +0 -1267
  357. /package/dist/element/{data.json.d.ts → data.json.gz.d.ts} +0 -0
  358. /package/dist/theme/{themes.js → themes.mjs} +0 -0
@@ -1,197 +1,253 @@
1
- <script lang="ts">import { PLOT_COLORS } from '../colors';
2
- import { StatusMessage } from '../feedback';
3
- import { decompress_file, handle_url_drop } from '../io';
4
- import { format_value } from '../labels';
5
- import { BarPlot } from '../plot';
6
- import { parse_any_structure } from '../structure/parse';
7
- import { is_crystal } from '../structure/validation';
8
- import { SvelteMap, SvelteSet } from 'svelte/reactivity';
9
- import { calc_coordination_nums } from './calc-coordination';
10
- let { structures, strategy = `electroneg_ratio`, split_mode = `by_element`, mode = $bindable(`grouped`), orientation = `vertical`, x_axis = {}, y_axis = {}, allow_file_drop = true, on_file_drop, loading = $bindable(false), error_msg = $bindable(), ...rest } = $props();
11
- let dragover = $state(false);
12
- let dropped_entries = $state([]);
13
- let is_horizontal = $derived(orientation === `horizontal`);
14
- // Normalize input to consistent array of { label, structure, color }
15
- const structure_entries = $derived.by(() => {
16
- if (!structures)
17
- return [];
1
+ <script lang="ts">
2
+ import { PLOT_COLORS } from '../colors'
3
+ import { StatusMessage } from '../feedback'
4
+ import { create_file_drop_handler } from '../io'
5
+ import { format_value } from '../labels'
6
+ import { BarPlot } from '../plot'
7
+ import type {
8
+ AxisConfig,
9
+ BarHandlerProps,
10
+ BarSeries,
11
+ Orientation,
12
+ } from '../plot/types'
13
+ import type { AnyStructure } from '../structure'
14
+ import type { BondingStrategy } from '../structure/bonding'
15
+ import { parse_any_structure } from '../structure/parse'
16
+ import { is_crystal } from '../structure/validation'
17
+ import type { ComponentProps } from 'svelte'
18
+ import { SvelteMap, SvelteSet } from 'svelte/reactivity'
19
+ import { calc_coordination_nums, type CoordinationData } from './calc-coordination'
20
+ import type { SplitMode } from './index'
21
+
22
+ type CoordinationMetadata = {
23
+ element?: string
24
+ structure_label?: string
25
+ } & Record<string, unknown>
26
+
27
+ interface StructureEntry {
28
+ label: string
29
+ structure: AnyStructure
30
+ color?: string
31
+ data?: CoordinationData
32
+ }
33
+ let {
34
+ structures,
35
+ strategy = `electroneg_ratio`,
36
+ split_mode = `by_element`,
37
+ mode = $bindable(`grouped`),
38
+ orientation = `vertical` as Orientation,
39
+ x_axis = {},
40
+ y_axis = {},
41
+ allow_file_drop = true,
42
+ on_file_drop,
43
+ loading = $bindable(false),
44
+ error_msg = $bindable(),
45
+ ...rest
46
+ }: Omit<ComponentProps<typeof BarPlot>, `series`> & {
47
+ structures:
48
+ | AnyStructure
49
+ | Record<string, AnyStructure | { structure: AnyStructure; color?: string }>
50
+ | StructureEntry[]
51
+ strategy?: BondingStrategy
52
+ split_mode?: SplitMode
53
+ x_axis?: AxisConfig
54
+ y_axis?: AxisConfig
55
+ allow_file_drop?: boolean
56
+ on_file_drop?: (content: string | ArrayBuffer, filename: string) => void
57
+ loading?: boolean
58
+ error_msg?: string
59
+ } = $props()
60
+
61
+ let dragover = $state(false)
62
+ let dropped_entries = $state<StructureEntry[]>([])
63
+ let is_horizontal = $derived(orientation === `horizontal`)
64
+
65
+ // Normalize input to consistent array of { label, structure, color }
66
+ const structure_entries = $derived.by<StructureEntry[]>(() => {
67
+ if (!structures) return []
68
+
18
69
  const base_entries = Array.isArray(structures)
19
- ? structures
20
- : (is_crystal(structures)
21
- ? [{ label: `Structure`, structure: structures }]
22
- : Object.entries(structures).map(([label, value]) => `structure` in value
23
- ? { label, ...value }
24
- : { label, structure: value }));
70
+ ? (structures as StructureEntry[])
71
+ : (is_crystal(structures)
72
+ ? [{ label: `Structure`, structure: structures as AnyStructure }]
73
+ : Object.entries(
74
+ structures as Record<
75
+ string,
76
+ AnyStructure | { structure: AnyStructure; color?: string }
77
+ >,
78
+ ).map(([label, value]) =>
79
+ `structure` in value
80
+ ? { label, ...value }
81
+ : { label, structure: value as AnyStructure }
82
+ ))
83
+
25
84
  // Merge user-provided structures with dropped structures
26
- return [...base_entries, ...dropped_entries];
27
- });
28
- // Compute coordination data for each structure
29
- const entries_with_data = $derived(structure_entries.map((entry) => ({
85
+ return [...base_entries, ...dropped_entries]
86
+ })
87
+
88
+ // Compute coordination data for each structure
89
+ const entries_with_data = $derived(structure_entries.map((entry) => ({
30
90
  ...entry,
31
91
  data: calc_coordination_nums(entry.structure, strategy),
32
- })));
33
- // Compute appropriate ranges
34
- const ranges = $derived.by(() => {
92
+ })))
93
+
94
+ // Compute appropriate ranges
95
+ const ranges = $derived.by(() => {
35
96
  // CN axis should always start at 0 and show at least [0,4]
36
- let max_cn = 4; // minimum max value
97
+ let max_cn = 4 // minimum max value
37
98
  for (const entry of entries_with_data) {
38
- for (const [cn] of entry.data.cn_histogram)
39
- max_cn = Math.max(max_cn, cn);
99
+ for (const [cn] of entry.data.cn_histogram) max_cn = Math.max(max_cn, cn)
40
100
  }
41
- const cn_range = [-0.5, max_cn + 0.5];
42
- return { count: [0, null], cn: cn_range }; // Count axis should always start at 0
43
- });
44
- // Derive integer CN ticks for axis labels
45
- const cn_ticks = $derived.by(() => {
46
- const all_cns = new SvelteSet();
101
+ const cn_range: [number, number] = [-0.5, max_cn + 0.5]
102
+
103
+ return { count: [0, null] as [number, null], cn: cn_range } // Count axis should always start at 0
104
+ })
105
+
106
+ // Derive integer CN ticks for axis labels
107
+ const cn_ticks = $derived.by(() => {
108
+ const all_cns = new SvelteSet<number>()
47
109
  // Always include minimum CN values 0-4
48
- for (let idx = 0; idx <= 4; idx++)
49
- all_cns.add(idx);
110
+ for (let idx = 0; idx <= 4; idx++) all_cns.add(idx)
50
111
  // Add actual CN values from data
51
112
  for (const entry of entries_with_data) {
52
- for (const [cn] of entry.data.cn_histogram)
53
- all_cns.add(cn);
113
+ for (const [cn] of entry.data.cn_histogram) all_cns.add(cn)
54
114
  }
55
- return Array.from(all_cns).sort((cn1, cn2) => cn1 - cn2);
56
- });
57
- // Build BarPlot series based on split_mode
58
- const bar_series = $derived.by(() => {
115
+ return Array.from(all_cns).sort((cn1, cn2) => cn1 - cn2)
116
+ })
117
+
118
+ // Build BarPlot series based on split_mode
119
+ const bar_series = $derived.by<BarSeries<CoordinationMetadata>[]>(() => {
59
120
  if (split_mode === `by_element`) {
60
- // One series per element across all structures
61
- const element_series_map = new SvelteMap();
62
- // Collect all unique CNs across all elements
63
- const all_cns = new SvelteSet();
64
- for (const entry of entries_with_data) {
65
- for (const [element, cn_histogram] of entry.data.cn_histogram_by_element) {
66
- if (!element_series_map.has(element)) {
67
- element_series_map.set(element, new SvelteMap());
68
- }
69
- const element_map = element_series_map.get(element);
70
- for (const [cn, count] of cn_histogram) {
71
- all_cns.add(cn);
72
- element_map.set(cn, (element_map.get(cn) ?? 0) + count);
73
- }
74
- }
75
- }
76
- // Sort CNs for consistent x-axis
77
- const sorted_cns = Array.from(all_cns).sort((a, b) => a - b);
78
- // Convert map to array and ensure all series have same x-values
79
- return Array.from(element_series_map.entries())
80
- .sort((a, b) => a[0].localeCompare(b[0]))
81
- .map(([element, cn_map], idx) => {
82
- return {
83
- x: sorted_cns,
84
- y: sorted_cns.map((cn) => cn_map.get(cn) ?? 0),
85
- label: element,
86
- color: PLOT_COLORS[idx % PLOT_COLORS.length],
87
- bar_width: 0.8,
88
- visible: true,
89
- metadata: { element },
90
- };
91
- });
92
- }
93
- else if (split_mode === `by_structure`) {
94
- // One series per structure
95
- // First collect all unique CNs
96
- const all_cns = new SvelteSet();
97
- for (const entry of entries_with_data) {
98
- for (const [cn] of entry.data.cn_histogram) {
99
- all_cns.add(cn);
100
- }
101
- }
102
- const sorted_cns = Array.from(all_cns).sort((a, b) => a - b);
103
- return entries_with_data.map((entry, idx) => {
104
- return {
105
- x: sorted_cns,
106
- y: sorted_cns.map((cn) => entry.data.cn_histogram.get(cn) ?? 0),
107
- label: entry.label,
108
- color: entry.color ?? PLOT_COLORS[idx % PLOT_COLORS.length],
109
- bar_width: 0.8,
110
- visible: true,
111
- metadata: { structure_label: entry.label },
112
- };
113
- });
114
- }
115
- else {
116
- // split_mode === 'none': combine all into single series
117
- const combined_histogram = new SvelteMap();
118
- for (const entry of entries_with_data) {
119
- for (const [cn, count] of entry.data.cn_histogram) {
120
- combined_histogram.set(cn, (combined_histogram.get(cn) ?? 0) + count);
121
- }
121
+ // One series per element across all structures
122
+ const element_series_map = new SvelteMap<string, Map<number, number>>()
123
+
124
+ // Collect all unique CNs across all elements
125
+ const all_cns = new SvelteSet<number>()
126
+
127
+ for (const entry of entries_with_data) {
128
+ for (const [element, cn_histogram] of entry.data.cn_histogram_by_element) {
129
+ if (!element_series_map.has(element)) {
130
+ element_series_map.set(element, new SvelteMap())
131
+ }
132
+ const element_map = element_series_map.get(element)
133
+ if (!element_map) continue
134
+
135
+ for (const [cn, count] of cn_histogram) {
136
+ all_cns.add(cn)
137
+ element_map.set(cn, (element_map.get(cn) ?? 0) + count)
138
+ }
122
139
  }
123
- const x_vals = Array.from(combined_histogram.keys()).sort((a, b) => a - b);
124
- const y_vals = x_vals.map((cn) => combined_histogram.get(cn));
125
- return [
126
- {
127
- x: x_vals,
128
- y: y_vals,
129
- label: `All Sites`,
130
- color: PLOT_COLORS[0],
131
- bar_width: 0.8,
132
- visible: true,
133
- metadata: {},
134
- },
135
- ];
136
- }
137
- });
138
- async function handle_file_drop(event) {
139
- event.preventDefault();
140
- dragover = false;
141
- if (!allow_file_drop)
142
- return;
143
- loading = true;
144
- error_msg = undefined;
145
- const compute_and_add = (content, filename) => {
146
- try {
147
- const text_content = content instanceof ArrayBuffer
148
- ? new TextDecoder().decode(content)
149
- : content;
150
- const parsed_structure = parse_any_structure(text_content, filename);
151
- if (is_crystal(parsed_structure)) {
152
- dropped_entries = [{
153
- label: filename || `Dropped structure`,
154
- structure: parsed_structure,
155
- }, ...dropped_entries];
156
- }
157
- else {
158
- error_msg = `Structure has no lattice or sites; cannot compute coordination`;
159
- }
140
+ }
141
+
142
+ // Sort CNs for consistent x-axis
143
+ const sorted_cns = Array.from(all_cns).sort((a, b) => a - b)
144
+
145
+ // Convert map to array and ensure all series have same x-values
146
+ return Array.from(element_series_map.entries())
147
+ .sort((a, b) => a[0].localeCompare(b[0]))
148
+ .map(([element, cn_map], idx) => {
149
+ return {
150
+ x: sorted_cns,
151
+ y: sorted_cns.map((cn) => cn_map.get(cn) ?? 0),
152
+ label: element,
153
+ color: PLOT_COLORS[idx % PLOT_COLORS.length],
154
+ bar_width: 0.8,
155
+ visible: true,
156
+ metadata: { element },
157
+ }
158
+ })
159
+ } else if (split_mode === `by_structure`) {
160
+ // One series per structure
161
+ // First collect all unique CNs
162
+ const all_cns = new SvelteSet<number>()
163
+ for (const entry of entries_with_data) {
164
+ for (const [cn] of entry.data.cn_histogram) {
165
+ all_cns.add(cn)
160
166
  }
161
- catch (exc) {
162
- error_msg = `Failed to process structure: ${exc instanceof Error ? exc.message : String(exc)}`;
167
+ }
168
+ const sorted_cns = Array.from(all_cns).sort((a, b) => a - b)
169
+
170
+ return entries_with_data.map((entry, idx) => {
171
+ return {
172
+ x: sorted_cns,
173
+ y: sorted_cns.map((cn) => entry.data.cn_histogram.get(cn) ?? 0),
174
+ label: entry.label,
175
+ color: entry.color ?? PLOT_COLORS[idx % PLOT_COLORS.length],
176
+ bar_width: 0.8,
177
+ visible: true,
178
+ metadata: { structure_label: entry.label },
163
179
  }
164
- };
165
- try {
166
- // Handle URL-based drops
167
- const handled = await handle_url_drop(event, on_file_drop || compute_and_add)
168
- .catch(() => false);
169
- if (handled)
170
- return;
171
- const file = event.dataTransfer?.files?.[0];
172
- if (file) {
173
- try {
174
- const { content, filename } = await decompress_file(file);
175
- if (content)
176
- (on_file_drop || compute_and_add)(content, filename);
177
- }
178
- catch (exc) {
179
- error_msg = `Failed to load file ${file.name}: ${exc instanceof Error ? exc.message : String(exc)}`;
180
- }
180
+ })
181
+ } else {
182
+ // split_mode === 'none': combine all into single series
183
+ const combined_histogram = new SvelteMap<number, number>()
184
+
185
+ for (const entry of entries_with_data) {
186
+ for (const [cn, count] of entry.data.cn_histogram) {
187
+ combined_histogram.set(cn, (combined_histogram.get(cn) ?? 0) + count)
181
188
  }
189
+ }
190
+
191
+ const x_vals = Array.from(combined_histogram.keys()).sort((a, b) => a - b)
192
+ const y_vals = x_vals.map((cn) => combined_histogram.get(cn) ?? 0)
193
+
194
+ return [
195
+ {
196
+ x: x_vals,
197
+ y: y_vals,
198
+ label: `All Sites`,
199
+ color: PLOT_COLORS[0],
200
+ bar_width: 0.8,
201
+ visible: true,
202
+ metadata: {},
203
+ },
204
+ ]
182
205
  }
183
- finally {
184
- loading = false;
206
+ })
207
+
208
+ const compute_and_add = (content: string | ArrayBuffer, filename: string) => {
209
+ try {
210
+ const text_content = content instanceof ArrayBuffer
211
+ ? new TextDecoder().decode(content)
212
+ : content
213
+ const parsed_structure = parse_any_structure(text_content, filename)
214
+ if (is_crystal(parsed_structure)) {
215
+ dropped_entries = [{
216
+ label: filename || `Dropped structure`,
217
+ structure: parsed_structure,
218
+ }, ...dropped_entries]
219
+ } else {
220
+ error_msg = `Structure has no lattice or sites; cannot compute coordination`
221
+ }
222
+ } catch (exc) {
223
+ error_msg = `Failed to process structure: ${
224
+ exc instanceof Error ? exc.message : String(exc)
225
+ }`
185
226
  }
186
- }
187
- let display = $state({ x_zero_line: false, y_zero_line: false });
188
- // Update display when orientation changes
189
- $effect(() => {
190
- display.x_zero_line = is_horizontal;
191
- display.y_zero_line = !is_horizontal;
192
- });
193
- const cn_axis = { label: `Coordination Number`, format: `d` };
194
- const count_axis = { label: `Count`, format: `d` };
227
+ }
228
+
229
+ const handle_file_drop = create_file_drop_handler({
230
+ allow: () => allow_file_drop,
231
+ on_drop: (content, filename) =>
232
+ (on_file_drop || compute_and_add)(content, filename),
233
+ on_error: (msg) => {
234
+ error_msg = msg
235
+ },
236
+ set_loading: (val) => {
237
+ loading = val
238
+ if (val) [error_msg, dragover] = [undefined, false]
239
+ },
240
+ })
241
+
242
+ let display = $state({ x_zero_line: false, y_zero_line: false })
243
+ // Update display when orientation changes
244
+ $effect(() => {
245
+ display.x_zero_line = is_horizontal
246
+ display.y_zero_line = !is_horizontal
247
+ })
248
+
249
+ const cn_axis = { label: `Coordination Number`, format: `d` }
250
+ const count_axis = { label: `Count`, format: `d` }
195
251
  </script>
196
252
 
197
253
  <StatusMessage bind:message={error_msg} type="error" dismissible />
@@ -1,26 +1,69 @@
1
- <script lang="ts">let { symbol = ``, name = ``, shells, adapt_size = true, shell_width = 20, size = adapt_size ? (shells.length + 1) * 2 * shell_width + 30 : 270, base_fill = `var(--text-color)`, orbital_period = 3, nucleus_props = {}, shell_props = {}, electron_props = {}, highlight_shell = null, number_electrons = false, electron_label_props = {}, ...rest } = $props();
2
- // Bohr atom electron orbital period is given by
3
- // T = (n^3 h^3) / (4pi^2 m K e^4 Z^2) = 1.52 * 10^-16 * n^3 / Z^2 s
4
- // with n the shell number, Z the atomic number, m the mass of the electron
5
- let _nucleus_props = $derived({
1
+ <script lang="ts">
2
+ import type { SVGAttributes } from 'svelte/elements'
3
+
4
+ type Props = SVGAttributes<SVGSVGElement> & {
5
+ // https://svelte.dev/repl/17d71b590f554b5a9eba6e04023dd41c
6
+ symbol?: string // usually H, He, etc. but can be anything
7
+ name?: string // usually Hydrogen, Helium, etc. but can be anything
8
+ shells: number[]
9
+ adapt_size?: boolean
10
+ shell_width?: number
11
+ size?: number
12
+ base_fill?: string
13
+ orbital_period?: number // time for inner-most electron orbit in seconds, 0 for no motion
14
+ // set properties like size, fill, stroke, stroke-width, for nucleus and electrons here
15
+ nucleus_props?: Record<string, string | number>
16
+ shell_props?: Record<string, string | number>
17
+ electron_props?: Record<string, string | number>
18
+ highlight_shell?: number | null
19
+ // if function, it'll be called with electron index and should return a string
20
+ number_electrons?:
21
+ | boolean
22
+ | `hierarchical`
23
+ | `sequential`
24
+ | ((idx: number) => string)
25
+ electron_label_props?: Record<string, string | number>
26
+ }
27
+
28
+ let {
29
+ symbol = ``,
30
+ name = ``,
31
+ shells,
32
+ adapt_size = true,
33
+ shell_width = 20,
34
+ size = adapt_size ? (shells.length + 1) * 2 * shell_width + 30 : 270,
35
+ base_fill = `var(--text-color)`,
36
+ orbital_period = 3,
37
+ nucleus_props = {},
38
+ shell_props = {},
39
+ electron_props = {},
40
+ highlight_shell = null,
41
+ number_electrons = false,
42
+ electron_label_props = {},
43
+ ...rest
44
+ }: Props = $props()
45
+
46
+ // Bohr atom electron orbital period is given by
47
+ // T = (n^3 h^3) / (4pi^2 m K e^4 Z^2) = 1.52 * 10^-16 * n^3 / Z^2 s
48
+ // with n the shell number, Z the atomic number, m the mass of the electron
49
+ let _nucleus_props = $derived({
6
50
  r: 20,
7
51
  fill: base_fill,
8
52
  'fill-opacity': `0.3`,
9
53
  ...nucleus_props,
10
- });
11
- let _shell_props = $derived({
54
+ })
55
+ let _shell_props = $derived({
12
56
  stroke: base_fill,
13
57
  fill: `none`,
14
58
  ...shell_props,
15
- });
16
- let _electron_props = $derived({
59
+ })
60
+ let _electron_props = $derived({
17
61
  r: 3,
18
62
  stroke: base_fill,
19
63
  fill: `blue`,
20
64
  ...electron_props,
21
- });
22
- let viewBox = $derived(`-${size / 2}, -${size / 2}, ${size}, ${size}`);
23
- export {};
65
+ })
66
+ let viewBox = $derived(`-${size / 2}, -${size / 2}, ${size}, ${size}`)
24
67
  </script>
25
68
 
26
69
  <svg
@@ -42,7 +85,7 @@ export {};
42
85
  {/if}
43
86
 
44
87
  <!-- electron orbitals -->
45
- {#each shells as electrons, shell_idx ([electrons, shell_idx])}
88
+ {#each shells as electrons, shell_idx (`${shell_idx}-${electrons}`)}
46
89
  {@const n = shell_idx + 1}
47
90
  {@const shell_radius = _nucleus_props.r + n * shell_width}
48
91
  {@const active = n === highlight_shell}
@@ -1,5 +1,10 @@
1
- <script lang="ts">let { element, ...rest } = $props();
2
- export {};
1
+ <script lang="ts">
2
+ import type { ChemicalElement } from './'
3
+ import type { HTMLAttributes } from 'svelte/elements'
4
+
5
+ let { element, ...rest }: HTMLAttributes<HTMLHeadingElement> & {
6
+ element: ChemicalElement
7
+ } = $props()
3
8
  </script>
4
9
 
5
10
  <h2 {...rest}>
@@ -1,12 +1,18 @@
1
- <script lang="ts">import Icon from '../Icon.svelte';
2
- let { element, missing_msg = `No image for `, ...rest } = $props();
3
- let { name, number } = $derived(element ?? {});
4
- let file = $derived(`elements/${number}-${name?.toLowerCase()}.avif`);
5
- let hidden = $state(false);
6
- $effect.pre(() => {
7
- if (file)
8
- hidden = false;
9
- }); // reset hidden to false when file changes
1
+ <script lang="ts">
2
+ import type { ChemicalElement } from './'
3
+ import Icon from '../Icon.svelte'
4
+ import type { HTMLAttributes } from 'svelte/elements'
5
+
6
+ let { element, missing_msg = `No image for `, ...rest }:
7
+ & HTMLAttributes<HTMLImageElement | HTMLDivElement>
8
+ & { element: ChemicalElement; missing_msg?: string } = $props()
9
+
10
+ let { name, number } = $derived(element ?? {})
11
+ let file = $derived(`elements/${number}-${name?.toLowerCase()}.avif`)
12
+ let hidden = $state(false)
13
+ $effect.pre(() => {
14
+ if (file) hidden = false
15
+ }) // reset hidden to false when file changes
10
16
  </script>
11
17
 
12
18
  {#if name && number}
@@ -1,7 +1,13 @@
1
- <script lang="ts">import Icon from '../Icon.svelte';
2
- import { format_num } from '../labels';
3
- import ElementHeading from './ElementHeading.svelte';
4
- let { element, ...rest } = $props();
1
+ <script lang="ts">
2
+ import type { ChemicalElement } from './'
3
+ import Icon from '../Icon.svelte'
4
+ import { format_num } from '../labels'
5
+ import ElementHeading from './ElementHeading.svelte'
6
+ import type { HTMLAttributes } from 'svelte/elements'
7
+
8
+ let { element, ...rest }: HTMLAttributes<HTMLDivElement> & {
9
+ element: ChemicalElement | null
10
+ } = $props()
5
11
  </script>
6
12
 
7
13
  {#if element}