numbl 0.4.1 → 0.4.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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Pure computation of the current axis limits for an `AxesState`.
3
+ *
4
+ * This is the source of truth for the query form `lim = axis`: the numbl
5
+ * runtime reduces its accumulated plot instructions into an `AxesState` and
6
+ * asks this module for the limit vector. It is deliberately rendering-free
7
+ * (no canvas, no DOM) so numbl-core can import it.
8
+ *
9
+ * For an axis with an explicit limit, that limit is returned verbatim (a
10
+ * `null` bound falls back to the data-derived bound). For a fully automatic
11
+ * axis the data extent is computed across every trace type and padded the
12
+ * same way `drawPlot` pads a default 2-D view, so the reported limits track
13
+ * what is drawn.
14
+ */
15
+ import type { AxesState } from "./figuresReducer.js";
16
+ /** Does this axes hold any 3-D content (so limits are a 6-vector)? */
17
+ export declare function axesIs3D(axes: AxesState): boolean;
18
+ /**
19
+ * Compute the limit vector for `lim = axis`.
20
+ * Returns 4 elements `[xmin xmax ymin ymax]` for a 2-D view, or 6 elements
21
+ * `[xmin xmax ymin ymax zmin zmax]` when the axes holds 3-D content.
22
+ */
23
+ export declare function computeAxisLimits(axes: AxesState): number[];
@@ -0,0 +1,73 @@
1
+ import type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace, PlotInstruction } from "./types.js";
2
+ export type AxesState = {
3
+ holdOn: boolean;
4
+ traces: PlotTrace[];
5
+ plot3Traces: Plot3Trace[];
6
+ surfTraces: SurfTrace[];
7
+ imagescTrace?: ImagescTrace;
8
+ pcolorTraces: PcolorTrace[];
9
+ contourTraces: ContourTrace[];
10
+ barTraces: BarTrace[];
11
+ barhTraces: BarTrace[];
12
+ bar3Traces: Bar3Trace[];
13
+ bar3hTraces: Bar3Trace[];
14
+ errorBarTraces: ErrorBarTrace[];
15
+ boxTraces: BoxTrace[];
16
+ pieTrace?: PieTrace;
17
+ heatmapTrace?: HeatmapTrace;
18
+ quiverTraces: QuiverTrace[];
19
+ quiver3Traces: Quiver3Trace[];
20
+ areaTraces: PlotTrace[];
21
+ areaBaseValue: number;
22
+ title?: string;
23
+ xlabel?: string;
24
+ ylabel?: string;
25
+ zlabel?: string;
26
+ shading?: "faceted" | "flat" | "interp";
27
+ legend?: string[];
28
+ gridOn?: boolean;
29
+ colorbar?: boolean;
30
+ colorbarLocation?: string;
31
+ colormap?: string;
32
+ colormapData?: number[][];
33
+ view?: {
34
+ az: number;
35
+ el: number;
36
+ };
37
+ axisMode?: string;
38
+ axisScale?: "linear" | "semilogx" | "semilogy" | "loglog";
39
+ caxis?: [number, number];
40
+ /** Explicit axis limits from `axis([...])` / `xlim` / `ylim`. Each bound
41
+ * may be `null`, meaning "use the data-derived bound" (partial limits). An
42
+ * absent field means the whole axis is automatic. */
43
+ xlim?: [number | null, number | null];
44
+ ylim?: [number | null, number | null];
45
+ zlim?: [number | null, number | null];
46
+ /** y-axis direction: "reverse" is `axis ij` (origin at top-left). */
47
+ yDir?: "normal" | "reverse";
48
+ /** Axes lines/background visibility (`axis off` sets this false). */
49
+ axisVisible?: boolean;
50
+ };
51
+ export type FigureState = {
52
+ subplotGrid?: {
53
+ rows: number;
54
+ cols: number;
55
+ };
56
+ currentAxesIndex: number;
57
+ sgtitle?: string;
58
+ axes: {
59
+ [index: number]: AxesState;
60
+ };
61
+ };
62
+ export type FiguresState = {
63
+ currentHandle: number;
64
+ figs: {
65
+ [handle: number]: FigureState;
66
+ };
67
+ };
68
+ /** Actions accepted by the figures reducer: any PlotInstruction, plus "clear" for UI resets. */
69
+ export type FiguresAction = PlotInstruction | {
70
+ type: "clear";
71
+ };
72
+ export declare const initialFiguresState: FiguresState;
73
+ export declare const figuresReducer: (state: FiguresState, action: FiguresAction) => FiguresState;
@@ -219,6 +219,12 @@ export interface HeatmapTrace {
219
219
  /** Y-axis labels (one per row) */
220
220
  yLabels?: string[];
221
221
  }
222
+ /** A single axis's limit request from `axis([...])` / `axis auto`.
223
+ * - A `[lo, hi]` pair, where either bound may be `null` to mean "keep the
224
+ * automatically-chosen bound" (from `inf`/`-inf` in the limits vector).
225
+ * - The string `"auto"` clears any explicit limit so the axis refits to its
226
+ * data (from `axis auto` / `axis 'auto x'`). */
227
+ export type AxisLimitSpec = [number | null, number | null] | "auto";
222
228
  export type PlotInstruction = {
223
229
  type: "set_figure_handle";
224
230
  handle: number;
@@ -332,6 +338,17 @@ export type PlotInstruction = {
332
338
  } | {
333
339
  type: "set_axis";
334
340
  value: string;
341
+ } | {
342
+ type: "set_axis_limits";
343
+ xlim?: AxisLimitSpec;
344
+ ylim?: AxisLimitSpec;
345
+ zlim?: AxisLimitSpec;
346
+ } | {
347
+ type: "set_axis_ydir";
348
+ dir: "normal" | "reverse";
349
+ } | {
350
+ type: "set_axis_visible";
351
+ value: boolean;
335
352
  } | {
336
353
  type: "set_axis_scale";
337
354
  value: "linear" | "semilogx" | "semilogy" | "loglog";