matterviz 0.3.7 → 0.4.0
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/Icon.svelte +7 -4
- package/dist/MillerIndexInput.svelte +1 -1
- package/dist/api/optimade.js +32 -26
- package/dist/app.css +0 -3
- package/dist/brillouin/BrillouinZone.svelte +8 -3
- package/dist/brillouin/BrillouinZone.svelte.d.ts +2 -1
- package/dist/brillouin/BrillouinZoneScene.svelte +52 -6
- package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -0
- package/dist/brillouin/BrillouinZoneTooltip.svelte +16 -25
- package/dist/brillouin/compute.js +10 -14
- package/dist/chempot-diagram/ChemPotDiagram.svelte +14 -13
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte +12 -15
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +8 -10
- package/dist/chempot-diagram/async-compute.svelte.js +3 -1
- package/dist/chempot-diagram/chempot-worker.js +2 -1
- package/dist/chempot-diagram/compute.d.ts +1 -1
- package/dist/chempot-diagram/compute.js +17 -19
- package/dist/colors/index.js +6 -5
- package/dist/composition/FormulaFilter.svelte +12 -6
- package/dist/composition/PieChart.svelte +6 -5
- package/dist/composition/chem-sys.d.ts +8 -0
- package/dist/composition/chem-sys.js +85 -0
- package/dist/composition/format.js +4 -2
- package/dist/composition/index.d.ts +1 -0
- package/dist/composition/index.js +1 -0
- package/dist/composition/parse.js +25 -13
- package/dist/convex-hull/ConvexHull2D.svelte +12 -10
- package/dist/convex-hull/ConvexHull3D.svelte +5 -5
- package/dist/convex-hull/ConvexHull4D.svelte +5 -9
- package/dist/convex-hull/ConvexHullStats.svelte +12 -12
- package/dist/convex-hull/GasPressureControls.svelte +4 -4
- package/dist/convex-hull/TemperatureSlider.svelte +2 -2
- package/dist/convex-hull/demo-temperature.d.ts +1 -1
- package/dist/convex-hull/demo-temperature.js +20 -22
- package/dist/convex-hull/gas-thermodynamics.d.ts +2 -2
- package/dist/convex-hull/gas-thermodynamics.js +22 -30
- package/dist/convex-hull/helpers.d.ts +3 -0
- package/dist/convex-hull/helpers.js +17 -9
- package/dist/convex-hull/index.d.ts +1 -1
- package/dist/convex-hull/thermodynamics.js +83 -78
- package/dist/convex-hull/types.d.ts +1 -1
- package/dist/coordination/CoordinationBarPlot.svelte +23 -23
- package/dist/coordination/CoordinationBarPlot.svelte.d.ts +1 -1
- package/dist/element/ElementTile.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSlice.svelte +13 -5
- package/dist/fermi-surface/FermiSurface.svelte +11 -5
- package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceControls.svelte +1 -1
- package/dist/fermi-surface/FermiSurfaceScene.svelte +3 -0
- package/dist/fermi-surface/FermiSurfaceTooltip.svelte +8 -34
- package/dist/fermi-surface/compute.js +59 -59
- package/dist/fermi-surface/export.js +3 -2
- package/dist/fermi-surface/parse.js +7 -4
- package/dist/fermi-surface/types.d.ts +1 -0
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +23 -21
- package/dist/heatmap-matrix/index.js +1 -1
- package/dist/io/decompress.js +4 -2
- package/dist/io/export.d.ts +4 -4
- package/dist/io/export.js +47 -25
- package/dist/io/fetch.js +5 -1
- package/dist/io/file-drop.d.ts +1 -1
- package/dist/io/file-drop.js +35 -36
- package/dist/io/url-drop.js +64 -33
- package/dist/isosurface/parse.js +6 -7
- package/dist/isosurface/slice.js +5 -4
- package/dist/isosurface/types.js +1 -1
- package/dist/keyboard.d.ts +3 -0
- package/dist/keyboard.js +23 -0
- package/dist/labels.d.ts +1 -1
- package/dist/labels.js +8 -7
- package/dist/layout/PropertyFilter.svelte +3 -2
- package/dist/layout/SettingsSection.svelte +1 -1
- package/dist/layout/json-tree/JsonNode.svelte +1 -1
- package/dist/layout/json-tree/JsonTree.svelte +2 -2
- package/dist/layout/json-tree/utils.js +5 -4
- package/dist/marching-cubes.js +8 -13
- package/dist/math.d.ts +5 -1
- package/dist/math.js +24 -9
- package/dist/overlays/DraggablePane.svelte +4 -4
- package/dist/periodic-table/PeriodicTable.svelte +20 -9
- package/dist/periodic-table/PropertySelect.svelte +1 -0
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +9 -3
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +2 -1
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte +1 -1
- package/dist/phase-diagram/build-diagram.js +2 -2
- package/dist/phase-diagram/parse.js +6 -5
- package/dist/phase-diagram/types.d.ts +1 -1
- package/dist/phase-diagram/utils.d.ts +3 -3
- package/dist/phase-diagram/utils.js +8 -12
- package/dist/plot/{BarPlot.svelte → bar/BarPlot.svelte} +229 -587
- package/dist/plot/{BarPlot.svelte.d.ts → bar/BarPlot.svelte.d.ts} +5 -5
- package/dist/plot/{BarPlotControls.svelte → bar/BarPlotControls.svelte} +6 -5
- package/dist/plot/{BarPlotControls.svelte.d.ts → bar/BarPlotControls.svelte.d.ts} +3 -3
- package/dist/plot/{SpacegroupBarPlot.svelte → bar/SpacegroupBarPlot.svelte} +6 -6
- package/dist/plot/{SpacegroupBarPlot.svelte.d.ts → bar/SpacegroupBarPlot.svelte.d.ts} +1 -1
- package/dist/plot/bar/data.d.ts +40 -0
- package/dist/plot/bar/data.js +154 -0
- package/dist/plot/bar/geometry.d.ts +39 -0
- package/dist/plot/bar/geometry.js +60 -0
- package/dist/plot/bar/index.d.ts +3 -0
- package/dist/plot/bar/index.js +3 -0
- package/dist/plot/box/BoxPlot.svelte +1462 -0
- package/dist/plot/box/BoxPlot.svelte.d.ts +94 -0
- package/dist/plot/box/BoxPlotControls.svelte +109 -0
- package/dist/plot/box/BoxPlotControls.svelte.d.ts +19 -0
- package/dist/plot/box/Violin.svelte +14 -0
- package/dist/plot/box/Violin.svelte.d.ts +70 -0
- package/dist/plot/box/box-plot.d.ts +55 -0
- package/dist/plot/box/box-plot.js +126 -0
- package/dist/plot/box/index.d.ts +5 -0
- package/dist/plot/box/index.js +5 -0
- package/dist/plot/box/kde.d.ts +16 -0
- package/dist/plot/box/kde.js +160 -0
- package/dist/plot/box/quantile.d.ts +3 -0
- package/dist/plot/box/quantile.js +53 -0
- package/dist/plot/{auto-place.js → core/auto-place.js} +2 -2
- package/dist/plot/core/axis-utils.d.ts +46 -0
- package/dist/plot/core/axis-utils.js +110 -0
- package/dist/plot/{AxisLabel.svelte → core/components/AxisLabel.svelte} +2 -2
- package/dist/plot/{AxisLabel.svelte.d.ts → core/components/AxisLabel.svelte.d.ts} +1 -1
- package/dist/plot/{ColorBar.svelte → core/components/ColorBar.svelte} +36 -33
- package/dist/plot/{ColorBar.svelte.d.ts → core/components/ColorBar.svelte.d.ts} +2 -2
- package/dist/plot/{ColorScaleSelect.svelte → core/components/ColorScaleSelect.svelte} +4 -3
- package/dist/plot/{ColorScaleSelect.svelte.d.ts → core/components/ColorScaleSelect.svelte.d.ts} +2 -2
- package/dist/plot/core/components/ControlPane.svelte +46 -0
- package/dist/plot/core/components/ControlPane.svelte.d.ts +13 -0
- package/dist/plot/{FillArea.svelte → core/components/FillArea.svelte} +17 -6
- package/dist/plot/{FillArea.svelte.d.ts → core/components/FillArea.svelte.d.ts} +1 -1
- package/dist/plot/{InteractiveAxisLabel.svelte → core/components/InteractiveAxisLabel.svelte} +3 -3
- package/dist/plot/{InteractiveAxisLabel.svelte.d.ts → core/components/InteractiveAxisLabel.svelte.d.ts} +2 -2
- package/dist/plot/{Line.svelte → core/components/Line.svelte} +30 -13
- package/dist/plot/{PlotAxis.svelte → core/components/PlotAxis.svelte} +7 -5
- package/dist/plot/{PlotAxis.svelte.d.ts → core/components/PlotAxis.svelte.d.ts} +3 -2
- package/dist/plot/{PlotControls.svelte → core/components/PlotControls.svelte} +17 -29
- package/dist/plot/core/components/PlotControls.svelte.d.ts +4 -0
- package/dist/plot/{PlotLegend.svelte → core/components/PlotLegend.svelte} +21 -10
- package/dist/plot/{PlotLegend.svelte.d.ts → core/components/PlotLegend.svelte.d.ts} +3 -2
- package/dist/plot/{PlotTooltip.svelte → core/components/PlotTooltip.svelte} +17 -1
- package/dist/plot/{PlotTooltip.svelte.d.ts → core/components/PlotTooltip.svelte.d.ts} +8 -0
- package/dist/plot/{PortalSelect.svelte → core/components/PortalSelect.svelte} +11 -7
- package/dist/plot/{ReferenceLine.svelte → core/components/ReferenceLine.svelte} +3 -3
- package/dist/plot/{ReferenceLine.svelte.d.ts → core/components/ReferenceLine.svelte.d.ts} +1 -1
- package/dist/plot/{ReferenceLine3D.svelte → core/components/ReferenceLine3D.svelte} +4 -4
- package/dist/plot/{ReferenceLine3D.svelte.d.ts → core/components/ReferenceLine3D.svelte.d.ts} +2 -2
- package/dist/plot/{ReferencePlane.svelte → core/components/ReferencePlane.svelte} +7 -7
- package/dist/plot/{ReferencePlane.svelte.d.ts → core/components/ReferencePlane.svelte.d.ts} +2 -2
- package/dist/plot/{ZeroLines.svelte → core/components/ZeroLines.svelte} +3 -3
- package/dist/plot/{ZeroLines.svelte.d.ts → core/components/ZeroLines.svelte.d.ts} +3 -3
- package/dist/plot/{ZoomRect.svelte → core/components/ZoomRect.svelte} +1 -1
- package/dist/plot/{ZoomRect.svelte.d.ts → core/components/ZoomRect.svelte.d.ts} +1 -1
- package/dist/plot/core/components/index.d.ts +17 -0
- package/dist/plot/core/components/index.js +17 -0
- package/dist/plot/{data-cleaning.d.ts → core/data-cleaning.d.ts} +71 -1
- package/dist/plot/{data-cleaning.js → core/data-cleaning.js} +3 -5
- package/dist/plot/{data-transform.d.ts → core/data-transform.d.ts} +2 -2
- package/dist/plot/{data-transform.js → core/data-transform.js} +3 -3
- package/dist/plot/core/fill-utils.d.ts +33 -0
- package/dist/plot/core/fill-utils.js +388 -0
- package/dist/plot/{hover-lock.svelte.js → core/hover-lock.svelte.js} +5 -6
- package/dist/plot/core/index.d.ts +10 -0
- package/dist/plot/core/index.js +11 -0
- package/dist/plot/core/interactions.d.ts +35 -0
- package/dist/plot/core/interactions.js +195 -0
- package/dist/plot/{layout.d.ts → core/layout.d.ts} +1 -0
- package/dist/plot/{layout.js → core/layout.js} +16 -8
- package/dist/plot/{reference-line.d.ts → core/reference-line.d.ts} +1 -1
- package/dist/plot/{reference-line.js → core/reference-line.js} +23 -36
- package/dist/plot/{scales.d.ts → core/scales.d.ts} +2 -2
- package/dist/plot/{scales.js → core/scales.js} +84 -85
- package/dist/plot/core/svg.d.ts +2 -0
- package/dist/plot/core/svg.js +41 -0
- package/dist/plot/{types.d.ts → core/types.d.ts} +19 -79
- package/dist/plot/{types.js → core/types.js} +1 -1
- package/dist/plot/{utils → core/utils}/label-placement.d.ts +2 -2
- package/dist/plot/core/utils/series-visibility.d.ts +26 -0
- package/dist/plot/{utils → core/utils}/series-visibility.js +29 -2
- package/dist/plot/core/utils.d.ts +11 -0
- package/dist/plot/core/utils.js +27 -0
- package/dist/plot/{Histogram.svelte → histogram/Histogram.svelte} +154 -294
- package/dist/plot/{Histogram.svelte.d.ts → histogram/Histogram.svelte.d.ts} +2 -2
- package/dist/plot/{HistogramControls.svelte → histogram/HistogramControls.svelte} +6 -6
- package/dist/plot/{HistogramControls.svelte.d.ts → histogram/HistogramControls.svelte.d.ts} +4 -4
- package/dist/plot/histogram/index.d.ts +2 -0
- package/dist/plot/histogram/index.js +2 -0
- package/dist/plot/index.d.ts +8 -41
- package/dist/plot/index.js +10 -39
- package/dist/plot/sankey/Sankey.svelte +700 -0
- package/dist/plot/sankey/Sankey.svelte.d.ts +74 -0
- package/dist/plot/sankey/SankeyControls.svelte +98 -0
- package/dist/plot/sankey/SankeyControls.svelte.d.ts +19 -0
- package/dist/plot/sankey/index.d.ts +4 -0
- package/dist/plot/sankey/index.js +3 -0
- package/dist/plot/sankey/sankey-types.d.ts +42 -0
- package/dist/plot/sankey/sankey-types.js +4 -0
- package/dist/plot/sankey/sankey.d.ts +52 -0
- package/dist/plot/sankey/sankey.js +187 -0
- package/dist/plot/{BinnedScatterPlot.svelte → scatter/BinnedScatterPlot.svelte} +61 -59
- package/dist/plot/{BinnedScatterPlot.svelte.d.ts → scatter/BinnedScatterPlot.svelte.d.ts} +4 -4
- package/dist/plot/{ElementScatter.svelte → scatter/ElementScatter.svelte} +6 -6
- package/dist/plot/{ElementScatter.svelte.d.ts → scatter/ElementScatter.svelte.d.ts} +2 -2
- package/dist/plot/{ScatterPlot.svelte → scatter/ScatterPlot.svelte} +221 -642
- package/dist/plot/{ScatterPlot.svelte.d.ts → scatter/ScatterPlot.svelte.d.ts} +7 -7
- package/dist/plot/{ScatterPlotControls.svelte → scatter/ScatterPlotControls.svelte} +6 -5
- package/dist/plot/{ScatterPlotControls.svelte.d.ts → scatter/ScatterPlotControls.svelte.d.ts} +1 -1
- package/dist/plot/{ScatterPoint.svelte → scatter/ScatterPoint.svelte} +7 -7
- package/dist/plot/{ScatterPoint.svelte.d.ts → scatter/ScatterPoint.svelte.d.ts} +3 -3
- package/dist/plot/{adaptive-density.d.ts → scatter/adaptive-density.d.ts} +14 -4
- package/dist/plot/{adaptive-density.js → scatter/adaptive-density.js} +46 -20
- package/dist/plot/{binned-scatter-types.d.ts → scatter/binned-scatter-types.d.ts} +3 -3
- package/dist/plot/scatter/index.d.ts +7 -0
- package/dist/plot/scatter/index.js +5 -0
- package/dist/plot/scatter/scatter-data.d.ts +19 -0
- package/dist/plot/scatter/scatter-data.js +212 -0
- package/dist/plot/{ScatterPlot3D.svelte → scatter-3d/ScatterPlot3D.svelte} +12 -10
- package/dist/plot/{ScatterPlot3D.svelte.d.ts → scatter-3d/ScatterPlot3D.svelte.d.ts} +7 -7
- package/dist/plot/{ScatterPlot3DControls.svelte → scatter-3d/ScatterPlot3DControls.svelte} +5 -4
- package/dist/plot/{ScatterPlot3DControls.svelte.d.ts → scatter-3d/ScatterPlot3DControls.svelte.d.ts} +2 -2
- package/dist/plot/{ScatterPlot3DScene.svelte → scatter-3d/ScatterPlot3DScene.svelte} +11 -11
- package/dist/plot/{ScatterPlot3DScene.svelte.d.ts → scatter-3d/ScatterPlot3DScene.svelte.d.ts} +3 -3
- package/dist/plot/{Surface3D.svelte → scatter-3d/Surface3D.svelte} +1 -1
- package/dist/plot/{Surface3D.svelte.d.ts → scatter-3d/Surface3D.svelte.d.ts} +1 -1
- package/dist/plot/scatter-3d/index.d.ts +4 -0
- package/dist/plot/scatter-3d/index.js +4 -0
- package/dist/plot/sunburst/Sunburst.svelte +1045 -0
- package/dist/plot/sunburst/Sunburst.svelte.d.ts +96 -0
- package/dist/plot/sunburst/SunburstControls.svelte +200 -0
- package/dist/plot/sunburst/SunburstControls.svelte.d.ts +26 -0
- package/dist/plot/sunburst/index.d.ts +4 -0
- package/dist/plot/sunburst/index.js +4 -0
- package/dist/plot/sunburst/render.d.ts +34 -0
- package/dist/plot/sunburst/render.js +122 -0
- package/dist/plot/sunburst/sunburst.d.ts +62 -0
- package/dist/plot/sunburst/sunburst.js +266 -0
- package/dist/rdf/RdfPlot.svelte +2 -1
- package/dist/rdf/calc-rdf.js +11 -24
- package/dist/sanitize.js +1 -1
- package/dist/settings.d.ts +65 -1
- package/dist/settings.js +262 -0
- package/dist/spectral/Bands.svelte +39 -29
- package/dist/spectral/Bands.svelte.d.ts +3 -4
- package/dist/spectral/BandsAndDos.svelte +1 -1
- package/dist/spectral/BrillouinBandsDos.svelte +39 -27
- package/dist/spectral/Dos.svelte +10 -19
- package/dist/spectral/Dos.svelte.d.ts +2 -2
- package/dist/spectral/helpers.d.ts +3 -1
- package/dist/spectral/helpers.js +95 -29
- package/dist/structure/AtomLegend.svelte +8 -9
- package/dist/structure/CellSelect.svelte +1 -2
- package/dist/structure/Cylinder.svelte +12 -8
- package/dist/structure/Cylinder.svelte.d.ts +4 -1
- package/dist/structure/Structure.svelte +78 -72
- package/dist/structure/Structure.svelte.d.ts +1 -1
- package/dist/structure/StructureInfoPane.svelte +5 -6
- package/dist/structure/StructureScene.svelte +11 -10
- package/dist/structure/atom-properties.js +6 -6
- package/dist/structure/bond-order-perception.js +1 -1
- package/dist/structure/bonding.d.ts +1 -0
- package/dist/structure/bonding.js +43 -15
- package/dist/structure/export.js +27 -23
- package/dist/structure/index.d.ts +2 -4
- package/dist/structure/index.js +1 -3
- package/dist/structure/label-placement.js +4 -4
- package/dist/structure/measure.d.ts +3 -2
- package/dist/structure/measure.js +6 -5
- package/dist/structure/parse.js +121 -103
- package/dist/structure/pbc.js +4 -0
- package/dist/symmetry/SymmetryStats.svelte +2 -2
- package/dist/symmetry/index.d.ts +1 -1
- package/dist/symmetry/index.js +22 -24
- package/dist/symmetry/spacegroups.d.ts +7 -0
- package/dist/symmetry/spacegroups.js +48 -13
- package/dist/table/HeatmapTable.svelte +63 -11
- package/dist/table/HeatmapTable.svelte.d.ts +1 -1
- package/dist/table/index.d.ts +1 -3
- package/dist/table/index.js +1 -1
- package/dist/theme/index.js +8 -8
- package/dist/tooltip/KCoords.svelte +45 -0
- package/dist/tooltip/KCoords.svelte.d.ts +8 -0
- package/dist/tooltip/index.d.ts +1 -0
- package/dist/tooltip/index.js +1 -0
- package/dist/trajectory/Trajectory.svelte +66 -40
- package/dist/trajectory/Trajectory.svelte.d.ts +2 -1
- package/dist/trajectory/TrajectoryExportPane.svelte +2 -1
- package/dist/trajectory/TrajectoryInfoPane.svelte +2 -1
- package/dist/trajectory/format-detect.d.ts +1 -0
- package/dist/trajectory/format-detect.js +25 -11
- package/dist/trajectory/frame-reader.js +17 -50
- package/dist/trajectory/helpers.js +1 -1
- package/dist/trajectory/index.js +1 -1
- package/dist/trajectory/parse/hdf5.js +1 -1
- package/dist/trajectory/parse/index.js +14 -6
- package/dist/trajectory/parse/vasp.js +36 -17
- package/dist/trajectory/parse/xyz.d.ts +24 -0
- package/dist/trajectory/parse/xyz.js +102 -89
- package/dist/trajectory/plotting.d.ts +1 -1
- package/dist/trajectory/plotting.js +15 -15
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +6 -4
- package/dist/xrd/XrdPlot.svelte +2 -1
- package/dist/xrd/calc-xrd.js +15 -12
- package/dist/xrd/parse.js +2 -2
- package/package.json +22 -18
- package/dist/plot/PlotControls.svelte.d.ts +0 -4
- package/dist/plot/axis-utils.d.ts +0 -19
- package/dist/plot/axis-utils.js +0 -78
- package/dist/plot/defaults.d.ts +0 -19
- package/dist/plot/defaults.js +0 -9
- package/dist/plot/fill-utils.d.ts +0 -46
- package/dist/plot/fill-utils.js +0 -322
- package/dist/plot/interactions.d.ts +0 -12
- package/dist/plot/interactions.js +0 -101
- package/dist/plot/svg.d.ts +0 -1
- package/dist/plot/svg.js +0 -11
- package/dist/plot/utils/series-visibility.d.ts +0 -15
- package/dist/plot/utils.d.ts +0 -1
- package/dist/plot/utils.js +0 -14
- /package/dist/plot/{auto-place.d.ts → core/auto-place.d.ts} +0 -0
- /package/dist/plot/{Line.svelte.d.ts → core/components/Line.svelte.d.ts} +0 -0
- /package/dist/plot/{PortalSelect.svelte.d.ts → core/components/PortalSelect.svelte.d.ts} +0 -0
- /package/dist/plot/{hover-lock.svelte.d.ts → core/hover-lock.svelte.d.ts} +0 -0
- /package/dist/plot/{utils → core/utils}/label-placement.js +0 -0
- /package/dist/plot/{binned-scatter-types.js → scatter/binned-scatter-types.js} +0 -0
|
@@ -1,4 +1,74 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Vec2 } from '../../math';
|
|
2
|
+
import type { DataSeries } from './types';
|
|
3
|
+
export interface OscillationWeights {
|
|
4
|
+
derivative_variance?: number;
|
|
5
|
+
amplitude_growth?: number;
|
|
6
|
+
sign_changes?: number;
|
|
7
|
+
}
|
|
8
|
+
export type InvalidValueMode = `remove` | `propagate` | `interpolate`;
|
|
9
|
+
export type TruncationMode = `hard_cut` | `mark_unstable`;
|
|
10
|
+
export interface PhysicalBounds {
|
|
11
|
+
min?: number | ((x: number) => number);
|
|
12
|
+
max?: number | ((x: number) => number);
|
|
13
|
+
mode?: `clamp` | `filter` | `null`;
|
|
14
|
+
}
|
|
15
|
+
export type SmoothingConfig = {
|
|
16
|
+
type: `moving_avg`;
|
|
17
|
+
window: number;
|
|
18
|
+
} | {
|
|
19
|
+
type: `savgol`;
|
|
20
|
+
window: number;
|
|
21
|
+
polynomial_order?: number;
|
|
22
|
+
} | {
|
|
23
|
+
type: `gaussian`;
|
|
24
|
+
sigma: number;
|
|
25
|
+
};
|
|
26
|
+
export interface LocalOutlierConfig {
|
|
27
|
+
window_half?: number;
|
|
28
|
+
mad_threshold?: number;
|
|
29
|
+
max_iterations?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface LocalOutlierResult {
|
|
32
|
+
kept_indices: number[];
|
|
33
|
+
removed_indices: number[];
|
|
34
|
+
iterations_used: number;
|
|
35
|
+
}
|
|
36
|
+
export interface CleaningConfig {
|
|
37
|
+
oscillation_threshold?: number;
|
|
38
|
+
oscillation_weights?: OscillationWeights;
|
|
39
|
+
window_size?: number;
|
|
40
|
+
invalid_values?: InvalidValueMode;
|
|
41
|
+
bounds?: PhysicalBounds;
|
|
42
|
+
smooth?: SmoothingConfig;
|
|
43
|
+
local_outliers?: LocalOutlierConfig;
|
|
44
|
+
truncation_mode?: TruncationMode;
|
|
45
|
+
in_place?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface CleaningQuality {
|
|
48
|
+
points_removed: number;
|
|
49
|
+
invalid_values_found: number;
|
|
50
|
+
oscillation_detected: boolean;
|
|
51
|
+
oscillation_score?: number;
|
|
52
|
+
bounds_violations: number;
|
|
53
|
+
outliers_removed?: number;
|
|
54
|
+
stable_range?: Vec2;
|
|
55
|
+
truncated_at_x?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface CleaningResult<T = DataSeries> {
|
|
58
|
+
series: T;
|
|
59
|
+
quality: CleaningQuality;
|
|
60
|
+
}
|
|
61
|
+
export interface InstabilityResult {
|
|
62
|
+
detected: boolean;
|
|
63
|
+
onset_index: number;
|
|
64
|
+
onset_x: number;
|
|
65
|
+
combined_score: number;
|
|
66
|
+
method_scores: {
|
|
67
|
+
derivative_variance: number;
|
|
68
|
+
amplitude_growth: number;
|
|
69
|
+
sign_changes: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
2
72
|
export declare function compute_local_variance(values: number[], window_size: number): number[];
|
|
3
73
|
export declare function detect_instability(x_values: readonly number[], y_values: readonly number[], config?: Pick<CleaningConfig, `oscillation_weights` | `oscillation_threshold` | `window_size`>): InstabilityResult;
|
|
4
74
|
export declare function smooth_moving_average(values: number[], window: number): number[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Data cleaning utilities for plot data
|
|
2
2
|
// Detects oscillations, enforces physical bounds, and handles multi-dimensional datasets
|
|
3
|
-
import { apply_gaussian_smearing } from '
|
|
3
|
+
import { apply_gaussian_smearing } from '../../spectral/helpers';
|
|
4
4
|
// Default configuration values
|
|
5
5
|
const DEFAULT_WINDOW_SIZE = 5;
|
|
6
6
|
const DEFAULT_OSCILLATION_THRESHOLD = 3.0;
|
|
@@ -243,7 +243,7 @@ function compute_savgol_coefficients(window, order) {
|
|
|
243
243
|
for (let idx = -half; idx <= half; idx++) {
|
|
244
244
|
const row = [];
|
|
245
245
|
for (let power = 0; power <= order; power++) {
|
|
246
|
-
row.push(
|
|
246
|
+
row.push(idx ** power);
|
|
247
247
|
}
|
|
248
248
|
vandermonde.push(row);
|
|
249
249
|
}
|
|
@@ -496,9 +496,7 @@ export function sync_metadata(metadata, kept_indices) {
|
|
|
496
496
|
return kept_indices.map((idx) => metadata[idx]);
|
|
497
497
|
}
|
|
498
498
|
// Filter arrays by kept indices
|
|
499
|
-
|
|
500
|
-
return kept_indices.map((idx) => arr[idx]);
|
|
501
|
-
}
|
|
499
|
+
const filter_by_indices = (arr, kept_indices) => kept_indices.map((idx) => arr[idx]);
|
|
502
500
|
// Check if value is within bounds (static or x-dependent)
|
|
503
501
|
function is_in_bounds(val, x_val, bounds) {
|
|
504
502
|
const min = typeof bounds.min === `function` ? bounds.min(x_val) : bounds.min;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { D3SymbolName } from '
|
|
2
|
-
import type { DataSeries, Point } from '
|
|
1
|
+
import type { D3SymbolName } from '../../labels';
|
|
2
|
+
import type { DataSeries, Point } from '..';
|
|
3
3
|
export declare const get_series_color: (series_idx: number) => string;
|
|
4
4
|
export declare const get_series_symbol: (series_idx: number) => D3SymbolName;
|
|
5
5
|
export declare const extract_series_color: (series_data: DataSeries) => string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { DEFAULT_SERIES_COLORS, DEFAULT_SERIES_SYMBOLS } from './types';
|
|
2
|
-
import { DEFAULTS } from '
|
|
2
|
+
import { DEFAULTS } from '../../settings';
|
|
3
3
|
// Get auto-cycling color for series at given index (wraps every 10)
|
|
4
4
|
export const get_series_color = (series_idx) => DEFAULT_SERIES_COLORS[series_idx % DEFAULT_SERIES_COLORS.length];
|
|
5
5
|
// Get auto-cycling symbol for series at given index (wraps every 7)
|
|
6
6
|
export const get_series_symbol = (series_idx) => DEFAULT_SERIES_SYMBOLS[series_idx % DEFAULT_SERIES_SYMBOLS.length];
|
|
7
7
|
// Extract the primary color from a series data object.
|
|
8
8
|
// Checks line stroke, then point fill (handling arrays), with fallback to default blue.
|
|
9
|
-
export const extract_series_color = (series_data) => series_data.line_style?.stroke
|
|
9
|
+
export const extract_series_color = (series_data) => (series_data.line_style?.stroke ??
|
|
10
10
|
(Array.isArray(series_data.point_style)
|
|
11
11
|
? series_data.point_style[0]?.fill
|
|
12
|
-
: series_data.point_style?.fill) ||
|
|
12
|
+
: series_data.point_style?.fill)) || // oxlint-disable-line @typescript-eslint/prefer-nullish-coalescing -- empty fill should use default color
|
|
13
13
|
`#4A9EFF`;
|
|
14
14
|
// Prepare legend data from series array
|
|
15
15
|
export const prepare_legend_data = (series) => series.map((series_data, series_idx) => ({
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DataSeries, ErrorBand, FillBoundary, FillCurveType, FillGradient, FillRegion } from './types';
|
|
2
|
+
export declare const LOG_EPSILON = 1e-10;
|
|
3
|
+
export interface Pt {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ResolvedBoundary {
|
|
8
|
+
points: Pt[];
|
|
9
|
+
curve: FillCurveType;
|
|
10
|
+
}
|
|
11
|
+
export interface FillSegment {
|
|
12
|
+
upper: Pt[];
|
|
13
|
+
lower: Pt[];
|
|
14
|
+
upper_curve: FillCurveType;
|
|
15
|
+
lower_curve: FillCurveType;
|
|
16
|
+
}
|
|
17
|
+
export declare function resolve_series_ref(ref: {
|
|
18
|
+
type: `series`;
|
|
19
|
+
series_idx?: number;
|
|
20
|
+
series_id?: string | number;
|
|
21
|
+
}, series: readonly DataSeries[]): DataSeries | null;
|
|
22
|
+
export declare function monotone_interpolate(xs: readonly number[], ys: readonly number[], x: number, tangents?: readonly number[]): number;
|
|
23
|
+
interface DomainContext {
|
|
24
|
+
x_domain: [number, number];
|
|
25
|
+
y_domain: [number, number];
|
|
26
|
+
y2_domain?: [number, number];
|
|
27
|
+
}
|
|
28
|
+
export declare function resolve_boundary_points(boundary: FillBoundary, series: readonly DataSeries[], domains: DomainContext, companion?: Pt[] | null): ResolvedBoundary | null;
|
|
29
|
+
export declare function compute_fill_segments(region: FillRegion, series: readonly DataSeries[], domains: DomainContext): FillSegment[];
|
|
30
|
+
export declare function generate_fill_path(upper: readonly Pt[], lower: readonly Pt[], upper_curve?: FillCurveType, lower_curve?: FillCurveType): string;
|
|
31
|
+
export declare function convert_error_band_to_fill_region(error_band: ErrorBand, series: readonly DataSeries[], default_color?: string): FillRegion | null;
|
|
32
|
+
export declare const is_fill_gradient: (fill: string | FillGradient | undefined) => fill is FillGradient;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
// Fill-between utility functions for ScatterPlot fill regions
|
|
2
|
+
// Each fill edge is traced through its boundary's own points with the same curve the series line
|
|
3
|
+
// uses (curveMonotoneX), so an unclipped fill edge coincides with the line it borders. When an
|
|
4
|
+
// edge is clipped (x_range / partial overlap), the inserted endpoint shifts the neighboring
|
|
5
|
+
// monotone tangent, so the clipped edge can deviate sub-pixel from the full series line.
|
|
6
|
+
import { curveBasis, curveCardinal, curveCatmullRom, curveLinear, curveMonotoneX, curveMonotoneY, curveNatural, curveStep, curveStepAfter, curveStepBefore, line, } from 'd3-shape';
|
|
7
|
+
// Epsilon value for log scale clamping (to avoid log(0) = -Infinity)
|
|
8
|
+
export const LOG_EPSILON = 1e-10;
|
|
9
|
+
// Resolves a series reference (by index or id) to the actual DataSeries
|
|
10
|
+
export function resolve_series_ref(ref, series) {
|
|
11
|
+
if (`series_idx` in ref && typeof ref.series_idx === `number`) {
|
|
12
|
+
const idx = ref.series_idx;
|
|
13
|
+
return idx >= 0 && idx < series.length ? series[idx] : null;
|
|
14
|
+
}
|
|
15
|
+
if (`series_id` in ref && ref.series_id !== undefined) {
|
|
16
|
+
return series.find((data_series) => data_series.id === ref.series_id) ?? null;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// === Monotone-cubic interpolation matching d3's curveMonotoneX ===
|
|
21
|
+
// Used to evaluate a boundary's y on its own curve (for endpoint clipping and where-condition
|
|
22
|
+
// detection) so interpolated points lie exactly on the rendered line.
|
|
23
|
+
// Mirrors d3-shape's own sign helper (returns 1 for 0, unlike Math.sign) so
|
|
24
|
+
// monotone_tangents reproduces curveMonotoneX exactly. Do NOT change to return 0
|
|
25
|
+
// for 0: that would diverge from the rendered curve. It's harmless either way here
|
|
26
|
+
// since s0/s1 === 0 forces the Math.min term below to 0 regardless.
|
|
27
|
+
const sign = (val) => (val < 0 ? -1 : 1);
|
|
28
|
+
// Per-knot tangents reproducing d3 curveMonotoneX (slope3 interior, slope2 endpoints)
|
|
29
|
+
function monotone_tangents(xs, ys) {
|
|
30
|
+
const num = xs.length;
|
|
31
|
+
if (num <= 1)
|
|
32
|
+
return Array(num).fill(0);
|
|
33
|
+
const secant = (idx) => (ys[idx + 1] - ys[idx]) / (xs[idx + 1] - xs[idx]);
|
|
34
|
+
if (num === 2) {
|
|
35
|
+
const slope = secant(0);
|
|
36
|
+
const safe = Number.isFinite(slope) ? slope : 0;
|
|
37
|
+
return [safe, safe];
|
|
38
|
+
}
|
|
39
|
+
const tangents = Array.from({ length: num }, () => 0);
|
|
40
|
+
for (let idx = 1; idx < num - 1; idx++) {
|
|
41
|
+
const h0 = xs[idx] - xs[idx - 1];
|
|
42
|
+
const h1 = xs[idx + 1] - xs[idx];
|
|
43
|
+
const s0 = (ys[idx] - ys[idx - 1]) / (h0 || (h1 < 0 ? -0 : 0));
|
|
44
|
+
const s1 = (ys[idx + 1] - ys[idx]) / (h1 || (h0 < 0 ? -0 : 0));
|
|
45
|
+
const par = (s0 * h1 + s1 * h0) / (h0 + h1);
|
|
46
|
+
tangents[idx] =
|
|
47
|
+
(sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(par)) || 0;
|
|
48
|
+
}
|
|
49
|
+
tangents[0] = (3 * secant(0) - tangents[1]) / 2;
|
|
50
|
+
tangents[num - 1] = (3 * secant(num - 2) - tangents[num - 2]) / 2;
|
|
51
|
+
return tangents;
|
|
52
|
+
}
|
|
53
|
+
// Index of the bracket [lo, lo+1] containing x (xs ascending); clamps to interior brackets
|
|
54
|
+
const bracket = (xs, x) => {
|
|
55
|
+
let lo = 0;
|
|
56
|
+
let hi = xs.length - 1;
|
|
57
|
+
while (hi - lo > 1) {
|
|
58
|
+
const mid = (lo + hi) >> 1;
|
|
59
|
+
if (xs[mid] <= x)
|
|
60
|
+
lo = mid;
|
|
61
|
+
else
|
|
62
|
+
hi = mid;
|
|
63
|
+
}
|
|
64
|
+
return lo;
|
|
65
|
+
};
|
|
66
|
+
// y clamped to the endpoint value when x is at/outside the domain (null when x is strictly inside)
|
|
67
|
+
const endpoint_clamp = (xs, ys, x) => {
|
|
68
|
+
if (xs.length === 0)
|
|
69
|
+
return NaN;
|
|
70
|
+
if (x <= xs[0])
|
|
71
|
+
return ys[0];
|
|
72
|
+
if (x >= xs[xs.length - 1])
|
|
73
|
+
return ys[xs.length - 1];
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
// Evaluate the d3 curveMonotoneX through (xs, ys) at x (xs ascending). Clamps outside the domain.
|
|
77
|
+
export function monotone_interpolate(xs, ys, x, tangents) {
|
|
78
|
+
const edge = endpoint_clamp(xs, ys, x);
|
|
79
|
+
if (edge !== null)
|
|
80
|
+
return edge;
|
|
81
|
+
const lo = bracket(xs, x);
|
|
82
|
+
const [x0, x1] = [xs[lo], xs[lo + 1]];
|
|
83
|
+
const span = x1 - x0;
|
|
84
|
+
if (span === 0)
|
|
85
|
+
return ys[lo];
|
|
86
|
+
const tang = tangents ?? monotone_tangents(xs, ys);
|
|
87
|
+
// d3 monotoneX uses equally-spaced x control points, so x is linear in t. y is the cubic Bezier
|
|
88
|
+
// through [y0, y0+dx*t0, y1-dx*t1, y1] with dx = span/3.
|
|
89
|
+
const dx = span / 3;
|
|
90
|
+
const p0 = ys[lo];
|
|
91
|
+
const p1 = ys[lo] + dx * tang[lo];
|
|
92
|
+
const p2 = ys[lo + 1] - dx * tang[lo + 1];
|
|
93
|
+
const p3 = ys[lo + 1];
|
|
94
|
+
const u = (x - x0) / span;
|
|
95
|
+
const mu = 1 - u;
|
|
96
|
+
return mu * mu * mu * p0 + 3 * mu * mu * u * p1 + 3 * mu * u * u * p2 + u * u * u * p3;
|
|
97
|
+
}
|
|
98
|
+
// Curve types whose interior follows a (near-)monotone cubic; evaluated via monotone_interpolate.
|
|
99
|
+
// Others (linear/step) evaluate piecewise (exact for them at clip points).
|
|
100
|
+
const MONOTONE_LIKE = new Set([
|
|
101
|
+
`monotoneX`,
|
|
102
|
+
`monotoneY`,
|
|
103
|
+
`natural`,
|
|
104
|
+
`cardinal`,
|
|
105
|
+
`catmullRom`,
|
|
106
|
+
`basis`,
|
|
107
|
+
]);
|
|
108
|
+
// Piecewise (non-cubic) evaluation honoring linear and the three step curves
|
|
109
|
+
const piecewise_eval = (xs, ys, x, curve) => {
|
|
110
|
+
const edge = endpoint_clamp(xs, ys, x);
|
|
111
|
+
if (edge !== null)
|
|
112
|
+
return edge;
|
|
113
|
+
const idx = bracket(xs, x);
|
|
114
|
+
const [x0, x1, y0, y1] = [xs[idx], xs[idx + 1], ys[idx], ys[idx + 1]];
|
|
115
|
+
if (curve === `stepAfter`)
|
|
116
|
+
return y0; // hold previous until the next knot
|
|
117
|
+
if (curve === `stepBefore`)
|
|
118
|
+
return y1; // jump to next value immediately past a knot
|
|
119
|
+
if (curve === `step`)
|
|
120
|
+
return x < (x0 + x1) / 2 ? y0 : y1; // switch at the midpoint
|
|
121
|
+
const span = x1 - x0;
|
|
122
|
+
return span === 0 ? y0 : y0 + ((x - x0) / span) * (y1 - y0);
|
|
123
|
+
};
|
|
124
|
+
// Build a boundary with a y(x) evaluator that precomputes tangents (monotone) once
|
|
125
|
+
function prepare_boundary(boundary) {
|
|
126
|
+
const { points, curve } = boundary;
|
|
127
|
+
const xs = points.map((pt) => pt.x);
|
|
128
|
+
const ys = points.map((pt) => pt.y);
|
|
129
|
+
if (MONOTONE_LIKE.has(curve)) {
|
|
130
|
+
const tangents = monotone_tangents(xs, ys);
|
|
131
|
+
return { points, curve, eval: (x) => monotone_interpolate(xs, ys, x, tangents) };
|
|
132
|
+
}
|
|
133
|
+
return { points, curve, eval: (x) => piecewise_eval(xs, ys, x, curve) };
|
|
134
|
+
}
|
|
135
|
+
// True when a boundary carries its own x (series or data-with-x), so it needs no companion x
|
|
136
|
+
const defines_own_x = (boundary) => typeof boundary !== `number` &&
|
|
137
|
+
(boundary.type === `series` || (boundary.type === `data` && boundary.x !== undefined));
|
|
138
|
+
// Keep only finite points, sorted by x
|
|
139
|
+
const clean_pts = (pts) => pts.filter((pt) => Number.isFinite(pt.x) && Number.isFinite(pt.y)).sort((a, b) => a.x - b.x);
|
|
140
|
+
// Zip parallel x/y arrays into finite, x-sorted points
|
|
141
|
+
const finite_points = (xs, ys) => clean_pts(Array.from({ length: Math.min(xs.length, ys.length) }, (_, idx) => ({
|
|
142
|
+
x: xs[idx],
|
|
143
|
+
y: ys[idx],
|
|
144
|
+
})));
|
|
145
|
+
// Resolve a boundary to native points + curve in data coordinates. `companion` supplies x
|
|
146
|
+
// positions for boundaries that don't define their own (constant/axis/function/data-without-x).
|
|
147
|
+
export function resolve_boundary_points(boundary, series, domains, companion) {
|
|
148
|
+
// x positions used for companion-relative boundaries
|
|
149
|
+
const span_xs = companion && companion.length > 0
|
|
150
|
+
? companion.map((pt) => pt.x)
|
|
151
|
+
: [domains.x_domain[0], domains.x_domain[1]];
|
|
152
|
+
// flat horizontal edge at constant y (number / constant / axis boundaries)
|
|
153
|
+
const flat_edge = (y) => ({
|
|
154
|
+
points: horizontal(span_xs, y),
|
|
155
|
+
curve: `linear`,
|
|
156
|
+
});
|
|
157
|
+
// series / function / data edges are traced with monotoneX (matches the series line)
|
|
158
|
+
const curved_edge = (points) => points.length > 0 ? { points, curve: `monotoneX` } : null;
|
|
159
|
+
if (typeof boundary === `number`)
|
|
160
|
+
return flat_edge(boundary);
|
|
161
|
+
if (boundary.type === `series`) {
|
|
162
|
+
const resolved = resolve_series_ref(boundary, series);
|
|
163
|
+
if (!resolved)
|
|
164
|
+
return null;
|
|
165
|
+
return curved_edge(finite_points(resolved.x, resolved.y));
|
|
166
|
+
}
|
|
167
|
+
if (boundary.type === `constant`)
|
|
168
|
+
return flat_edge(boundary.value);
|
|
169
|
+
if (boundary.type === `axis`) {
|
|
170
|
+
return flat_edge(boundary.value ??
|
|
171
|
+
(boundary.axis === `y2` ? domains.y2_domain?.[0] : undefined) ??
|
|
172
|
+
domains.y_domain[0]);
|
|
173
|
+
}
|
|
174
|
+
if (boundary.type === `function`) {
|
|
175
|
+
// sample densely so the traced curve hugs the function
|
|
176
|
+
const [x0, x1] = [span_xs[0], span_xs[span_xs.length - 1]];
|
|
177
|
+
const steps = 100;
|
|
178
|
+
const points = [];
|
|
179
|
+
for (let idx = 0; idx <= steps; idx++) {
|
|
180
|
+
const x = x0 + ((x1 - x0) * idx) / steps;
|
|
181
|
+
const y = boundary.fn(x);
|
|
182
|
+
if (Number.isFinite(y))
|
|
183
|
+
points.push({ x, y });
|
|
184
|
+
}
|
|
185
|
+
return curved_edge(points);
|
|
186
|
+
}
|
|
187
|
+
if (boundary.type === `data`) {
|
|
188
|
+
if (boundary.values.length === 0)
|
|
189
|
+
return null;
|
|
190
|
+
if (boundary.x)
|
|
191
|
+
return curved_edge(finite_points(boundary.x, boundary.values));
|
|
192
|
+
// No x: align values to the companion's x by index (or fraction when lengths differ)
|
|
193
|
+
const num_values = boundary.values.length;
|
|
194
|
+
const companion_x = (idx) => span_xs.length === num_values
|
|
195
|
+
? span_xs[idx]
|
|
196
|
+
: span_xs[Math.round((idx / Math.max(1, num_values - 1)) * (span_xs.length - 1))];
|
|
197
|
+
const points = boundary.values.map((value, idx) => ({ x: companion_x(idx), y: value }));
|
|
198
|
+
return curved_edge(clean_pts(points));
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
// Two points spanning [first, last] of xs at constant y
|
|
203
|
+
const horizontal = (xs, y) => xs.length === 0
|
|
204
|
+
? []
|
|
205
|
+
: [
|
|
206
|
+
{ x: xs[0], y },
|
|
207
|
+
{ x: xs[xs.length - 1], y },
|
|
208
|
+
];
|
|
209
|
+
// Clip a prepared boundary to [xa, xb], inserting on-curve endpoints so the edge starts/ends at xa/xb
|
|
210
|
+
function clip_boundary(boundary, xa, xb) {
|
|
211
|
+
const inside = boundary.points.filter((pt) => pt.x > xa && pt.x < xb);
|
|
212
|
+
const start = { x: xa, y: boundary.eval(xa) };
|
|
213
|
+
const end = { x: xb, y: boundary.eval(xb) };
|
|
214
|
+
const pts = [start, ...inside, end];
|
|
215
|
+
return pts.filter((pt) => Number.isFinite(pt.y));
|
|
216
|
+
}
|
|
217
|
+
// Binary-search the x where a `where` toggle occurs between two grid samples (boundaries linear between them)
|
|
218
|
+
function where_crossing(xa, xb, ya_up, ya_lo, yb_up, yb_lo, where) {
|
|
219
|
+
let left = xa;
|
|
220
|
+
let right = xb;
|
|
221
|
+
const cond_left = where(xa, ya_up, ya_lo);
|
|
222
|
+
for (let iter = 0; iter < 24; iter++) {
|
|
223
|
+
const mid = (left + right) / 2;
|
|
224
|
+
const frac = (mid - xa) / (xb - xa);
|
|
225
|
+
const up = ya_up + frac * (yb_up - ya_up);
|
|
226
|
+
const lo = ya_lo + frac * (yb_lo - ya_lo);
|
|
227
|
+
if (where(mid, up, lo) === cond_left)
|
|
228
|
+
left = mid;
|
|
229
|
+
else
|
|
230
|
+
right = mid;
|
|
231
|
+
}
|
|
232
|
+
return (left + right) / 2;
|
|
233
|
+
}
|
|
234
|
+
// Split the overlap into x-intervals where region.where passes (whole overlap when no condition)
|
|
235
|
+
function where_intervals(upper, lower, xa, xb, where) {
|
|
236
|
+
if (!where)
|
|
237
|
+
return [[xa, xb]];
|
|
238
|
+
// detection grid: native x of both boundaries within the overlap, plus the endpoints
|
|
239
|
+
const grid = [
|
|
240
|
+
...new Set([xa, xb, ...upper.points.map((pt) => pt.x), ...lower.points.map((pt) => pt.x)].filter((x) => x >= xa && x <= xb)),
|
|
241
|
+
].sort((a, b) => a - b);
|
|
242
|
+
const intervals = [];
|
|
243
|
+
let seg_start = null;
|
|
244
|
+
// carry the previous grid sample so each point's two evals + where() run once, not twice
|
|
245
|
+
let prev_x = NaN;
|
|
246
|
+
let prev_up = NaN;
|
|
247
|
+
let prev_lo = NaN;
|
|
248
|
+
let prev_passes = false;
|
|
249
|
+
for (let idx = 0; idx < grid.length; idx++) {
|
|
250
|
+
const x = grid[idx];
|
|
251
|
+
const up = upper.eval(x);
|
|
252
|
+
const lo = lower.eval(x);
|
|
253
|
+
const passes = where(x, up, lo);
|
|
254
|
+
if (idx > 0 && passes !== prev_passes) {
|
|
255
|
+
const cross = where_crossing(prev_x, x, prev_up, prev_lo, up, lo, where);
|
|
256
|
+
if (seg_start !== null) {
|
|
257
|
+
intervals.push([seg_start, cross]);
|
|
258
|
+
seg_start = null;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
seg_start = cross;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (passes && seg_start === null)
|
|
265
|
+
seg_start = x;
|
|
266
|
+
if (!passes && seg_start !== null) {
|
|
267
|
+
intervals.push([seg_start, x]);
|
|
268
|
+
seg_start = null;
|
|
269
|
+
}
|
|
270
|
+
prev_x = x;
|
|
271
|
+
prev_up = up;
|
|
272
|
+
prev_lo = lo;
|
|
273
|
+
prev_passes = passes;
|
|
274
|
+
}
|
|
275
|
+
if (seg_start !== null)
|
|
276
|
+
intervals.push([seg_start, xb]);
|
|
277
|
+
return intervals.filter(([a, b]) => b > a);
|
|
278
|
+
}
|
|
279
|
+
// Compute renderable fill segments (data coordinates) for a region.
|
|
280
|
+
// Handles boundary resolution, x-overlap clipping, where-segmentation and y_range clamping.
|
|
281
|
+
export function compute_fill_segments(region, series, domains) {
|
|
282
|
+
// Resolve self-defining boundaries (series / data-with-x) first; companion-relative ones
|
|
283
|
+
// (constant/axis/function/data-without-x) then borrow the other's x positions.
|
|
284
|
+
let upper = defines_own_x(region.upper)
|
|
285
|
+
? resolve_boundary_points(region.upper, series, domains)
|
|
286
|
+
: null;
|
|
287
|
+
let lower = defines_own_x(region.lower)
|
|
288
|
+
? resolve_boundary_points(region.lower, series, domains)
|
|
289
|
+
: null;
|
|
290
|
+
upper ??= resolve_boundary_points(region.upper, series, domains, lower?.points);
|
|
291
|
+
lower ??= resolve_boundary_points(region.lower, series, domains, upper?.points);
|
|
292
|
+
if (!upper || !lower || upper.points.length === 0 || lower.points.length === 0)
|
|
293
|
+
return [];
|
|
294
|
+
// An explicit region.curve overrides the per-boundary curve (advanced: may no longer match the
|
|
295
|
+
// series line). Default leaves series edges at monotoneX so they coincide with the line.
|
|
296
|
+
if (region.curve) {
|
|
297
|
+
upper.curve = region.curve;
|
|
298
|
+
lower.curve = region.curve;
|
|
299
|
+
}
|
|
300
|
+
// Prepare once: precomputes monotone tangents / lookup so the where + clip passes below are
|
|
301
|
+
// O(grid) instead of recomputing an O(n) evaluator on every sample.
|
|
302
|
+
const up = prepare_boundary(upper);
|
|
303
|
+
const lo = prepare_boundary(lower);
|
|
304
|
+
// x-overlap = intersection of both x-domains, constrained by region.x_range
|
|
305
|
+
const [x_lo, x_hi] = region.x_range ?? [null, null];
|
|
306
|
+
const xa = Math.max(up.points[0].x, lo.points[0].x, x_lo ?? -Infinity);
|
|
307
|
+
const xb = Math.min(up.points[up.points.length - 1].x, lo.points[lo.points.length - 1].x, x_hi ?? Infinity);
|
|
308
|
+
if (!(xb > xa))
|
|
309
|
+
return [];
|
|
310
|
+
const [y_min, y_max] = region.y_range ?? [null, null];
|
|
311
|
+
const clamp_y = (pt) => ({
|
|
312
|
+
x: pt.x,
|
|
313
|
+
y: Math.min(y_max ?? Infinity, Math.max(y_min ?? -Infinity, pt.y)),
|
|
314
|
+
});
|
|
315
|
+
const intervals = where_intervals(up, lo, xa, xb, region.where);
|
|
316
|
+
const segments = [];
|
|
317
|
+
for (const [sa, sb] of intervals) {
|
|
318
|
+
const up_pts = clip_boundary(up, sa, sb).map(clamp_y);
|
|
319
|
+
const lo_pts = clip_boundary(lo, sa, sb).map(clamp_y);
|
|
320
|
+
if (up_pts.length >= 2 && lo_pts.length >= 2) {
|
|
321
|
+
segments.push({
|
|
322
|
+
upper: up_pts,
|
|
323
|
+
lower: lo_pts,
|
|
324
|
+
upper_curve: up.curve,
|
|
325
|
+
lower_curve: lo.curve,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return segments;
|
|
330
|
+
}
|
|
331
|
+
// === Path generation ===
|
|
332
|
+
const CURVE_MAP = {
|
|
333
|
+
linear: curveLinear,
|
|
334
|
+
monotoneX: curveMonotoneX,
|
|
335
|
+
monotoneY: curveMonotoneY,
|
|
336
|
+
step: curveStep,
|
|
337
|
+
stepBefore: curveStepBefore,
|
|
338
|
+
stepAfter: curveStepAfter,
|
|
339
|
+
basis: curveBasis,
|
|
340
|
+
cardinal: curveCardinal,
|
|
341
|
+
catmullRom: curveCatmullRom,
|
|
342
|
+
natural: curveNatural,
|
|
343
|
+
};
|
|
344
|
+
const get_curve = (curve_type) => CURVE_MAP[curve_type] ?? curveMonotoneX;
|
|
345
|
+
const trace = (points, curve_type) => line()
|
|
346
|
+
.x((pt) => pt.x)
|
|
347
|
+
.y((pt) => pt.y)
|
|
348
|
+
.curve(get_curve(curve_type))(points) ?? ``;
|
|
349
|
+
// Generate the closed SVG path for a fill segment (pixel coordinates). The upper edge is traced
|
|
350
|
+
// forward and the lower edge backward, each through its own points with its own curve via the same
|
|
351
|
+
// line generator the series uses, so an unclipped edge matches the corresponding series line.
|
|
352
|
+
export function generate_fill_path(upper, lower, upper_curve = `monotoneX`, lower_curve = upper_curve) {
|
|
353
|
+
if (upper.length < 2 || lower.length < 2)
|
|
354
|
+
return ``;
|
|
355
|
+
const upper_path = trace(upper, upper_curve);
|
|
356
|
+
const lower_path = trace(lower.toReversed(), lower_curve);
|
|
357
|
+
if (!upper_path || !lower_path)
|
|
358
|
+
return ``;
|
|
359
|
+
// join upper end -> lower end (drop the lower path's leading "M"), then close to upper start
|
|
360
|
+
return `${upper_path}L${lower_path.slice(1)}Z`;
|
|
361
|
+
}
|
|
362
|
+
// Helper to expand error definition to array
|
|
363
|
+
const expand_error = (err, length) => typeof err === `number` ? Array(length).fill(err) : err;
|
|
364
|
+
// Convert an ErrorBand convenience type to a full FillRegion (carrying the series x so the band
|
|
365
|
+
// traces the central series exactly)
|
|
366
|
+
export function convert_error_band_to_fill_region(error_band, series, default_color) {
|
|
367
|
+
const resolved = resolve_series_ref(error_band.series, series);
|
|
368
|
+
if (!resolved)
|
|
369
|
+
return null;
|
|
370
|
+
const { x, y } = resolved;
|
|
371
|
+
const { error } = error_band;
|
|
372
|
+
const [upper_err, lower_err] = typeof error === `object` && `upper` in error
|
|
373
|
+
? [expand_error(error.upper, y.length), expand_error(error.lower, y.length)]
|
|
374
|
+
: [expand_error(error, y.length), expand_error(error, y.length)];
|
|
375
|
+
return {
|
|
376
|
+
id: error_band.id,
|
|
377
|
+
label: error_band.label,
|
|
378
|
+
upper: { type: `data`, x, values: y.map((val, idx) => val + upper_err[idx]) },
|
|
379
|
+
lower: { type: `data`, x, values: y.map((val, idx) => val - lower_err[idx]) },
|
|
380
|
+
fill: error_band.fill ?? default_color ?? `#4e79a7`,
|
|
381
|
+
fill_opacity: error_band.fill_opacity ?? 0.3,
|
|
382
|
+
edge_upper: error_band.edge_style,
|
|
383
|
+
edge_lower: error_band.edge_style,
|
|
384
|
+
show_in_legend: error_band.show_in_legend ?? true,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
// Type guard to check if fill is a gradient
|
|
388
|
+
export const is_fill_gradient = (fill) => typeof fill === `object` && fill !== null && `type` in fill && `stops` in fill;
|
|
@@ -14,14 +14,13 @@ export function create_hover_lock() {
|
|
|
14
14
|
return {
|
|
15
15
|
is_locked: locked_ref,
|
|
16
16
|
set_locked(locked) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// Always clear any pending unlock so rapid calls don't queue multiple timeouts
|
|
18
|
+
if (timeout)
|
|
19
|
+
clearTimeout(timeout);
|
|
20
|
+
if (locked)
|
|
20
21
|
is_locked = true;
|
|
21
|
-
|
|
22
|
-
else {
|
|
22
|
+
else
|
|
23
23
|
timeout = setTimeout(() => (is_locked = false), HOVER_DEBOUNCE_MS);
|
|
24
|
-
}
|
|
25
24
|
},
|
|
26
25
|
// Clear pending timeout to prevent state updates after unmount
|
|
27
26
|
cleanup() {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './components';
|
|
2
|
+
export * from './data-cleaning';
|
|
3
|
+
export * from './fill-utils';
|
|
4
|
+
export * from './interactions';
|
|
5
|
+
export * from './layout';
|
|
6
|
+
export * from './reference-line';
|
|
7
|
+
export * from './scales';
|
|
8
|
+
export * from './svg';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './utils';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Shared cross-chart foundation: types, scales, layout, interactions + primitive components
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from './data-cleaning';
|
|
4
|
+
export * from './fill-utils';
|
|
5
|
+
export * from './interactions';
|
|
6
|
+
export * from './layout';
|
|
7
|
+
export * from './reference-line';
|
|
8
|
+
export * from './scales';
|
|
9
|
+
export * from './svg';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export * from './utils';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Point2D, type Vec2 } from '../../math';
|
|
2
|
+
import type { AxisRanges, ScaleType, Y2SyncConfig, Y2SyncMode } from './types';
|
|
3
|
+
export declare function get_relative_coords(evt: MouseEvent, element?: EventTarget | null): Point2D | null;
|
|
4
|
+
export declare function closest_data_idx(event: Event, attr: string, root?: Element | null): number | null;
|
|
5
|
+
export declare function normalize_y2_sync(sync: Y2SyncConfig | Y2SyncMode | undefined): Y2SyncConfig;
|
|
6
|
+
export declare function sync_y2_range(y1_range: Vec2, y2_base_range: Vec2, sync: Y2SyncConfig): Vec2;
|
|
7
|
+
export declare function pan_range_by_pixels(range: Vec2, pixel_delta: number, pixel_span: number, scale_type?: ScaleType): Vec2;
|
|
8
|
+
export declare function zoom_range_by_factor(range: Vec2, factor: number, scale_type?: ScaleType): Vec2;
|
|
9
|
+
export declare const to_epoch_num: (val: number | Date) => number;
|
|
10
|
+
export declare function remove_drag_listeners(move_handlers: ((evt: MouseEvent) => void)[], up_handlers: ((evt: MouseEvent) => void)[]): void;
|
|
11
|
+
export declare const sorted_range: (a: number, b: number) => Vec2;
|
|
12
|
+
export declare const vec2_equal: (a: Vec2, b: Vec2) => boolean;
|
|
13
|
+
export declare const axis_ranges_equal: (a: AxisRanges, b: AxisRanges) => boolean;
|
|
14
|
+
type AxisRangeOverride = {
|
|
15
|
+
range?: [number | null, number | null];
|
|
16
|
+
};
|
|
17
|
+
type AutoRanges = {
|
|
18
|
+
x: readonly number[];
|
|
19
|
+
x2: readonly number[];
|
|
20
|
+
y: readonly number[];
|
|
21
|
+
y2: readonly number[];
|
|
22
|
+
};
|
|
23
|
+
export declare function resolve_axis_ranges(axes: {
|
|
24
|
+
x: AxisRangeOverride;
|
|
25
|
+
x2: AxisRangeOverride;
|
|
26
|
+
y: AxisRangeOverride;
|
|
27
|
+
y2: AxisRangeOverride;
|
|
28
|
+
}, auto: AutoRanges): AxisRanges | null;
|
|
29
|
+
export declare const PINCH_ZOOM_THRESHOLD = 0.1;
|
|
30
|
+
export declare const MIN_TOUCH_DISTANCE_PIXELS = 10;
|
|
31
|
+
export declare function expand_range_if_needed(current: Vec2, new_range: Vec2): {
|
|
32
|
+
range: Vec2;
|
|
33
|
+
changed: boolean;
|
|
34
|
+
};
|
|
35
|
+
export {};
|