matterviz 0.3.7 → 0.4.1

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 (486) hide show
  1. package/dist/Icon.svelte +7 -4
  2. package/dist/MillerIndexInput.svelte +1 -1
  3. package/dist/api/optimade.js +32 -26
  4. package/dist/app.css +0 -3
  5. package/dist/brillouin/BrillouinZone.svelte +76 -148
  6. package/dist/brillouin/BrillouinZone.svelte.d.ts +6 -14
  7. package/dist/brillouin/BrillouinZoneExportPane.svelte +43 -96
  8. package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
  9. package/dist/brillouin/BrillouinZoneInfoPane.svelte +9 -32
  10. package/dist/brillouin/BrillouinZoneInfoPane.svelte.d.ts +2 -3
  11. package/dist/brillouin/BrillouinZoneScene.svelte +97 -205
  12. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +4 -23
  13. package/dist/brillouin/BrillouinZoneTooltip.svelte +16 -25
  14. package/dist/brillouin/ReciprocalVectors.svelte +39 -0
  15. package/dist/brillouin/ReciprocalVectors.svelte.d.ts +9 -0
  16. package/dist/brillouin/compute.d.ts +2 -0
  17. package/dist/brillouin/compute.js +89 -90
  18. package/dist/brillouin/geometry.d.ts +8 -0
  19. package/dist/brillouin/geometry.js +57 -0
  20. package/dist/brillouin/index.d.ts +2 -0
  21. package/dist/brillouin/index.js +2 -0
  22. package/dist/brillouin/types.d.ts +2 -2
  23. package/dist/chempot-diagram/ChemPotDiagram.svelte +14 -13
  24. package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +1 -1
  25. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +109 -203
  26. package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +4 -1
  27. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +180 -470
  28. package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +7 -1
  29. package/dist/chempot-diagram/async-compute.svelte.js +3 -1
  30. package/dist/chempot-diagram/chempot-worker.js +2 -1
  31. package/dist/chempot-diagram/color.d.ts +3 -6
  32. package/dist/chempot-diagram/color.js +5 -5
  33. package/dist/chempot-diagram/compute.d.ts +4 -4
  34. package/dist/chempot-diagram/compute.js +20 -20
  35. package/dist/chempot-diagram/controls-state.svelte.d.ts +10 -0
  36. package/dist/chempot-diagram/controls-state.svelte.js +42 -0
  37. package/dist/chempot-diagram/export.d.ts +47 -0
  38. package/dist/chempot-diagram/export.js +133 -0
  39. package/dist/chempot-diagram/index.d.ts +1 -0
  40. package/dist/chempot-diagram/index.js +1 -0
  41. package/dist/chempot-diagram/pointer.d.ts +0 -10
  42. package/dist/chempot-diagram/pointer.js +4 -4
  43. package/dist/chempot-diagram/types.d.ts +3 -3
  44. package/dist/colors/index.js +8 -7
  45. package/dist/composition/FormulaFilter.svelte +18 -11
  46. package/dist/composition/PieChart.svelte +11 -10
  47. package/dist/composition/chem-sys.d.ts +8 -0
  48. package/dist/composition/chem-sys.js +86 -0
  49. package/dist/composition/format.js +7 -4
  50. package/dist/composition/index.d.ts +1 -0
  51. package/dist/composition/index.js +1 -0
  52. package/dist/composition/parse.d.ts +0 -1
  53. package/dist/composition/parse.js +41 -31
  54. package/dist/controls.d.ts +1 -0
  55. package/dist/controls.js +0 -1
  56. package/dist/convex-hull/ConvexHull.svelte +8 -10
  57. package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -4
  58. package/dist/convex-hull/ConvexHull2D.svelte +106 -185
  59. package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
  60. package/dist/convex-hull/ConvexHull3D.svelte +179 -683
  61. package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
  62. package/dist/convex-hull/ConvexHull4D.svelte +183 -687
  63. package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
  64. package/dist/convex-hull/ConvexHullChrome.svelte +268 -0
  65. package/dist/convex-hull/ConvexHullChrome.svelte.d.ts +30 -0
  66. package/dist/convex-hull/ConvexHullControls.svelte +88 -7
  67. package/dist/convex-hull/ConvexHullControls.svelte.d.ts +7 -6
  68. package/dist/convex-hull/ConvexHullInfoPane.svelte +18 -5
  69. package/dist/convex-hull/ConvexHullInfoPane.svelte.d.ts +6 -5
  70. package/dist/convex-hull/ConvexHullStats.svelte +36 -175
  71. package/dist/convex-hull/ConvexHullStats.svelte.d.ts +3 -1
  72. package/dist/convex-hull/ConvexHullTooltip.svelte +11 -2
  73. package/dist/convex-hull/ConvexHullTooltip.svelte.d.ts +2 -1
  74. package/dist/convex-hull/GasPressureControls.svelte +4 -4
  75. package/dist/convex-hull/TemperatureSlider.svelte +2 -2
  76. package/dist/convex-hull/barycentric-coords.d.ts +2 -4
  77. package/dist/convex-hull/barycentric-coords.js +6 -33
  78. package/dist/convex-hull/canvas-interactions.svelte.d.ts +79 -0
  79. package/dist/convex-hull/canvas-interactions.svelte.js +278 -0
  80. package/dist/convex-hull/demo-temperature.d.ts +1 -1
  81. package/dist/convex-hull/demo-temperature.js +20 -22
  82. package/dist/convex-hull/gas-thermodynamics.d.ts +2 -2
  83. package/dist/convex-hull/gas-thermodynamics.js +22 -30
  84. package/dist/convex-hull/helpers.d.ts +42 -7
  85. package/dist/convex-hull/helpers.js +171 -78
  86. package/dist/convex-hull/hull-state.svelte.d.ts +44 -0
  87. package/dist/convex-hull/hull-state.svelte.js +124 -0
  88. package/dist/convex-hull/index.d.ts +10 -8
  89. package/dist/convex-hull/index.js +7 -2
  90. package/dist/convex-hull/thermodynamics.js +136 -960
  91. package/dist/convex-hull/types.d.ts +13 -5
  92. package/dist/convex-hull/types.js +12 -0
  93. package/dist/coordination/CoordinationBarPlot.svelte +27 -34
  94. package/dist/coordination/CoordinationBarPlot.svelte.d.ts +1 -1
  95. package/dist/element/BohrAtom.svelte +2 -1
  96. package/dist/element/index.d.ts +4 -0
  97. package/dist/element/index.js +18 -0
  98. package/dist/feedback/DragOverlay.svelte +3 -1
  99. package/dist/feedback/DragOverlay.svelte.d.ts +1 -0
  100. package/dist/feedback/StatusMessage.svelte +13 -3
  101. package/dist/fermi-surface/FermiSlice.svelte +13 -5
  102. package/dist/fermi-surface/FermiSurface.svelte +78 -151
  103. package/dist/fermi-surface/FermiSurface.svelte.d.ts +5 -14
  104. package/dist/fermi-surface/FermiSurfaceControls.svelte +1 -1
  105. package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
  106. package/dist/fermi-surface/FermiSurfaceScene.svelte +72 -221
  107. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +3 -23
  108. package/dist/fermi-surface/FermiSurfaceTooltip.svelte +8 -34
  109. package/dist/fermi-surface/compute.js +67 -66
  110. package/dist/fermi-surface/export.js +6 -16
  111. package/dist/fermi-surface/index.d.ts +0 -1
  112. package/dist/fermi-surface/index.js +0 -1
  113. package/dist/fermi-surface/parse.d.ts +1 -1
  114. package/dist/fermi-surface/parse.js +71 -79
  115. package/dist/fermi-surface/types.d.ts +3 -2
  116. package/dist/heatmap-matrix/HeatmapMatrix.svelte +69 -52
  117. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +4 -3
  118. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +3 -2
  119. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +5 -5
  120. package/dist/heatmap-matrix/index.d.ts +3 -2
  121. package/dist/heatmap-matrix/index.js +1 -1
  122. package/dist/index.d.ts +1 -0
  123. package/dist/index.js +1 -0
  124. package/dist/io/ExportPane.svelte +166 -0
  125. package/dist/io/ExportPane.svelte.d.ts +17 -0
  126. package/dist/io/decompress.js +5 -4
  127. package/dist/io/export.d.ts +9 -5
  128. package/dist/io/export.js +77 -51
  129. package/dist/io/fetch.d.ts +2 -1
  130. package/dist/io/fetch.js +5 -1
  131. package/dist/io/file-drop.d.ts +8 -1
  132. package/dist/io/file-drop.js +48 -36
  133. package/dist/io/index.d.ts +2 -0
  134. package/dist/io/index.js +10 -0
  135. package/dist/io/types.d.ts +13 -0
  136. package/dist/io/url-drop.js +64 -33
  137. package/dist/isosurface/parse.js +52 -51
  138. package/dist/isosurface/slice.js +5 -4
  139. package/dist/isosurface/types.js +1 -1
  140. package/dist/keyboard.d.ts +3 -0
  141. package/dist/keyboard.js +23 -0
  142. package/dist/labels.d.ts +1 -1
  143. package/dist/labels.js +9 -8
  144. package/dist/layout/FullscreenButton.svelte +33 -0
  145. package/dist/layout/FullscreenButton.svelte.d.ts +10 -0
  146. package/dist/layout/FullscreenToggle.svelte +8 -14
  147. package/dist/layout/PropertyFilter.svelte +3 -2
  148. package/dist/layout/SettingsSection.svelte +1 -1
  149. package/dist/layout/ViewerChrome.svelte +116 -0
  150. package/dist/layout/ViewerChrome.svelte.d.ts +17 -0
  151. package/dist/layout/fullscreen.d.ts +4 -0
  152. package/dist/layout/fullscreen.svelte.d.ts +8 -0
  153. package/dist/layout/fullscreen.svelte.js +37 -0
  154. package/dist/layout/index.d.ts +3 -0
  155. package/dist/layout/index.js +3 -0
  156. package/dist/layout/json-tree/JsonNode.svelte +1 -1
  157. package/dist/layout/json-tree/JsonTree.svelte +2 -2
  158. package/dist/layout/json-tree/utils.js +5 -4
  159. package/dist/marching-cubes.js +8 -13
  160. package/dist/math.d.ts +12 -4
  161. package/dist/math.js +42 -30
  162. package/dist/overlays/DraggablePane.svelte +4 -4
  163. package/dist/overlays/index.d.ts +4 -0
  164. package/dist/periodic-table/PeriodicTable.svelte +27 -15
  165. package/dist/periodic-table/PropertySelect.svelte +1 -0
  166. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +9 -3
  167. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
  168. package/dist/phase-diagram/PhaseDiagramControls.svelte +3 -2
  169. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +4 -3
  170. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +4 -2
  171. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +2 -3
  172. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +47 -132
  173. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +3 -4
  174. package/dist/phase-diagram/PhaseDiagramTooltip.svelte +1 -1
  175. package/dist/phase-diagram/build-diagram.js +2 -2
  176. package/dist/phase-diagram/colors.js +1 -1
  177. package/dist/phase-diagram/parse.d.ts +2 -1
  178. package/dist/phase-diagram/parse.js +6 -5
  179. package/dist/phase-diagram/types.d.ts +1 -1
  180. package/dist/phase-diagram/utils.d.ts +3 -3
  181. package/dist/phase-diagram/utils.js +8 -12
  182. package/dist/plot/{BarPlot.svelte → bar/BarPlot.svelte} +246 -841
  183. package/dist/plot/{BarPlot.svelte.d.ts → bar/BarPlot.svelte.d.ts} +8 -16
  184. package/dist/plot/{BarPlotControls.svelte → bar/BarPlotControls.svelte} +6 -5
  185. package/dist/plot/{BarPlotControls.svelte.d.ts → bar/BarPlotControls.svelte.d.ts} +3 -3
  186. package/dist/plot/{SpacegroupBarPlot.svelte → bar/SpacegroupBarPlot.svelte} +8 -7
  187. package/dist/plot/{SpacegroupBarPlot.svelte.d.ts → bar/SpacegroupBarPlot.svelte.d.ts} +1 -1
  188. package/dist/plot/bar/data.d.ts +40 -0
  189. package/dist/plot/bar/data.js +154 -0
  190. package/dist/plot/bar/geometry.d.ts +39 -0
  191. package/dist/plot/bar/geometry.js +60 -0
  192. package/dist/plot/bar/index.d.ts +3 -0
  193. package/dist/plot/bar/index.js +3 -0
  194. package/dist/plot/box/BoxPlot.svelte +1292 -0
  195. package/dist/plot/box/BoxPlot.svelte.d.ts +95 -0
  196. package/dist/plot/box/BoxPlotControls.svelte +109 -0
  197. package/dist/plot/box/BoxPlotControls.svelte.d.ts +19 -0
  198. package/dist/plot/box/Violin.svelte +14 -0
  199. package/dist/plot/box/Violin.svelte.d.ts +70 -0
  200. package/dist/plot/box/box-plot.d.ts +56 -0
  201. package/dist/plot/box/box-plot.js +129 -0
  202. package/dist/plot/box/index.d.ts +5 -0
  203. package/dist/plot/box/index.js +5 -0
  204. package/dist/plot/box/kde.d.ts +17 -0
  205. package/dist/plot/box/kde.js +160 -0
  206. package/dist/plot/box/quantile.d.ts +3 -0
  207. package/dist/plot/box/quantile.js +53 -0
  208. package/dist/plot/{auto-place.d.ts → core/auto-place.d.ts} +1 -1
  209. package/dist/plot/{auto-place.js → core/auto-place.js} +6 -3
  210. package/dist/plot/core/axis-utils.d.ts +46 -0
  211. package/dist/plot/core/axis-utils.js +110 -0
  212. package/dist/plot/{AxisLabel.svelte → core/components/AxisLabel.svelte} +2 -2
  213. package/dist/plot/{AxisLabel.svelte.d.ts → core/components/AxisLabel.svelte.d.ts} +1 -1
  214. package/dist/plot/{ColorBar.svelte → core/components/ColorBar.svelte} +41 -38
  215. package/dist/plot/{ColorBar.svelte.d.ts → core/components/ColorBar.svelte.d.ts} +7 -6
  216. package/dist/plot/{ColorScaleSelect.svelte → core/components/ColorScaleSelect.svelte} +4 -3
  217. package/dist/plot/{ColorScaleSelect.svelte.d.ts → core/components/ColorScaleSelect.svelte.d.ts} +2 -2
  218. package/dist/plot/core/components/ControlPane.svelte +46 -0
  219. package/dist/plot/core/components/ControlPane.svelte.d.ts +13 -0
  220. package/dist/plot/{FillArea.svelte → core/components/FillArea.svelte} +17 -6
  221. package/dist/plot/{FillArea.svelte.d.ts → core/components/FillArea.svelte.d.ts} +1 -1
  222. package/dist/plot/{InteractiveAxisLabel.svelte → core/components/InteractiveAxisLabel.svelte} +3 -3
  223. package/dist/plot/{InteractiveAxisLabel.svelte.d.ts → core/components/InteractiveAxisLabel.svelte.d.ts} +2 -2
  224. package/dist/plot/{Line.svelte → core/components/Line.svelte} +33 -15
  225. package/dist/plot/{Line.svelte.d.ts → core/components/Line.svelte.d.ts} +3 -2
  226. package/dist/plot/{PlotAxis.svelte → core/components/PlotAxis.svelte} +9 -6
  227. package/dist/plot/{PlotAxis.svelte.d.ts → core/components/PlotAxis.svelte.d.ts} +5 -3
  228. package/dist/plot/{PlotControls.svelte → core/components/PlotControls.svelte} +17 -29
  229. package/dist/plot/core/components/PlotControls.svelte.d.ts +4 -0
  230. package/dist/plot/{PlotLegend.svelte → core/components/PlotLegend.svelte} +21 -10
  231. package/dist/plot/{PlotLegend.svelte.d.ts → core/components/PlotLegend.svelte.d.ts} +3 -2
  232. package/dist/plot/{PlotTooltip.svelte → core/components/PlotTooltip.svelte} +17 -1
  233. package/dist/plot/{PlotTooltip.svelte.d.ts → core/components/PlotTooltip.svelte.d.ts} +8 -0
  234. package/dist/plot/{PortalSelect.svelte → core/components/PortalSelect.svelte} +11 -7
  235. package/dist/plot/{ReferenceLine.svelte → core/components/ReferenceLine.svelte} +3 -3
  236. package/dist/plot/{ReferenceLine.svelte.d.ts → core/components/ReferenceLine.svelte.d.ts} +1 -1
  237. package/dist/plot/{ReferenceLine3D.svelte → core/components/ReferenceLine3D.svelte} +5 -5
  238. package/dist/plot/{ReferenceLine3D.svelte.d.ts → core/components/ReferenceLine3D.svelte.d.ts} +5 -5
  239. package/dist/plot/{ReferencePlane.svelte → core/components/ReferencePlane.svelte} +8 -8
  240. package/dist/plot/{ReferencePlane.svelte.d.ts → core/components/ReferencePlane.svelte.d.ts} +5 -5
  241. package/dist/plot/{ZeroLines.svelte → core/components/ZeroLines.svelte} +3 -3
  242. package/dist/plot/{ZeroLines.svelte.d.ts → core/components/ZeroLines.svelte.d.ts} +3 -3
  243. package/dist/plot/{ZoomRect.svelte → core/components/ZoomRect.svelte} +1 -1
  244. package/dist/plot/{ZoomRect.svelte.d.ts → core/components/ZoomRect.svelte.d.ts} +1 -1
  245. package/dist/plot/core/components/index.d.ts +17 -0
  246. package/dist/plot/core/components/index.js +17 -0
  247. package/dist/plot/{data-cleaning.d.ts → core/data-cleaning.d.ts} +71 -1
  248. package/dist/plot/{data-cleaning.js → core/data-cleaning.js} +21 -23
  249. package/dist/plot/{data-transform.d.ts → core/data-transform.d.ts} +2 -2
  250. package/dist/plot/{data-transform.js → core/data-transform.js} +3 -3
  251. package/dist/plot/core/fill-utils.d.ts +34 -0
  252. package/dist/plot/core/fill-utils.js +391 -0
  253. package/dist/plot/core/index.d.ts +10 -0
  254. package/dist/plot/core/index.js +11 -0
  255. package/dist/plot/core/interactions.d.ts +39 -0
  256. package/dist/plot/core/interactions.js +209 -0
  257. package/dist/plot/{layout.d.ts → core/layout.d.ts} +1 -0
  258. package/dist/plot/{layout.js → core/layout.js} +16 -8
  259. package/dist/plot/core/pan-zoom.svelte.d.ts +35 -0
  260. package/dist/plot/core/pan-zoom.svelte.js +221 -0
  261. package/dist/plot/core/placed-tween.svelte.d.ts +21 -0
  262. package/dist/plot/core/placed-tween.svelte.js +68 -0
  263. package/dist/plot/{reference-line.d.ts → core/reference-line.d.ts} +11 -11
  264. package/dist/plot/{reference-line.js → core/reference-line.js} +29 -42
  265. package/dist/plot/core/scales.d.ts +40 -0
  266. package/dist/plot/{scales.js → core/scales.js} +94 -93
  267. package/dist/plot/core/svg.d.ts +3 -0
  268. package/dist/plot/core/svg.js +41 -0
  269. package/dist/plot/{types.d.ts → core/types.d.ts} +36 -85
  270. package/dist/plot/{types.js → core/types.js} +1 -1
  271. package/dist/plot/{utils → core/utils}/label-placement.d.ts +3 -3
  272. package/dist/plot/{utils → core/utils}/label-placement.js +3 -3
  273. package/dist/plot/core/utils/series-visibility.d.ts +26 -0
  274. package/dist/plot/{utils → core/utils}/series-visibility.js +29 -2
  275. package/dist/plot/core/utils.d.ts +12 -0
  276. package/dist/plot/core/utils.js +27 -0
  277. package/dist/plot/{Histogram.svelte → histogram/Histogram.svelte} +174 -551
  278. package/dist/plot/{Histogram.svelte.d.ts → histogram/Histogram.svelte.d.ts} +2 -2
  279. package/dist/plot/{HistogramControls.svelte → histogram/HistogramControls.svelte} +6 -6
  280. package/dist/plot/{HistogramControls.svelte.d.ts → histogram/HistogramControls.svelte.d.ts} +4 -4
  281. package/dist/plot/histogram/index.d.ts +2 -0
  282. package/dist/plot/histogram/index.js +2 -0
  283. package/dist/plot/index.d.ts +8 -41
  284. package/dist/plot/index.js +10 -39
  285. package/dist/plot/sankey/Sankey.svelte +697 -0
  286. package/dist/plot/sankey/Sankey.svelte.d.ts +74 -0
  287. package/dist/plot/sankey/SankeyControls.svelte +98 -0
  288. package/dist/plot/sankey/SankeyControls.svelte.d.ts +19 -0
  289. package/dist/plot/sankey/index.d.ts +4 -0
  290. package/dist/plot/sankey/index.js +3 -0
  291. package/dist/plot/sankey/sankey-types.d.ts +42 -0
  292. package/dist/plot/sankey/sankey-types.js +4 -0
  293. package/dist/plot/sankey/sankey.d.ts +52 -0
  294. package/dist/plot/sankey/sankey.js +189 -0
  295. package/dist/plot/{BinnedScatterPlot.svelte → scatter/BinnedScatterPlot.svelte} +64 -64
  296. package/dist/plot/{BinnedScatterPlot.svelte.d.ts → scatter/BinnedScatterPlot.svelte.d.ts} +6 -6
  297. package/dist/plot/{ElementScatter.svelte → scatter/ElementScatter.svelte} +6 -6
  298. package/dist/plot/{ElementScatter.svelte.d.ts → scatter/ElementScatter.svelte.d.ts} +2 -2
  299. package/dist/plot/{ScatterPlot.svelte → scatter/ScatterPlot.svelte} +297 -1008
  300. package/dist/plot/{ScatterPlot.svelte.d.ts → scatter/ScatterPlot.svelte.d.ts} +10 -18
  301. package/dist/plot/{ScatterPlotControls.svelte → scatter/ScatterPlotControls.svelte} +6 -5
  302. package/dist/plot/{ScatterPlotControls.svelte.d.ts → scatter/ScatterPlotControls.svelte.d.ts} +2 -2
  303. package/dist/plot/{ScatterPoint.svelte → scatter/ScatterPoint.svelte} +7 -7
  304. package/dist/plot/{ScatterPoint.svelte.d.ts → scatter/ScatterPoint.svelte.d.ts} +3 -3
  305. package/dist/plot/{adaptive-density.d.ts → scatter/adaptive-density.d.ts} +14 -4
  306. package/dist/plot/{adaptive-density.js → scatter/adaptive-density.js} +46 -20
  307. package/dist/plot/{binned-scatter-types.d.ts → scatter/binned-scatter-types.d.ts} +5 -12
  308. package/dist/plot/scatter/index.d.ts +7 -0
  309. package/dist/plot/scatter/index.js +5 -0
  310. package/dist/plot/scatter/scatter-data.d.ts +19 -0
  311. package/dist/plot/scatter/scatter-data.js +212 -0
  312. package/dist/plot/{ScatterPlot3D.svelte → scatter-3d/ScatterPlot3D.svelte} +25 -34
  313. package/dist/plot/{ScatterPlot3D.svelte.d.ts → scatter-3d/ScatterPlot3D.svelte.d.ts} +9 -17
  314. package/dist/plot/{ScatterPlot3DControls.svelte → scatter-3d/ScatterPlot3DControls.svelte} +14 -14
  315. package/dist/plot/{ScatterPlot3DControls.svelte.d.ts → scatter-3d/ScatterPlot3DControls.svelte.d.ts} +6 -6
  316. package/dist/plot/{ScatterPlot3DScene.svelte → scatter-3d/ScatterPlot3DScene.svelte} +129 -128
  317. package/dist/plot/{ScatterPlot3DScene.svelte.d.ts → scatter-3d/ScatterPlot3DScene.svelte.d.ts} +6 -15
  318. package/dist/plot/{Surface3D.svelte → scatter-3d/Surface3D.svelte} +7 -6
  319. package/dist/plot/{Surface3D.svelte.d.ts → scatter-3d/Surface3D.svelte.d.ts} +5 -4
  320. package/dist/plot/scatter-3d/index.d.ts +4 -0
  321. package/dist/plot/scatter-3d/index.js +4 -0
  322. package/dist/plot/sunburst/Sunburst.svelte +1041 -0
  323. package/dist/plot/sunburst/Sunburst.svelte.d.ts +97 -0
  324. package/dist/plot/sunburst/SunburstControls.svelte +200 -0
  325. package/dist/plot/sunburst/SunburstControls.svelte.d.ts +26 -0
  326. package/dist/plot/sunburst/index.d.ts +4 -0
  327. package/dist/plot/sunburst/index.js +4 -0
  328. package/dist/plot/sunburst/render.d.ts +34 -0
  329. package/dist/plot/sunburst/render.js +122 -0
  330. package/dist/plot/sunburst/sunburst.d.ts +62 -0
  331. package/dist/plot/sunburst/sunburst.js +269 -0
  332. package/dist/rdf/RdfPlot.svelte +2 -1
  333. package/dist/rdf/RdfPlot.svelte.d.ts +1 -1
  334. package/dist/rdf/calc-rdf.js +11 -24
  335. package/dist/sanitize.js +14 -3
  336. package/dist/scene/SceneCamera.svelte +62 -0
  337. package/dist/scene/SceneCamera.svelte.d.ts +19 -0
  338. package/dist/scene/bind-renderer.svelte.d.ts +2 -0
  339. package/dist/scene/bind-renderer.svelte.js +14 -0
  340. package/dist/scene/index.d.ts +4 -0
  341. package/dist/scene/index.js +5 -0
  342. package/dist/scene/props.js +52 -0
  343. package/dist/scene/types.d.ts +26 -0
  344. package/dist/scene/types.js +1 -0
  345. package/dist/settings.d.ts +79 -3
  346. package/dist/settings.js +321 -1
  347. package/dist/spectral/Bands.svelte +47 -36
  348. package/dist/spectral/Bands.svelte.d.ts +6 -6
  349. package/dist/spectral/BandsAndDos.svelte +23 -25
  350. package/dist/spectral/BrillouinBandsDos.svelte +42 -30
  351. package/dist/spectral/Dos.svelte +15 -23
  352. package/dist/spectral/Dos.svelte.d.ts +4 -3
  353. package/dist/spectral/helpers.d.ts +8 -6
  354. package/dist/spectral/helpers.js +137 -65
  355. package/dist/state.svelte.d.ts +0 -7
  356. package/dist/state.svelte.js +0 -6
  357. package/dist/structure/Arrow.svelte +2 -4
  358. package/dist/structure/AtomLegend.svelte +8 -9
  359. package/dist/structure/AtomLegend.svelte.d.ts +1 -1
  360. package/dist/structure/CanvasTooltip.svelte +1 -0
  361. package/dist/structure/CellSelect.svelte +12 -5
  362. package/dist/structure/CellSelect.svelte.d.ts +2 -1
  363. package/dist/structure/Cylinder.svelte +12 -8
  364. package/dist/structure/Cylinder.svelte.d.ts +4 -1
  365. package/dist/structure/Lattice.svelte +2 -2
  366. package/dist/structure/Structure.svelte +365 -423
  367. package/dist/structure/Structure.svelte.d.ts +5 -15
  368. package/dist/structure/StructureControls.svelte +217 -2
  369. package/dist/structure/StructureControls.svelte.d.ts +5 -3
  370. package/dist/structure/StructureExportPane.svelte +54 -156
  371. package/dist/structure/StructureExportPane.svelte.d.ts +4 -5
  372. package/dist/structure/StructureInfoPane.svelte +10 -9
  373. package/dist/structure/StructureInfoPane.svelte.d.ts +5 -5
  374. package/dist/structure/StructureScene.svelte +376 -208
  375. package/dist/structure/StructureScene.svelte.d.ts +22 -20
  376. package/dist/structure/{label-placement.d.ts → atom-label-placement.d.ts} +3 -3
  377. package/dist/structure/{label-placement.js → atom-label-placement.js} +15 -5
  378. package/dist/structure/atom-properties.d.ts +1 -1
  379. package/dist/structure/atom-properties.js +17 -22
  380. package/dist/structure/bond-order-perception.js +3 -5
  381. package/dist/structure/bonding.d.ts +4 -0
  382. package/dist/structure/bonding.js +134 -63
  383. package/dist/structure/export.d.ts +24 -4
  384. package/dist/structure/export.js +89 -143
  385. package/dist/structure/index.d.ts +4 -4
  386. package/dist/structure/index.js +3 -3
  387. package/dist/structure/measure.d.ts +3 -2
  388. package/dist/structure/measure.js +6 -5
  389. package/dist/structure/parse.d.ts +3 -2
  390. package/dist/structure/parse.js +419 -438
  391. package/dist/structure/partial-occupancy.d.ts +0 -1
  392. package/dist/structure/partial-occupancy.js +1 -1
  393. package/dist/structure/pbc.d.ts +1 -1
  394. package/dist/structure/pbc.js +190 -13
  395. package/dist/structure/polyhedra.d.ts +41 -0
  396. package/dist/structure/polyhedra.js +602 -0
  397. package/dist/structure/site.d.ts +4 -0
  398. package/dist/structure/site.js +1 -0
  399. package/dist/structure/supercell.js +3 -2
  400. package/dist/structure/validation.js +5 -6
  401. package/dist/symmetry/SymmetryElementControls.svelte +69 -0
  402. package/dist/symmetry/SymmetryElementControls.svelte.d.ts +9 -0
  403. package/dist/symmetry/SymmetryElements.svelte +354 -0
  404. package/dist/symmetry/SymmetryElements.svelte.d.ts +24 -0
  405. package/dist/symmetry/SymmetryStats.svelte +113 -8
  406. package/dist/symmetry/WyckoffTable.svelte +68 -7
  407. package/dist/symmetry/WyckoffTable.svelte.d.ts +3 -0
  408. package/dist/symmetry/cell-transform.js +7 -14
  409. package/dist/symmetry/index.d.ts +14 -4
  410. package/dist/symmetry/index.js +291 -72
  411. package/dist/symmetry/spacegroups.d.ts +12 -1
  412. package/dist/symmetry/spacegroups.js +63 -14
  413. package/dist/symmetry/symmetry-elements.d.ts +33 -0
  414. package/dist/symmetry/symmetry-elements.js +521 -0
  415. package/dist/symmetry/wyckoff-db.d.ts +9 -0
  416. package/dist/symmetry/wyckoff-db.js +87 -0
  417. package/dist/table/HeatmapTable.svelte +66 -25
  418. package/dist/table/HeatmapTable.svelte.d.ts +1 -1
  419. package/dist/table/index.d.ts +1 -3
  420. package/dist/table/index.js +1 -1
  421. package/dist/theme/index.js +8 -8
  422. package/dist/tooltip/KCoords.svelte +45 -0
  423. package/dist/tooltip/KCoords.svelte.d.ts +8 -0
  424. package/dist/tooltip/index.d.ts +1 -0
  425. package/dist/tooltip/index.js +1 -0
  426. package/dist/trajectory/Trajectory.svelte +123 -100
  427. package/dist/trajectory/Trajectory.svelte.d.ts +11 -22
  428. package/dist/trajectory/TrajectoryExportPane.svelte +17 -25
  429. package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +4 -5
  430. package/dist/trajectory/TrajectoryInfoPane.svelte +5 -3
  431. package/dist/trajectory/TrajectoryInfoPane.svelte.d.ts +3 -2
  432. package/dist/trajectory/constants.js +6 -2
  433. package/dist/trajectory/extract.js +17 -37
  434. package/dist/trajectory/format-detect.d.ts +1 -1
  435. package/dist/trajectory/format-detect.js +27 -19
  436. package/dist/trajectory/frame-reader.d.ts +0 -1
  437. package/dist/trajectory/frame-reader.js +63 -162
  438. package/dist/trajectory/helpers.d.ts +10 -2
  439. package/dist/trajectory/helpers.js +56 -36
  440. package/dist/trajectory/index.js +1 -1
  441. package/dist/trajectory/parse/ase.d.ts +9 -1
  442. package/dist/trajectory/parse/ase.js +47 -32
  443. package/dist/trajectory/parse/diagnostics.d.ts +3 -0
  444. package/dist/trajectory/parse/diagnostics.js +14 -0
  445. package/dist/trajectory/parse/hdf5.js +1 -1
  446. package/dist/trajectory/parse/index.d.ts +1 -1
  447. package/dist/trajectory/parse/index.js +65 -105
  448. package/dist/trajectory/parse/lammps.d.ts +0 -2
  449. package/dist/trajectory/parse/lammps.js +8 -6
  450. package/dist/trajectory/parse/pymatgen.d.ts +2 -0
  451. package/dist/trajectory/parse/pymatgen.js +74 -0
  452. package/dist/trajectory/parse/vasp.js +38 -18
  453. package/dist/trajectory/parse/xyz.d.ts +13 -1
  454. package/dist/trajectory/parse/xyz.js +102 -94
  455. package/dist/trajectory/plotting.d.ts +1 -2
  456. package/dist/trajectory/plotting.js +16 -113
  457. package/dist/utils.d.ts +2 -0
  458. package/dist/utils.js +7 -5
  459. package/dist/xrd/XrdPlot.svelte +16 -30
  460. package/dist/xrd/broadening.d.ts +2 -1
  461. package/dist/xrd/calc-xrd.js +18 -20
  462. package/dist/xrd/index.d.ts +2 -2
  463. package/dist/xrd/parse.js +2 -2
  464. package/package.json +43 -26
  465. package/dist/element/data.json +0 -11864
  466. package/dist/fermi-surface/marching-cubes.d.ts +0 -2
  467. package/dist/fermi-surface/marching-cubes.js +0 -2
  468. package/dist/plot/PlotControls.svelte.d.ts +0 -4
  469. package/dist/plot/axis-utils.d.ts +0 -19
  470. package/dist/plot/axis-utils.js +0 -78
  471. package/dist/plot/defaults.d.ts +0 -19
  472. package/dist/plot/defaults.js +0 -9
  473. package/dist/plot/fill-utils.d.ts +0 -46
  474. package/dist/plot/fill-utils.js +0 -322
  475. package/dist/plot/hover-lock.svelte.d.ts +0 -14
  476. package/dist/plot/hover-lock.svelte.js +0 -46
  477. package/dist/plot/interactions.d.ts +0 -12
  478. package/dist/plot/interactions.js +0 -101
  479. package/dist/plot/scales.d.ts +0 -48
  480. package/dist/plot/svg.d.ts +0 -1
  481. package/dist/plot/svg.js +0 -11
  482. package/dist/plot/utils/series-visibility.d.ts +0 -15
  483. package/dist/plot/utils.d.ts +0 -1
  484. package/dist/plot/utils.js +0 -14
  485. /package/dist/plot/{PortalSelect.svelte.d.ts → core/components/PortalSelect.svelte.d.ts} +0 -0
  486. /package/dist/plot/{binned-scatter-types.js → scatter/binned-scatter-types.js} +0 -0
