matterviz 0.3.1 → 0.3.2

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 (257) hide show
  1. package/dist/FilePicker.svelte +37 -20
  2. package/dist/Icon.svelte +2 -2
  3. package/dist/app.css +29 -0
  4. package/dist/brillouin/BrillouinZone.svelte +19 -61
  5. package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
  6. package/dist/brillouin/BrillouinZoneExportPane.svelte +12 -20
  7. package/dist/brillouin/BrillouinZoneScene.svelte +2 -2
  8. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -1
  9. package/dist/chempot-diagram/ChemPotDiagram.svelte +192 -0
  10. package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +13 -0
  11. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +677 -0
  12. package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +16 -0
  13. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +2688 -0
  14. package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +16 -0
  15. package/dist/chempot-diagram/ChemPotScene3D.svelte +8 -0
  16. package/dist/chempot-diagram/ChemPotScene3D.svelte.d.ts +7 -0
  17. package/dist/chempot-diagram/color.d.ts +10 -0
  18. package/dist/chempot-diagram/color.js +33 -0
  19. package/dist/chempot-diagram/compute.d.ts +38 -0
  20. package/dist/chempot-diagram/compute.js +650 -0
  21. package/dist/chempot-diagram/index.d.ts +5 -0
  22. package/dist/chempot-diagram/index.js +5 -0
  23. package/dist/chempot-diagram/pointer.d.ts +16 -0
  24. package/dist/chempot-diagram/pointer.js +40 -0
  25. package/dist/chempot-diagram/temperature.d.ts +15 -0
  26. package/dist/chempot-diagram/temperature.js +37 -0
  27. package/dist/chempot-diagram/types.d.ts +83 -0
  28. package/dist/chempot-diagram/types.js +27 -0
  29. package/dist/colors/index.d.ts +3 -1
  30. package/dist/colors/index.js +4 -0
  31. package/dist/composition/BarChart.svelte +13 -22
  32. package/dist/composition/BubbleChart.svelte +5 -3
  33. package/dist/composition/FormulaFilter.svelte +586 -94
  34. package/dist/composition/FormulaFilter.svelte.d.ts +35 -1
  35. package/dist/composition/PieChart.svelte +43 -18
  36. package/dist/composition/PieChart.svelte.d.ts +1 -1
  37. package/dist/convex-hull/ConvexHull.svelte +4 -2
  38. package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -1
  39. package/dist/convex-hull/ConvexHull2D.svelte +13 -44
  40. package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
  41. package/dist/convex-hull/ConvexHull3D.svelte +16 -7
  42. package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
  43. package/dist/convex-hull/ConvexHull4D.svelte +17 -7
  44. package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
  45. package/dist/convex-hull/ConvexHullControls.svelte.d.ts +1 -1
  46. package/dist/convex-hull/ConvexHullStats.svelte +701 -226
  47. package/dist/convex-hull/ConvexHullStats.svelte.d.ts +6 -1
  48. package/dist/convex-hull/ConvexHullTooltip.svelte +1 -0
  49. package/dist/convex-hull/demo-temperature.d.ts +6 -0
  50. package/dist/convex-hull/demo-temperature.js +36 -0
  51. package/dist/convex-hull/helpers.d.ts +1 -1
  52. package/dist/convex-hull/helpers.js +2 -4
  53. package/dist/convex-hull/index.d.ts +1 -0
  54. package/dist/convex-hull/index.js +1 -0
  55. package/dist/convex-hull/thermodynamics.d.ts +8 -21
  56. package/dist/convex-hull/thermodynamics.js +106 -17
  57. package/dist/convex-hull/types.d.ts +5 -0
  58. package/dist/convex-hull/types.js +5 -0
  59. package/dist/coordination/CoordinationBarPlot.svelte +29 -46
  60. package/dist/element/BohrAtom.svelte +1 -1
  61. package/dist/element/data.js +2 -14
  62. package/dist/element/data.json.gz +0 -0
  63. package/dist/element/types.d.ts +1 -0
  64. package/dist/fermi-surface/FermiSurface.svelte +20 -64
  65. package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
  66. package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
  67. package/dist/fermi-surface/FermiSurfaceScene.svelte +1 -1
  68. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +1 -1
  69. package/dist/fermi-surface/parse.js +16 -22
  70. package/dist/heatmap-matrix/HeatmapMatrix.svelte +1273 -0
  71. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +110 -0
  72. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +171 -0
  73. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +31 -0
  74. package/dist/heatmap-matrix/index.d.ts +53 -0
  75. package/dist/heatmap-matrix/index.js +100 -0
  76. package/dist/heatmap-matrix/shared.d.ts +2 -0
  77. package/dist/heatmap-matrix/shared.js +4 -0
  78. package/dist/icons.d.ts +111 -0
  79. package/dist/icons.js +111 -0
  80. package/dist/index.d.ts +3 -1
  81. package/dist/index.js +3 -1
  82. package/dist/io/export.js +15 -3
  83. package/dist/io/file-drop.d.ts +7 -0
  84. package/dist/io/file-drop.js +43 -0
  85. package/dist/io/index.d.ts +2 -2
  86. package/dist/io/index.js +2 -112
  87. package/dist/io/types.d.ts +1 -0
  88. package/dist/io/url-drop.d.ts +2 -0
  89. package/dist/io/url-drop.js +118 -0
  90. package/dist/isosurface/Isosurface.svelte +101 -45
  91. package/dist/isosurface/IsosurfaceControls.svelte +19 -0
  92. package/dist/isosurface/parse.js +73 -30
  93. package/dist/isosurface/slice.d.ts +2 -1
  94. package/dist/isosurface/slice.js +3 -3
  95. package/dist/isosurface/types.d.ts +13 -1
  96. package/dist/isosurface/types.js +98 -0
  97. package/dist/labels.d.ts +2 -1
  98. package/dist/labels.js +1 -0
  99. package/dist/layout/InfoTag.svelte +62 -62
  100. package/dist/layout/SubpageGrid.svelte +74 -0
  101. package/dist/layout/SubpageGrid.svelte.d.ts +14 -0
  102. package/dist/layout/index.d.ts +1 -0
  103. package/dist/layout/index.js +1 -0
  104. package/dist/layout/json-tree/JsonNode.svelte +83 -85
  105. package/dist/layout/json-tree/JsonTree.svelte +20 -19
  106. package/dist/layout/json-tree/JsonTree.svelte.d.ts +1 -1
  107. package/dist/layout/json-tree/JsonValue.svelte +196 -116
  108. package/dist/layout/json-tree/types.d.ts +10 -2
  109. package/dist/layout/json-tree/utils.d.ts +2 -0
  110. package/dist/layout/json-tree/utils.js +33 -0
  111. package/dist/math.d.ts +7 -0
  112. package/dist/math.js +358 -7
  113. package/dist/overlays/ContextMenu.svelte +3 -2
  114. package/dist/overlays/DraggablePane.svelte +163 -58
  115. package/dist/overlays/DraggablePane.svelte.d.ts +2 -0
  116. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +232 -77
  117. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +6 -2
  118. package/dist/phase-diagram/PhaseDiagramControls.svelte +32 -11
  119. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +3 -2
  120. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +103 -0
  121. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +15 -0
  122. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +102 -95
  123. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +7 -0
  124. package/dist/phase-diagram/PhaseDiagramTooltip.svelte +100 -26
  125. package/dist/phase-diagram/PhaseDiagramTooltip.svelte.d.ts +6 -3
  126. package/dist/phase-diagram/index.d.ts +2 -0
  127. package/dist/phase-diagram/index.js +2 -0
  128. package/dist/phase-diagram/svg-to-diagram.d.ts +2 -0
  129. package/dist/phase-diagram/svg-to-diagram.js +865 -0
  130. package/dist/phase-diagram/types.d.ts +10 -0
  131. package/dist/phase-diagram/utils.d.ts +7 -4
  132. package/dist/phase-diagram/utils.js +149 -59
  133. package/dist/plot/AxisLabel.svelte +26 -0
  134. package/dist/plot/AxisLabel.svelte.d.ts +16 -0
  135. package/dist/plot/BarPlot.svelte +473 -228
  136. package/dist/plot/BarPlot.svelte.d.ts +3 -3
  137. package/dist/plot/BarPlotControls.svelte +3 -2
  138. package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
  139. package/dist/plot/ColorBar.svelte +54 -54
  140. package/dist/plot/ColorBar.svelte.d.ts +1 -1
  141. package/dist/plot/ColorScaleSelect.svelte +1 -1
  142. package/dist/plot/ElementScatter.svelte +3 -2
  143. package/dist/plot/FillArea.svelte +4 -1
  144. package/dist/plot/Histogram.svelte +320 -230
  145. package/dist/plot/Histogram.svelte.d.ts +2 -2
  146. package/dist/plot/HistogramControls.svelte +29 -10
  147. package/dist/plot/HistogramControls.svelte.d.ts +6 -2
  148. package/dist/plot/InteractiveAxisLabel.svelte.d.ts +2 -2
  149. package/dist/plot/PlotControls.svelte +109 -27
  150. package/dist/plot/PlotControls.svelte.d.ts +1 -1
  151. package/dist/plot/PlotLegend.svelte +1 -1
  152. package/dist/plot/PortalSelect.svelte +2 -1
  153. package/dist/plot/ReferenceLine.svelte +2 -1
  154. package/dist/plot/ReferenceLine.svelte.d.ts +1 -0
  155. package/dist/plot/ReferencePlane.svelte +1 -3
  156. package/dist/plot/ScatterPlot.svelte +343 -209
  157. package/dist/plot/ScatterPlot.svelte.d.ts +3 -3
  158. package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
  159. package/dist/plot/ScatterPlot3DControls.svelte +203 -250
  160. package/dist/plot/ScatterPlot3DScene.svelte +4 -7
  161. package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
  162. package/dist/plot/ScatterPlotControls.svelte +95 -55
  163. package/dist/plot/ScatterPlotControls.svelte.d.ts +1 -1
  164. package/dist/plot/ZeroLines.svelte +44 -0
  165. package/dist/plot/ZeroLines.svelte.d.ts +32 -0
  166. package/dist/plot/ZoomRect.svelte +21 -0
  167. package/dist/plot/ZoomRect.svelte.d.ts +8 -0
  168. package/dist/plot/axis-utils.d.ts +1 -1
  169. package/dist/plot/index.d.ts +6 -2
  170. package/dist/plot/index.js +6 -2
  171. package/dist/plot/interactions.d.ts +8 -10
  172. package/dist/plot/interactions.js +2 -3
  173. package/dist/plot/layout.d.ts +7 -1
  174. package/dist/plot/layout.js +12 -4
  175. package/dist/plot/reference-line.d.ts +4 -21
  176. package/dist/plot/reference-line.js +7 -81
  177. package/dist/plot/types.d.ts +42 -17
  178. package/dist/plot/types.js +10 -0
  179. package/dist/plot/utils/label-placement.js +13 -10
  180. package/dist/plot/utils.d.ts +1 -0
  181. package/dist/plot/utils.js +14 -0
  182. package/dist/rdf/RdfPlot.svelte +55 -66
  183. package/dist/settings.d.ts +3 -0
  184. package/dist/settings.js +17 -3
  185. package/dist/spectral/Bands.svelte +515 -143
  186. package/dist/spectral/Bands.svelte.d.ts +22 -2
  187. package/dist/spectral/helpers.d.ts +23 -1
  188. package/dist/spectral/helpers.js +65 -9
  189. package/dist/spectral/types.d.ts +2 -0
  190. package/dist/structure/AtomLegend.svelte +29 -8
  191. package/dist/structure/AtomLegend.svelte.d.ts +1 -1
  192. package/dist/structure/CellSelect.svelte +92 -22
  193. package/dist/structure/Structure.svelte +108 -118
  194. package/dist/structure/Structure.svelte.d.ts +1 -1
  195. package/dist/structure/StructureControls.svelte +25 -22
  196. package/dist/structure/StructureControls.svelte.d.ts +1 -1
  197. package/dist/structure/StructureInfoPane.svelte +7 -1
  198. package/dist/structure/StructureScene.svelte +104 -66
  199. package/dist/structure/StructureScene.svelte.d.ts +2 -1
  200. package/dist/structure/atom-properties.d.ts +6 -2
  201. package/dist/structure/atom-properties.js +38 -25
  202. package/dist/structure/export.js +10 -7
  203. package/dist/structure/ferrox-wasm-types.d.ts +3 -2
  204. package/dist/structure/ferrox-wasm-types.js +0 -3
  205. package/dist/structure/ferrox-wasm.d.ts +3 -2
  206. package/dist/structure/ferrox-wasm.js +1 -2
  207. package/dist/structure/index.d.ts +6 -0
  208. package/dist/structure/index.js +22 -0
  209. package/dist/structure/parse.js +19 -16
  210. package/dist/structure/partial-occupancy.d.ts +25 -0
  211. package/dist/structure/partial-occupancy.js +102 -0
  212. package/dist/structure/validation.js +6 -3
  213. package/dist/symmetry/SymmetryStats.svelte +18 -4
  214. package/dist/symmetry/WyckoffTable.svelte +18 -10
  215. package/dist/symmetry/index.d.ts +7 -4
  216. package/dist/symmetry/index.js +83 -18
  217. package/dist/table/HeatmapTable.svelte +425 -65
  218. package/dist/table/HeatmapTable.svelte.d.ts +12 -1
  219. package/dist/table/ToggleMenu.svelte +2 -0
  220. package/dist/table/index.d.ts +2 -0
  221. package/dist/trajectory/Trajectory.svelte +147 -145
  222. package/dist/trajectory/TrajectoryExportPane.svelte +13 -9
  223. package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +1 -1
  224. package/dist/trajectory/constants.d.ts +6 -0
  225. package/dist/trajectory/constants.js +7 -0
  226. package/dist/trajectory/extract.js +3 -5
  227. package/dist/trajectory/format-detect.d.ts +9 -0
  228. package/dist/trajectory/format-detect.js +76 -0
  229. package/dist/trajectory/frame-reader.d.ts +17 -0
  230. package/dist/trajectory/frame-reader.js +339 -0
  231. package/dist/trajectory/helpers.d.ts +15 -0
  232. package/dist/trajectory/helpers.js +187 -0
  233. package/dist/trajectory/index.d.ts +1 -0
  234. package/dist/trajectory/index.js +11 -4
  235. package/dist/trajectory/parse/ase.d.ts +2 -0
  236. package/dist/trajectory/parse/ase.js +76 -0
  237. package/dist/trajectory/parse/hdf5.d.ts +2 -0
  238. package/dist/trajectory/parse/hdf5.js +121 -0
  239. package/dist/trajectory/parse/index.d.ts +12 -0
  240. package/dist/trajectory/parse/index.js +304 -0
  241. package/dist/trajectory/parse/lammps.d.ts +5 -0
  242. package/dist/trajectory/parse/lammps.js +169 -0
  243. package/dist/trajectory/parse/vasp.d.ts +2 -0
  244. package/dist/trajectory/parse/vasp.js +65 -0
  245. package/dist/trajectory/parse/xyz.d.ts +2 -0
  246. package/dist/trajectory/parse/xyz.js +109 -0
  247. package/dist/trajectory/types.d.ts +11 -0
  248. package/dist/trajectory/types.js +1 -0
  249. package/dist/utils.d.ts +2 -0
  250. package/dist/utils.js +4 -0
  251. package/dist/xrd/XrdPlot.svelte +6 -4
  252. package/dist/xrd/calc-xrd.js +0 -1
  253. package/package.json +30 -24
  254. package/readme.md +4 -4
  255. package/dist/trajectory/parse.d.ts +0 -42
  256. package/dist/trajectory/parse.js +0 -1267
  257. /package/dist/element/{data.json.d.ts → data.json.gz.d.ts} +0 -0
