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,112 +1,169 @@
1
- <script lang="ts">import { format_num, format_value } from '../labels';
2
- import { BarPlot } from './';
3
- import * as symmetry from '../symmetry';
4
- import * as spg from '../symmetry/spacegroups';
5
- import { SvelteMap } from 'svelte/reactivity';
6
- // Merge tick config with default rotation, preserving user overrides
7
- const with_rotation = (tick, default_rot) => ({
1
+ <script lang="ts">
2
+ import { format_num, format_value } from '../labels'
3
+ import type { BarHandlerProps, BarSeries, TickConfig } from './'
4
+ import { BarPlot } from './'
5
+ import type { CrystalSystem } from '../symmetry'
6
+ import * as symmetry from '../symmetry'
7
+ import * as spg from '../symmetry/spacegroups'
8
+ import type { ComponentProps } from 'svelte'
9
+ import { SvelteMap } from 'svelte/reactivity'
10
+
11
+ // Merge tick config with default rotation, preserving user overrides
12
+ const with_rotation = (
13
+ tick: TickConfig | undefined,
14
+ default_rot: number,
15
+ ): TickConfig => ({
8
16
  ...tick,
9
17
  label: { ...tick?.label, rotation: tick?.label?.rotation ?? default_rot },
10
- });
11
- const MAX_SPACEGROUP = 230;
12
- let { data, show_counts = true, orientation = `vertical`, x_axis = {}, y_axis = {}, ...rest } = $props();
13
- // Normalize input data to space group numbers
14
- const normalized_data = $derived(data.map(spg.normalize_spacegroup).filter((sg) => sg !== null));
15
- // Compute histogram of space group numbers
16
- const histogram = $derived.by(() => {
17
- const hist = new SvelteMap();
18
+ })
19
+
20
+ const MAX_SPACEGROUP = 230
21
+ let {
22
+ data,
23
+ show_counts = true,
24
+ orientation = `vertical`,
25
+ x_axis = {},
26
+ y_axis = {},
27
+ ...rest
28
+ }: ComponentProps<typeof BarPlot> & {
29
+ data: (number | string)[]
30
+ show_counts?: boolean
31
+ } = $props()
32
+
33
+ // Normalize input data to space group numbers
34
+ const normalized_data = $derived(
35
+ data.map(spg.normalize_spacegroup).filter((sg): sg is number => sg !== null),
36
+ )
37
+
38
+ // Compute histogram of space group numbers
39
+ const histogram = $derived.by(() => {
40
+ const hist = new SvelteMap<number, number>()
41
+
18
42
  // Count occurrences
19
43
  for (const sg of normalized_data) {
20
- hist.set(sg, (hist.get(sg) ?? 0) + 1);
44
+ hist.set(sg, (hist.get(sg) ?? 0) + 1)
21
45
  }
22
- return hist;
23
- });
24
- // Group counts by crystal system
25
- const crystal_system_stats = $derived.by(() => {
26
- const stats = new SvelteMap();
46
+
47
+ return hist
48
+ })
49
+
50
+ // Group counts by crystal system
51
+ const crystal_system_stats = $derived.by(() => {
52
+ const stats = new SvelteMap<
53
+ CrystalSystem,
54
+ { count: number; spacegroups: number[] }
55
+ >()
56
+
27
57
  for (const system of symmetry.CRYSTAL_SYSTEMS) {
28
- stats.set(system, { count: 0, spacegroups: [] });
58
+ stats.set(system, { count: 0, spacegroups: [] })
29
59
  }
60
+
30
61
  for (const [sg, count] of histogram) {
31
- const system = spg.spacegroup_to_crystal_sys(sg);
32
- if (system) {
33
- const stat = stats.get(system);
34
- stat.count += count;
35
- stat.spacegroups.push(sg);
36
- }
62
+ const system = spg.spacegroup_to_crystal_sys(sg)
63
+ if (!system) continue
64
+ const stat = stats.get(system)
65
+ if (!stat) continue
66
+ stat.count += count
67
+ stat.spacegroups.push(sg)
37
68
  }
38
- return stats;
39
- });
40
- // Create sorted list of space groups for x-axis
41
- const sorted_spacegroups = $derived(Array.from(histogram.keys()).sort((a, b) => a - b));
42
- // Smart tick selection: thin out ticks for dense data
43
- const x_axis_ticks = $derived.by(() => {
44
- const non_zero_count = sorted_spacegroups.filter((sg) => (histogram.get(sg) ?? 0) > 0).length;
69
+
70
+ return stats
71
+ })
72
+
73
+ // Create sorted list of space groups for x-axis
74
+ const sorted_spacegroups = $derived(
75
+ Array.from(histogram.keys()).sort((a, b) => a - b),
76
+ )
77
+
78
+ // Smart tick selection: thin out ticks for dense data
79
+ const x_axis_ticks = $derived.by(() => {
80
+ const non_zero_count = sorted_spacegroups.filter(
81
+ (sg) => (histogram.get(sg) ?? 0) > 0,
82
+ ).length
83
+
45
84
  // If data is dense (>40 space groups with data), show only multiples of 5
46
85
  return non_zero_count > 40
47
- ? sorted_spacegroups.filter((sg) => sg % 5 === 0)
48
- : sorted_spacegroups;
49
- });
50
- // Build BarSeries - one series per crystal system for proper coloring
51
- const bar_series = $derived.by(() => {
52
- const series_by_system = new SvelteMap();
86
+ ? sorted_spacegroups.filter((sg) => sg % 5 === 0)
87
+ : sorted_spacegroups
88
+ })
89
+
90
+ // Build BarSeries - one series per crystal system for proper coloring
91
+ const bar_series = $derived.by<BarSeries[]>(() => {
92
+ const series_by_system = new SvelteMap<
93
+ CrystalSystem,
94
+ { x: number[]; y: number[] }
95
+ >()
96
+
53
97
  // Group data by crystal system
54
98
  for (const sg of sorted_spacegroups) {
55
- const system = spg.spacegroup_to_crystal_sys(sg);
56
- if (system) {
57
- let series = series_by_system.get(system);
58
- if (!series) {
59
- series = { x: [], y: [] };
60
- series_by_system.set(system, series);
61
- }
62
- series.x.push(sg);
63
- series.y.push(histogram.get(sg) ?? 0);
99
+ const system = spg.spacegroup_to_crystal_sys(sg)
100
+ if (system) {
101
+ let series = series_by_system.get(system)
102
+ if (!series) {
103
+ series = { x: [], y: [] }
104
+ series_by_system.set(system, series)
64
105
  }
106
+ series.x.push(sg)
107
+ series.y.push(histogram.get(sg) ?? 0)
108
+ }
65
109
  }
110
+
66
111
  // Convert to BarSeries array, maintaining order of crystal systems
67
- const result = [];
112
+ const result: BarSeries[] = []
68
113
  for (const system of symmetry.CRYSTAL_SYSTEMS) {
69
- const data = series_by_system.get(system);
70
- if (data) {
71
- const { x, y } = data;
72
- const color = symmetry.CRYSTAL_SYSTEM_COLORS[system];
73
- result.push({ x, y, color, label: system, bar_width: 0.9, visible: true });
74
- }
114
+ const data = series_by_system.get(system)
115
+ if (data) {
116
+ const { x, y } = data
117
+ const color = symmetry.CRYSTAL_SYSTEM_COLORS[system]
118
+ result.push({ x, y, color, label: system, bar_width: 0.9, visible: true })
119
+ }
75
120
  }
76
- return result;
77
- });
78
- // Always show full space group range (1-230)
79
- const x_range = [0.5, MAX_SPACEGROUP + 0.5];
80
- // Calculate crystal system region boundaries using full theoretical ranges
81
- const crystal_system_regions = $derived.by(() => {
82
- const [range_min, range_max] = x_range;
121
+ return result
122
+ })
123
+
124
+ // Always show full space group range (1-230)
125
+ const x_range: [number, number] = [0.5, MAX_SPACEGROUP + 0.5]
126
+
127
+ // Calculate crystal system region boundaries using full theoretical ranges
128
+ const crystal_system_regions = $derived.by(() => {
129
+ const [range_min, range_max] = x_range
130
+
83
131
  return symmetry.CRYSTAL_SYSTEMS.map((system) => {
84
- const [sg_start, sg_end] = symmetry.CRYSTAL_SYSTEM_RANGES[system];
85
- const stats = crystal_system_stats.get(system);
86
- const count = stats?.count ?? 0;
87
- const color = symmetry.CRYSTAL_SYSTEM_COLORS[system];
88
- return { system, sg_start, sg_end, count, color };
89
- }).filter((region) => region.sg_end >= range_min && region.sg_start <= range_max);
90
- });
91
- const total_count = $derived(normalized_data.length);
92
- // Build axis configurations based on orientation
93
- const x_axis_config = $derived(orientation === `horizontal` ? { ...x_axis, label: x_axis.label ?? `Counts` } : {
94
- ...x_axis,
95
- label: x_axis.label ?? `International Spacegroup Number`,
96
- range: x_range,
97
- ticks: x_axis_ticks,
98
- tick: with_rotation(x_axis.tick, 90), // Rotate ticks 90° to avoid overlap
99
- label_shift: { x: 0, y: 20, ...x_axis.label_shift }, // Move label down for rotated ticks
100
- });
101
- const y_axis_config = $derived(orientation === `horizontal`
102
- ? {
132
+ const [sg_start, sg_end] = symmetry.CRYSTAL_SYSTEM_RANGES[system]
133
+ const stats = crystal_system_stats.get(system)
134
+ const count = stats?.count ?? 0
135
+ const color = symmetry.CRYSTAL_SYSTEM_COLORS[system]
136
+ return { system, sg_start, sg_end, count, color }
137
+ }).filter(
138
+ (region) => region.sg_end >= range_min && region.sg_start <= range_max, // Only visible systems
139
+ )
140
+ })
141
+
142
+ const total_count = $derived(normalized_data.length)
143
+
144
+ // Build axis configurations based on orientation
145
+ const x_axis_config = $derived(
146
+ orientation === `horizontal` ? { ...x_axis, label: x_axis.label ?? `Counts` } : {
147
+ ...x_axis,
148
+ label: x_axis.label ?? `International Spacegroup Number`,
149
+ range: x_range,
150
+ ticks: x_axis_ticks,
151
+ tick: with_rotation(x_axis.tick, 90), // Rotate ticks 90° to avoid overlap
152
+ label_shift: { x: 0, y: 20, ...x_axis.label_shift }, // Move label down for rotated ticks
153
+ },
154
+ )
155
+
156
+ const y_axis_config = $derived(
157
+ orientation === `horizontal`
158
+ ? {
103
159
  ...y_axis,
104
160
  label: y_axis.label ?? `International Spacegroup Number`,
105
161
  range: x_range,
106
162
  ticks: x_axis_ticks,
107
163
  tick: with_rotation(y_axis.tick, 0),
108
- }
109
- : { ...y_axis, label: y_axis.label ?? `Counts` });
164
+ }
165
+ : { ...y_axis, label: y_axis.label ?? `Counts` },
166
+ )
110
167
  </script>