@@ -0,0 +1,391 @@
1
+ // Fill-between utility functions for ScatterPlot fill regions
2
+ // Each fill edge is traced through its boundary's own points with the same curve the series line
3
+ // uses (curveMonotoneX), so an unclipped fill edge coincides with the line it borders. When an
4
+ // edge is clipped (x_range / partial overlap), the inserted endpoint shifts the neighboring
5
+ // monotone tangent, so the clipped edge can deviate sub-pixel from the full series line.
6
+ import { curveBasis, curveCardinal, curveCatmullRom, curveLinear, curveMonotoneX, curveMonotoneY, curveNatural, curveStep, curveStepAfter, curveStepBefore, line, } from 'd3-shape';
7
+ // Epsilon value for log scale clamping (to avoid log(0) = -Infinity)
8
+ export const LOG_EPSILON = 1e-10;
9
+ // Resolves a series reference (by index or id) to the actual DataSeries
10
+ export function resolve_series_ref(ref, series) {
11
+ if (`series_idx` in ref && typeof ref.series_idx === `number`) {
12
+ const idx = ref.series_idx;
13
+ return idx >= 0 && idx < series.length ? series[idx] : null;
14
+ }
15
+ if (`series_id` in ref && ref.series_id !== undefined) {
16
+ return series.find((data_series) => data_series.id === ref.series_id) ?? null;
17
+ }
18
+ return null;
19
+ }
20
+ // === Monotone-cubic interpolation matching d3's curveMonotoneX ===
21
+ // Used to evaluate a boundary's y on its own curve (for endpoint clipping and where-condition
22
+ // detection) so interpolated points lie exactly on the rendered line.
23
+ // Mirrors d3-shape's own sign helper (returns 1 for 0, unlike Math.sign) so
24
+ // monotone_tangents reproduces curveMonotoneX exactly. Do NOT change to return 0
25
+ // for 0: that would diverge from the rendered curve. It's harmless either way here
26
+ // since s0/s1 === 0 forces the Math.min term below to 0 regardless.
27
+ const sign = (val) => (val < 0 ? -1 : 1);
28
+ // Per-knot tangents reproducing d3 curveMonotoneX (slope3 interior, slope2 endpoints)
29
+ function monotone_tangents(xs, ys) {
30
+ const num = xs.length;
31
+ if (num <= 1)
32
+ return Array(num).fill(0);
33
+ const secant = (idx) => (ys[idx + 1] - ys[idx]) / (xs[idx + 1] - xs[idx]);
34
+ if (num === 2) {
35
+ const slope = secant(0);
36
+ const safe = Number.isFinite(slope) ? slope : 0;
37
+ return [safe, safe];
38
+ }
39
+ const tangents = Array.from({ length: num }, () => 0);
40
+ for (let idx = 1; idx < num - 1; idx++) {
41
+ const h0 = xs[idx] - xs[idx - 1];
42
+ const h1 = xs[idx + 1] - xs[idx];
43
+ const s0 = (ys[idx] - ys[idx - 1]) / (h0 || (h1 < 0 ? -0 : 0));
44
+ const s1 = (ys[idx + 1] - ys[idx]) / (h1 || (h0 < 0 ? -0 : 0));
45
+ const par = (s0 * h1 + s1 * h0) / (h0 + h1);
46
+ tangents[idx] =
47
+ (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(par)) || 0;
48
+ }
49
+ tangents[0] = (3 * secant(0) - tangents[1]) / 2;
50
+ tangents[num - 1] = (3 * secant(num - 2) - tangents[num - 2]) / 2;
51
+ return tangents;
52
+ }
53
+ // Index of the bracket [lo, lo+1] containing x (xs ascending); clamps to interior brackets
54
+ const bracket = (xs, x) => {
55
+ let lo = 0;
56
+ let hi = xs.length - 1;
57
+ while (hi - lo > 1) {
58
+ const mid = (lo + hi) >> 1;
59
+ if (xs[mid] <= x)
60
+ lo = mid;
61
+ else
62
+ hi = mid;
63
+ }
64
+ return lo;
65
+ };
66
+ // y clamped to the endpoint value when x is at/outside the domain (null when x is strictly inside)
67
+ const endpoint_clamp = (xs, ys, x) => {
68
+ if (xs.length === 0)
69
+ return NaN;
70
+ if (x <= xs[0])
71
+ return ys[0];
72
+ if (x >= xs[xs.length - 1])
73
+ return ys[xs.length - 1];
74
+ return null;
75
+ };
76
+ // Evaluate the d3 curveMonotoneX through (xs, ys) at x (xs ascending). Clamps outside the domain.
77
+ export function monotone_interpolate(xs, ys, x, tangents) {
78
+ const edge = endpoint_clamp(xs, ys, x);
79
+ if (edge !== null)
80
+ return edge;
81
+ const lo = bracket(xs, x);
82
+ const [x0, x1] = [xs[lo], xs[lo + 1]];
83
+ const span = x1 - x0;
84
+ if (span === 0)
85
+ return ys[lo];
86
+ const tang = tangents ?? monotone_tangents(xs, ys);
87
+ // d3 monotoneX uses equally-spaced x control points, so x is linear in t. y is the cubic Bezier
88
+ // through [y0, y0+dx*t0, y1-dx*t1, y1] with dx = span/3.
89
+ const dx = span / 3;
90
+ const p0 = ys[lo];
91
+ const p1 = ys[lo] + dx * tang[lo];
92
+ const p2 = ys[lo + 1] - dx * tang[lo + 1];
93
+ const p3 = ys[lo + 1];
94
+ const frac = (x - x0) / span;
95
+ const mu = 1 - frac;
96
+ return (mu * mu * mu * p0 +
97
+ 3 * mu * mu * frac * p1 +
98
+ 3 * mu * frac * frac * p2 +
99
+ frac * frac * frac * p3);
100
+ }
101
+ // Curve types whose interior follows a (near-)monotone cubic; evaluated via monotone_interpolate.
102
+ // Others (linear/step) evaluate piecewise (exact for them at clip points).
103
+ const MONOTONE_LIKE = new Set([
104
+ `monotoneX`,
105
+ `monotoneY`,
106
+ `natural`,
107
+ `cardinal`,
108
+ `catmullRom`,
109
+ `basis`,
110
+ ]);
111
+ // Piecewise (non-cubic) evaluation honoring linear and the three step curves
112
+ const piecewise_eval = (xs, ys, x, curve) => {
113
+ const edge = endpoint_clamp(xs, ys, x);
114
+ if (edge !== null)
115
+ return edge;
116
+ const idx = bracket(xs, x);
117
+ const [x0, x1, y0, y1] = [xs[idx], xs[idx + 1], ys[idx], ys[idx + 1]];
118
+ if (curve === `stepAfter`)
119
+ return y0; // hold previous until the next knot
120
+ if (curve === `stepBefore`)
121
+ return y1; // jump to next value immediately past a knot
122
+ if (curve === `step`)
123
+ return x < (x0 + x1) / 2 ? y0 : y1; // switch at the midpoint
124
+ const span = x1 - x0;
125
+ return span === 0 ? y0 : y0 + ((x - x0) / span) * (y1 - y0);
126
+ };
127
+ // Build a boundary with a y(x) evaluator that precomputes tangents (monotone) once
128
+ function prepare_boundary(boundary) {
129
+ const { points, curve } = boundary;
130
+ const xs = points.map((pt) => pt.x);
131
+ const ys = points.map((pt) => pt.y);
132
+ if (MONOTONE_LIKE.has(curve)) {
133
+ const tangents = monotone_tangents(xs, ys);
134
+ return { points, curve, eval: (x) => monotone_interpolate(xs, ys, x, tangents) };
135
+ }
136
+ return { points, curve, eval: (x) => piecewise_eval(xs, ys, x, curve) };
137
+ }
138
+ // True when a boundary carries its own x (series or data-with-x), so it needs no companion x
139
+ const defines_own_x = (boundary) => typeof boundary !== `number` &&
140
+ (boundary.type === `series` || (boundary.type === `data` && boundary.x !== undefined));
141
+ // Keep only finite points, sorted by x
142
+ const clean_pts = (pts) => pts.filter((pt) => Number.isFinite(pt.x) && Number.isFinite(pt.y)).sort((a, b) => a.x - b.x);
143
+ // Zip parallel x/y arrays into finite, x-sorted points
144
+ const finite_points = (xs, ys) => clean_pts(Array.from({ length: Math.min(xs.length, ys.length) }, (_, idx) => ({
145
+ x: xs[idx],
146
+ y: ys[idx],
147
+ })));
148
+ // Resolve a boundary to native points + curve in data coordinates. `companion` supplies x
149
+ // positions for boundaries that don't define their own (constant/axis/function/data-without-x).
150
+ export function resolve_boundary_points(boundary, series, domains, companion) {
151
+ // x positions used for companion-relative boundaries
152
+ const span_xs = companion && companion.length > 0
153
+ ? companion.map((pt) => pt.x)
154
+ : [domains.x_domain[0], domains.x_domain[1]];
155
+ // flat horizontal edge at constant y (number / constant / axis boundaries)
156
+ const flat_edge = (y) => ({
157
+ points: horizontal(span_xs, y),
158
+ curve: `linear`,
159
+ });
160
+ // series / function / data edges are traced with monotoneX (matches the series line)
161
+ const curved_edge = (points) => points.length > 0 ? { points, curve: `monotoneX` } : null;
162
+ if (typeof boundary === `number`)
163
+ return flat_edge(boundary);
164
+ if (boundary.type === `series`) {
165
+ const resolved = resolve_series_ref(boundary, series);
166
+ if (!resolved)
167
+ return null;
168
+ return curved_edge(finite_points(resolved.x, resolved.y));
169
+ }
170
+ if (boundary.type === `constant`)
171
+ return flat_edge(boundary.value);
172
+ if (boundary.type === `axis`) {
173
+ return flat_edge(boundary.value ??
174
+ (boundary.axis === `y2` ? domains.y2_domain?.[0] : undefined) ??
175
+ domains.y_domain[0]);
176
+ }
177
+ if (boundary.type === `function`) {
178
+ // sample densely so the traced curve hugs the function
179
+ const [x0, x1] = [span_xs[0], span_xs[span_xs.length - 1]];
180
+ const steps = 100;
181
+ const points = [];
182
+ for (let idx = 0; idx <= steps; idx++) {
183
+ const x = x0 + ((x1 - x0) * idx) / steps;
184
+ const y = boundary.fn(x);
185
+ if (Number.isFinite(y))
186
+ points.push({ x, y });
187
+ }
188
+ return curved_edge(points);
189
+ }
190
+ if (boundary.type === `data`) {
191
+ if (boundary.values.length === 0)
192
+ return null;
193
+ if (boundary.x)
194
+ return curved_edge(finite_points(boundary.x, boundary.values));
195
+ // No x: align values to the companion's x by index (or fraction when lengths differ)
196
+ const num_values = boundary.values.length;
197
+ const companion_x = (idx) => span_xs.length === num_values
198
+ ? span_xs[idx]
199
+ : span_xs[Math.round((idx / Math.max(1, num_values - 1)) * (span_xs.length - 1))];
200
+ const points = boundary.values.map((value, idx) => ({ x: companion_x(idx), y: value }));
201
+ return curved_edge(clean_pts(points));
202
+ }
203
+ return null;
204
+ }
205
+ // Two points spanning [first, last] of xs at constant y
206
+ const horizontal = (xs, y) => xs.length === 0
207
+ ? []
208
+ : [
209
+ { x: xs[0], y },
210
+ { x: xs[xs.length - 1], y },
211
+ ];
212
+ // Clip a prepared boundary to [xa, xb], inserting on-curve endpoints so the edge starts/ends at xa/xb
213
+ function clip_boundary(boundary, xa, xb) {
214
+ const inside = boundary.points.filter((pt) => pt.x > xa && pt.x < xb);
215
+ const start = { x: xa, y: boundary.eval(xa) };
216
+ const end = { x: xb, y: boundary.eval(xb) };
217
+ const pts = [start, ...inside, end];
218
+ return pts.filter((pt) => Number.isFinite(pt.y));
219
+ }
220
+ // Binary-search the x where a `where` toggle occurs between two grid samples (boundaries linear between them)
221
+ function where_crossing(xa, xb, ya_up, ya_lo, yb_up, yb_lo, where) {
222
+ let left = xa;
223
+ let right = xb;
224
+ const cond_left = where(xa, ya_up, ya_lo);
225
+ for (let iter = 0; iter < 24; iter++) {
226
+ const mid = (left + right) / 2;
227
+ const frac = (mid - xa) / (xb - xa);
228
+ const up = ya_up + frac * (yb_up - ya_up);
229
+ const lo = ya_lo + frac * (yb_lo - ya_lo);
230
+ if (where(mid, up, lo) === cond_left)
231
+ left = mid;
232
+ else
233
+ right = mid;
234
+ }
235
+ return (left + right) / 2;
236
+ }
237
+ // Split the overlap into x-intervals where region.where passes (whole overlap when no condition)
238
+ function where_intervals(upper, lower, xa, xb, where) {
239
+ if (!where)
240
+ return [[xa, xb]];
241
+ // detection grid: native x of both boundaries within the overlap, plus the endpoints
242
+ const grid = [
243
+ ...new Set([xa, xb, ...upper.points.map((pt) => pt.x), ...lower.points.map((pt) => pt.x)].filter((x) => x >= xa && x <= xb)),
244
+ ].sort((a, b) => a - b);
245
+ const intervals = [];
246
+ let seg_start = null;
247
+ // carry the previous grid sample so each point's two evals + where() run once, not twice
248
+ let prev_x = NaN;
249
+ let prev_up = NaN;
250
+ let prev_lo = NaN;
251
+ let prev_passes = false;
252
+ for (let idx = 0; idx < grid.length; idx++) {
253
+ const x = grid[idx];
254
+ const up = upper.eval(x);
255
+ const lo = lower.eval(x);
256
+ const passes = where(x, up, lo);
257
+ if (idx > 0 && passes !== prev_passes) {
258
+ const cross = where_crossing(prev_x, x, prev_up, prev_lo, up, lo, where);
259
+ if (seg_start !== null) {
260
+ intervals.push([seg_start, cross]);
261
+ seg_start = null;
262
+ }
263
+ else {
264
+ seg_start = cross;
265
+ }
266
+ }
267
+ if (passes && seg_start === null)
268
+ seg_start = x;
269
+ if (!passes && seg_start !== null) {
270
+ intervals.push([seg_start, x]);
271
+ seg_start = null;
272
+ }
273
+ prev_x = x;
274
+ prev_up = up;
275
+ prev_lo = lo;
276
+ prev_passes = passes;
277
+ }
278
+ if (seg_start !== null)
279
+ intervals.push([seg_start, xb]);
280
+ return intervals.filter(([a, b]) => b > a);
281
+ }
282
+ // Compute renderable fill segments (data coordinates) for a region.
283
+ // Handles boundary resolution, x-overlap clipping, where-segmentation and y_range clamping.
284
+ export function compute_fill_segments(region, series, domains) {
285
+ // Resolve self-defining boundaries (series / data-with-x) first; companion-relative ones
286
+ // (constant/axis/function/data-without-x) then borrow the other's x positions.
287
+ let upper = defines_own_x(region.upper)
288
+ ? resolve_boundary_points(region.upper, series, domains)
289
+ : null;
290
+ let lower = defines_own_x(region.lower)
291
+ ? resolve_boundary_points(region.lower, series, domains)
292
+ : null;
293
+ upper ??= resolve_boundary_points(region.upper, series, domains, lower?.points);
294
+ lower ??= resolve_boundary_points(region.lower, series, domains, upper?.points);
295
+ if (!upper || !lower || upper.points.length === 0 || lower.points.length === 0)
296
+ return [];
297
+ // An explicit region.curve overrides the per-boundary curve (advanced: may no longer match the
298
+ // series line). Default leaves series edges at monotoneX so they coincide with the line.
299
+ if (region.curve) {
300
+ upper.curve = region.curve;
301
+ lower.curve = region.curve;
302
+ }
303
+ // Prepare once: precomputes monotone tangents / lookup so the where + clip passes below are
304
+ // O(grid) instead of recomputing an O(n) evaluator on every sample.
305
+ const up = prepare_boundary(upper);
306
+ const lo = prepare_boundary(lower);
307
+ // x-overlap = intersection of both x-domains, constrained by region.x_range
308
+ const [x_lo, x_hi] = region.x_range ?? [null, null];
309
+ const xa = Math.max(up.points[0].x, lo.points[0].x, x_lo ?? -Infinity);
310
+ const xb = Math.min(up.points[up.points.length - 1].x, lo.points[lo.points.length - 1].x, x_hi ?? Infinity);
311
+ if (!(xb > xa))
312
+ return [];
313
+ const [y_min, y_max] = region.y_range ?? [null, null];
314
+ const clamp_y = (pt) => ({
315
+ x: pt.x,
316
+ y: Math.min(y_max ?? Infinity, Math.max(y_min ?? -Infinity, pt.y)),
317
+ });
318
+ const intervals = where_intervals(up, lo, xa, xb, region.where);
319
+ const segments = [];
320
+ for (const [sa, sb] of intervals) {
321
+ const up_pts = clip_boundary(up, sa, sb).map(clamp_y);
322
+ const lo_pts = clip_boundary(lo, sa, sb).map(clamp_y);
323
+ if (up_pts.length >= 2 && lo_pts.length >= 2) {
324
+ segments.push({
325
+ upper: up_pts,
326
+ lower: lo_pts,
327
+ upper_curve: up.curve,
328
+ lower_curve: lo.curve,
329
+ });
330
+ }
331
+ }
332
+ return segments;
333
+ }
334
+ // === Path generation ===
335
+ const CURVE_MAP = {
336
+ linear: curveLinear,
337
+ monotoneX: curveMonotoneX,
338
+ monotoneY: curveMonotoneY,
339
+ step: curveStep,
340
+ stepBefore: curveStepBefore,
341
+ stepAfter: curveStepAfter,
342
+ basis: curveBasis,
343
+ cardinal: curveCardinal,
344
+ catmullRom: curveCatmullRom,
345
+ natural: curveNatural,
346
+ };
347
+ const get_curve = (curve_type) => CURVE_MAP[curve_type] ?? curveMonotoneX;
348
+ const trace = (points, curve_type) => line()
349
+ .x((pt) => pt.x)
350
+ .y((pt) => pt.y)
351
+ .curve(get_curve(curve_type))(points) ?? ``;
352
+ // Generate the closed SVG path for a fill segment (pixel coordinates). The upper edge is traced
353
+ // forward and the lower edge backward, each through its own points with its own curve via the same
354
+ // line generator the series uses, so an unclipped edge matches the corresponding series line.
355
+ export function generate_fill_path(upper, lower, upper_curve = `monotoneX`, lower_curve = upper_curve) {
356
+ if (upper.length < 2 || lower.length < 2)
357
+ return ``;
358
+ const upper_path = trace(upper, upper_curve);
359
+ const lower_path = trace(lower.toReversed(), lower_curve);
360
+ if (!upper_path || !lower_path)
361
+ return ``;
362
+ // join upper end -> lower end (drop the lower path's leading "M"), then close to upper start
363
+ return `${upper_path}L${lower_path.slice(1)}Z`;
364
+ }
365
+ // Helper to expand error definition to array
366
+ const expand_error = (err, length) => typeof err === `number` ? Array(length).fill(err) : err;
367
+ // Convert an ErrorBand convenience type to a full FillRegion (carrying the series x so the band
368
+ // traces the central series exactly)
369
+ export function convert_error_band_to_fill_region(error_band, series, default_color) {
370
+ const resolved = resolve_series_ref(error_band.series, series);
371
+ if (!resolved)
372
+ return null;
373
+ const { x, y } = resolved;
374
+ const { error } = error_band;
375
+ const [upper_err, lower_err] = typeof error === `object` && `upper` in error
376
+ ? [expand_error(error.upper, y.length), expand_error(error.lower, y.length)]
377
+ : [expand_error(error, y.length), expand_error(error, y.length)];
378
+ return {
379
+ id: error_band.id,
380
+ label: error_band.label,
381
+ upper: { type: `data`, x, values: y.map((val, idx) => val + upper_err[idx]) },
382
+ lower: { type: `data`, x, values: y.map((val, idx) => val - lower_err[idx]) },
383
+ fill: error_band.fill ?? default_color ?? `#4e79a7`,
384
+ fill_opacity: error_band.fill_opacity ?? 0.3,
385
+ edge_upper: error_band.edge_style,
386
+ edge_lower: error_band.edge_style,
387
+ show_in_legend: error_band.show_in_legend ?? true,
388
+ };
389
+ }
390
+ // Type guard to check if fill is a gradient
391
+ export const is_fill_gradient = (fill) => typeof fill === `object` && fill !== null && `type` in fill && `stops` in fill;
@@ -0,0 +1,10 @@
1
+ export * from './components';
2
+ export * from './data-cleaning';
3
+ export * from './fill-utils';
4
+ export * from './interactions';
5
+ export * from './layout';
6
+ export * from './reference-line';
7
+ export * from './scales';
8
+ export * from './svg';
9
+ export * from './types';
10
+ export * from './utils';
@@ -0,0 +1,11 @@
1
+ // Shared cross-chart foundation: types, scales, layout, interactions + primitive components
2
+ export * from './components';
3
+ export * from './data-cleaning';
4
+ export * from './fill-utils';
5
+ export * from './interactions';
6
+ export * from './layout';
7
+ export * from './reference-line';
8
+ export * from './scales';
9
+ export * from './svg';
10
+ export * from './types';
11
+ export * from './utils';
@@ -0,0 +1,39 @@
1
+ import { type Point2D, type Vec2 } from '../../math';
2
+ import type { AxisRanges, InitialRanges, ScaleType, Y2SyncConfig, Y2SyncMode } from './types';
3
+ export declare function get_relative_coords(evt: MouseEvent, element?: EventTarget | null): Point2D | null;
4
+ export declare function closest_data_idx(event: Event, attr: string, root?: Element | null): number | null;
5
+ export declare function normalize_y2_sync(sync: Y2SyncConfig | Y2SyncMode | undefined): Y2SyncConfig;
6
+ export declare function sync_y2_range(y1_range: Vec2, y2_base_range: Vec2, sync: Y2SyncConfig): Vec2;
7
+ export declare const snapshot_ranges: ({ x, x2, y, y2 }: AxisRanges) => InitialRanges;
8
+ export declare function pan_range_by_pixels(range: Vec2, pixel_delta: number, pixel_span: number, scale_type?: ScaleType): Vec2;
9
+ export declare function zoom_range_by_factor(range: Vec2, factor: number, scale_type?: ScaleType): Vec2;
10
+ export declare const to_epoch_num: (val: number | Date) => number;
11
+ export declare function remove_drag_listeners(move_handlers: ((evt: MouseEvent) => void)[], up_handlers: ((evt: MouseEvent) => void)[]): void;
12
+ export declare const sorted_range: (a: number, b: number) => Vec2;
13
+ export declare function invert_rect_range(scale: {
14
+ invert: (px: number) => number | Date;
15
+ }, a_px: number, b_px: number): Vec2 | null;
16
+ export declare const vec2_equal: (a: Vec2, b: Vec2) => boolean;
17
+ export declare const axis_ranges_equal: (a: AxisRanges, b: AxisRanges) => boolean;
18
+ type AxisRangeOverride = {
19
+ range?: [number | null, number | null];
20
+ };
21
+ type AutoRanges = {
22
+ x: readonly number[];
23
+ x2: readonly number[];
24
+ y: readonly number[];
25
+ y2: readonly number[];
26
+ };
27
+ export declare function resolve_axis_ranges(axes: {
28
+ x: AxisRangeOverride;
29
+ x2: AxisRangeOverride;
30
+ y: AxisRangeOverride;
31
+ y2: AxisRangeOverride;
32
+ }, auto: AutoRanges): AxisRanges | null;
33
+ export declare const PINCH_ZOOM_THRESHOLD = 0.1;
34
+ export declare const MIN_TOUCH_DISTANCE_PIXELS = 10;
35
+ export declare function expand_range_if_needed(current: Vec2, new_range: Vec2): {
36
+ range: Vec2;
37
+ changed: boolean;
38
+ };
39
+ export {};
@@ -0,0 +1,209 @@
1
+ import { LOG_EPS } from '../../math';
2
+ import { get_arcsinh_threshold, get_scale_type_name } from './types';
3
+ // Get coordinates of a mouse event relative to an element (the event's
4
+ // currentTarget by default; pass `element` when the handler is delegated and the
5
+ // reference frame differs, e.g. coordinates relative to the svg root)
6
+ export function get_relative_coords(evt, element = evt.currentTarget) {
7
+ if (!(element instanceof Element))
8
+ return null;
9
+ const box = element.getBoundingClientRect();
10
+ if (!box)
11
+ return null;
12
+ return { x: evt.clientX - box.left, y: evt.clientY - box.top };
13
+ }
14
+ // Resolve a delegated event to the integer value of the nearest ancestor's data
15
+ // attribute (e.g. data-sunburst-node-idx), scoped to `root` so targets outside the
16
+ // component don't leak in. Returns null when the event didn't hit an indexed element.
17
+ export function closest_data_idx(event, attr, root) {
18
+ const target = event.target instanceof Element ? event.target.closest(`[${attr}]`) : null;
19
+ if (!target || (root && !root.contains(target)))
20
+ return null;
21
+ const idx = Number(target.getAttribute(attr));
22
+ return Number.isInteger(idx) ? idx : null;
23
+ }
24
+ // Normalize Y2 sync config (handle shorthand string vs full object)
25
+ export function normalize_y2_sync(sync) {
26
+ if (!sync || sync === `none`)
27
+ return { mode: `none` };
28
+ if (typeof sync === `string`)
29
+ return { mode: sync };
30
+ return sync;
31
+ }
32
+ // Helper to check if all values in ranges are finite
33
+ const all_finite = (...ranges) => ranges.every(([a, b]) => Number.isFinite(a) && Number.isFinite(b));
34
+ // Calculate synced y2 range based on sync mode
35
+ export function sync_y2_range(y1_range, y2_base_range, sync) {
36
+ if (sync.mode === `none`)
37
+ return y2_base_range;
38
+ if (!all_finite(y1_range, y2_base_range))
39
+ return y2_base_range;
40
+ // Synced: Y2 has exact same range as Y1
41
+ if (sync.mode === `synced`) {
42
+ return [y1_range[0], y1_range[1]];
43
+ }
44
+ // Align: Position so align_val (default 0) is at same relative position on both axes
45
+ // Y2 range expands as needed to show all data while maintaining alignment
46
+ if (sync.mode === `align`) {
47
+ const align_val = sync.align_value ?? 0;
48
+ const y1_span = y1_range[1] - y1_range[0];
49
+ if (y1_span === 0)
50
+ return y2_base_range;
51
+ // Where is align_val in Y1's range? (0 = bottom, 1 = top)
52
+ const rel_pos = (align_val - y1_range[0]) / y1_span;
53
+ // Ensure Y2 range includes both align_val and all data
54
+ const y2_min_data = Math.min(y2_base_range[0], align_val);
55
+ const y2_max_data = Math.max(y2_base_range[1], align_val);
56
+ // Calculate minimum span needed to fit all data while keeping align_val at rel_pos
57
+ // Constraints: y2_min <= y2_min_data AND y2_max >= y2_max_data
58
+ let y2_span = y2_max_data - y2_min_data;
59
+ if (rel_pos > 0) {
60
+ y2_span = Math.max(y2_span, (align_val - y2_min_data) / rel_pos);
61
+ }
62
+ if (rel_pos < 1) {
63
+ y2_span = Math.max(y2_span, (y2_max_data - align_val) / (1 - rel_pos));
64
+ }
65
+ const y2_min_computed = align_val - rel_pos * y2_span;
66
+ const y2_max_computed = align_val + (1 - rel_pos) * y2_span;
67
+ // When align_val is outside y1_range (rel_pos < 0 or > 1), the formula can produce
68
+ // a range that omits y2_base_range or align_val. Ensure both are always included.
69
+ const y2_min = Math.min(y2_min_computed, y2_base_range[0], align_val);
70
+ const y2_max = Math.max(y2_max_computed, y2_base_range[1], align_val);
71
+ return [y2_min, y2_max];
72
+ }
73
+ return y2_base_range;
74
+ }
75
+ // Forward/inverse transform pair mapping an axis's data values onto its visual
76
+ // metric (the space where equal pixel steps are equal steps; identity for
77
+ // linear/time). Pan and pinch must be uniform in *screen* space - doing the math
78
+ // linearly on a log axis stretches one end of the view and shifts past zero into
79
+ // an all-NaN domain. log clamps at LOG_EPS so a non-positive bound (stale explicit
80
+ // range) recovers instead of propagating -Infinity.
81
+ function axis_transform(scale_type) {
82
+ const name = get_scale_type_name(scale_type);
83
+ if (name === `log`) {
84
+ return { to: (val) => Math.log(Math.max(val, LOG_EPS)), from: Math.exp };
85
+ }
86
+ if (name === `arcsinh`) {
87
+ const threshold = get_arcsinh_threshold(scale_type);
88
+ const to = (val) => Math.asinh(val / threshold);
89
+ const from = (val) => Math.sinh(val) * threshold;
90
+ return { to, from };
91
+ }
92
+ return { to: (val) => val, from: (val) => val };
93
+ }
94
+ // Snapshot the four axis ranges as fresh tuples at pan/zoom/touch interaction start
95
+ export const snapshot_ranges = ({ x, x2, y, y2 }) => ({
96
+ initial_x_range: [...x],
97
+ initial_x2_range: [...x2],
98
+ initial_y_range: [...y],
99
+ initial_y2_range: [...y2],
100
+ });
101
+ // Pan a range by a pixel delta, uniformly in screen space: linear axes shift by a
102
+ // constant amount, log axes by a constant factor (which also can't cross zero).
103
+ // `pixel_span` is the plot's pixel extent along the axis.
104
+ export function pan_range_by_pixels(range, pixel_delta, pixel_span, scale_type) {
105
+ if (pixel_span === 0)
106
+ return range;
107
+ const { to, from } = axis_transform(scale_type);
108
+ const [t0, t1] = [to(range[0]), to(range[1])];
109
+ const t_delta = (pixel_delta / pixel_span) * (t1 - t0);
110
+ return [from(t0 + t_delta), from(t1 + t_delta)];
111
+ }
112
+ // Zoom a range about its screen-space center by `factor` (pinch: >1 zooms in).
113
+ // On log axes the fixed point is the geometric mean - the visual center.
114
+ export function zoom_range_by_factor(range, factor, scale_type) {
115
+ // Guard invalid factors (0/negative/NaN) that would emit Infinity/NaN into axis state
116
+ if (!Number.isFinite(factor) || factor <= 0)
117
+ return range;
118
+ const { to, from } = axis_transform(scale_type);
119
+ const [t0, t1] = [to(range[0]), to(range[1])];
120
+ const center = (t0 + t1) / 2;
121
+ const half_span = (t1 - t0) / factor / 2;
122
+ return [from(center - half_span), from(center + half_span)];
123
+ }
124
+ // Coerce a scale.invert result (number, or Date for time scales) to an epoch number
125
+ export const to_epoch_num = (val) => val instanceof Date ? val.getTime() : val;
126
+ // Remove window drag/pan listeners and reset the body cursor. Call from onDestroy:
127
+ // a component unmounting mid-drag would otherwise leak its listeners and leave the
128
+ // cursor stuck (the mouseup that normally cleans up never fires after unmount).
129
+ export function remove_drag_listeners(move_handlers, up_handlers) {
130
+ if (typeof window === `undefined`)
131
+ return;
132
+ for (const handler of move_handlers) {
133
+ window.removeEventListener(`mousemove`, handler);
134
+ }
135
+ for (const handler of up_handlers) {
136
+ window.removeEventListener(`mouseup`, handler);
137
+ }
138
+ document.body.style.cursor = ``;
139
+ }
140
+ // Sorted [min, max] from two scalar bounds (rect-zoom inverts drag start/end,
141
+ // which arrive in either order depending on drag direction)
142
+ export const sorted_range = (a, b) => [Math.min(a, b), Math.max(a, b)];
143
+ // Invert a drag-rect edge pair through a scale to a sorted finite data range
144
+ // (time scales invert to Dates, coerced to epoch numbers). Returns null when
145
+ // either bound is non-finite or the range is degenerate (zero span).
146
+ export function invert_rect_range(scale, a_px, b_px) {
147
+ const range = sorted_range(to_epoch_num(scale.invert(a_px)), to_epoch_num(scale.invert(b_px)));
148
+ return range.every(Number.isFinite) && range[0] !== range[1] ? range : null;
149
+ }
150
+ // Strict per-bound equality of two [min, max] ranges
151
+ export const vec2_equal = (a, b) => a[0] === b[0] && a[1] === b[1];
152
+ // True when all four axis ranges match. The range-sync effects use this to skip
153
+ // no-op writes that would otherwise re-trigger the effect and loop.
154
+ export const axis_ranges_equal = (a, b) => vec2_equal(a.x, b.x) &&
155
+ vec2_equal(a.x2, b.x2) &&
156
+ vec2_equal(a.y, b.y) &&
157
+ vec2_equal(a.y2, b.y2);
158
+ // Merge each axis's explicit range over its auto range (per-bound: a null bound
159
+ // falls back to the auto value). Returns null if any resolved bound is non-finite so
160
+ // the caller can skip the sync - writing NaN breaks scales and, since NaN !== NaN,
161
+ // makes the change comparison never settle (an infinite effect loop).
162
+ export function resolve_axis_ranges(axes, auto) {
163
+ const resolve = (axis, fallback) => [
164
+ axis.range?.[0] ?? fallback[0],
165
+ axis.range?.[1] ?? fallback[1],
166
+ ];
167
+ const next = {
168
+ x: resolve(axes.x, auto.x),
169
+ x2: resolve(axes.x2, auto.x2),
170
+ y: resolve(axes.y, auto.y),
171
+ y2: resolve(axes.y2, auto.y2),
172
+ };
173
+ for (const [lo, hi] of [next.x, next.x2, next.y, next.y2]) {
174
+ if (!Number.isFinite(lo) || !Number.isFinite(hi))
175
+ return null;
176
+ }
177
+ return next;
178
+ }
179
+ // Threshold for distinguishing pinch-zoom from pan in touch gestures
180
+ // Scale change > this value triggers zoom instead of pan
181
+ export const PINCH_ZOOM_THRESHOLD = 0.1;
182
+ // Minimum start distance (px) between two touches to treat the gesture as a valid pinch.
183
+ // Guards curr_dist / start_dist scale from blowing up on near-coincident touches
184
+ export const MIN_TOUCH_DISTANCE_PIXELS = 10;
185
+ // Helper to check if range is the default [0, 1] sentinel (no data)
186
+ // Note: min === 0 handles -0 correctly since -0 === 0 in JavaScript
187
+ const is_default_range = ([min, max]) => min === 0 && max === 1;
188
+ // Adopt the new data range, unless all series were hidden (sentinel [0, 1] fallback).
189
+ // NOTE: [0, 1] is the "no data" sentinel - when all series are hidden, auto ranges
190
+ // fall back to [0, 1]. Actual data spanning exactly [0, 1] is a rare edge case.
191
+ export function expand_range_if_needed(current, new_range) {
192
+ // Guard against NaN/Infinity - prefer valid range, fall back to sentinel [0, 1] if both invalid
193
+ const current_valid = all_finite(current);
194
+ const new_valid = all_finite(new_range);
195
+ if (!current_valid && !new_valid)
196
+ return { range: [0, 1], changed: true };
197
+ if (!new_valid)
198
+ return { range: current, changed: false };
199
+ if (!current_valid)
200
+ return { range: new_range, changed: true };
201
+ // When all series are hidden, auto ranges fall back to [0, 1] sentinel.
202
+ // Don't shrink to that — preserve the current view so it doesn't jump.
203
+ if (!is_default_range(current) && is_default_range(new_range)) {
204
+ return { range: current, changed: false };
205
+ }
206
+ // Otherwise adopt the new range directly (both expand and shrink)
207
+ const changed = new_range[0] !== current[0] || new_range[1] !== current[1];
208
+ return { range: new_range, changed };
209
+ }
@@ -6,6 +6,7 @@ export type Sides = {
6
6
  r?: number;
7
7
  };
8
8
  export declare const LABEL_GAP_DEFAULT = 30;
9
+ export declare function y2_axis_label_x(axis: AxisConfig, width: number, pad_r: number, max_tick_width: number): number;
9
10
  export declare const filter_padding: (padding: Partial<Sides> | undefined | null, defaults: Required<Sides>) => Required<Sides>;
10
11
  export declare function measure_text_width(text: string, font?: string): number;
11
12
  export declare function measure_full_footprint(el: HTMLElement): {