matterviz 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EmptyState.svelte +10 -2
- package/dist/FilePicker.svelte +154 -96
- package/dist/Icon.svelte +20 -14
- package/dist/MillerIndexInput.svelte +27 -21
- package/dist/api/optimade.js +6 -6
- package/dist/app.css +216 -178
- package/dist/brillouin/BrillouinZone.svelte +299 -198
- package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneControls.svelte +32 -5
- package/dist/brillouin/BrillouinZoneExportPane.svelte +74 -55
- package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneInfoPane.svelte +99 -68
- package/dist/brillouin/BrillouinZoneScene.svelte +277 -165
- 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 +327 -0
- package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +13 -0
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte +847 -0
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +16 -0
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +3194 -0
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +16 -0
- package/dist/chempot-diagram/ChemPotScene3D.svelte +11 -0
- package/dist/chempot-diagram/ChemPotScene3D.svelte.d.ts +7 -0
- 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.d.ts +10 -0
- package/dist/chempot-diagram/color.js +32 -0
- package/dist/chempot-diagram/compute.d.ts +48 -0
- package/dist/chempot-diagram/compute.js +812 -0
- package/dist/chempot-diagram/index.d.ts +6 -0
- package/dist/chempot-diagram/index.js +6 -0
- package/dist/chempot-diagram/pointer.d.ts +16 -0
- package/dist/chempot-diagram/pointer.js +40 -0
- package/dist/chempot-diagram/temperature.d.ts +15 -0
- package/dist/chempot-diagram/temperature.js +36 -0
- package/dist/chempot-diagram/types.d.ts +86 -0
- package/dist/chempot-diagram/types.js +28 -0
- package/dist/colors/index.d.ts +3 -1
- package/dist/colors/index.js +9 -3
- package/dist/composition/BarChart.svelte +141 -77
- package/dist/composition/BubbleChart.svelte +107 -52
- package/dist/composition/Composition.svelte +100 -79
- package/dist/composition/Formula.svelte +108 -62
- package/dist/composition/FormulaFilter.svelte +973 -353
- package/dist/composition/FormulaFilter.svelte.d.ts +35 -1
- package/dist/composition/PieChart.svelte +199 -99
- package/dist/composition/PieChart.svelte.d.ts +1 -1
- 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 -38
- package/dist/convex-hull/ConvexHull2D.svelte +551 -393
- package/dist/convex-hull/ConvexHull3D.svelte +1303 -825
- package/dist/convex-hull/ConvexHull4D.svelte +1012 -686
- package/dist/convex-hull/ConvexHullControls.svelte +115 -28
- package/dist/convex-hull/ConvexHullInfoPane.svelte +29 -3
- package/dist/convex-hull/ConvexHullStats.svelte +821 -249
- package/dist/convex-hull/ConvexHullStats.svelte.d.ts +6 -1
- package/dist/convex-hull/ConvexHullTooltip.svelte +41 -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.d.ts +6 -0
- package/dist/convex-hull/demo-temperature.js +40 -0
- package/dist/convex-hull/gas-thermodynamics.js +17 -12
- package/dist/convex-hull/helpers.d.ts +10 -1
- package/dist/convex-hull/helpers.js +79 -38
- package/dist/convex-hull/index.d.ts +1 -0
- package/dist/convex-hull/index.js +1 -0
- package/dist/convex-hull/thermodynamics.d.ts +8 -21
- package/dist/convex-hull/thermodynamics.js +163 -69
- package/dist/convex-hull/types.d.ts +12 -12
- package/dist/convex-hull/types.js +0 -12
- package/dist/coordination/CoordinationBarPlot.svelte +232 -176
- package/dist/element/BohrAtom.svelte +56 -13
- 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/element/data.js +2 -14
- package/dist/element/data.json.gz +0 -0
- package/dist/element/types.d.ts +1 -0
- 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 +336 -239
- package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceControls.svelte +113 -46
- package/dist/fermi-surface/FermiSurfaceScene.svelte +536 -343
- 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 +37 -33
- package/dist/fermi-surface/symmetry.js +2 -7
- package/dist/fermi-surface/types.d.ts +3 -5
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +1527 -0
- package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +110 -0
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +225 -0
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +30 -0
- package/dist/heatmap-matrix/index.d.ts +53 -0
- package/dist/heatmap-matrix/index.js +100 -0
- package/dist/heatmap-matrix/shared.d.ts +2 -0
- package/dist/heatmap-matrix/shared.js +4 -0
- package/dist/icons.d.ts +111 -0
- package/dist/icons.js +158 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/io/decompress.js +1 -1
- package/dist/io/export.d.ts +3 -0
- package/dist/io/export.js +138 -140
- package/dist/io/file-drop.d.ts +7 -0
- package/dist/io/file-drop.js +43 -0
- package/dist/io/index.d.ts +2 -2
- package/dist/io/index.js +2 -112
- package/dist/io/is-binary.js +2 -3
- package/dist/io/types.d.ts +1 -0
- package/dist/io/url-drop.d.ts +2 -0
- package/dist/io/url-drop.js +117 -0
- package/dist/isosurface/Isosurface.svelte +220 -110
- package/dist/isosurface/IsosurfaceControls.svelte +65 -28
- package/dist/isosurface/parse.js +104 -56
- package/dist/isosurface/slice.d.ts +2 -1
- package/dist/isosurface/slice.js +8 -13
- package/dist/isosurface/types.d.ts +14 -1
- package/dist/isosurface/types.js +152 -5
- package/dist/labels.d.ts +2 -1
- package/dist/labels.js +12 -8
- package/dist/layout/FullscreenToggle.svelte +11 -2
- package/dist/layout/InfoCard.svelte +38 -6
- package/dist/layout/InfoTag.svelte +125 -94
- package/dist/layout/PropertyFilter.svelte +82 -37
- package/dist/layout/SettingsSection.svelte +85 -55
- package/dist/layout/SubpageGrid.svelte +82 -0
- package/dist/layout/SubpageGrid.svelte.d.ts +14 -0
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +1 -0
- package/dist/layout/json-tree/JsonNode.svelte +266 -223
- package/dist/layout/json-tree/JsonTree.svelte +516 -429
- package/dist/layout/json-tree/JsonTree.svelte.d.ts +1 -1
- package/dist/layout/json-tree/JsonValue.svelte +281 -173
- package/dist/layout/json-tree/types.d.ts +10 -2
- package/dist/layout/json-tree/utils.d.ts +2 -0
- package/dist/layout/json-tree/utils.js +37 -2
- package/dist/marching-cubes.js +25 -2
- package/dist/math.d.ts +20 -17
- package/dist/math.js +474 -57
- package/dist/overlays/ContextMenu.svelte +66 -40
- package/dist/overlays/DraggablePane.svelte +331 -154
- package/dist/overlays/DraggablePane.svelte.d.ts +2 -0
- 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 +559 -267
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +6 -2
- package/dist/phase-diagram/PhaseDiagramControls.svelte +131 -51
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +3 -2
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +126 -0
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +15 -0
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte +160 -110
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +8 -1
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte +217 -86
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte.d.ts +6 -3
- 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/index.d.ts +2 -0
- package/dist/phase-diagram/index.js +2 -0
- package/dist/phase-diagram/parse.js +10 -9
- package/dist/phase-diagram/svg-to-diagram.d.ts +2 -0
- package/dist/phase-diagram/svg-to-diagram.js +869 -0
- package/dist/phase-diagram/types.d.ts +10 -0
- package/dist/phase-diagram/utils.d.ts +8 -4
- package/dist/phase-diagram/utils.js +219 -74
- package/dist/plot/AxisLabel.svelte +51 -0
- package/dist/plot/AxisLabel.svelte.d.ts +16 -0
- package/dist/plot/BarPlot.svelte +1461 -768
- package/dist/plot/BarPlot.svelte.d.ts +3 -3
- package/dist/plot/BarPlotControls.svelte +33 -6
- package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ColorBar.svelte +533 -383
- package/dist/plot/ColorBar.svelte.d.ts +1 -1
- package/dist/plot/ColorScaleSelect.svelte +28 -7
- package/dist/plot/ElementScatter.svelte +38 -16
- package/dist/plot/FillArea.svelte +152 -92
- package/dist/plot/Histogram.svelte +1162 -709
- package/dist/plot/Histogram.svelte.d.ts +1 -1
- package/dist/plot/HistogramControls.svelte +81 -18
- package/dist/plot/HistogramControls.svelte.d.ts +6 -2
- 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 +221 -96
- 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 -146
- package/dist/plot/ReferenceLine.svelte +77 -22
- package/dist/plot/ReferenceLine.svelte.d.ts +1 -0
- package/dist/plot/ReferenceLine3D.svelte +132 -107
- package/dist/plot/ReferencePlane.svelte +146 -123
- package/dist/plot/ScatterPlot.svelte +1880 -1156
- package/dist/plot/ScatterPlot.svelte.d.ts +3 -3
- package/dist/plot/ScatterPlot3D.svelte +256 -131
- package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlot3DControls.svelte +300 -297
- package/dist/plot/ScatterPlot3DControls.svelte.d.ts +2 -1
- package/dist/plot/ScatterPlot3DScene.svelte +608 -406
- package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlotControls.svelte +150 -70
- 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 +96 -0
- package/dist/plot/ZeroLines.svelte.d.ts +32 -0
- package/dist/plot/ZoomRect.svelte +23 -0
- package/dist/plot/ZoomRect.svelte.d.ts +8 -0
- package/dist/plot/axis-utils.d.ts +1 -1
- 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/index.d.ts +6 -2
- package/dist/plot/index.js +6 -2
- package/dist/plot/interactions.d.ts +8 -10
- package/dist/plot/interactions.js +2 -3
- package/dist/plot/layout.d.ts +11 -2
- package/dist/plot/layout.js +44 -17
- package/dist/plot/reference-line.d.ts +5 -22
- package/dist/plot/reference-line.js +12 -84
- package/dist/plot/scales.js +24 -36
- package/dist/plot/types.d.ts +53 -40
- package/dist/plot/types.js +12 -7
- package/dist/plot/utils/label-placement.d.ts +32 -15
- package/dist/plot/utils/label-placement.js +227 -63
- package/dist/plot/utils/series-visibility.js +2 -3
- package/dist/plot/utils.d.ts +1 -0
- package/dist/plot/utils.js +14 -0
- package/dist/rdf/RdfPlot.svelte +173 -132
- 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 +21 -6
- package/dist/settings.js +63 -19
- package/dist/spectral/Bands.svelte +963 -412
- package/dist/spectral/Bands.svelte.d.ts +22 -2
- 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.d.ts +23 -1
- package/dist/spectral/helpers.js +119 -51
- package/dist/spectral/types.d.ts +2 -0
- 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 +231 -129
- package/dist/structure/AtomLegend.svelte.d.ts +1 -1
- package/dist/structure/Bond.svelte +73 -47
- package/dist/structure/CanvasTooltip.svelte +10 -2
- package/dist/structure/CellSelect.svelte +148 -51
- package/dist/structure/Cylinder.svelte +33 -17
- package/dist/structure/Lattice.svelte +88 -33
- package/dist/structure/Structure.svelte +1077 -821
- package/dist/structure/Structure.svelte.d.ts +1 -1
- package/dist/structure/StructureControls.svelte +373 -139
- package/dist/structure/StructureControls.svelte.d.ts +1 -1
- package/dist/structure/StructureExportPane.svelte +124 -89
- package/dist/structure/StructureExportPane.svelte.d.ts +1 -1
- package/dist/structure/StructureInfoPane.svelte +304 -231
- package/dist/structure/StructureScene.svelte +919 -445
- package/dist/structure/StructureScene.svelte.d.ts +16 -7
- package/dist/structure/atom-properties.d.ts +6 -2
- package/dist/structure/atom-properties.js +42 -29
- package/dist/structure/bonding.js +6 -7
- package/dist/structure/export.js +22 -34
- package/dist/structure/ferrox-wasm-types.d.ts +3 -2
- package/dist/structure/ferrox-wasm-types.js +0 -3
- package/dist/structure/ferrox-wasm.d.ts +3 -2
- package/dist/structure/ferrox-wasm.js +2 -3
- package/dist/structure/index.d.ts +16 -0
- package/dist/structure/index.js +88 -6
- package/dist/structure/measure.d.ts +2 -2
- package/dist/structure/measure.js +4 -44
- package/dist/structure/parse.js +130 -155
- package/dist/structure/partial-occupancy.d.ts +25 -0
- package/dist/structure/partial-occupancy.js +99 -0
- 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 +5 -3
- package/dist/symmetry/SymmetryStats.svelte +94 -37
- package/dist/symmetry/WyckoffTable.svelte +42 -14
- package/dist/symmetry/cell-transform.js +5 -3
- package/dist/symmetry/index.d.ts +7 -4
- package/dist/symmetry/index.js +87 -21
- package/dist/symmetry/spacegroups.js +148 -148
- package/dist/table/HeatmapTable.svelte +1112 -516
- package/dist/table/HeatmapTable.svelte.d.ts +12 -1
- package/dist/table/ToggleMenu.svelte +125 -90
- package/dist/table/index.d.ts +2 -0
- 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 +889 -687
- package/dist/trajectory/TrajectoryError.svelte +14 -3
- package/dist/trajectory/TrajectoryExportPane.svelte +148 -90
- package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +1 -1
- package/dist/trajectory/TrajectoryInfoPane.svelte +272 -143
- package/dist/trajectory/constants.d.ts +6 -0
- package/dist/trajectory/constants.js +7 -0
- package/dist/trajectory/extract.js +13 -31
- package/dist/trajectory/format-detect.d.ts +9 -0
- package/dist/trajectory/format-detect.js +76 -0
- package/dist/trajectory/frame-reader.d.ts +17 -0
- package/dist/trajectory/frame-reader.js +332 -0
- package/dist/trajectory/helpers.d.ts +14 -0
- package/dist/trajectory/helpers.js +172 -0
- package/dist/trajectory/index.d.ts +1 -0
- package/dist/trajectory/index.js +23 -14
- package/dist/trajectory/parse/ase.d.ts +2 -0
- package/dist/trajectory/parse/ase.js +77 -0
- package/dist/trajectory/parse/hdf5.d.ts +2 -0
- package/dist/trajectory/parse/hdf5.js +129 -0
- package/dist/trajectory/parse/index.d.ts +12 -0
- package/dist/trajectory/parse/index.js +299 -0
- package/dist/trajectory/parse/lammps.d.ts +5 -0
- package/dist/trajectory/parse/lammps.js +179 -0
- package/dist/trajectory/parse/vasp.d.ts +2 -0
- package/dist/trajectory/parse/vasp.js +68 -0
- package/dist/trajectory/parse/xyz.d.ts +2 -0
- package/dist/trajectory/parse/xyz.js +110 -0
- package/dist/trajectory/plotting.js +13 -8
- package/dist/trajectory/types.d.ts +11 -0
- package/dist/trajectory/types.js +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +17 -0
- package/dist/xrd/XrdPlot.svelte +337 -245
- package/dist/xrd/broadening.js +14 -9
- package/dist/xrd/calc-xrd.js +12 -19
- package/dist/xrd/parse.d.ts +1 -1
- package/dist/xrd/parse.js +17 -17
- package/package.json +103 -101
- package/readme.md +4 -4
- package/dist/trajectory/parse.d.ts +0 -42
- package/dist/trajectory/parse.js +0 -1267
- /package/dist/element/{data.json.d.ts → data.json.gz.d.ts} +0 -0
- /package/dist/theme/{themes.js → themes.mjs} +0 -0
|
@@ -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,23 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { XyObj } from './'
|
|
3
|
+
|
|
4
|
+
let { start, current }: { start: XyObj | null; current: XyObj | null } = $props()
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#if start && current && isFinite(start.x) && isFinite(start.y) &&
|
|
8
|
+
isFinite(current.x) && isFinite(current.y)}
|
|
9
|
+
{@const x = Math.min(start.x, current.x)}
|
|
10
|
+
{@const y = Math.min(start.y, current.y)}
|
|
11
|
+
{@const rect_width = Math.abs(start.x - current.x)}
|
|
12
|
+
{@const rect_height = Math.abs(start.y - current.y)}
|
|
13
|
+
<rect class="zoom-rect" {x} {y} width={rect_width} height={rect_height} />
|
|
14
|
+
{/if}
|
|
15
|
+
|
|
16
|
+
<style>
|
|
17
|
+
.zoom-rect {
|
|
18
|
+
fill: var(--plot-zoom-rect-fill, rgba(100, 100, 255, 0.2));
|
|
19
|
+
stroke: var(--plot-zoom-rect-stroke, rgba(100, 100, 255, 0.8));
|
|
20
|
+
stroke-width: var(--plot-zoom-rect-stroke-width, 1);
|
|
21
|
+
pointer-events: none;
|
|
22
|
+
}
|
|
23
|
+
</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;
|
package/dist/plot/axis-utils.js
CHANGED
|
@@ -10,9 +10,7 @@ export function merge_series_state(old_series, new_series) {
|
|
|
10
10
|
}
|
|
11
11
|
return new_series.map((new_srs, idx) => {
|
|
12
12
|
// Match by id if available (string or number), otherwise fall back to index
|
|
13
|
-
const old_srs = (new_srs.id !== undefined && new_srs.id !== ``
|
|
14
|
-
? by_id.get(new_srs.id)
|
|
15
|
-
: undefined) ??
|
|
13
|
+
const old_srs = (new_srs.id !== undefined && new_srs.id !== `` ? by_id.get(new_srs.id) : undefined) ??
|
|
16
14
|
old_series[idx];
|
|
17
15
|
if (!old_srs) {
|
|
18
16
|
return new_srs;
|
|
@@ -21,9 +21,7 @@ export function compute_local_variance(values, window_size) {
|
|
|
21
21
|
const start = Math.max(0, idx - half_window);
|
|
22
22
|
const end = Math.min(len, idx + half_window + 1);
|
|
23
23
|
// Welford's online variance calculation
|
|
24
|
-
let mean = 0;
|
|
25
|
-
let m2 = 0;
|
|
26
|
-
let count = 0;
|
|
24
|
+
let [mean, m2, count] = [0, 0, 0];
|
|
27
25
|
for (let jdx = start; jdx < end; jdx++) {
|
|
28
26
|
const val = values[jdx];
|
|
29
27
|
if (!Number.isFinite(val))
|
|
@@ -170,13 +168,9 @@ export function detect_instability(x_values, y_values, config = {}) {
|
|
|
170
168
|
}
|
|
171
169
|
}
|
|
172
170
|
if (valid_y.length < window_size * 2) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
onset_x: NaN,
|
|
177
|
-
combined_score: 0,
|
|
178
|
-
method_scores: { derivative_variance: 0, amplitude_growth: 0, sign_changes: 0 },
|
|
179
|
-
};
|
|
171
|
+
const method_scores = { derivative_variance: 0, amplitude_growth: 0, sign_changes: 0 };
|
|
172
|
+
const detected = false;
|
|
173
|
+
return { detected, onset_index: -1, onset_x: NaN, combined_score: 0, method_scores };
|
|
180
174
|
}
|
|
181
175
|
// Run all three detection methods
|
|
182
176
|
const deriv_result = detect_derivative_variance(valid_y, window_size, threshold);
|
|
@@ -188,12 +182,12 @@ export function detect_instability(x_values, y_values, config = {}) {
|
|
|
188
182
|
sign_changes: sign_result.score,
|
|
189
183
|
};
|
|
190
184
|
// Compute weighted combined score
|
|
191
|
-
const total_weight = weights.derivative_variance + weights.amplitude_growth +
|
|
192
|
-
weights.sign_changes;
|
|
185
|
+
const total_weight = weights.derivative_variance + weights.amplitude_growth + weights.sign_changes;
|
|
193
186
|
const combined_score = total_weight > 0
|
|
194
187
|
? (weights.derivative_variance * deriv_result.score +
|
|
195
188
|
weights.amplitude_growth * amp_result.score +
|
|
196
|
-
weights.sign_changes * sign_result.score) /
|
|
189
|
+
weights.sign_changes * sign_result.score) /
|
|
190
|
+
total_weight
|
|
197
191
|
: 0;
|
|
198
192
|
// Find earliest onset across all methods that exceeded threshold
|
|
199
193
|
const onset_candidates = [
|
|
@@ -214,16 +208,8 @@ export function detect_instability(x_values, y_values, config = {}) {
|
|
|
214
208
|
}
|
|
215
209
|
}
|
|
216
210
|
const detected = combined_score >= threshold || onset_index >= 0;
|
|
217
|
-
const onset_x = onset_index >= 0 && onset_index < x_values.length
|
|
218
|
-
|
|
219
|
-
: NaN;
|
|
220
|
-
return {
|
|
221
|
-
detected,
|
|
222
|
-
onset_index,
|
|
223
|
-
onset_x,
|
|
224
|
-
combined_score,
|
|
225
|
-
method_scores,
|
|
226
|
-
};
|
|
211
|
+
const onset_x = onset_index >= 0 && onset_index < x_values.length ? x_values[onset_index] : NaN;
|
|
212
|
+
return { detected, onset_index, onset_x, combined_score, method_scores };
|
|
227
213
|
}
|
|
228
214
|
// --- Smoothing Functions ---
|
|
229
215
|
// Moving average - O(n)
|
|
@@ -235,8 +221,7 @@ export function smooth_moving_average(values, window) {
|
|
|
235
221
|
for (let idx = 0; idx < values.length; idx++) {
|
|
236
222
|
const start = Math.max(0, idx - half_window);
|
|
237
223
|
const end = Math.min(values.length, idx + half_window + 1);
|
|
238
|
-
let sum = 0;
|
|
239
|
-
let count = 0;
|
|
224
|
+
let [sum, count] = [0, 0];
|
|
240
225
|
for (let jdx = start; jdx < end; jdx++) {
|
|
241
226
|
if (Number.isFinite(values[jdx])) {
|
|
242
227
|
sum += values[jdx];
|
|
@@ -291,8 +276,7 @@ export function smooth_savitzky_golay(values, window, polynomial_order = DEFAULT
|
|
|
291
276
|
// Cache coefficient sum to avoid O(n × window) redundant reductions in loop
|
|
292
277
|
const coeffs_sum = coeffs.reduce((a, b) => a + b, 0);
|
|
293
278
|
for (let idx = 0; idx < values.length; idx++) {
|
|
294
|
-
let sum = 0;
|
|
295
|
-
let weight_sum = 0;
|
|
279
|
+
let [sum, weight_sum] = [0, 0];
|
|
296
280
|
for (let jdx = 0; jdx < actual_window; jdx++) {
|
|
297
281
|
const data_idx = idx - half + jdx;
|
|
298
282
|
if (data_idx >= 0 && data_idx < values.length && Number.isFinite(values[data_idx])) {
|
|
@@ -300,7 +284,7 @@ export function smooth_savitzky_golay(values, window, polynomial_order = DEFAULT
|
|
|
300
284
|
weight_sum += coeffs[jdx];
|
|
301
285
|
}
|
|
302
286
|
}
|
|
303
|
-
result[idx] = weight_sum !== 0 ? sum / weight_sum * coeffs_sum : values[idx];
|
|
287
|
+
result[idx] = weight_sum !== 0 ? (sum / weight_sum) * coeffs_sum : values[idx];
|
|
304
288
|
}
|
|
305
289
|
return result;
|
|
306
290
|
}
|
|
@@ -17,6 +17,7 @@ export const prepare_legend_data = (series) => series.map((series_data, series_i
|
|
|
17
17
|
label: series_data.label ?? `Series ${series_idx + 1}`,
|
|
18
18
|
visible: series_data.visible ?? true,
|
|
19
19
|
display_style: {
|
|
20
|
+
// Prefer the series’ symbol when present, falling back to settings
|
|
20
21
|
symbol_type: !Array.isArray(series_data.point_style)
|
|
21
22
|
? (series_data.point_style?.symbol_type ?? DEFAULTS.scatter.symbol_type)
|
|
22
23
|
: DEFAULTS.scatter.symbol_type,
|
|
@@ -38,7 +39,7 @@ export const create_data_points = (series, filter_fn) => series
|
|
|
38
39
|
// If prop is a scalar, returns the scalar (applied to all indices).
|
|
39
40
|
// Returns undefined if prop is null/undefined.
|
|
40
41
|
export function process_prop(prop, idx) {
|
|
41
|
-
if (prop
|
|
42
|
+
if (prop == null)
|
|
42
43
|
return undefined;
|
|
43
44
|
return Array.isArray(prop) ? prop[idx] : prop;
|
|
44
45
|
}
|
package/dist/plot/fill-utils.js
CHANGED
|
@@ -113,6 +113,8 @@ export function resolve_boundary(boundary, series, x_values, domains) {
|
|
|
113
113
|
case `function`:
|
|
114
114
|
return x_values.map((curr_x) => boundary.fn(curr_x));
|
|
115
115
|
case `data`:
|
|
116
|
+
if (boundary.values.length === 0)
|
|
117
|
+
return Array(x_values.length).fill(NaN);
|
|
116
118
|
// If lengths match, use directly; otherwise interpolate
|
|
117
119
|
if (boundary.values.length === x_values.length) {
|
|
118
120
|
return [...boundary.values];
|
package/dist/plot/index.d.ts
CHANGED
|
@@ -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 './
|
|
41
|
+
export * from './utils';
|
|
42
|
+
export { default as ZeroLines } from './ZeroLines.svelte';
|
|
43
|
+
export { default as ZoomRect } from './ZoomRect.svelte';
|
package/dist/plot/index.js
CHANGED
|
@@ -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 './
|
|
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 {
|
|
2
|
-
|
|
3
|
-
|
|
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:
|
|
8
|
-
export declare function pan_range(current:
|
|
9
|
-
export declare function pixels_to_data_delta(pixel_delta: number, data_range:
|
|
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:
|
|
12
|
-
range:
|
|
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
|
|
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 [
|
|
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
|
package/dist/plot/layout.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { AxisConfig, Sides } from './';
|
|
2
2
|
export declare const LABEL_GAP_DEFAULT = 30;
|
|
3
|
-
export declare const filter_padding:
|
|
3
|
+
export declare const filter_padding: (padding: Partial<Sides> | undefined | null, defaults: Required<Sides>) => Required<Sides>;
|
|
4
4
|
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
|
|
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;
|
|
@@ -28,6 +34,9 @@ export interface Rect {
|
|
|
28
34
|
width: number;
|
|
29
35
|
height: number;
|
|
30
36
|
}
|
|
37
|
+
export declare const pad_rect: (rect: Rect, padding: number) => Rect;
|
|
38
|
+
export declare const centered_rect: (center_x: number, top_y: number, width: number, height: number) => Rect;
|
|
39
|
+
export declare const rect_within_rect: (rect: Rect, bounds: Rect) => boolean;
|
|
31
40
|
export interface ElementPlacementConfig {
|
|
32
41
|
plot_bounds: Rect;
|
|
33
42
|
element_size: {
|
package/dist/plot/layout.js
CHANGED
|
@@ -22,18 +22,28 @@ 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
|
-
//
|
|
26
|
-
const measure_max_tick_width = (ticks, format = ``) => ticks.length === 0
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
27
|
+
? 0
|
|
28
|
+
: Math.max(...ticks.map((tick) => {
|
|
29
|
+
const label = typeof tick === `string` ? tick : format_value(tick, format);
|
|
30
|
+
return measure_text_width(label, `12px sans-serif`);
|
|
31
|
+
}));
|
|
32
|
+
// Estimated height of a single tick label line (font-size 0.8em ≈ 12px + leading)
|
|
33
|
+
export const TICK_LABEL_HEIGHT = 16;
|
|
34
|
+
// Estimated height of an axis label (font-size ~14px + margin)
|
|
35
|
+
export const AXIS_LABEL_HEIGHT = 20;
|
|
36
|
+
export const calc_auto_padding = ({ padding, default_padding, x2_axis = {}, y_axis = {}, y2_axis = {}, label_gap = LABEL_GAP_DEFAULT, }) => {
|
|
37
|
+
const x2_ticks = x2_axis.tick_values ?? [];
|
|
31
38
|
const y_ticks = y_axis.tick_values ?? [];
|
|
32
39
|
const y_format = y_axis.format ?? ``;
|
|
33
40
|
const y2_ticks = y2_axis.tick_values ?? [];
|
|
34
41
|
const y2_format = y2_axis.format ?? ``;
|
|
35
42
|
return {
|
|
36
|
-
t: padding.t ??
|
|
43
|
+
t: padding.t ??
|
|
44
|
+
(x2_ticks.length > 0
|
|
45
|
+
? Math.max(default_padding.t, TICK_LABEL_HEIGHT + label_gap + (x2_axis.label ? AXIS_LABEL_HEIGHT : 0))
|
|
46
|
+
: default_padding.t),
|
|
37
47
|
b: padding.b ?? default_padding.b,
|
|
38
48
|
l: padding.l ??
|
|
39
49
|
Math.max(default_padding.l, measure_max_tick_width(y_ticks, y_format) + label_gap),
|
|
@@ -60,18 +70,22 @@ export function constrain_tooltip_position(cursor_x, cursor_y, tooltip_width, to
|
|
|
60
70
|
const abs_offset_y = Math.abs(offset_y);
|
|
61
71
|
// Determine X position based on preferred side and flip state
|
|
62
72
|
let raw_x;
|
|
63
|
-
if (offset_x >= 0) {
|
|
73
|
+
if (offset_x >= 0) {
|
|
74
|
+
// Prefer right side: flip to left if overflows
|
|
64
75
|
raw_x = flip_x ? cursor_x - abs_offset_x - tooltip_width : cursor_x + abs_offset_x;
|
|
65
76
|
}
|
|
66
|
-
else {
|
|
77
|
+
else {
|
|
78
|
+
// Prefer left side: flip to right if overflows
|
|
67
79
|
raw_x = flip_x ? cursor_x + abs_offset_x : cursor_x - abs_offset_x - tooltip_width;
|
|
68
80
|
}
|
|
69
81
|
// Determine Y position based on preferred side and flip state
|
|
70
82
|
let raw_y;
|
|
71
|
-
if (offset_y >= 0) {
|
|
83
|
+
if (offset_y >= 0) {
|
|
84
|
+
// Prefer bottom: flip to top if overflows
|
|
72
85
|
raw_y = flip_y ? cursor_y - abs_offset_y - tooltip_height : cursor_y + abs_offset_y;
|
|
73
86
|
}
|
|
74
|
-
else {
|
|
87
|
+
else {
|
|
88
|
+
// Prefer top: flip to bottom if overflows
|
|
75
89
|
raw_y = flip_y ? cursor_y + abs_offset_y : cursor_y - abs_offset_y - tooltip_height;
|
|
76
90
|
}
|
|
77
91
|
// Clamp to viewport bounds
|
|
@@ -79,6 +93,22 @@ export function constrain_tooltip_position(cursor_x, cursor_y, tooltip_width, to
|
|
|
79
93
|
const y_pos = Math.max(0, Math.min(raw_y, viewport_height - tooltip_height));
|
|
80
94
|
return { x: x_pos, y: y_pos };
|
|
81
95
|
}
|
|
96
|
+
export const pad_rect = (rect, padding) => ({
|
|
97
|
+
x: rect.x - padding,
|
|
98
|
+
y: rect.y - padding,
|
|
99
|
+
width: rect.width + 2 * padding,
|
|
100
|
+
height: rect.height + 2 * padding,
|
|
101
|
+
});
|
|
102
|
+
export const centered_rect = (center_x, top_y, width, height) => ({
|
|
103
|
+
x: center_x - width / 2,
|
|
104
|
+
y: top_y,
|
|
105
|
+
width,
|
|
106
|
+
height,
|
|
107
|
+
});
|
|
108
|
+
export const rect_within_rect = (rect, bounds) => rect.x >= bounds.x &&
|
|
109
|
+
rect.x + rect.width <= bounds.x + bounds.width &&
|
|
110
|
+
rect.y >= bounds.y &&
|
|
111
|
+
rect.y + rect.height <= bounds.y + bounds.height;
|
|
82
112
|
// Scoring constants
|
|
83
113
|
const EXCLUSION_PENALTY = 1000;
|
|
84
114
|
const DISTANCE_WEIGHT = 0.001;
|
|
@@ -121,7 +151,7 @@ export function compute_element_placement(config) {
|
|
|
121
151
|
const effective_y_max = Math.max(valid_y_min, valid_y_max);
|
|
122
152
|
// Subsample points for performance
|
|
123
153
|
const sampled_points = points.length > MAX_SAMPLE_POINTS
|
|
124
|
-
? Array.from({ length: MAX_SAMPLE_POINTS }, (_, idx) => points[Math.floor(idx * points.length / MAX_SAMPLE_POINTS)])
|
|
154
|
+
? Array.from({ length: MAX_SAMPLE_POINTS }, (_, idx) => points[Math.floor((idx * points.length) / MAX_SAMPLE_POINTS)])
|
|
125
155
|
: points;
|
|
126
156
|
let best_result = {
|
|
127
157
|
x: effective_x_min,
|
|
@@ -189,11 +219,8 @@ export function compute_element_placement(config) {
|
|
|
189
219
|
euclidean_dist([cand_x, elem_bottom], [plot_left, plot_bottom]), // bottom-left
|
|
190
220
|
euclidean_dist([elem_right, elem_bottom], [plot_right, plot_bottom]));
|
|
191
221
|
// Higher bonus for positions closer to corners (0 = at corner, 1 = far from all)
|
|
192
|
-
const corner_bonus = max_corner_dist > 0
|
|
193
|
-
|
|
194
|
-
: 0;
|
|
195
|
-
const score = -overlap_count + min_distance * DISTANCE_WEIGHT + corner_bonus -
|
|
196
|
-
exclusion_penalty;
|
|
222
|
+
const corner_bonus = max_corner_dist > 0 ? (1 - min_corner_dist / max_corner_dist) * CORNER_WEIGHT : 0;
|
|
223
|
+
const score = -overlap_count + min_distance * DISTANCE_WEIGHT + corner_bonus - exclusion_penalty;
|
|
197
224
|
if (score > best_result.score) {
|
|
198
225
|
best_result = { x: cand_x, y: cand_y, score };
|
|
199
226
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
16
|
-
export declare function
|
|
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;
|
|
33
|
-
export declare function resolve_line_endpoints(ref_line: RefLine, { x_min, x_max, y_min, y_max }: {
|
|
14
|
+
export declare const normalize_point: (point: [RefLineValue, RefLineValue]) => [number, number];
|
|
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,10 @@ export function normalize_value(value) {
|
|
|
48
48
|
return 0;
|
|
49
49
|
}
|
|
50
50
|
// Normalize a point tuple
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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) => [
|
|
52
|
+
normalize_value(point[0]),
|
|
53
|
+
normalize_value(point[1]),
|
|
54
|
+
];
|
|
122
55
|
// Clip a line segment to a rectangle using Liang-Barsky algorithm
|
|
123
56
|
// Returns clipped [x1, y1, x2, y2] or null if segment is entirely outside
|
|
124
57
|
function clip_segment_to_rect(p1x, p1y, p2x, p2y, x_min, x_max, y_min, y_max) {
|
|
@@ -147,17 +80,13 @@ function clip_segment_to_rect(p1x, p1y, p2x, p2y, x_min, x_max, y_min, y_max) {
|
|
|
147
80
|
}
|
|
148
81
|
if (t_enter > t_leave)
|
|
149
82
|
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
|
-
];
|
|
83
|
+
return [p1x + t_enter * dx, p1y + t_enter * dy, p1x + t_leave * dx, p1y + t_leave * dy];
|
|
156
84
|
}
|
|
157
85
|
// Compute the screen coordinates for a reference line
|
|
158
86
|
// 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
|
|
87
|
+
export function resolve_line_endpoints(ref_line, { x_min, x_max, y_min, y_max, }, { x_scale, x2_scale, y_scale, y2_scale, }) {
|
|
88
|
+
// Determine which scales to use based on axis assignment
|
|
89
|
+
const active_x_scale = ref_line.x_axis === `x2` && x2_scale ? x2_scale : x_scale;
|
|
161
90
|
const active_y_scale = ref_line.y_axis === `y2` && y2_scale ? y2_scale : y_scale;
|
|
162
91
|
// Check if value is within plot bounds (for visibility)
|
|
163
92
|
const is_x_visible = (x_val) => x_val >= x_min && x_val <= x_max;
|
|
@@ -273,9 +202,9 @@ export function resolve_line_endpoints(ref_line, { x_min, x_max, y_min, y_max },
|
|
|
273
202
|
return null;
|
|
274
203
|
}
|
|
275
204
|
// Convert data coordinates to screen pixels
|
|
276
|
-
const x1_px =
|
|
205
|
+
const x1_px = active_x_scale(x1_data);
|
|
277
206
|
const y1_px = active_y_scale(y1_data);
|
|
278
|
-
const x2_px =
|
|
207
|
+
const x2_px = active_x_scale(x2_data);
|
|
279
208
|
const y2_px = active_y_scale(y2_data);
|
|
280
209
|
// Validate that pixels are finite
|
|
281
210
|
if (!isFinite(x1_px) || !isFinite(y1_px) || !isFinite(x2_px) || !isFinite(y2_px)) {
|
|
@@ -317,7 +246,7 @@ export function calculate_annotation_position(x1, y1, x2, y2, annotation) {
|
|
|
317
246
|
if (side === `above` || side === `below`) {
|
|
318
247
|
// In SVG, y increases downward. Flip sign if 'above' and perpendicular points down (ny > 0),
|
|
319
248
|
// or if 'below' and perpendicular points up (ny <= 0), to ensure offset is in correct direction
|
|
320
|
-
const sign = (side === `above`) ===
|
|
249
|
+
const sign = (side === `above`) === ny > 0 ? -1 : 1;
|
|
321
250
|
perp_x = sign * nx * gap;
|
|
322
251
|
perp_y = sign * ny * gap;
|
|
323
252
|
}
|
|
@@ -341,8 +270,7 @@ export function calculate_annotation_position(x1, y1, x2, y2, annotation) {
|
|
|
341
270
|
text_anchor = `start`; // text starts at gap point, extends right
|
|
342
271
|
}
|
|
343
272
|
else {
|
|
344
|
-
text_anchor = ({ start: `start`, end: `end`, center: `middle` }[position] ??
|
|
345
|
-
`middle`);
|
|
273
|
+
text_anchor = ({ start: `start`, end: `end`, center: `middle` }[position] ?? `middle`);
|
|
346
274
|
}
|
|
347
275
|
const dominant_baseline = ({
|
|
348
276
|
above: `auto`,
|