111
168
 
112
169
  {#snippet tooltip(info: BarHandlerProps)}
@@ -1,137 +1,188 @@
1
- <script lang="ts">import { T } from '@threlte/core';
2
- import * as THREE from 'three';
3
- let { config, x_range = [0, 1], y_range = [0, 1], z_range = [0, 1], scene_x = 10, scene_y = 10, scene_z = 5, } = $props();
4
- // Normalize value to scene coordinates (centered around 0)
5
- function normalize(value, [min_val, max_val], scene_size) {
6
- return ((value - min_val) / (max_val - min_val || 1) - 0.5) * scene_size;
7
- }
8
- // Parse color to THREE.Color with fallback
9
- function parse_color(color) {
1
+ <script lang="ts">
2
+ import type { Surface3DConfig } from './types'
3
+ import { T } from '@threlte/core'
4
+ import * as THREE from 'three'
5
+
6
+ let {
7
+ config,
8
+ x_range = [0, 1],
9
+ y_range = [0, 1],
10
+ z_range = [0, 1],
11
+ scene_x = 10,
12
+ scene_y = 10,
13
+ scene_z = 5,
14
+ }: {
15
+ config: Surface3DConfig
16
+ x_range?: [number, number]
17
+ y_range?: [number, number]
18
+ z_range?: [number, number]
19
+ scene_x?: number
20
+ scene_y?: number
21
+ scene_z?: number
22
+ } = $props()
23
+
24
+ // Normalize value to scene coordinates (centered around 0)
25
+ function normalize(
26
+ value: number,
27
+ [min_val, max_val]: [number, number],
28
+ scene_size: number,
29
+ ): number {
30
+ return ((value - min_val) / (max_val - min_val || 1) - 0.5) * scene_size
31
+ }
32
+
33
+ // Parse color to THREE.Color with fallback
34
+ function parse_color(color: string): THREE.Color {
10
35
  try {
11
- return new THREE.Color(color);
36
+ return new THREE.Color(color)
37
+ } catch {
38
+ return new THREE.Color(0x4488ff)
12
39
  }
13
- catch {
14
- return new THREE.Color(0x4488ff);
15
- }
16
- }
17
- // Calculate vertex color based on config
18
- function get_vertex_color(x_val, y_val, z_val) {
19
- if (config.color_fn)
20
- return parse_color(config.color_fn(x_val, y_val, z_val));
21
- if (config.color)
22
- return parse_color(config.color);
40
+ }
41
+
42
+ // Calculate vertex color based on config
43
+ function get_vertex_color(
44
+ x_val: number,
45
+ y_val: number,
46
+ z_val: number,
47
+ ): THREE.Color {
48
+ if (config.color_fn) return parse_color(config.color_fn(x_val, y_val, z_val))
49
+ if (config.color) return parse_color(config.color)
23
50
  // Default: color by z value (blue to red gradient)
24
- const z_norm = (z_val - z_range[0]) / (z_range[1] - z_range[0] || 1);
25
- return new THREE.Color().setHSL(0.66 - z_norm * 0.66, 0.8, 0.5);
26
- }
27
- // Add vertex position (with Y/Z swap for Three.js) and color to arrays
28
- function add_vertex(positions, colors, x_val, y_val, z_val) {
29
- positions.push(normalize(x_val, x_range, scene_x), normalize(z_val, z_range, scene_z), // user Z → Three.js Y (vertical)
30
- normalize(y_val, y_range, scene_y));
31
- const color = get_vertex_color(x_val, y_val, z_val);
32
- colors.push(color.r, color.g, color.b);
33
- }
34
- // Build geometry from positions/colors arrays with optional grid indices
35
- function build_geometry(positions, colors, res_a, res_b, triangles) {
36
- const geom = new THREE.BufferGeometry();
37
- geom.setAttribute(`position`, new THREE.Float32BufferAttribute(positions, 3));
38
- geom.setAttribute(`color`, new THREE.Float32BufferAttribute(colors, 3));
51
+ const z_norm = (z_val - z_range[0]) / (z_range[1] - z_range[0] || 1)
52
+ return new THREE.Color().setHSL(0.66 - z_norm * 0.66, 0.8, 0.5)
53
+ }
54
+
55
+ // Add vertex position (with Y/Z swap for Three.js) and color to arrays
56
+ function add_vertex(
57
+ positions: number[],
58
+ colors: number[],
59
+ x_val: number,
60
+ y_val: number,
61
+ z_val: number,
62
+ ): void {
63
+ positions.push(
64
+ normalize(x_val, x_range, scene_x),
65
+ normalize(z_val, z_range, scene_z), // user Z → Three.js Y (vertical)
66
+ normalize(y_val, y_range, scene_y), // user Y → Three.js Z (depth)
67
+ )
68
+ const color = get_vertex_color(x_val, y_val, z_val)
69
+ colors.push(color.r, color.g, color.b)
70
+ }
71
+
72
+ // Build geometry from positions/colors arrays with optional grid indices
73
+ function build_geometry(
74
+ positions: number[],
75
+ colors: number[],
76
+ res_a?: number,
77
+ res_b?: number,
78
+ triangles?: number[][],
79
+ ): THREE.BufferGeometry {
80
+ const geom = new THREE.BufferGeometry()
81
+ geom.setAttribute(`position`, new THREE.Float32BufferAttribute(positions, 3))
82
+ geom.setAttribute(`color`, new THREE.Float32BufferAttribute(colors, 3))
39
83
  // Set indices: either from explicit triangles or generate grid
40
84
  if (triangles?.length) {
41
- geom.setIndex(triangles.flat());
42
- }
43
- else if (res_a && res_b && res_a >= 2 && res_b >= 2) {
44
- const indices = [];
45
- for (let ib = 0; ib < res_b - 1; ib++) {
46
- for (let ia = 0; ia < res_a - 1; ia++) {
47
- const tl = ib * res_a + ia;
48
- indices.push(tl, tl + res_a, tl + 1, tl + 1, tl + res_a, tl + res_a + 1);
49
- }
85
+ geom.setIndex(triangles.flat())
86
+ } else if (res_a && res_b && res_a >= 2 && res_b >= 2) {
87
+ const indices: number[] = []
88
+ for (let ib = 0; ib < res_b - 1; ib++) {
89
+ for (let ia = 0; ia < res_a - 1; ia++) {
90
+ const tl = ib * res_a + ia
91
+ indices.push(tl, tl + res_a, tl + 1, tl + 1, tl + res_a, tl + res_a + 1)
50
92
  }
51
- geom.setIndex(indices);
93
+ }
94
+ geom.setIndex(indices)
52
95
  }
53
- geom.computeVertexNormals();
54
- return geom;
55
- }
56
- // Parse resolution config into [res_a, res_b]
57
- function get_resolution() {
96
+ geom.computeVertexNormals()
97
+ return geom
98
+ }
99
+
100
+ // Parse resolution config into [res_a, res_b]
101
+ function get_resolution(): [number, number] {
58
102
  return Array.isArray(config.resolution)
59
- ? config.resolution
60
- : [config.resolution ?? 20, config.resolution ?? 20];
61
- }
62
- function create_geometry() {
63
- const [res_a, res_b] = get_resolution();
64
- const positions = [];
65
- const colors = [];
103
+ ? config.resolution
104
+ : [config.resolution ?? 20, config.resolution ?? 20]
105
+ }
106
+
107
+ function create_geometry(): THREE.BufferGeometry | null {
108
+ const [res_a, res_b] = get_resolution()
109
+ const positions: number[] = []
110
+ const colors: number[] = []
111
+
66
112
  if (config.type === `grid` && config.z_fn) {
67
- if (res_a < 2 || res_b < 2)
68
- return new THREE.BufferGeometry();
69
- const [x0, x1] = config.x_range ?? x_range;
70
- const [y0, y1] = config.y_range ?? y_range;
71
- const x_step = (x1 - x0) / (res_a - 1);
72
- const y_step = (y1 - y0) / (res_b - 1);
73
- for (let ib = 0; ib < res_b; ib++) {
74
- for (let ia = 0; ia < res_a; ia++) {
75
- const x_val = x0 + ia * x_step;
76
- const y_val = y0 + ib * y_step;
77
- add_vertex(positions, colors, x_val, y_val, config.z_fn(x_val, y_val));
78
- }
113
+ if (res_a < 2 || res_b < 2) return new THREE.BufferGeometry()
114
+ const [x0, x1] = config.x_range ?? x_range
115
+ const [y0, y1] = config.y_range ?? y_range
116
+ const x_step = (x1 - x0) / (res_a - 1)
117
+ const y_step = (y1 - y0) / (res_b - 1)
118
+ for (let ib = 0; ib < res_b; ib++) {
119
+ for (let ia = 0; ia < res_a; ia++) {
120
+ const x_val = x0 + ia * x_step
121
+ const y_val = y0 + ib * y_step
122
+ add_vertex(positions, colors, x_val, y_val, config.z_fn(x_val, y_val))
79
123
  }
80
- return build_geometry(positions, colors, res_a, res_b);
124
+ }
125
+ return build_geometry(positions, colors, res_a, res_b)
81
126
  }
127
+
82
128
  if (config.type === `parametric` && config.parametric_fn) {
83
- if (res_a < 2 || res_b < 2)
84
- return new THREE.BufferGeometry();
85
- const [u0, u1] = config.u_range ?? [0, 1];
86
- const [v0, v1] = config.v_range ?? [0, 1];
87
- const u_step = (u1 - u0) / (res_a - 1);
88
- const v_step = (v1 - v0) / (res_b - 1);
89
- for (let ib = 0; ib < res_b; ib++) {
90
- for (let ia = 0; ia < res_a; ia++) {
91
- const pt = config.parametric_fn(u0 + ia * u_step, v0 + ib * v_step);
92
- add_vertex(positions, colors, pt.x, pt.y, pt.z);
93
- }
129
+ if (res_a < 2 || res_b < 2) return new THREE.BufferGeometry()
130
+ const [u0, u1] = config.u_range ?? [0, 1]
131
+ const [v0, v1] = config.v_range ?? [0, 1]
132
+ const u_step = (u1 - u0) / (res_a - 1)
133
+ const v_step = (v1 - v0) / (res_b - 1)
134
+ for (let ib = 0; ib < res_b; ib++) {
135
+ for (let ia = 0; ia < res_a; ia++) {
136
+ const pt = config.parametric_fn(u0 + ia * u_step, v0 + ib * v_step)
137
+ add_vertex(positions, colors, pt.x, pt.y, pt.z)
94
138
  }
95
- return build_geometry(positions, colors, res_a, res_b);
139
+ }
140
+ return build_geometry(positions, colors, res_a, res_b)
96
141
  }
142
+
97
143
  if (config.type === `triangulated` && config.points?.length) {
98
- for (const pt of config.points) {
99
- add_vertex(positions, colors, pt.x, pt.y, pt.z);
100
- }
101
- return build_geometry(positions, colors, undefined, undefined, config.triangles);
144
+ for (const pt of config.points) {
145
+ add_vertex(positions, colors, pt.x, pt.y, pt.z)
146
+ }
147
+ return build_geometry(positions, colors, undefined, undefined, config.triangles)
102
148
  }
103
- return null;
104
- }
105
- // Geometry with proper disposal on change/unmount
106
- let geometry = $state(null);
107
- let wireframe_geometry = $state(null);
108
- $effect(() => {
109
- const new_geom = create_geometry();
110
- const new_wireframe = new_geom ? new THREE.WireframeGeometry(new_geom) : null;
111
- geometry = new_geom;
112
- wireframe_geometry = new_wireframe;
149
+
150
+ return null
151
+ }
152
+
153
+ // Geometry with proper disposal on change/unmount
154
+ let geometry: THREE.BufferGeometry | null = $state(null)
155
+ let wireframe_geometry: THREE.WireframeGeometry | null = $state(null)
156
+
157
+ $effect(() => {
158
+ const new_geom = create_geometry()
159
+ const new_wireframe = new_geom ? new THREE.WireframeGeometry(new_geom) : null
160
+ geometry = new_geom
161
+ wireframe_geometry = new_wireframe
113
162
  return () => {
114
- new_geom?.dispose();
115
- new_wireframe?.dispose();
116
- };
117
- });
118
- // Material properties
119
- let is_transparent = $derived((config.opacity ?? 1) < 1);
120
- let material_props = $derived({
163
+ new_geom?.dispose()
164
+ new_wireframe?.dispose()
165
+ }
166
+ })
167
+
168
+ // Material properties
169
+ let is_transparent = $derived((config.opacity ?? 1) < 1)
170
+ let material_props = $derived({
121
171
  transparent: is_transparent,
122
172
  opacity: config.opacity ?? 1,
123
173
  side: (config.double_sided ?? is_transparent)
124
- ? THREE.DoubleSide
125
- : THREE.FrontSide,
174
+ ? THREE.DoubleSide
175
+ : THREE.FrontSide,
126
176
  vertexColors: true,
127
177
  depthWrite: true,
128
- });
129
- let wireframe_props = $derived({
178
+ })
179
+
180
+ let wireframe_props = $derived({
130
181
  color: config.wireframe_color ?? `#333`,
131
182
  linewidth: config.wireframe_width ?? 1,
132
183
  transparent: true,
133
184
  opacity: 0.5,
134
- });
185
+ })
135
186
  </script>
136
187
 
137
188
  {#if geometry}
@@ -0,0 +1,96 @@
1
+ <script lang="ts">
2
+ import type { Vec2 } from '../math'
3
+ import { get_scale_type_name, type ScaleType, type Sides } from './'
4
+
5
+ let {
6
+ display,
7
+ x_scale_fn,
8
+ x2_scale_fn,
9
+ y_scale_fn,
10
+ y2_scale_fn,
11
+ x_range,
12
+ x2_range,
13
+ y_range,
14
+ y2_range,
15
+ x_scale_type,
16
+ x2_scale_type,
17
+ y_scale_type,
18
+ y2_scale_type,
19
+ x_is_time = false,
20
+ x2_is_time = false,
21
+ has_x2 = false,
22
+ has_y2 = false,
23
+ width,
24
+ height,
25
+ pad,
26
+ }: {
27
+ display: {
28
+ x_zero_line?: boolean
29
+ x2_zero_line?: boolean
30
+ y_zero_line?: boolean
31
+ y2_zero_line?: boolean
32
+ }
33
+ x_scale_fn: (val: number) => number
34
+ x2_scale_fn?: (val: number) => number
35
+ y_scale_fn: (val: number) => number
36
+ y2_scale_fn?: (val: number) => number
37
+ x_range: Vec2
38
+ x2_range?: Vec2
39
+ y_range: Vec2
40
+ y2_range?: Vec2
41
+ x_scale_type?: ScaleType
42
+ x2_scale_type?: ScaleType
43
+ y_scale_type?: ScaleType
44
+ y2_scale_type?: ScaleType
45
+ x_is_time?: boolean
46
+ x2_is_time?: boolean
47
+ has_x2?: boolean
48
+ has_y2?: boolean
49
+ width: number
50
+ height: number
51
+ pad: Required<Sides>
52
+ } = $props()
53
+
54
+ const spans_zero = (range: Vec2): boolean =>
55
+ Math.min(range[0], range[1]) <= 0 && Math.max(range[0], range[1]) >= 0
56
+ </script>
57
+
58
+ {#if display.x_zero_line && get_scale_type_name(x_scale_type) !== `log` &&
59
+ !x_is_time && spans_zero(x_range)}
60
+ {@const zero_x = x_scale_fn(0)}
61
+ {#if isFinite(zero_x)}
62
+ <line class="zero-line" x1={zero_x} x2={zero_x} y1={pad.t} y2={height - pad.b} />
63
+ {/if}
64
+ {/if}
65
+
66
+ {#if display.x2_zero_line && has_x2 && x2_scale_fn && x2_range &&
67
+ get_scale_type_name(x2_scale_type) !== `log` && !x2_is_time && spans_zero(x2_range)}
68
+ {@const zero_x2 = x2_scale_fn(0)}
69
+ {#if isFinite(zero_x2)}
70
+ <line class="zero-line" x1={zero_x2} x2={zero_x2} y1={pad.t} y2={height - pad.b} />
71
+ {/if}
72
+ {/if}
73
+
74
+ {#if display.y_zero_line && get_scale_type_name(y_scale_type) !== `log` &&
75
+ spans_zero(y_range)}
76
+ {@const zero_y = y_scale_fn(0)}
77
+ {#if isFinite(zero_y)}
78
+ <line class="zero-line" x1={pad.l} x2={width - pad.r} y1={zero_y} y2={zero_y} />
79
+ {/if}
80
+ {/if}
81
+
82
+ {#if display.y2_zero_line && has_y2 && y2_scale_fn && y2_range &&
83
+ get_scale_type_name(y2_scale_type) !== `log` && spans_zero(y2_range)}
84
+ {@const zero_y2 = y2_scale_fn(0)}
85
+ {#if isFinite(zero_y2)}
86
+ <line class="zero-line" x1={pad.l} x2={width - pad.r} y1={zero_y2} y2={zero_y2} />
87
+ {/if}
88
+ {/if}
89
+
90
+ <style>
91
+ .zero-line {
92
+ stroke: var(--plot-zero-line-color, light-dark(black, white));
93
+ stroke-width: var(--plot-zero-line-width, 1);
94
+ opacity: var(--plot-zero-line-opacity, 0.3);
95
+ }
96
+ </style>