matterviz 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EmptyState.svelte +10 -2
- package/dist/FilePicker.svelte +123 -82
- package/dist/Icon.svelte +18 -12
- package/dist/MillerIndexInput.svelte +27 -21
- package/dist/api/optimade.js +6 -6
- package/dist/app.css +216 -207
- package/dist/brillouin/BrillouinZone.svelte +292 -149
- package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneControls.svelte +32 -5
- package/dist/brillouin/BrillouinZoneExportPane.svelte +69 -42
- package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneInfoPane.svelte +99 -68
- package/dist/brillouin/BrillouinZoneScene.svelte +275 -163
- package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneTooltip.svelte +17 -7
- package/dist/brillouin/compute.js +11 -6
- package/dist/chempot-diagram/ChemPotDiagram.svelte +162 -27
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte +451 -281
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +2148 -1642
- package/dist/chempot-diagram/ChemPotScene3D.svelte +8 -5
- package/dist/chempot-diagram/async-compute.svelte.d.ts +3 -0
- package/dist/chempot-diagram/async-compute.svelte.js +77 -0
- package/dist/chempot-diagram/chempot-worker.d.ts +1 -0
- package/dist/chempot-diagram/chempot-worker.js +11 -0
- package/dist/chempot-diagram/color.js +1 -2
- package/dist/chempot-diagram/compute.d.ts +10 -0
- package/dist/chempot-diagram/compute.js +250 -88
- package/dist/chempot-diagram/index.d.ts +2 -1
- package/dist/chempot-diagram/index.js +2 -1
- package/dist/chempot-diagram/temperature.js +8 -9
- package/dist/chempot-diagram/types.d.ts +3 -0
- package/dist/chempot-diagram/types.js +1 -0
- package/dist/colors/index.d.ts +1 -1
- package/dist/colors/index.js +5 -3
- package/dist/composition/BarChart.svelte +128 -55
- package/dist/composition/BubbleChart.svelte +102 -49
- package/dist/composition/Composition.svelte +100 -79
- package/dist/composition/Formula.svelte +108 -62
- package/dist/composition/FormulaFilter.svelte +665 -537
- package/dist/composition/PieChart.svelte +183 -108
- package/dist/composition/format.d.ts +5 -0
- package/dist/composition/format.js +20 -3
- package/dist/composition/parse.js +14 -9
- package/dist/convex-hull/ConvexHull.svelte +93 -40
- package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull2D.svelte +549 -360
- package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull3D.svelte +1296 -827
- package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull4D.svelte +1004 -688
- package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHullControls.svelte +115 -28
- package/dist/convex-hull/ConvexHullControls.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHullInfoPane.svelte +29 -3
- package/dist/convex-hull/ConvexHullStats.svelte +425 -328
- package/dist/convex-hull/ConvexHullTooltip.svelte +40 -16
- package/dist/convex-hull/GasPressureControls.svelte +104 -61
- package/dist/convex-hull/StructurePopup.svelte +25 -4
- package/dist/convex-hull/TemperatureSlider.svelte +45 -25
- package/dist/convex-hull/barycentric-coords.js +13 -7
- package/dist/convex-hull/demo-temperature.js +8 -4
- package/dist/convex-hull/gas-thermodynamics.js +17 -12
- package/dist/convex-hull/helpers.d.ts +9 -0
- package/dist/convex-hull/helpers.js +77 -34
- package/dist/convex-hull/thermodynamics.js +61 -56
- package/dist/convex-hull/types.d.ts +9 -14
- package/dist/convex-hull/types.js +0 -17
- package/dist/coordination/CoordinationBarPlot.svelte +227 -154
- package/dist/element/BohrAtom.svelte +55 -12
- package/dist/element/ElementHeading.svelte +7 -2
- package/dist/element/ElementPhoto.svelte +15 -9
- package/dist/element/ElementStats.svelte +10 -4
- package/dist/element/ElementTile.svelte +137 -73
- package/dist/element/Nucleus.svelte +39 -11
- package/dist/feedback/ClickFeedback.svelte +16 -5
- package/dist/feedback/DragOverlay.svelte +10 -2
- package/dist/feedback/Spinner.svelte +4 -2
- package/dist/feedback/StatusMessage.svelte +8 -2
- package/dist/fermi-surface/FermiSlice.svelte +118 -88
- package/dist/fermi-surface/FermiSurface.svelte +328 -187
- package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceControls.svelte +113 -46
- package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceScene.svelte +535 -342
- package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceTooltip.svelte +14 -5
- package/dist/fermi-surface/compute.js +16 -20
- package/dist/fermi-surface/parse.js +24 -14
- package/dist/fermi-surface/symmetry.js +2 -7
- package/dist/fermi-surface/types.d.ts +3 -5
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +1019 -765
- package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +1 -1
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +76 -22
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +2 -3
- package/dist/icons.js +47 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/io/decompress.js +1 -1
- package/dist/io/export.d.ts +3 -0
- package/dist/io/export.js +129 -143
- package/dist/io/is-binary.js +2 -3
- package/dist/io/url-drop.js +1 -2
- package/dist/isosurface/Isosurface.svelte +202 -148
- package/dist/isosurface/IsosurfaceControls.svelte +46 -28
- package/dist/isosurface/parse.js +34 -29
- package/dist/isosurface/slice.js +5 -10
- package/dist/isosurface/types.d.ts +2 -1
- package/dist/isosurface/types.js +61 -12
- package/dist/labels.js +11 -8
- package/dist/layout/FullscreenToggle.svelte +11 -2
- package/dist/layout/InfoCard.svelte +38 -6
- package/dist/layout/InfoTag.svelte +63 -32
- package/dist/layout/PropertyFilter.svelte +82 -37
- package/dist/layout/SettingsSection.svelte +85 -55
- package/dist/layout/SubpageGrid.svelte +10 -2
- package/dist/layout/json-tree/JsonNode.svelte +183 -138
- package/dist/layout/json-tree/JsonTree.svelte +499 -413
- package/dist/layout/json-tree/JsonValue.svelte +127 -99
- package/dist/layout/json-tree/utils.js +4 -2
- package/dist/marching-cubes.js +25 -2
- package/dist/math.d.ts +13 -17
- package/dist/math.js +133 -67
- package/dist/overlays/ContextMenu.svelte +65 -40
- package/dist/overlays/DraggablePane.svelte +211 -139
- package/dist/periodic-table/PeriodicTable.svelte +278 -145
- package/dist/periodic-table/PeriodicTableControls.svelte +178 -128
- package/dist/periodic-table/PropertySelect.svelte +25 -7
- package/dist/periodic-table/TableInset.svelte +8 -3
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +446 -309
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramControls.svelte +102 -43
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +63 -40
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte +71 -28
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte +158 -101
- package/dist/phase-diagram/TdbInfoPanel.svelte +28 -4
- package/dist/phase-diagram/build-diagram.js +9 -9
- package/dist/phase-diagram/colors.js +1 -3
- package/dist/phase-diagram/parse.js +10 -9
- package/dist/phase-diagram/svg-to-diagram.js +53 -49
- package/dist/phase-diagram/utils.d.ts +1 -0
- package/dist/phase-diagram/utils.js +80 -25
- package/dist/plot/AxisLabel.svelte +28 -3
- package/dist/plot/BarPlot.svelte +1182 -734
- package/dist/plot/BarPlot.svelte.d.ts +2 -2
- package/dist/plot/BarPlotControls.svelte +31 -5
- package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ColorBar.svelte +479 -329
- package/dist/plot/ColorScaleSelect.svelte +27 -6
- package/dist/plot/ElementScatter.svelte +36 -15
- package/dist/plot/FillArea.svelte +152 -95
- package/dist/plot/Histogram.svelte +934 -571
- package/dist/plot/Histogram.svelte.d.ts +1 -1
- package/dist/plot/HistogramControls.svelte +53 -9
- package/dist/plot/HistogramControls.svelte.d.ts +1 -1
- package/dist/plot/InteractiveAxisLabel.svelte +34 -11
- package/dist/plot/InteractiveAxisLabel.svelte.d.ts +1 -1
- package/dist/plot/Line.svelte +63 -28
- package/dist/plot/PlotControls.svelte +157 -114
- package/dist/plot/PlotControls.svelte.d.ts +1 -1
- package/dist/plot/PlotLegend.svelte +174 -91
- package/dist/plot/PlotTooltip.svelte +45 -6
- package/dist/plot/PortalSelect.svelte +175 -147
- package/dist/plot/ReferenceLine.svelte +76 -22
- package/dist/plot/ReferenceLine3D.svelte +132 -107
- package/dist/plot/ReferencePlane.svelte +146 -121
- package/dist/plot/ScatterPlot.svelte +1681 -1091
- package/dist/plot/ScatterPlot.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlot3D.svelte +256 -131
- package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlot3DControls.svelte +113 -63
- package/dist/plot/ScatterPlot3DControls.svelte.d.ts +2 -1
- package/dist/plot/ScatterPlot3DScene.svelte +608 -403
- package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlotControls.svelte +65 -25
- package/dist/plot/ScatterPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ScatterPoint.svelte +98 -26
- package/dist/plot/ScatterPoint.svelte.d.ts +1 -0
- package/dist/plot/SpacegroupBarPlot.svelte +142 -85
- package/dist/plot/Surface3D.svelte +159 -108
- package/dist/plot/ZeroLines.svelte +55 -3
- package/dist/plot/ZoomRect.svelte +4 -2
- package/dist/plot/axis-utils.js +1 -3
- package/dist/plot/data-cleaning.js +12 -28
- package/dist/plot/data-transform.js +2 -1
- package/dist/plot/fill-utils.js +2 -0
- package/dist/plot/layout.d.ts +4 -1
- package/dist/plot/layout.js +33 -14
- package/dist/plot/reference-line.d.ts +2 -2
- package/dist/plot/reference-line.js +7 -5
- package/dist/plot/scales.js +24 -36
- package/dist/plot/types.d.ts +11 -23
- package/dist/plot/types.js +6 -11
- package/dist/plot/utils/label-placement.d.ts +32 -15
- package/dist/plot/utils/label-placement.js +227 -66
- package/dist/plot/utils/series-visibility.js +2 -3
- package/dist/rdf/RdfPlot.svelte +143 -91
- package/dist/rdf/calc-rdf.js +4 -5
- package/dist/sanitize.d.ts +4 -0
- package/dist/sanitize.js +107 -0
- package/dist/settings.d.ts +18 -6
- package/dist/settings.js +46 -16
- package/dist/spectral/Bands.svelte +632 -453
- package/dist/spectral/BandsAndDos.svelte +90 -49
- package/dist/spectral/BrillouinBandsDos.svelte +151 -93
- package/dist/spectral/Dos.svelte +389 -258
- package/dist/spectral/helpers.js +55 -43
- package/dist/state.svelte.d.ts +1 -1
- package/dist/state.svelte.js +3 -2
- package/dist/structure/Arrow.svelte +59 -20
- package/dist/structure/AtomLegend.svelte +215 -134
- package/dist/structure/Bond.svelte +73 -47
- package/dist/structure/CanvasTooltip.svelte +10 -2
- package/dist/structure/CellSelect.svelte +72 -45
- package/dist/structure/Cylinder.svelte +33 -17
- package/dist/structure/Lattice.svelte +88 -33
- package/dist/structure/Structure.svelte +1063 -797
- package/dist/structure/Structure.svelte.d.ts +1 -1
- package/dist/structure/StructureControls.svelte +349 -118
- package/dist/structure/StructureExportPane.svelte +124 -89
- package/dist/structure/StructureExportPane.svelte.d.ts +1 -1
- package/dist/structure/StructureInfoPane.svelte +304 -237
- package/dist/structure/StructureScene.svelte +879 -443
- package/dist/structure/StructureScene.svelte.d.ts +15 -7
- package/dist/structure/atom-properties.js +8 -8
- package/dist/structure/bonding.js +6 -7
- package/dist/structure/export.js +14 -29
- package/dist/structure/ferrox-wasm.js +1 -1
- package/dist/structure/index.d.ts +13 -3
- package/dist/structure/index.js +83 -23
- package/dist/structure/measure.d.ts +2 -2
- package/dist/structure/measure.js +4 -44
- package/dist/structure/parse.js +113 -141
- package/dist/structure/partial-occupancy.js +7 -10
- package/dist/structure/pbc.d.ts +1 -0
- package/dist/structure/pbc.js +16 -6
- package/dist/structure/supercell.d.ts +2 -2
- package/dist/structure/supercell.js +12 -22
- package/dist/structure/validation.js +1 -2
- package/dist/symmetry/SymmetryStats.svelte +84 -41
- package/dist/symmetry/WyckoffTable.svelte +26 -6
- package/dist/symmetry/cell-transform.js +5 -3
- package/dist/symmetry/index.js +8 -7
- package/dist/symmetry/spacegroups.js +148 -148
- package/dist/table/HeatmapTable.svelte +790 -554
- package/dist/table/HeatmapTable.svelte.d.ts +1 -1
- package/dist/table/ToggleMenu.svelte +125 -92
- package/dist/table/index.js +2 -4
- package/dist/theme/ThemeControl.svelte +21 -12
- package/dist/time.js +4 -1
- package/dist/tooltip/TooltipContent.svelte +33 -8
- package/dist/trajectory/Trajectory.svelte +758 -558
- package/dist/trajectory/TrajectoryError.svelte +14 -3
- package/dist/trajectory/TrajectoryExportPane.svelte +137 -83
- package/dist/trajectory/TrajectoryInfoPane.svelte +272 -143
- package/dist/trajectory/extract.js +10 -26
- package/dist/trajectory/format-detect.js +5 -5
- package/dist/trajectory/frame-reader.d.ts +1 -1
- package/dist/trajectory/frame-reader.js +5 -12
- package/dist/trajectory/helpers.d.ts +0 -1
- package/dist/trajectory/helpers.js +2 -17
- package/dist/trajectory/index.js +14 -12
- package/dist/trajectory/parse/ase.js +5 -4
- package/dist/trajectory/parse/hdf5.js +26 -18
- package/dist/trajectory/parse/index.js +13 -18
- package/dist/trajectory/parse/lammps.js +17 -7
- package/dist/trajectory/parse/vasp.js +5 -2
- package/dist/trajectory/parse/xyz.js +8 -7
- package/dist/trajectory/plotting.js +13 -8
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +13 -0
- package/dist/xrd/XrdPlot.svelte +337 -247
- package/dist/xrd/broadening.js +14 -9
- package/dist/xrd/calc-xrd.js +12 -18
- package/dist/xrd/parse.d.ts +1 -1
- package/dist/xrd/parse.js +17 -17
- package/package.json +99 -103
- package/readme.md +1 -1
- /package/dist/theme/{themes.js → themes.mjs} +0 -0
|
@@ -1,641 +1,840 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ShowControlsProp } from '../controls'
|
|
3
|
+
import { normalize_show_controls } from '../controls'
|
|
4
|
+
import type { ElementSymbol } from '../element'
|
|
5
|
+
import EmptyState from '../EmptyState.svelte'
|
|
6
|
+
import Spinner from '../feedback/Spinner.svelte'
|
|
7
|
+
import Icon from '../Icon.svelte'
|
|
8
|
+
import { handle_url_drop, load_from_url } from '../io'
|
|
9
|
+
import { format_num, trajectory_property_config } from '../labels'
|
|
10
|
+
import { sanitize_html } from '../sanitize'
|
|
11
|
+
import { toggle_fullscreen } from '../layout'
|
|
12
|
+
import type { ControlsConfig, DataSeries, Orientation, Point } from '../plot'
|
|
13
|
+
import { Histogram, ScatterPlot } from '../plot'
|
|
14
|
+
import { toggle_series_visibility } from '../plot/utils/series-visibility'
|
|
15
|
+
import { DEFAULTS } from '../settings'
|
|
16
|
+
import Structure from '../structure/Structure.svelte'
|
|
17
|
+
import { scaleLinear } from 'd3-scale'
|
|
18
|
+
import type { ComponentProps, Snippet } from 'svelte'
|
|
19
|
+
import { untrack } from 'svelte'
|
|
20
|
+
import { tooltip } from 'svelte-multiselect/attachments'
|
|
21
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
22
|
+
import { full_data_extractor } from './extract'
|
|
23
|
+
import type {
|
|
24
|
+
ParseProgress,
|
|
25
|
+
TrajectoryDataExtractor,
|
|
26
|
+
TrajectoryFrame,
|
|
27
|
+
TrajectoryType,
|
|
28
|
+
TrajHandlerData,
|
|
29
|
+
} from './index'
|
|
30
|
+
import { TrajectoryError, TrajectoryExportPane, TrajectoryInfoPane } from './index'
|
|
31
|
+
import type { AtomTypeMapping, LoadingOptions } from './parse'
|
|
32
|
+
import {
|
|
33
|
+
create_frame_loader,
|
|
34
|
+
get_unsupported_format_message,
|
|
35
|
+
MAX_BIN_FILE_SIZE,
|
|
36
|
+
MAX_TEXT_FILE_SIZE,
|
|
37
|
+
parse_trajectory_async,
|
|
38
|
+
} from './parse'
|
|
39
|
+
import {
|
|
40
|
+
generate_axis_labels,
|
|
41
|
+
generate_plot_series,
|
|
42
|
+
generate_streaming_plot_series,
|
|
43
|
+
should_hide_plot,
|
|
44
|
+
} from './plotting'
|
|
45
|
+
|
|
46
|
+
type EventHandlers = {
|
|
47
|
+
on_play?: (data: TrajHandlerData) => void
|
|
48
|
+
on_pause?: (data: TrajHandlerData) => void
|
|
49
|
+
on_step_change?: (data: TrajHandlerData) => void
|
|
50
|
+
on_end?: (data: TrajHandlerData) => void
|
|
51
|
+
on_loop?: (data: TrajHandlerData) => void
|
|
52
|
+
on_frame_rate_change?: (data: TrajHandlerData) => void
|
|
53
|
+
on_display_mode_change?: (data: TrajHandlerData) => void
|
|
54
|
+
on_fullscreen_change?: (data: TrajHandlerData) => void
|
|
55
|
+
on_file_load?: (data: TrajHandlerData) => void
|
|
56
|
+
on_error?: (data: TrajHandlerData) => void
|
|
57
|
+
}
|
|
58
|
+
type ControlsProps = {
|
|
59
|
+
trajectory: TrajectoryType
|
|
60
|
+
current_step_idx: number
|
|
61
|
+
total_frames: number
|
|
62
|
+
on_step_change: (idx: number) => void
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let {
|
|
66
|
+
trajectory = $bindable(),
|
|
67
|
+
data_url,
|
|
68
|
+
current_step_idx = $bindable(0),
|
|
69
|
+
data_extractor = full_data_extractor,
|
|
70
|
+
allow_file_drop = true,
|
|
71
|
+
layout = `auto`,
|
|
72
|
+
structure_props = {},
|
|
73
|
+
scatter_props = {},
|
|
74
|
+
histogram_props = {},
|
|
75
|
+
spinner_props = {},
|
|
76
|
+
trajectory_controls,
|
|
77
|
+
error_snippet,
|
|
78
|
+
show_controls,
|
|
79
|
+
fullscreen_toggle = DEFAULTS.trajectory.fullscreen_toggle,
|
|
80
|
+
auto_play = false,
|
|
81
|
+
display_mode = $bindable(`structure+scatter`),
|
|
82
|
+
step_labels = 5,
|
|
83
|
+
visible_properties = $bindable(),
|
|
84
|
+
ELEM_PROPERTY_LABELS,
|
|
85
|
+
on_play,
|
|
86
|
+
on_pause,
|
|
87
|
+
on_step_change,
|
|
88
|
+
on_end,
|
|
89
|
+
on_loop,
|
|
90
|
+
on_frame_rate_change,
|
|
91
|
+
on_display_mode_change,
|
|
92
|
+
on_fullscreen_change,
|
|
93
|
+
on_file_load,
|
|
94
|
+
on_error,
|
|
95
|
+
fps_range = DEFAULTS.trajectory.fps_range,
|
|
96
|
+
fps = $bindable(5),
|
|
97
|
+
loading_options = {},
|
|
98
|
+
atom_type_mapping,
|
|
99
|
+
plot_skimming = true,
|
|
100
|
+
...rest
|
|
101
|
+
}: EventHandlers & HTMLAttributes<HTMLDivElement> & {
|
|
102
|
+
// trajectory data - can be provided directly or loaded from file
|
|
103
|
+
trajectory?: TrajectoryType
|
|
104
|
+
// URL to load trajectory from (alternative to providing trajectory directly)
|
|
105
|
+
data_url?: string
|
|
106
|
+
// current step index being displayed
|
|
107
|
+
current_step_idx?: number
|
|
108
|
+
// custom function to extract plot data from trajectory frames
|
|
109
|
+
data_extractor?: TrajectoryDataExtractor
|
|
110
|
+
|
|
111
|
+
// file drop handlers
|
|
112
|
+
allow_file_drop?: boolean
|
|
113
|
+
// layout configuration - 'auto' (default) adapts to element size, 'horizontal'/'vertical' forces layout
|
|
114
|
+
layout?: `auto` | Orientation
|
|
115
|
+
// structure viewer props (passed to Structure component)
|
|
116
|
+
structure_props?: ComponentProps<typeof Structure>
|
|
117
|
+
// plot props (passed to ScatterPlot component)
|
|
118
|
+
scatter_props?: ComponentProps<typeof ScatterPlot>
|
|
119
|
+
// histogram props (passed to Histogram component, excluding series which is handled separately)
|
|
120
|
+
histogram_props?: Omit<ComponentProps<typeof Histogram>, `series`>
|
|
121
|
+
// spinner props (passed to Spinner component)
|
|
122
|
+
spinner_props?: ComponentProps<typeof Spinner>
|
|
123
|
+
// custom snippets for additional UI elements
|
|
124
|
+
trajectory_controls?: Snippet<[ControlsProps]>
|
|
125
|
+
// Custom error snippet for advanced error handling
|
|
126
|
+
error_snippet?: Snippet<[{ error_msg: string; on_dismiss: () => void }]>
|
|
127
|
+
// Controls visibility configuration.
|
|
128
|
+
// - 'always': controls always visible
|
|
129
|
+
// - 'hover': controls visible on component hover (default)
|
|
130
|
+
// - 'never': controls never visible
|
|
131
|
+
// - object: { mode, hidden, style } for fine-grained control
|
|
132
|
+
// Control names: 'filename', 'nav', 'step', 'fps', 'info-pane', 'export-pane', 'view-mode', 'fullscreen'
|
|
133
|
+
show_controls?: ShowControlsProp
|
|
134
|
+
// show/hide the fullscreen button
|
|
135
|
+
fullscreen_toggle?: Snippet<[{ fullscreen: boolean }]> | boolean
|
|
136
|
+
// automatically start playing when trajectory data is loaded
|
|
137
|
+
auto_play?: boolean
|
|
138
|
+
// display mode: 'structure+scatter' (default), 'structure' (only structure), 'scatter' (only scatter), 'histogram' (only histogram), 'structure+histogram' (structure with histogram)
|
|
139
|
+
display_mode?:
|
|
140
|
+
| `structure+scatter`
|
|
141
|
+
| `structure`
|
|
142
|
+
| `scatter`
|
|
143
|
+
| `histogram`
|
|
144
|
+
| `structure+histogram`
|
|
145
|
+
// step labels configuration for slider
|
|
146
|
+
// - positive number: number of evenly spaced ticks
|
|
147
|
+
// - negative number: spacing between ticks (e.g. -10 = every 10th step)
|
|
148
|
+
// - array: exact step indices to label
|
|
149
|
+
// - undefined: no labels
|
|
150
|
+
step_labels?: number | number[]
|
|
151
|
+
// visible properties - bindable array of property keys currently shown in the plot
|
|
152
|
+
// - controls which trajectory properties are plotted (e.g. ['energy', 'volume', 'force_max'])
|
|
153
|
+
// - bindable: reflects current visibility state and can be used for external control
|
|
154
|
+
// - if not provided, uses default visible properties (energy, force_max, stress_frobenius)
|
|
155
|
+
// - if specified properties don't exist in data, falls back to automatic selection
|
|
156
|
+
visible_properties?: string[]
|
|
157
|
+
// custom labels for trajectory properties - maps property keys to display labels
|
|
158
|
+
// - e.g. {energy: 'Total Energy', volume: 'Cell Volume', force_max: 'Max Force'}
|
|
159
|
+
// - merged with built-in trajectory_property_config
|
|
160
|
+
ELEM_PROPERTY_LABELS?: Record<string, string>
|
|
161
|
+
// units configuration - developers can override these (deprecated - use ELEM_PROPERTY_LABELS instead)
|
|
162
|
+
units?: {
|
|
163
|
+
energy?: string
|
|
164
|
+
energy_per_atom?: string
|
|
165
|
+
force_max?: string
|
|
166
|
+
force_norm?: string
|
|
167
|
+
stress_max?: string
|
|
168
|
+
volume?: string
|
|
169
|
+
density?: string
|
|
170
|
+
temperature?: string
|
|
171
|
+
pressure?: string
|
|
172
|
+
length?: string
|
|
173
|
+
a?: string
|
|
174
|
+
b?: string
|
|
175
|
+
c?: string
|
|
176
|
+
[key: string]: string | undefined
|
|
177
|
+
}
|
|
178
|
+
fps_range?: [number, number] // allowed FPS range [min_fps, max_fps]
|
|
179
|
+
fps?: number // frame rate for playback
|
|
180
|
+
// Loading options for large files
|
|
181
|
+
loading_options?: LoadingOptions
|
|
182
|
+
// Map LAMMPS atom types to element symbols (e.g. {1: 'Na', 2: 'Cl'})
|
|
183
|
+
atom_type_mapping?: AtomTypeMapping
|
|
184
|
+
// Disable plot skimming (mouse over plot doesn't update structure/step slider)
|
|
185
|
+
plot_skimming?: boolean
|
|
186
|
+
} = $props()
|
|
187
|
+
|
|
188
|
+
let dragover = $state(false)
|
|
189
|
+
let loading = $state(false)
|
|
190
|
+
let error_msg = $state<string | null>(null)
|
|
191
|
+
let is_playing = $state(false)
|
|
192
|
+
let play_interval: ReturnType<typeof setInterval> | undefined = $state(undefined)
|
|
193
|
+
|
|
194
|
+
// Ensure fps is within the allowed range
|
|
195
|
+
$effect(() => {
|
|
27
196
|
if (fps < fps_range[0]) {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
let controls_config = $derived(normalize_show_controls(show_controls))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
197
|
+
fps = fps_range[0]
|
|
198
|
+
} else if (fps > fps_range[1]) {
|
|
199
|
+
fps = fps_range[1]
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
let current_filename = $state<string | undefined>(undefined)
|
|
203
|
+
let current_file_path = $state<string | null>(null)
|
|
204
|
+
let file_size = $state<number | undefined>(undefined)
|
|
205
|
+
let file_object = $state<File | null>(null)
|
|
206
|
+
let wrapper = $state<HTMLDivElement | undefined>(undefined)
|
|
207
|
+
let info_pane_open = $state(false)
|
|
208
|
+
let parsing_progress = $state<ParseProgress | null>(null)
|
|
209
|
+
let element_size = $state({ width: 0, height: 0 })
|
|
210
|
+
let filename_copied = $state(false)
|
|
211
|
+
let orig_data = $state<string | ArrayBuffer | null>(null)
|
|
212
|
+
|
|
213
|
+
let controls_config = $derived(normalize_show_controls(show_controls))
|
|
214
|
+
|
|
215
|
+
// Reactive layout based on element aspect ratio (for auto mode)
|
|
216
|
+
let actual_layout = $derived.by(() => {
|
|
217
|
+
if (layout === `horizontal` || layout === `vertical`) return layout
|
|
49
218
|
// For auto layout, use element dimensions to determine orientation
|
|
50
219
|
if (element_size.width > 0 && element_size.height > 0) {
|
|
51
|
-
|
|
220
|
+
return element_size.width > element_size.height ? `horizontal` : `vertical`
|
|
52
221
|
}
|
|
53
|
-
return `horizontal
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
222
|
+
return `horizontal` // Fallback to horizontal if dimensions not available yet
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
// Get total frame count (supports both regular and indexed trajectories)
|
|
226
|
+
let total_frames = $derived(
|
|
227
|
+
trajectory?.total_frames || trajectory?.frames.length || 0,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
// Current frame - load on demand for indexed trajectories
|
|
231
|
+
let current_frame = $state<TrajectoryFrame | null>(null)
|
|
232
|
+
|
|
233
|
+
// Auto-play when trajectory changes (handles both props and file loading)
|
|
234
|
+
$effect(() => {
|
|
61
235
|
if (auto_play && trajectory && !untrack(() => is_playing) && total_frames > 1) {
|
|
62
|
-
|
|
236
|
+
start_playback()
|
|
63
237
|
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
// Update current frame when step changes
|
|
241
|
+
$effect(() => {
|
|
67
242
|
if (trajectory && current_step_idx >= 0 && current_step_idx < total_frames) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
else {
|
|
78
|
-
current_frame = null;
|
|
243
|
+
if (trajectory.frame_loader) {
|
|
244
|
+
// Load frame on demand (works for both indexed files and external streaming)
|
|
245
|
+
load_frame_on_demand(current_step_idx)
|
|
246
|
+
} else {
|
|
247
|
+
// Use in-memory frame for regular trajectories
|
|
248
|
+
current_frame = trajectory.frames[current_step_idx] || null
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
current_frame = null
|
|
79
252
|
}
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
// Load frame on demand - works for both indexed files and external streaming
|
|
256
|
+
async function load_frame_on_demand(frame_idx: number) {
|
|
257
|
+
if (!trajectory?.frame_loader) return
|
|
258
|
+
|
|
85
259
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
260
|
+
const frame = await trajectory.frame_loader.load_frame(
|
|
261
|
+
orig_data || ``, // Use original_data for indexed files, empty string for external streaming
|
|
262
|
+
frame_idx,
|
|
263
|
+
)
|
|
264
|
+
current_frame = frame
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error(`Failed to load frame ${frame_idx}:`, error)
|
|
267
|
+
current_frame = null
|
|
268
|
+
on_error?.({
|
|
269
|
+
error_msg: `Failed to load frame ${frame_idx}: ${error}`,
|
|
270
|
+
filename: current_filename,
|
|
271
|
+
file_size,
|
|
272
|
+
step_idx: frame_idx,
|
|
273
|
+
frame_count: total_frames,
|
|
274
|
+
})
|
|
100
275
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Current frame structure for display
|
|
279
|
+
let current_structure = $derived(current_frame?.structure)
|
|
280
|
+
|
|
281
|
+
// Track hidden elements (persists across frame changes)
|
|
282
|
+
let hidden_elements = $state(new Set<ElementSymbol>())
|
|
283
|
+
|
|
284
|
+
let step_label_positions = $derived.by((): number[] => {
|
|
285
|
+
if (!step_labels || total_frames <= 1) return []
|
|
286
|
+
|
|
109
287
|
if (Array.isArray(step_labels)) {
|
|
110
|
-
|
|
288
|
+
return step_labels.filter((idx) => idx >= 0 && idx < total_frames)
|
|
111
289
|
}
|
|
290
|
+
|
|
112
291
|
if (typeof step_labels === `number`) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
292
|
+
if (step_labels > 0) {
|
|
293
|
+
return scaleLinear().domain([0, total_frames - 1]).nice()
|
|
294
|
+
.ticks(Math.min(step_labels, total_frames))
|
|
295
|
+
.map((t) => Math.round(t))
|
|
296
|
+
.filter((t, i, arr) => t >= 0 && t < total_frames && arr.indexOf(t) === i)
|
|
297
|
+
}
|
|
298
|
+
if (step_labels < 0) {
|
|
299
|
+
const spacing = Math.abs(step_labels)
|
|
300
|
+
const positions = Array.from(
|
|
301
|
+
{ length: Math.ceil(total_frames / spacing) },
|
|
302
|
+
(_, idx) => idx * spacing,
|
|
303
|
+
)
|
|
304
|
+
return positions.at(-1) === total_frames - 1
|
|
305
|
+
? positions
|
|
306
|
+
: [...positions, total_frames - 1]
|
|
307
|
+
}
|
|
126
308
|
}
|
|
127
|
-
return []
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
309
|
+
return []
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
// Build extended property config with custom labels if provided
|
|
313
|
+
let extended_config = $derived.by(() => {
|
|
314
|
+
if (!ELEM_PROPERTY_LABELS) return trajectory_property_config
|
|
315
|
+
|
|
316
|
+
const custom_config: Record<string, { label: string; unit: string }> = {}
|
|
134
317
|
for (const [key, label] of Object.entries(ELEM_PROPERTY_LABELS)) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
318
|
+
const existing = trajectory_property_config[key] ||
|
|
319
|
+
trajectory_property_config[key.toLowerCase()]
|
|
320
|
+
custom_config[key] = { label, unit: existing?.unit || `` }
|
|
138
321
|
}
|
|
139
|
-
return { ...trajectory_property_config, ...custom_config }
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
322
|
+
return { ...trajectory_property_config, ...custom_config }
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
// Plot series state (not derived so we can update on legend toggle)
|
|
326
|
+
let plot_series = $state<DataSeries[]>([])
|
|
327
|
+
// Prevent circular updates when syncing legend toggles back to bindable visible_properties.
|
|
328
|
+
let syncing_visible_properties = false
|
|
329
|
+
|
|
330
|
+
// Regenerate plot series when trajectory, config, or visible_properties change
|
|
331
|
+
$effect(() => {
|
|
332
|
+
if (syncing_visible_properties) return
|
|
333
|
+
const keys_set = visible_properties ? new Set(visible_properties) : undefined
|
|
334
|
+
|
|
150
335
|
if (trajectory?.plot_metadata) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return;
|
|
336
|
+
plot_series = generate_streaming_plot_series(trajectory.plot_metadata, {
|
|
337
|
+
property_config: extended_config,
|
|
338
|
+
default_visible_properties: keys_set,
|
|
339
|
+
})
|
|
340
|
+
} else if (trajectory) {
|
|
341
|
+
plot_series = generate_plot_series(trajectory, data_extractor, {
|
|
342
|
+
property_config: extended_config,
|
|
343
|
+
default_visible_properties: keys_set,
|
|
344
|
+
})
|
|
345
|
+
} else {
|
|
346
|
+
plot_series = []
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
// Update visible_properties binding when user toggles series visibility in legend
|
|
351
|
+
$effect(() => {
|
|
352
|
+
if (!plot_series.length) return
|
|
353
|
+
|
|
170
354
|
// Extract property keys from visible series metadata
|
|
171
355
|
const visible_keys = plot_series.flatMap((srs) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
356
|
+
if (!srs.visible) return []
|
|
357
|
+
const metadata = Array.isArray(srs.metadata) ? srs.metadata[0] : srs.metadata
|
|
358
|
+
const key = metadata?.property_key
|
|
359
|
+
return key ? [key as string] : []
|
|
360
|
+
})
|
|
361
|
+
|
|
178
362
|
// Only update if changed (use untrack to avoid circular dependency)
|
|
179
|
-
const current = untrack(() => visible_properties) || []
|
|
363
|
+
const current = untrack(() => visible_properties) || []
|
|
180
364
|
const has_changed = visible_keys.length !== current.length ||
|
|
181
|
-
|
|
365
|
+
!visible_keys.every((key, idx) => key === current[idx])
|
|
366
|
+
|
|
182
367
|
if (has_changed) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
368
|
+
syncing_visible_properties = true
|
|
369
|
+
visible_properties = visible_keys
|
|
370
|
+
queueMicrotask(() => (syncing_visible_properties = false))
|
|
186
371
|
}
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
// Handler for legend toggle - updates plot_series state
|
|
375
|
+
function handle_legend_toggle(series_idx: number) {
|
|
376
|
+
plot_series = toggle_series_visibility(plot_series, series_idx)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
let x_axis = $derived({
|
|
193
380
|
label: `Step`,
|
|
194
381
|
format: `.3~s`,
|
|
195
382
|
ticks: step_label_positions,
|
|
196
|
-
})
|
|
197
|
-
// Generate axis labels based on first visible series on each axis
|
|
198
|
-
let y_axis_labels = $derived(generate_axis_labels(plot_series))
|
|
199
|
-
let y_axis = $derived({
|
|
383
|
+
})
|
|
384
|
+
// Generate axis labels based on first visible series on each axis
|
|
385
|
+
let y_axis_labels = $derived(generate_axis_labels(plot_series))
|
|
386
|
+
let y_axis = $derived({
|
|
200
387
|
label: y_axis_labels.y1,
|
|
201
388
|
format: `.2~s`,
|
|
202
389
|
label_shift: { y: 10 },
|
|
203
|
-
})
|
|
204
|
-
let y2_axis = $derived({
|
|
390
|
+
})
|
|
391
|
+
let y2_axis = $derived({
|
|
205
392
|
label: y_axis_labels.y2,
|
|
206
393
|
format: `.2~s`,
|
|
207
394
|
label_shift: { y: 80 },
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
// hide plot if all plotted values are constant (no variation)
|
|
398
|
+
let show_plot = $derived(
|
|
399
|
+
display_mode !== `structure` && !should_hide_plot(trajectory, plot_series),
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
// Determine what to show based on display mode
|
|
403
|
+
let show_structure = $derived(![`scatter`, `histogram`].includes(display_mode))
|
|
404
|
+
let actual_show_plot = $derived(display_mode !== `structure` && show_plot)
|
|
405
|
+
|
|
406
|
+
// Check if there are any Y2 series to determine padding
|
|
407
|
+
let has_y2_series = $derived(
|
|
408
|
+
plot_series.some((srs) => srs.y_axis === `y2` && srs.visible),
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
// Step navigation functions
|
|
412
|
+
function next_step() {
|
|
218
413
|
if (current_step_idx < total_frames - 1) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
414
|
+
current_step_idx++
|
|
415
|
+
// Streaming frame loading handled by reactive effect
|
|
416
|
+
if (trajectory) {
|
|
417
|
+
on_step_change?.({
|
|
418
|
+
trajectory,
|
|
419
|
+
step_idx: current_step_idx,
|
|
420
|
+
frame_count: total_frames,
|
|
421
|
+
frame: current_frame || undefined,
|
|
422
|
+
})
|
|
423
|
+
}
|
|
229
424
|
}
|
|
230
|
-
}
|
|
231
|
-
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function prev_step() {
|
|
232
428
|
if (current_step_idx > 0) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
429
|
+
current_step_idx--
|
|
430
|
+
// Streaming frame loading handled by reactive effect
|
|
431
|
+
if (trajectory) {
|
|
432
|
+
on_step_change?.({
|
|
433
|
+
trajectory,
|
|
434
|
+
step_idx: current_step_idx,
|
|
435
|
+
frame_count: total_frames,
|
|
436
|
+
frame: current_frame || undefined,
|
|
437
|
+
})
|
|
438
|
+
}
|
|
243
439
|
}
|
|
244
|
-
}
|
|
245
|
-
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function go_to_step(idx: number) {
|
|
246
443
|
if (idx >= 0 && idx < total_frames) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
444
|
+
current_step_idx = idx
|
|
445
|
+
// Note: streaming frame loading is handled by reactive effect
|
|
446
|
+
// Handle callbacks for both traditional and streaming modes
|
|
447
|
+
if (trajectory) {
|
|
448
|
+
on_step_change?.({
|
|
449
|
+
trajectory,
|
|
450
|
+
step_idx: current_step_idx,
|
|
451
|
+
frame_count: total_frames,
|
|
452
|
+
frame: current_frame || undefined,
|
|
453
|
+
})
|
|
454
|
+
}
|
|
258
455
|
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Handle plot point clicks to jump to that step
|
|
459
|
+
function handle_plot_change(data: (Point & { series: DataSeries }) | null) {
|
|
262
460
|
if (data?.x !== undefined && typeof data.x === `number`) {
|
|
263
|
-
|
|
461
|
+
go_to_step(Math.round(data.x))
|
|
264
462
|
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Helper function to read file content
|
|
466
|
+
async function read_file_content(file: File): Promise<string | ArrayBuffer> {
|
|
268
467
|
return new Promise((resolve, reject) => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// Play/pause functionality
|
|
281
|
-
function toggle_play() {
|
|
282
|
-
if (is_playing)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (total_frames <= 1)
|
|
289
|
-
return;
|
|
290
|
-
is_playing = true;
|
|
468
|
+
const reader = new FileReader()
|
|
469
|
+
reader.onload = () => resolve(reader.result as string | ArrayBuffer)
|
|
470
|
+
reader.onerror = () => reject(new Error(`Failed to read file`))
|
|
471
|
+
|
|
472
|
+
// Read as text for text-based formats, binary for others
|
|
473
|
+
if (file.name.toLowerCase().match(/\.(xyz|json|extxyz|lammpstrj)$/)) {
|
|
474
|
+
reader.readAsText(file)
|
|
475
|
+
} else reader.readAsArrayBuffer(file)
|
|
476
|
+
})
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Play/pause functionality
|
|
480
|
+
function toggle_play() {
|
|
481
|
+
if (is_playing) pause_playback()
|
|
482
|
+
else start_playback()
|
|
483
|
+
}
|
|
484
|
+
function start_playback() {
|
|
485
|
+
if (total_frames <= 1) return
|
|
486
|
+
is_playing = true
|
|
291
487
|
if (trajectory) {
|
|
292
|
-
|
|
488
|
+
on_play?.({ trajectory, step_idx: current_step_idx, frame_count: total_frames })
|
|
293
489
|
}
|
|
294
|
-
}
|
|
295
|
-
function pause_playback() {
|
|
296
|
-
is_playing = false
|
|
490
|
+
}
|
|
491
|
+
function pause_playback() {
|
|
492
|
+
is_playing = false
|
|
297
493
|
if (trajectory) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
494
|
+
on_pause?.({
|
|
495
|
+
trajectory: trajectory,
|
|
496
|
+
step_idx: current_step_idx,
|
|
497
|
+
frame_count: total_frames,
|
|
498
|
+
})
|
|
303
499
|
}
|
|
304
|
-
}
|
|
305
|
-
$effect(() => {
|
|
500
|
+
}
|
|
501
|
+
$effect(() => { // Effect to manage playback interval
|
|
306
502
|
// Only watch is_playing and frame_rate_ms, not play_interval itself
|
|
307
|
-
const playing = is_playing
|
|
308
|
-
const rate_ms = 1000 / fps
|
|
503
|
+
const playing = is_playing
|
|
504
|
+
const rate_ms = 1000 / fps
|
|
505
|
+
|
|
309
506
|
if (playing) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
clearInterval(current_interval);
|
|
339
|
-
play_interval = undefined;
|
|
340
|
-
}
|
|
507
|
+
// Clear existing interval if it exists - use untrack to avoid circular dependency
|
|
508
|
+
const current_interval = untrack(() => play_interval)
|
|
509
|
+
if (current_interval !== undefined) clearInterval(current_interval)
|
|
510
|
+
|
|
511
|
+
// Create new interval with current frame rate
|
|
512
|
+
play_interval = setInterval(() => {
|
|
513
|
+
if (current_step_idx >= total_frames - 1) {
|
|
514
|
+
if (trajectory) {
|
|
515
|
+
on_end?.({
|
|
516
|
+
trajectory,
|
|
517
|
+
step_idx: current_step_idx,
|
|
518
|
+
frame_count: total_frames,
|
|
519
|
+
frame: current_frame || undefined,
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
go_to_step(0) // Loop back to 1st step
|
|
523
|
+
if (trajectory) {
|
|
524
|
+
on_loop?.({ trajectory, frame_count: total_frames })
|
|
525
|
+
}
|
|
526
|
+
} else next_step()
|
|
527
|
+
}, rate_ms)
|
|
528
|
+
} else {
|
|
529
|
+
// Clear interval when not playing - use untrack to avoid circular dependency
|
|
530
|
+
const current_interval = untrack(() => play_interval)
|
|
531
|
+
if (current_interval !== undefined) {
|
|
532
|
+
clearInterval(current_interval)
|
|
533
|
+
play_interval = undefined
|
|
534
|
+
}
|
|
341
535
|
}
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
|
|
536
|
+
})
|
|
537
|
+
|
|
538
|
+
// Cleanup interval on component destroy
|
|
539
|
+
$effect(() => () => {
|
|
540
|
+
if (play_interval !== undefined) clearInterval(play_interval)
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
// Handle internal file format drops
|
|
544
|
+
async function handle_internal_file_drop(internal_data: string): Promise<boolean> {
|
|
350
545
|
try {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
else {
|
|
367
|
-
await load_trajectory_data(file_info.content, file_info.name);
|
|
546
|
+
const file_info = JSON.parse(internal_data)
|
|
547
|
+
|
|
548
|
+
// Check if this is a binary file
|
|
549
|
+
if (file_info.is_binary) {
|
|
550
|
+
if (file_info.content instanceof ArrayBuffer) {
|
|
551
|
+
await load_trajectory_data(file_info.content, file_info.name)
|
|
552
|
+
} else if (file_info.content_url) {
|
|
553
|
+
const response = await fetch(file_info.content_url)
|
|
554
|
+
const array_buffer = await response.arrayBuffer()
|
|
555
|
+
await load_trajectory_data(array_buffer, file_info.name)
|
|
556
|
+
} else {
|
|
557
|
+
console.warn(
|
|
558
|
+
`Binary file without ArrayBuffer or blob URL:`,
|
|
559
|
+
file_info.name,
|
|
560
|
+
)
|
|
368
561
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
562
|
+
} else {
|
|
563
|
+
await load_trajectory_data(file_info.content, file_info.name)
|
|
564
|
+
}
|
|
565
|
+
return true
|
|
566
|
+
} catch (error) {
|
|
567
|
+
console.warn(`Failed to parse internal file data:`, error)
|
|
568
|
+
return false
|
|
374
569
|
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// Handle file drop events with optimized large file support
|
|
573
|
+
async function handle_file_drop(event: DragEvent) {
|
|
574
|
+
event.preventDefault()
|
|
575
|
+
dragover = false
|
|
576
|
+
if (!allow_file_drop) return
|
|
577
|
+
|
|
578
|
+
loading = true
|
|
579
|
+
|
|
383
580
|
try {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
581
|
+
// Check for our custom internal file format first
|
|
582
|
+
const internal_data = event.dataTransfer?.getData(
|
|
583
|
+
`application/x-matterviz-file`,
|
|
584
|
+
)
|
|
585
|
+
if (internal_data) {
|
|
586
|
+
const handled = await handle_internal_file_drop(internal_data)
|
|
587
|
+
if (handled) return
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// Handle URL-based files (e.g. from FilePicker)
|
|
591
|
+
const handled = await handle_url_drop(event, async (content, filename) => {
|
|
592
|
+
current_filename = filename
|
|
593
|
+
file_size = content instanceof ArrayBuffer
|
|
594
|
+
? content.byteLength
|
|
595
|
+
: new Blob([content]).size
|
|
596
|
+
await load_trajectory_data(content, filename)
|
|
597
|
+
}).catch(() => false)
|
|
598
|
+
|
|
599
|
+
if (handled) {
|
|
600
|
+
return
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// Handle file system drops with optimized large file support
|
|
604
|
+
const file = event.dataTransfer?.files[0]
|
|
605
|
+
if (file) {
|
|
606
|
+
file_size = file.size
|
|
607
|
+
current_file_path = file.webkitRelativePath || file.name
|
|
608
|
+
file_object = file
|
|
609
|
+
|
|
610
|
+
// Read file content directly
|
|
611
|
+
const content = await read_file_content(file)
|
|
612
|
+
await load_trajectory_data(content, file.name)
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Check for plain text data (fallback)
|
|
616
|
+
const text_data = event.dataTransfer?.getData(`text/plain`)
|
|
617
|
+
if (text_data) {
|
|
618
|
+
file_size = new Blob([text_data]).size // Calculate byte size of text data
|
|
619
|
+
await load_trajectory_data(text_data, `trajectory.json`)
|
|
620
|
+
return
|
|
621
|
+
}
|
|
622
|
+
} catch (error) {
|
|
623
|
+
console.error(`File drop failed:`, error)
|
|
624
|
+
error_msg = `Failed to load file: ${error}`
|
|
625
|
+
on_error?.({ error_msg, filename: current_filename, file_size })
|
|
626
|
+
} finally {
|
|
627
|
+
loading = false
|
|
427
628
|
}
|
|
428
|
-
}
|
|
429
|
-
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
$effect(() => { // Load trajectory from URL when data_url is provided
|
|
430
632
|
if (data_url && !trajectory) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
633
|
+
loading = true
|
|
634
|
+
error_msg = null
|
|
635
|
+
|
|
636
|
+
load_from_url(data_url, async (content, filename) => {
|
|
637
|
+
current_filename = filename
|
|
638
|
+
file_size = content instanceof ArrayBuffer
|
|
639
|
+
? content.byteLength
|
|
640
|
+
: new Blob([content]).size
|
|
641
|
+
await load_trajectory_data(content, filename)
|
|
642
|
+
})
|
|
643
|
+
.then(() => {
|
|
644
|
+
loading = false
|
|
442
645
|
})
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
error_msg,
|
|
451
|
-
filename: current_filename || undefined,
|
|
452
|
-
file_size: file_size || undefined,
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
// Watch for frame rate changes
|
|
458
|
-
$effect(() => {
|
|
459
|
-
on_frame_rate_change?.({ trajectory, fps: fps });
|
|
460
|
-
});
|
|
461
|
-
async function load_trajectory_data(data, filename) {
|
|
462
|
-
loading = true;
|
|
463
|
-
error_msg = null;
|
|
464
|
-
parsing_progress = null;
|
|
465
|
-
// Reset previous loading state
|
|
466
|
-
orig_data = null;
|
|
467
|
-
try {
|
|
468
|
-
const data_size = data instanceof ArrayBuffer ? data.byteLength : data.length;
|
|
469
|
-
// Determine loading strategy based on file size
|
|
470
|
-
const bin_file_threshold = loading_options.bin_file_threshold ??
|
|
471
|
-
MAX_BIN_FILE_SIZE;
|
|
472
|
-
const text_file_threshold = loading_options.text_file_threshold ??
|
|
473
|
-
MAX_TEXT_FILE_SIZE;
|
|
474
|
-
if ((data instanceof ArrayBuffer && data_size > bin_file_threshold) ||
|
|
475
|
-
(typeof data === `string` && data_size > text_file_threshold)) { // Large files: Use indexed loading
|
|
476
|
-
await load_with_indexing(data, filename);
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
// Small files: Use regular loading
|
|
480
|
-
const merged_options = { ...loading_options, atom_type_mapping };
|
|
481
|
-
trajectory = await parse_trajectory_async(data, filename, (progress) => {
|
|
482
|
-
parsing_progress = progress;
|
|
483
|
-
}, merged_options);
|
|
484
|
-
}
|
|
485
|
-
current_step_idx = 0;
|
|
486
|
-
current_filename = filename;
|
|
487
|
-
const file_size_bytes = data instanceof ArrayBuffer
|
|
488
|
-
? data.byteLength
|
|
489
|
-
: new Blob([data]).size;
|
|
490
|
-
on_file_load?.({
|
|
491
|
-
trajectory,
|
|
492
|
-
frame_count: trajectory?.frames.length ?? 0,
|
|
493
|
-
total_atoms: trajectory?.frames[0]?.structure.sites.length ?? 0,
|
|
494
|
-
filename,
|
|
495
|
-
file_size: file_size_bytes,
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
catch (err) {
|
|
499
|
-
const unsupported_message = get_unsupported_format_message(filename, typeof data === `string` ? data : ``);
|
|
500
|
-
error_msg = unsupported_message || `Failed to parse trajectory: ${err}`;
|
|
501
|
-
current_filename = undefined;
|
|
502
|
-
file_size = undefined;
|
|
503
|
-
on_error?.({
|
|
646
|
+
.catch((err: Error) => {
|
|
647
|
+
console.error(`Failed to load trajectory from URL:`, err)
|
|
648
|
+
error_msg = `Failed to load trajectory: ${err.message}`
|
|
649
|
+
current_filename = undefined
|
|
650
|
+
file_size = undefined
|
|
651
|
+
loading = false
|
|
652
|
+
on_error?.({
|
|
504
653
|
error_msg,
|
|
505
654
|
filename: current_filename || undefined,
|
|
506
655
|
file_size: file_size || undefined,
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
finally {
|
|
510
|
-
parsing_progress = null;
|
|
511
|
-
loading = false;
|
|
656
|
+
})
|
|
657
|
+
})
|
|
512
658
|
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
// Watch for frame rate changes
|
|
662
|
+
$effect(() => {
|
|
663
|
+
on_frame_rate_change?.({ trajectory, fps: fps })
|
|
664
|
+
})
|
|
665
|
+
|
|
666
|
+
async function load_trajectory_data(data: string | ArrayBuffer, filename: string) {
|
|
667
|
+
loading = true
|
|
668
|
+
error_msg = null
|
|
669
|
+
parsing_progress = null
|
|
670
|
+
|
|
671
|
+
// Reset previous loading state
|
|
672
|
+
orig_data = null
|
|
673
|
+
|
|
674
|
+
try {
|
|
675
|
+
const data_size = data instanceof ArrayBuffer ? data.byteLength : data.length
|
|
676
|
+
|
|
677
|
+
// Determine loading strategy based on file size
|
|
678
|
+
const bin_file_threshold = loading_options.bin_file_threshold ??
|
|
679
|
+
MAX_BIN_FILE_SIZE
|
|
680
|
+
const text_file_threshold = loading_options.text_file_threshold ??
|
|
681
|
+
MAX_TEXT_FILE_SIZE
|
|
682
|
+
if (
|
|
683
|
+
(data instanceof ArrayBuffer && data_size > bin_file_threshold) ||
|
|
684
|
+
(typeof data === `string` && data_size > text_file_threshold)
|
|
685
|
+
) { // Large files: Use indexed loading
|
|
686
|
+
await load_with_indexing(data, filename)
|
|
687
|
+
} else {
|
|
688
|
+
// Small files: Use regular loading
|
|
689
|
+
const merged_options = { ...loading_options, atom_type_mapping }
|
|
522
690
|
trajectory = await parse_trajectory_async(data, filename, (progress) => {
|
|
523
|
-
|
|
524
|
-
}, merged_options)
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
691
|
+
parsing_progress = progress
|
|
692
|
+
}, merged_options)
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
current_step_idx = 0
|
|
696
|
+
current_filename = filename
|
|
697
|
+
|
|
698
|
+
const file_size_bytes = data instanceof ArrayBuffer
|
|
699
|
+
? data.byteLength
|
|
700
|
+
: new Blob([data]).size
|
|
701
|
+
on_file_load?.({ // emit file load event
|
|
702
|
+
trajectory,
|
|
703
|
+
frame_count: trajectory?.frames.length ?? 0,
|
|
704
|
+
total_atoms: trajectory?.frames[0]?.structure.sites.length ?? 0,
|
|
705
|
+
filename,
|
|
706
|
+
file_size: file_size_bytes,
|
|
707
|
+
})
|
|
708
|
+
} catch (err) {
|
|
709
|
+
const unsupported_message = get_unsupported_format_message(
|
|
710
|
+
filename,
|
|
711
|
+
typeof data === `string` ? data : ``,
|
|
712
|
+
)
|
|
713
|
+
error_msg = unsupported_message || `Failed to parse trajectory: ${err}`
|
|
714
|
+
current_filename = undefined
|
|
715
|
+
file_size = undefined
|
|
716
|
+
|
|
717
|
+
on_error?.({ // emit error event
|
|
718
|
+
error_msg,
|
|
719
|
+
filename: current_filename || undefined,
|
|
720
|
+
file_size: file_size || undefined,
|
|
721
|
+
})
|
|
722
|
+
} finally {
|
|
723
|
+
parsing_progress = null
|
|
724
|
+
loading = false
|
|
528
725
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// Load using indexed parsing for large files
|
|
729
|
+
async function load_with_indexing(data: string | ArrayBuffer, filename: string) {
|
|
730
|
+
try { // Use indexed parsing for efficient large file handling
|
|
731
|
+
const merged_options = {
|
|
732
|
+
use_indexing: true,
|
|
733
|
+
...loading_options,
|
|
734
|
+
atom_type_mapping,
|
|
735
|
+
}
|
|
736
|
+
trajectory = await parse_trajectory_async(data, filename, (progress) => {
|
|
737
|
+
parsing_progress = progress
|
|
738
|
+
}, merged_options)
|
|
739
|
+
|
|
740
|
+
// Attach frame loader and original data directly to trajectory for unified access
|
|
741
|
+
orig_data = data
|
|
742
|
+
trajectory.frame_loader = create_frame_loader(filename)
|
|
743
|
+
} catch (error) {
|
|
744
|
+
console.error(`Indexed loading failed:`, error)
|
|
745
|
+
throw error
|
|
532
746
|
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
if (display_mode === `scatter`)
|
|
539
|
-
|
|
540
|
-
if (display_mode === `histogram`)
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
function handle_click_outside(event) {
|
|
551
|
-
const target = event.target;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// Get current view mode label
|
|
750
|
+
let current_view_label = $derived.by(() => {
|
|
751
|
+
if (display_mode === `structure`) return `Structure Only`
|
|
752
|
+
if (display_mode === `scatter`) return `Scatter Only`
|
|
753
|
+
if (display_mode === `histogram`) return `Histogram Only`
|
|
754
|
+
if (display_mode === `structure+histogram`) return `Structure + Histogram`
|
|
755
|
+
if (display_mode === `structure+scatter`) return `Structure + Scatter`
|
|
756
|
+
throw new Error(`Unexpected display mode: ${display_mode}`)
|
|
757
|
+
})
|
|
758
|
+
|
|
759
|
+
let view_mode_dropdown_open = $state(false)
|
|
760
|
+
|
|
761
|
+
// Handle click outside to close dropdowns
|
|
762
|
+
function handle_click_outside(event: MouseEvent) {
|
|
763
|
+
const target = event.target as Element
|
|
552
764
|
if (view_mode_dropdown_open) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
view_mode_dropdown_open = false;
|
|
765
|
+
const dropdown_wrapper = target.closest(`.view-mode-dropdown-wrapper`)
|
|
766
|
+
// Don't close if clicking on dropdown wrapper (contains both button and menu)
|
|
767
|
+
if (!dropdown_wrapper) view_mode_dropdown_open = false
|
|
557
768
|
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// Handle keyboard shortcuts
|
|
772
|
+
function onkeydown(event: KeyboardEvent) {
|
|
773
|
+
if (!trajectory) return
|
|
774
|
+
|
|
563
775
|
// Don't handle shortcuts if user is typing in an input field (but allow if it's our step input and not focused)
|
|
564
|
-
const target = event.target
|
|
565
|
-
const is_step_input = target.classList.contains(`step-input`)
|
|
776
|
+
const target = event.target as HTMLElement
|
|
777
|
+
const is_step_input = target.classList.contains(`step-input`)
|
|
566
778
|
const is_input_focused = target.tagName === `INPUT` ||
|
|
567
|
-
|
|
779
|
+
target.tagName === `TEXTAREA`
|
|
780
|
+
|
|
568
781
|
// Skip if typing in an input that's not our step input
|
|
569
|
-
if (is_input_focused && !is_step_input)
|
|
570
|
-
|
|
782
|
+
if (is_input_focused && !is_step_input) return
|
|
783
|
+
|
|
571
784
|
// If typing in step input, only handle certain navigation keys
|
|
572
785
|
if (is_step_input && is_input_focused) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
return;
|
|
786
|
+
// Allow normal typing, but handle special navigation keys
|
|
787
|
+
if ([`Escape`, `Enter`].includes(event.key)) target.blur() // Remove focus from input
|
|
788
|
+
return
|
|
577
789
|
}
|
|
578
|
-
|
|
790
|
+
|
|
791
|
+
const is_cmd_or_ctrl = event.metaKey || event.ctrlKey
|
|
792
|
+
|
|
579
793
|
// Navigation shortcuts
|
|
580
|
-
if (event.key === ` `)
|
|
581
|
-
toggle_play();
|
|
794
|
+
if (event.key === ` `) toggle_play()
|
|
582
795
|
else if (event.key === `ArrowLeft`) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
else if (event.key === `
|
|
589
|
-
|
|
590
|
-
go_to_step(total_frames - 1);
|
|
591
|
-
else
|
|
592
|
-
next_step();
|
|
593
|
-
}
|
|
594
|
-
else if (event.key === `Home`)
|
|
595
|
-
go_to_step(0);
|
|
596
|
-
else if (event.key === `End`)
|
|
597
|
-
go_to_step(total_frames - 1);
|
|
796
|
+
if (is_cmd_or_ctrl) go_to_step(0)
|
|
797
|
+
else prev_step()
|
|
798
|
+
} else if (event.key === `ArrowRight`) {
|
|
799
|
+
if (is_cmd_or_ctrl) go_to_step(total_frames - 1)
|
|
800
|
+
else next_step()
|
|
801
|
+
} else if (event.key === `Home`) go_to_step(0)
|
|
802
|
+
else if (event.key === `End`) go_to_step(total_frames - 1)
|
|
598
803
|
else if (event.key === `j`) {
|
|
599
|
-
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
else if (event.key === `
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
else if (event.key === `PageDown`) {
|
|
608
|
-
go_to_step(Math.min(total_frames - 1, current_step_idx + 25));
|
|
804
|
+
go_to_step(Math.max(0, current_step_idx - 10))
|
|
805
|
+
} else if (event.key === `l`) {
|
|
806
|
+
go_to_step(Math.min(total_frames - 1, current_step_idx + 10))
|
|
807
|
+
} else if (event.key === `PageUp`) {
|
|
808
|
+
go_to_step(Math.max(0, current_step_idx - 25))
|
|
809
|
+
} else if (event.key === `PageDown`) {
|
|
810
|
+
go_to_step(Math.min(total_frames - 1, current_step_idx + 25))
|
|
609
811
|
} // Interface shortcuts
|
|
610
|
-
else if (event.key === `f` && fullscreen_toggle)
|
|
611
|
-
toggle_fullscreen(wrapper);
|
|
812
|
+
else if (event.key === `f` && fullscreen_toggle) toggle_fullscreen(wrapper)
|
|
612
813
|
// 'i' key handled by the TrajectoryInfoPane's built-in toggle
|
|
613
814
|
// Playback speed shortcuts (only when playing)
|
|
614
815
|
else if ((event.key === `=` || event.key === `+`) && is_playing) {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
on_frame_rate_change?.({ trajectory, fps: fps });
|
|
816
|
+
fps = Math.min(fps_range[1], fps + 0.2)
|
|
817
|
+
on_frame_rate_change?.({ trajectory, fps: fps })
|
|
818
|
+
} else if (event.key === `-` && is_playing) {
|
|
819
|
+
fps = Math.max(fps_range[0], fps - 0.2)
|
|
820
|
+
on_frame_rate_change?.({ trajectory, fps: fps })
|
|
621
821
|
} // System shortcuts
|
|
622
822
|
else if (event.key === `Escape`) {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
view_mode_dropdown_open = false;
|
|
627
|
-
// Escape key for info pane handled by DraggablePane
|
|
823
|
+
if (document.fullscreenElement) document.exitFullscreen()
|
|
824
|
+
else if (view_mode_dropdown_open) view_mode_dropdown_open = false
|
|
825
|
+
// Escape key for info pane handled by DraggablePane
|
|
628
826
|
} // Number keys 0-9 - jump to percentage of trajectory
|
|
629
827
|
else if (event.key >= `0` && event.key <= `9`) {
|
|
630
|
-
|
|
828
|
+
go_to_step(Math.floor((parseInt(event.key, 10) / 10) * (total_frames - 1)))
|
|
631
829
|
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
let
|
|
636
|
-
let
|
|
637
|
-
let
|
|
638
|
-
let
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// Separate state variables for each pane to match component prop types
|
|
833
|
+
let structure_info_open = $state(false)
|
|
834
|
+
let structure_controls_open = $state(false)
|
|
835
|
+
let scatter_controls = $state<ControlsConfig>({ open: false })
|
|
836
|
+
let trajectory_export_open = $state(false)
|
|
837
|
+
let fullscreen = $state(false)
|
|
639
838
|
</script>
|
|
640
839
|
|
|
641
840
|
<svelte:document
|
|
@@ -981,7 +1180,7 @@ let fullscreen = $state(false);
|
|
|
981
1180
|
{#snippet tooltip({ x, y, metadata, label })}
|
|
982
1181
|
{@const formatted_y = typeof y === `number` ? format_num(y) : y}
|
|
983
1182
|
Step: {Math.round(x)}<br />
|
|
984
|
-
{@html metadata?.series_label || label || `Value`}: {formatted_y}
|
|
1183
|
+
{@html sanitize_html(metadata?.series_label || label || `Value`)}: {formatted_y}
|
|
985
1184
|
{/snippet}
|
|
986
1185
|
</ScatterPlot>
|
|
987
1186
|
{:else if display_mode === `histogram` || display_mode === `structure+histogram`}
|
|
@@ -1084,7 +1283,8 @@ let fullscreen = $state(false);
|
|
|
1084
1283
|
border: var(--traj-dragover-border, var(--dragover-border));
|
|
1085
1284
|
}
|
|
1086
1285
|
/* Mode: hover - controls visible on component hover */
|
|
1087
|
-
&:hover .trajectory-controls.hover-visible
|
|
1286
|
+
&:hover .trajectory-controls.hover-visible,
|
|
1287
|
+
&:focus-within .trajectory-controls.hover-visible {
|
|
1088
1288
|
opacity: 1;
|
|
1089
1289
|
pointer-events: auto;
|
|
1090
1290
|
}
|