@@ -4,8 +4,16 @@ import { DEFAULTS } from '../settings';
4
4
  import { tooltip } from 'svelte-multiselect/attachments';
5
5
  // Unique ID prefix to avoid conflicts when multiple instances on same page
6
6
  const uid = crypto.randomUUID().slice(0, 8);
7
- let { series = [], x_axis = $bindable({}), y_axis = $bindable({}), y2_axis = $bindable({}), display = $bindable({}), styles = $bindable({}), selected_series_idx = $bindable(0), on_touch, children, ...rest } = $props();
8
- let has_multiple_series = $derived(series.filter(Boolean).length > 1);
7
+ let { series = [], x_axis = $bindable({}), x2_axis = $bindable({}), y_axis = $bindable({}), y2_axis = $bindable({}), display = $bindable({}), styles = $bindable({}), selected_series_idx = $bindable(0), on_touch, children, ...rest } = $props();
8
+ let non_null_series = $derived(series.filter((srs) => srs != null));
9
+ let visible_series = $derived(non_null_series.filter((srs) => (srs.visible ?? true)));
10
+ let has_multiple_series = $derived(non_null_series.length > 1);
11
+ // Derive what marker types are present, and whether color/size are data-driven
12
+ const markers_include = (mode) => visible_series.some((srs) => (srs?.markers ?? `line+points`).includes(mode));
13
+ let has_any_lines = $derived(markers_include(`line`));
14
+ let has_any_points = $derived(markers_include(`points`));
15
+ let has_color_data = $derived(visible_series.some((srs) => srs?.color_values?.some((val) => val != null)));
16
+ let has_size_data = $derived(visible_series.some((srs) => srs?.size_values?.some((val) => val != null)));
9
17
  $effect(() => {
10
18
  styles.show_points ??= DEFAULTS.scatter.show_points;
11
19
  styles.show_lines ??= DEFAULTS.scatter.show_lines;
@@ -17,30 +25,52 @@ const touch = ({ target }) => {
17
25
  };
18
26
  </script>
19
27
 
20
- <PlotControls bind:x_axis bind:y_axis bind:y2_axis bind:display show_controls {...rest}>
21
- {@render children?.({ x_axis, y_axis, y2_axis, display, styles, selected_series_idx })}
22
- <SettingsSection
23
- title="Markers"
24
- current_values={{ show_points: styles.show_points, show_lines: styles.show_lines }}
25
- on_reset={() => {
26
- styles.show_points = DEFAULTS.scatter.show_points
27
- styles.show_lines = DEFAULTS.scatter.show_lines
28
- }}
29
- style="display: flex; flex-wrap: wrap; gap: 1ex"
30
- >
31
- <label
32
- {@attach tooltip({ content: `Toggle visibility of data points in the scatter plot` })}
28
+ <PlotControls
29
+ bind:x_axis
30
+ bind:x2_axis
31
+ bind:y_axis
32
+ bind:y2_axis
33
+ bind:display
34
+ show_controls
35
+ {...rest}
36
+ >
37
+ {@render children?.({
38
+ x_axis,
39
+ x2_axis,
40
+ y_axis,
41
+ y2_axis,
42
+ display,
43
+ styles,
44
+ selected_series_idx,
45
+ })}
46
+ {#if has_any_points || has_any_lines}
47
+ <SettingsSection
48
+ title="Markers"
49
+ current_values={{ show_points: styles.show_points, show_lines: styles.show_lines }}
50
+ on_reset={() => {
51
+ styles.show_points = DEFAULTS.scatter.show_points
52
+ styles.show_lines = DEFAULTS.scatter.show_lines
53
+ }}
54
+ style="display: flex; flex-wrap: wrap; gap: 1ex"
33
55
  >
34
- <input type="checkbox" bind:checked={styles.show_points} /> Show points
35
- </label>
36
- <label
37
- {@attach tooltip({
38
- content: `Toggle visibility of connecting lines between data points`,
39
- })}
40
- >
41
- <input type="checkbox" bind:checked={styles.show_lines} /> Show lines
42
- </label>
43
- </SettingsSection>
56
+ {#if has_any_points}
57
+ <label
58
+ {@attach tooltip({ content: `Toggle visibility of data points in the scatter plot` })}
59
+ >
60
+ <input type="checkbox" bind:checked={styles.show_points} /> Show points
61
+ </label>
62
+ {/if}
63
+ {#if has_any_lines}
64
+ <label
65
+ {@attach tooltip({
66
+ content: `Toggle visibility of connecting lines between data points`,
67
+ })}
68
+ >
69
+ <input type="checkbox" bind:checked={styles.show_lines} /> Show lines
70
+ </label>
71
+ {/if}
72
+ </SettingsSection>
73
+ {/if}
44
74
 
45
75
  {#snippet post_children()}
46
76
  <!-- Series Selection (for multi-series style controls) -->
@@ -59,8 +89,8 @@ const touch = ({ target }) => {
59
89
  </div>
60
90
  {/if}
61
91
 
62
- <!-- Point Style Controls -->
63
- {#if styles.show_points}
92
+ <!-- Point Style Controls: only when points exist and are visible -->
93
+ {#if has_any_points && styles.show_points}
64
94
  <SettingsSection
65
95
  title="Point Style"
66
96
  current_values={styles.point ?? {}}
@@ -71,28 +101,36 @@ const touch = ({ target }) => {
71
101
  oninput={touch}
72
102
  >
73
103
  {#if styles.point}
74
- <div class="pane-row" data-key="point.size">
75
- <label for="{uid}-point-size">Size:</label>
76
- <input
77
- id="{uid}-point-size"
78
- type="range"
79
- min="1"
80
- max="20"
81
- step="0.5"
82
- bind:value={styles.point.size}
83
- />
84
- <input
85
- type="number"
86
- min="1"
87
- max="20"
88
- step="0.5"
89
- bind:value={styles.point.size}
90
- />
91
- </div>
92
- <div class="pane-row" data-key="point.color">
93
- <label for="{uid}-point-color">Color:</label>
94
- <input id="{uid}-point-color" type="color" bind:value={styles.point.color} />
95
- </div>
104
+ {#if !has_size_data}
105
+ <div class="pane-row" data-key="point.size">
106
+ <label for="{uid}-point-size">Size:</label>
107
+ <input
108
+ id="{uid}-point-size"
109
+ type="range"
110
+ min="1"
111
+ max="20"
112
+ step="0.5"
113
+ bind:value={styles.point.size}
114
+ />
115
+ <input
116
+ type="number"
117
+ min="1"
118
+ max="20"
119
+ step="0.5"
120
+ bind:value={styles.point.size}
121
+ />
122
+ </div>
123
+ {/if}
124
+ {#if !has_color_data}
125
+ <div class="pane-row" data-key="point.color">
126
+ <label for="{uid}-point-color">Color:</label>
127
+ <input
128
+ id="{uid}-point-color"
129
+ type="color"
130
+ bind:value={styles.point.color}
131
+ />
132
+ </div>
133
+ {/if}
96
134
  <div class="pane-row" data-key="point.opacity">
97
135
  <label for="{uid}-point-opacity">Opacity:</label>
98
136
  <input
@@ -159,8 +197,8 @@ const touch = ({ target }) => {
159
197
  </SettingsSection>
160
198
  {/if}
161
199
 
162
- <!-- Line Style Controls -->
163
- {#if styles.show_lines}
200
+ <!-- Line Style Controls: only when lines exist and are visible -->
201
+ {#if has_any_lines && styles.show_lines}
164
202
  <SettingsSection
165
203
  title="Line Style"
166
204
  current_values={styles.line ?? {}}
@@ -189,10 +227,12 @@ const touch = ({ target }) => {
189
227
  bind:value={styles.line.width}
190
228
  />
191
229
  </div>
192
- <div class="pane-row" data-key="line.color">
193
- <label for="{uid}-line-color">Color:</label>
194
- <input id="{uid}-line-color" type="color" bind:value={styles.line.color} />
195
- </div>
230
+ {#if !has_color_data}
231
+ <div class="pane-row" data-key="line.color">
232
+ <label for="{uid}-line-color">Color:</label>
233
+ <input id="{uid}-line-color" type="color" bind:value={styles.line.color} />
234
+ </div>
235
+ {/if}
196
236
  <div class="pane-row" data-key="line.opacity">
197
237
  <label for="{uid}-line-opacity">Opacity:</label>
198
238
  <input
@@ -12,6 +12,6 @@ type $$ComponentProps = Omit<PlotControlsProps, `children` | `post_children`> &
12
12
  } & Required<PlotConfig>
13
13
  ]>;
14
14
  };
15
- declare const ScatterPlotControls: import("svelte").Component<$$ComponentProps, {}, "display" | "x_axis" | "y_axis" | "y2_axis" | "selected_series_idx" | "styles">;
15
+ declare const ScatterPlotControls: import("svelte").Component<$$ComponentProps, {}, "display" | "x_axis" | "x2_axis" | "y_axis" | "y2_axis" | "selected_series_idx" | "styles">;
16
16
  type ScatterPlotControls = ReturnType<typeof ScatterPlotControls>;
17
17
  export default ScatterPlotControls;
@@ -0,0 +1,44 @@
1
+ <script lang="ts">import { get_scale_type_name } from './';
2
+ let { display, x_scale_fn, x2_scale_fn, y_scale_fn, y2_scale_fn, x_range, x2_range, y_range, y2_range, x_scale_type, x2_scale_type, y_scale_type, y2_scale_type, x_is_time = false, x2_is_time = false, has_x2 = false, has_y2 = false, width, height, pad, } = $props();
3
+ const spans_zero = (range) => Math.min(range[0], range[1]) <= 0 && Math.max(range[0], range[1]) >= 0;
4
+ </script>
5
+
6
+ {#if display.x_zero_line && get_scale_type_name(x_scale_type) !== `log` &&
7
+ !x_is_time && spans_zero(x_range)}
8
+ {@const zero_x = x_scale_fn(0)}
9
+ {#if isFinite(zero_x)}
10
+ <line class="zero-line" x1={zero_x} x2={zero_x} y1={pad.t} y2={height - pad.b} />
11
+ {/if}
12
+ {/if}
13
+
14
+ {#if display.x2_zero_line && has_x2 && x2_scale_fn && x2_range &&
15
+ get_scale_type_name(x2_scale_type) !== `log` && !x2_is_time && spans_zero(x2_range)}
16
+ {@const zero_x2 = x2_scale_fn(0)}
17
+ {#if isFinite(zero_x2)}
18
+ <line class="zero-line" x1={zero_x2} x2={zero_x2} y1={pad.t} y2={height - pad.b} />
19
+ {/if}
20
+ {/if}
21
+
22
+ {#if display.y_zero_line && get_scale_type_name(y_scale_type) !== `log` &&
23
+ spans_zero(y_range)}
24
+ {@const zero_y = y_scale_fn(0)}
25
+ {#if isFinite(zero_y)}
26
+ <line class="zero-line" x1={pad.l} x2={width - pad.r} y1={zero_y} y2={zero_y} />
27
+ {/if}
28
+ {/if}
29
+
30
+ {#if display.y2_zero_line && has_y2 && y2_scale_fn && y2_range &&
31
+ get_scale_type_name(y2_scale_type) !== `log` && spans_zero(y2_range)}
32
+ {@const zero_y2 = y2_scale_fn(0)}
33
+ {#if isFinite(zero_y2)}
34
+ <line class="zero-line" x1={pad.l} x2={width - pad.r} y1={zero_y2} y2={zero_y2} />
35
+ {/if}
36
+ {/if}
37
+
38
+ <style>
39
+ .zero-line {
40
+ stroke: var(--plot-zero-line-color, light-dark(black, white));
41
+ stroke-width: var(--plot-zero-line-width, 1);
42
+ opacity: var(--plot-zero-line-opacity, 0.3);
43
+ }
44
+ </style>
@@ -0,0 +1,32 @@
1
+ import type { Vec2 } from '../math';
2
+ import { type ScaleType, type Sides } from './';
3
+ type $$ComponentProps = {
4
+ display: {
5
+ x_zero_line?: boolean;
6
+ x2_zero_line?: boolean;
7
+ y_zero_line?: boolean;
8
+ y2_zero_line?: boolean;
9
+ };
10
+ x_scale_fn: (val: number) => number;
11
+ x2_scale_fn?: (val: number) => number;
12
+ y_scale_fn: (val: number) => number;
13
+ y2_scale_fn?: (val: number) => number;
14
+ x_range: Vec2;
15
+ x2_range?: Vec2;
16
+ y_range: Vec2;
17
+ y2_range?: Vec2;
18
+ x_scale_type?: ScaleType;
19
+ x2_scale_type?: ScaleType;
20
+ y_scale_type?: ScaleType;
21
+ y2_scale_type?: ScaleType;
22
+ x_is_time?: boolean;
23
+ x2_is_time?: boolean;
24
+ has_x2?: boolean;
25
+ has_y2?: boolean;
26
+ width: number;
27
+ height: number;
28
+ pad: Required<Sides>;
29
+ };
30
+ declare const ZeroLines: import("svelte").Component<$$ComponentProps, {}, "">;
31
+ type ZeroLines = ReturnType<typeof ZeroLines>;
32
+ export default ZeroLines;
@@ -0,0 +1,21 @@
1
+ <script lang="ts">let { start, current } = $props();
2
+ export {};
3
+ </script>
4
+
5
+ {#if start && current && isFinite(start.x) && isFinite(start.y) &&
6
+ isFinite(current.x) && isFinite(current.y)}
7
+ {@const x = Math.min(start.x, current.x)}
8
+ {@const y = Math.min(start.y, current.y)}
9
+ {@const rect_width = Math.abs(start.x - current.x)}
10
+ {@const rect_height = Math.abs(start.y - current.y)}
11
+ <rect class="zoom-rect" {x} {y} width={rect_width} height={rect_height} />
12
+ {/if}
13
+
14
+ <style>
15
+ .zoom-rect {
16
+ fill: var(--plot-zoom-rect-fill, rgba(100, 100, 255, 0.2));
17
+ stroke: var(--plot-zoom-rect-stroke, rgba(100, 100, 255, 0.8));
18
+ stroke-width: var(--plot-zoom-rect-stroke-width, 1);
19
+ pointer-events: none;
20
+ }
21
+ </style>
@@ -0,0 +1,8 @@
1
+ import type { XyObj } from './';
2
+ type $$ComponentProps = {
3
+ start: XyObj | null;
4
+ current: XyObj | null;
5
+ };
6
+ declare const ZoomRect: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type ZoomRect = ReturnType<typeof ZoomRect>;
8
+ export default ZoomRect;
@@ -1,5 +1,5 @@
1
1
  import type { AxisConfig, AxisLoadError, BarSeries, DataLoaderFn, DataSeries } from './types';
2
- type AxisType = `x` | `y` | `y2`;
2
+ type AxisType = `x` | `x2` | `y` | `y2`;
3
3
  export declare function merge_series_state<T extends DataSeries | BarSeries>(old_series: T[], new_series: T[]): T[];
4
4
  export interface AxisChangeState<T extends DataSeries | BarSeries> {
5
5
  get_axis: (axis: AxisType) => AxisConfig;
@@ -4,17 +4,19 @@ export interface TweenedOptions<T> {
4
4
  easing?: (t: number) => number;
5
5
  interpolate?: (a: T, b: T) => (t: number) => T;
6
6
  }
7
+ export { default as AxisLabel } from './AxisLabel.svelte';
7
8
  export { default as BarPlot } from './BarPlot.svelte';
8
9
  export { default as BarPlotControls } from './BarPlotControls.svelte';
9
10
  export { default as ColorBar } from './ColorBar.svelte';
10
11
  export { default as ColorScaleSelect } from './ColorScaleSelect.svelte';
12
+ export * from './data-cleaning';
11
13
  export { default as ElementScatter } from './ElementScatter.svelte';
12
14
  export * from './fill-utils';
13
15
  export { default as FillArea } from './FillArea.svelte';
14
16
  export { default as Histogram } from './Histogram.svelte';
15
17
  export { default as HistogramControls } from './HistogramControls.svelte';
16
- export { default as InteractiveAxisLabel } from './InteractiveAxisLabel.svelte';
17
18
  export * from './interactions';
19
+ export { default as InteractiveAxisLabel } from './InteractiveAxisLabel.svelte';
18
20
  export * from './layout';
19
21
  export { default as Line } from './Line.svelte';
20
22
  export { default as PlotControls } from './PlotControls.svelte';
@@ -36,4 +38,6 @@ export { default as SpacegroupBarPlot } from './SpacegroupBarPlot.svelte';
36
38
  export { default as Surface3D } from './Surface3D.svelte';
37
39
  export * from './svg';
38
40
  export * from './types';
39
- export * from './data-cleaning';
41
+ export * from './utils';
42
+ export { default as ZeroLines } from './ZeroLines.svelte';
43
+ export { default as ZoomRect } from './ZoomRect.svelte';
@@ -1,14 +1,16 @@
1
+ export { default as AxisLabel } from './AxisLabel.svelte';
1
2
  export { default as BarPlot } from './BarPlot.svelte';
2
3
  export { default as BarPlotControls } from './BarPlotControls.svelte';
3
4
  export { default as ColorBar } from './ColorBar.svelte';
4
5
  export { default as ColorScaleSelect } from './ColorScaleSelect.svelte';
6
+ export * from './data-cleaning';
5
7
  export { default as ElementScatter } from './ElementScatter.svelte';
6
8
  export * from './fill-utils';
7
9
  export { default as FillArea } from './FillArea.svelte';
8
10
  export { default as Histogram } from './Histogram.svelte';
9
11
  export { default as HistogramControls } from './HistogramControls.svelte';
10
- export { default as InteractiveAxisLabel } from './InteractiveAxisLabel.svelte';
11
12
  export * from './interactions';
13
+ export { default as InteractiveAxisLabel } from './InteractiveAxisLabel.svelte';
12
14
  export * from './layout';
13
15
  export { default as Line } from './Line.svelte';
14
16
  export { default as PlotControls } from './PlotControls.svelte';
@@ -30,4 +32,6 @@ export { default as SpacegroupBarPlot } from './SpacegroupBarPlot.svelte';
30
32
  export { default as Surface3D } from './Surface3D.svelte';
31
33
  export * from './svg';
32
34
  export * from './types';
33
- export * from './data-cleaning';
35
+ export * from './utils';
36
+ export { default as ZeroLines } from './ZeroLines.svelte';
37
+ export { default as ZoomRect } from './ZoomRect.svelte';
@@ -1,14 +1,12 @@
1
- import type { Y2SyncConfig, Y2SyncMode } from './types';
2
- export declare function get_relative_coords(evt: MouseEvent): {
3
- x: number;
4
- y: number;
5
- } | null;
1
+ import type { Vec2 } from '../math';
2
+ import type { XyObj, Y2SyncConfig, Y2SyncMode } from './types';
3
+ export declare function get_relative_coords(evt: MouseEvent): XyObj | null;
6
4
  export declare function normalize_y2_sync(sync: Y2SyncConfig | Y2SyncMode | undefined): Y2SyncConfig;
7
- export declare function sync_y2_range(y1_range: [number, number], y2_base_range: [number, number], sync: Y2SyncConfig): [number, number];
8
- export declare function pan_range(current: [number, number], delta: number): [number, number];
9
- export declare function pixels_to_data_delta(pixel_delta: number, data_range: [number, number], pixel_range: number): number;
5
+ export declare function sync_y2_range(y1_range: Vec2, y2_base_range: Vec2, sync: Y2SyncConfig): Vec2;
6
+ export declare function pan_range(current: Vec2, delta: number): Vec2;
7
+ export declare function pixels_to_data_delta(pixel_delta: number, data_range: Vec2, pixel_range: number): number;
10
8
  export declare const PINCH_ZOOM_THRESHOLD = 0.1;
11
- export declare function expand_range_if_needed(current: [number, number], new_range: [number, number]): {
12
- range: [number, number];
9
+ export declare function expand_range_if_needed(current: Vec2, new_range: Vec2): {
10
+ range: Vec2;
13
11
  changed: boolean;
14
12
  };
@@ -1,9 +1,8 @@
1
1
  // Get relative coordinates from a mouse event
2
2
  export function get_relative_coords(evt) {
3
3
  const current_target = evt.currentTarget;
4
- if (!current_target || typeof current_target.getBoundingClientRect !== `function`) {
4
+ if (!(current_target instanceof SVGElement))
5
5
  return null;
6
- }
7
6
  const svg_box = current_target.getBoundingClientRect();
8
7
  if (!svg_box)
9
8
  return null;
@@ -27,7 +26,7 @@ export function sync_y2_range(y1_range, y2_base_range, sync) {
27
26
  return y2_base_range;
28
27
  // Synced: Y2 has exact same range as Y1
29
28
  if (sync.mode === `synced`) {
30
- return [...y1_range];
29
+ return [y1_range[0], y1_range[1]];
31
30
  }
32
31
  // Align: Position so align_val (default 0) is at same relative position on both axes
33
32
  // Y2 range expands as needed to show all data while maintaining alignment
@@ -5,6 +5,9 @@ export declare function measure_text_width(text: string, font?: string): number;
5
5
  export interface AutoPaddingConfig {
6
6
  padding: Partial<Sides>;
7
7
  default_padding: Required<Sides>;
8
+ x2_axis?: AxisConfig & {
9
+ tick_values?: (string | number)[];
10
+ };
8
11
  y_axis?: AxisConfig & {
9
12
  tick_values?: (string | number)[];
10
13
  };
@@ -13,7 +16,10 @@ export interface AutoPaddingConfig {
13
16
  };
14
17
  label_gap?: number;
15
18
  }
16
- export declare const calc_auto_padding: ({ padding, default_padding, y_axis, y2_axis, label_gap, }: AutoPaddingConfig) => Required<Sides>;
19
+ export declare const measure_max_tick_width: (ticks: (string | number)[], format?: string) => number;
20
+ export declare const TICK_LABEL_HEIGHT = 16;
21
+ export declare const AXIS_LABEL_HEIGHT = 20;
22
+ export declare const calc_auto_padding: ({ padding, default_padding, x2_axis, y_axis, y2_axis, label_gap, }: AutoPaddingConfig) => Required<Sides>;
17
23
  export declare function constrain_tooltip_position(cursor_x: number, cursor_y: number, tooltip_width: number, tooltip_height: number, viewport_width: number, viewport_height: number, options?: {
18
24
  offset?: number;
19
25
  offset_x?: number;
@@ -22,18 +22,26 @@ export function measure_text_width(text, font = `12px sans-serif`) {
22
22
  ctx.font = font;
23
23
  return ctx.measureText(text).width;
24
24
  }
25
- // Helper to measure max tick width
26
- const measure_max_tick_width = (ticks, format = ``) => ticks.length === 0 ? 0 : Math.max(...ticks.map((tick) => {
25
+ // Measure the widest formatted tick label. Used for auto-padding and label placement.
26
+ export const measure_max_tick_width = (ticks, format = ``) => ticks.length === 0 ? 0 : Math.max(...ticks.map((tick) => {
27
27
  const label = typeof tick === `string` ? tick : format_value(tick, format);
28
28
  return measure_text_width(label, `12px sans-serif`);
29
29
  }));
30
- export const calc_auto_padding = ({ padding, default_padding, y_axis = {}, y2_axis = {}, label_gap = LABEL_GAP_DEFAULT, }) => {
30
+ // Estimated height of a single tick label line (font-size 0.8em 12px + leading)
31
+ export const TICK_LABEL_HEIGHT = 16;
32
+ // Estimated height of an axis label (font-size ~14px + margin)
33
+ export const AXIS_LABEL_HEIGHT = 20;
34
+ export const calc_auto_padding = ({ padding, default_padding, x2_axis = {}, y_axis = {}, y2_axis = {}, label_gap = LABEL_GAP_DEFAULT, }) => {
35
+ const x2_ticks = x2_axis.tick_values ?? [];
31
36
  const y_ticks = y_axis.tick_values ?? [];
32
37
  const y_format = y_axis.format ?? ``;
33
38
  const y2_ticks = y2_axis.tick_values ?? [];
34
39
  const y2_format = y2_axis.format ?? ``;
35
40
  return {
36
- t: padding.t ?? default_padding.t,
41
+ t: padding.t ??
42
+ (x2_ticks.length > 0
43
+ ? Math.max(default_padding.t, TICK_LABEL_HEIGHT + label_gap + (x2_axis.label ? AXIS_LABEL_HEIGHT : 0))
44
+ : default_padding.t),
37
45
  b: padding.b ?? default_padding.b,
38
46
  l: padding.l ??
39
47
  Math.max(default_padding.l, measure_max_tick_width(y_ticks, y_format) + label_gap),
@@ -1,5 +1,4 @@
1
- import type { Vec3 } from '../math';
2
- import type { RefLine, RefLine3D, RefLine3DBase, RefLineBase, RefLineValue, RefPlane, RefPlaneBase } from './types';
1
+ import type { RefLine, RefLineValue } from './types';
3
2
  export type IndexedRefLine = RefLine & {
4
3
  idx: number;
5
4
  };
@@ -12,31 +11,15 @@ export interface RefLinesByZIndex {
12
11
  }
13
12
  export declare function group_ref_lines_by_z(lines: IndexedRefLine[]): RefLinesByZIndex;
14
13
  export declare function normalize_value(value: RefLineValue): number;
15
- export declare function normalize_point(point: [RefLineValue, RefLineValue]): [number, number];
16
- export declare function horizontal_line(y_value: RefLineValue, opts?: Partial<RefLineBase>): RefLine;
17
- export declare function vertical_line(x_value: RefLineValue, opts?: Partial<RefLineBase>): RefLine;
18
- export declare function diagonal_line(slope: number, intercept: number, opts?: Partial<RefLineBase>): RefLine;
19
- export declare function line_segment(p1: [RefLineValue, RefLineValue], p2: [RefLineValue, RefLineValue], opts?: Partial<RefLineBase>): RefLine;
20
- export declare function line_through(p1: [RefLineValue, RefLineValue], p2: [RefLineValue, RefLineValue], opts?: Partial<RefLineBase>): RefLine;
21
- export declare function horizontal_lines(values: RefLineValue[], opts?: Partial<RefLineBase>): RefLine[];
22
- export declare function vertical_lines(values: RefLineValue[], opts?: Partial<RefLineBase>): RefLine[];
23
- export declare function plane_xy(z_value: number, opts?: Partial<RefPlaneBase>): RefPlane;
24
- export declare function plane_xz(y_value: number, opts?: Partial<RefPlaneBase>): RefPlane;
25
- export declare function plane_yz(x_value: number, opts?: Partial<RefPlaneBase>): RefPlane;
26
- export declare function plane_normal(normal: Vec3, point: Vec3, opts?: Partial<RefPlaneBase>): RefPlane;
27
- export declare function plane_through_points(p1: Vec3, p2: Vec3, p3: Vec3, opts?: Partial<RefPlaneBase>): RefPlane;
28
- export declare function line_x_axis(y_value: number, z_value: number, opts?: Partial<RefLine3DBase>): RefLine3D;
29
- export declare function line_y_axis(x_value: number, z_value: number, opts?: Partial<RefLine3DBase>): RefLine3D;
30
- export declare function line_z_axis(x_value: number, y_value: number, opts?: Partial<RefLine3DBase>): RefLine3D;
31
- export declare function line_segment_3d(p1: [number, number, number], p2: [number, number, number], opts?: Partial<RefLine3DBase>): RefLine3D;
32
- export declare function line_through_3d(p1: [number, number, number], p2: [number, number, number], opts?: Partial<RefLine3DBase>): RefLine3D;
14
+ export declare const normalize_point: (point: [RefLineValue, RefLineValue]) => [number, number];
33
15
  export declare function resolve_line_endpoints(ref_line: RefLine, { x_min, x_max, y_min, y_max }: {
34
16
  x_min: number;
35
17
  x_max: number;
36
18
  y_min: number;
37
19
  y_max: number;
38
- }, { x_scale, y_scale, y2_scale }: {
20
+ }, { x_scale, x2_scale, y_scale, y2_scale }: {
39
21
  x_scale: (val: number) => number;
22
+ x2_scale?: (val: number) => number;
40
23
  y_scale: (val: number) => number;
41
24
  y2_scale?: (val: number) => number;
42
25
  }): [number, number, number, number] | null;
@@ -48,77 +48,7 @@ export function normalize_value(value) {
48
48
  return 0;
49
49
  }
50
50
  // Normalize a point tuple
51
- export function normalize_point(point) {
52
- return [normalize_value(point[0]), normalize_value(point[1])];
53
- }
54
- // Create a horizontal reference line at y = value
55
- export function horizontal_line(y_value, opts) {
56
- return { type: `horizontal`, y: y_value, ...opts };
57
- }
58
- // Create a vertical reference line at x = value
59
- export function vertical_line(x_value, opts) {
60
- return { type: `vertical`, x: x_value, ...opts };
61
- }
62
- // Create a diagonal reference line with y = slope * x + intercept
63
- export function diagonal_line(slope, intercept, opts) {
64
- return { type: `diagonal`, slope, intercept, ...opts };
65
- }
66
- // Create a line segment between two points
67
- export function line_segment(p1, p2, opts) {
68
- return { type: `segment`, p1, p2, ...opts };
69
- }
70
- // Create a line through two points, extended to plot edges
71
- export function line_through(p1, p2, opts) {
72
- return { type: `line`, p1, p2, ...opts };
73
- }
74
- // Batch helper: create multiple horizontal lines
75
- export function horizontal_lines(values, opts) {
76
- return values.map((y_value) => horizontal_line(y_value, opts));
77
- }
78
- // Batch helper: create multiple vertical lines
79
- export function vertical_lines(values, opts) {
80
- return values.map((x_value) => vertical_line(x_value, opts));
81
- }
82
- // Create an XY plane at z = value (horizontal plane)
83
- export function plane_xy(z_value, opts) {
84
- return { type: `xy`, z: z_value, ...opts };
85
- }
86
- // Create an XZ plane at y = value
87
- export function plane_xz(y_value, opts) {
88
- return { type: `xz`, y: y_value, ...opts };
89
- }
90
- // Create a YZ plane at x = value
91
- export function plane_yz(x_value, opts) {
92
- return { type: `yz`, x: x_value, ...opts };
93
- }
94
- // Create a plane defined by normal vector and a point on the plane
95
- export function plane_normal(normal, point, opts) {
96
- return { type: `normal`, normal, point, ...opts };
97
- }
98
- // Create a plane through three points
99
- export function plane_through_points(p1, p2, p3, opts) {
100
- return { type: `points`, p1, p2, p3, ...opts };
101
- }
102
- // Create a 3D line parallel to x-axis at given y, z
103
- export function line_x_axis(y_value, z_value, opts) {
104
- return { type: `x-axis`, y: y_value, z: z_value, ...opts };
105
- }
106
- // Create a 3D line parallel to y-axis at given x, z
107
- export function line_y_axis(x_value, z_value, opts) {
108
- return { type: `y-axis`, x: x_value, z: z_value, ...opts };
109
- }
110
- // Create a 3D line parallel to z-axis at given x, y
111
- export function line_z_axis(x_value, y_value, opts) {
112
- return { type: `z-axis`, x: x_value, y: y_value, ...opts };
113
- }
114
- // Create a 3D line segment between two points
115
- export function line_segment_3d(p1, p2, opts) {
116
- return { type: `segment`, p1, p2, ...opts };
117
- }
118
- // Create a 3D line through two points, extended to bounds
119
- export function line_through_3d(p1, p2, opts) {
120
- return { type: `line`, p1, p2, ...opts };
121
- }
51
+ export const normalize_point = (point) => [normalize_value(point[0]), normalize_value(point[1])];
122
52
  // Clip a line segment to a rectangle using Liang-Barsky algorithm
123
53
  // Returns clipped [x1, y1, x2, y2] or null if segment is entirely outside
124
54
  function clip_segment_to_rect(p1x, p1y, p2x, p2y, x_min, x_max, y_min, y_max) {
@@ -147,17 +77,13 @@ function clip_segment_to_rect(p1x, p1y, p2x, p2y, x_min, x_max, y_min, y_max) {
147
77
  }
148
78
  if (t_enter > t_leave)
149
79
  return null; // Segment entirely outside
150
- return [
151
- p1x + t_enter * dx,
152
- p1y + t_enter * dy,
153
- p1x + t_leave * dx,
154
- p1y + t_leave * dy,
155
- ];
80
+ return [p1x + t_enter * dx, p1y + t_enter * dy, p1x + t_leave * dx, p1y + t_leave * dy];
156
81
  }
157
82
  // Compute the screen coordinates for a reference line
158
83
  // Returns [x1, y1, x2, y2] in pixel coordinates, or null if line is not visible
159
- export function resolve_line_endpoints(ref_line, { x_min, x_max, y_min, y_max }, { x_scale, y_scale, y2_scale }) {
160
- // Determine which y-scale to use
84
+ export function resolve_line_endpoints(ref_line, { x_min, x_max, y_min, y_max }, { x_scale, x2_scale, y_scale, y2_scale }) {
85
+ // Determine which scales to use based on axis assignment
86
+ const active_x_scale = ref_line.x_axis === `x2` && x2_scale ? x2_scale : x_scale;
161
87
  const active_y_scale = ref_line.y_axis === `y2` && y2_scale ? y2_scale : y_scale;
162
88
  // Check if value is within plot bounds (for visibility)
163
89
  const is_x_visible = (x_val) => x_val >= x_min && x_val <= x_max;
@@ -273,9 +199,9 @@ export function resolve_line_endpoints(ref_line, { x_min, x_max, y_min, y_max },
273
199
  return null;
274
200
  }
275
201
  // Convert data coordinates to screen pixels
276
- const x1_px = x_scale(x1_data);
202
+ const x1_px = active_x_scale(x1_data);
277
203
  const y1_px = active_y_scale(y1_data);
278
- const x2_px = x_scale(x2_data);
204
+ const x2_px = active_x_scale(x2_data);
279
205
  const y2_px = active_y_scale(y2_data);
280
206
  // Validate that pixels are finite
281
207
  if (!isFinite(x1_px) || !isFinite(y1_px) || !isFinite(x2_px) || !isFinite(y2_px)) {