@weasel-js/plot 0.0.0-stage → 1.15.1
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/LICENSE +21 -0
- package/README.md +93 -2
- package/dist/chunk-HA77BIQF.js +320 -0
- package/dist/chunk-HA77BIQF.js.map +1 -0
- package/dist/index.d.ts +1457 -0
- package/dist/index.js +3888 -0
- package/dist/index.js.map +1 -0
- package/dist/scales.d.ts +2 -0
- package/dist/scales.entry-BoLQpsxi.d.ts +275 -0
- package/dist/scales.js +3 -0
- package/dist/scales.js.map +1 -0
- package/package.json +54 -4
package/dist/scales.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { B as BandScale, g as BandScaleOptions, C as ContinuousScale, h as ContinuousScaleFactory, L as LinearScale, i as LinearScaleOptions, j as LogScale, k as LogScaleOptions, O as OrdinalScale, l as OrdinalScaleOptions, c as PolarScale, m as PolarScaleOptions, S as Scale, p as SpacedTickOptions, q as TickFormatCtx, r as TickFormatter, s as TickSet, T as TimeScale, t as TimeScaleOptions, u as bandScale, v as decimalsOf, w as formatInstant, x as formatNumber, y as formatTick, z as linearScale, A as logScale, D as niceDomain, E as niceStep, F as ordinalScale, G as polarScale, H as stepTicks, I as tickDecimals, J as tickStep, K as timeScale } from './scales.entry-BoLQpsxi.js';
|
|
2
|
+
import '@weasel-js/geom';
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { Path } from '@weasel-js/geom';
|
|
2
|
+
|
|
3
|
+
/** What every positional scale answers, and what an axis is drawn from: where a value sits along its range, the
|
|
4
|
+
* values an axis marks, and how one reads. */
|
|
5
|
+
interface Scale<T> {
|
|
6
|
+
readonly kind: 'linear' | 'log' | 'band' | 'time';
|
|
7
|
+
/** Where the scale's output runs, in drawing units: start to end, either way round. */
|
|
8
|
+
readonly range: readonly [number, number];
|
|
9
|
+
/** Where `value` sits along the range. A band scale answers its band's center. */
|
|
10
|
+
position(value: T): number;
|
|
11
|
+
/** The values an axis marks, about `count` of them where the scale chooses. */
|
|
12
|
+
ticks(count?: number): T[];
|
|
13
|
+
/** `value` as an axis label reads it. */
|
|
14
|
+
format(value: T): string;
|
|
15
|
+
}
|
|
16
|
+
/** A scale over numbers that maps both ways. */
|
|
17
|
+
interface ContinuousScale extends Scale<number> {
|
|
18
|
+
readonly kind: 'linear' | 'log' | 'time';
|
|
19
|
+
readonly domain: readonly [number, number];
|
|
20
|
+
/** `value` along the range; the same as {@link Scale.position}. */
|
|
21
|
+
map(value: number): number;
|
|
22
|
+
/** The value at `at` along the range. */
|
|
23
|
+
invert(at: number): number;
|
|
24
|
+
}
|
|
25
|
+
/** What builds a continuous scale from its two ends: `linearScale`, `logScale`, `timeScale`, or one of your own.
|
|
26
|
+
* A control that places values along its track takes one and calls it with a range of `[0, 1]`. */
|
|
27
|
+
type ContinuousScaleFactory = (opts: {
|
|
28
|
+
domain: readonly [number, number];
|
|
29
|
+
range: readonly [number, number];
|
|
30
|
+
}) => ContinuousScale;
|
|
31
|
+
|
|
32
|
+
/** Options for {@link linearScale}. */
|
|
33
|
+
interface LinearScaleOptions {
|
|
34
|
+
domain: readonly [number, number];
|
|
35
|
+
range: readonly [number, number];
|
|
36
|
+
/** Widen the domain out to whole tick steps for about this many ticks. Default no widening. */
|
|
37
|
+
nice?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Options for {@link LinearScale.spacedTicks}. */
|
|
40
|
+
interface SpacedTickOptions {
|
|
41
|
+
/** Smallest gap between neighboring ticks, in range units (px, for a scale onto the screen). */
|
|
42
|
+
minSpacing: number;
|
|
43
|
+
/** Ticks closer than this to either end of the range are dropped, in range units. Default 0. */
|
|
44
|
+
inset?: number;
|
|
45
|
+
}
|
|
46
|
+
/** A column of ticks and the facts its labels share. */
|
|
47
|
+
interface TickSet {
|
|
48
|
+
/** Ascending, whichever way the domain runs. */
|
|
49
|
+
values: number[];
|
|
50
|
+
/** Distance between neighboring ticks. */
|
|
51
|
+
step: number;
|
|
52
|
+
/** Places after the point every label in the column shares. */
|
|
53
|
+
decimals: number;
|
|
54
|
+
}
|
|
55
|
+
/** A scale that maps numbers proportionally, as a value axis does. */
|
|
56
|
+
interface LinearScale extends ContinuousScale {
|
|
57
|
+
readonly kind: 'linear';
|
|
58
|
+
/** The distance between ticks when about `count` are asked for. */
|
|
59
|
+
tickStep(count?: number): number;
|
|
60
|
+
/** Ticks on the finest 1/2/5 step that keeps neighbors `minSpacing` apart along the range, so a longer axis
|
|
61
|
+
* gets more of them. Empty for an empty domain or range. */
|
|
62
|
+
spacedTicks(options: SpacedTickOptions): TickSet;
|
|
63
|
+
}
|
|
64
|
+
/** The round step, 1, 2 or 5 times a power of ten, that cuts `lo`..`hi` into about `count` pieces. */
|
|
65
|
+
declare function tickStep(lo: number, hi: number, count?: number): number;
|
|
66
|
+
/** How many decimals a value on a grid of `step` needs; 0 for a step that is not a positive number. */
|
|
67
|
+
declare function decimalsOf(step: number): number;
|
|
68
|
+
/** The smallest of 1, 2 or 5 times a power of ten that is at least `rough`. Unlike {@link tickStep}, which
|
|
69
|
+
* rounds to the nearest, this never goes under: a minimum spacing stays a minimum. */
|
|
70
|
+
declare function niceStep(rough: number): number;
|
|
71
|
+
/** Every multiple of `step` from `lo` to `hi`, inclusive. */
|
|
72
|
+
declare function stepTicks(lo: number, hi: number, step: number): number[];
|
|
73
|
+
/** `value` written as plainly as a grid of `step` allows: no trailing zeros, no exponent. */
|
|
74
|
+
declare function formatNumber(value: number, step: number): string;
|
|
75
|
+
/** `domain` widened to whole steps of a tick grid of about `count` ticks. */
|
|
76
|
+
declare function niceDomain(domain: readonly [number, number], count?: number): [number, number];
|
|
77
|
+
/** A linear scale from `domain` onto `range`. */
|
|
78
|
+
declare function linearScale(opts: LinearScaleOptions): LinearScale;
|
|
79
|
+
|
|
80
|
+
/** What a tick label formatter knows about the column it is part of. */
|
|
81
|
+
interface TickFormatCtx {
|
|
82
|
+
/** Places after the point that every label in the column shares. */
|
|
83
|
+
decimals: number;
|
|
84
|
+
/** Distance between neighboring ticks, or 0 when the ticks were given explicitly and are not evenly spaced. */
|
|
85
|
+
step: number;
|
|
86
|
+
}
|
|
87
|
+
/** Turns a tick value into its label. */
|
|
88
|
+
type TickFormatter = (value: number, ctx: TickFormatCtx) => string;
|
|
89
|
+
/** The most places after the point any of `values` needs, for a column of ticks given rather than generated. */
|
|
90
|
+
declare function tickDecimals(values: readonly number[]): number;
|
|
91
|
+
/** `value` fixed to its column's shared decimals, with no negative zero, so a column of labels lines up. */
|
|
92
|
+
declare function formatTick(value: number, ctx: TickFormatCtx): string;
|
|
93
|
+
|
|
94
|
+
/** Options for {@link logScale}. */
|
|
95
|
+
interface LogScaleOptions {
|
|
96
|
+
/** Both ends above zero. */
|
|
97
|
+
domain: readonly [number, number];
|
|
98
|
+
range: readonly [number, number];
|
|
99
|
+
/** Default 10. */
|
|
100
|
+
base?: number;
|
|
101
|
+
}
|
|
102
|
+
/** A scale that maps the logarithm of a value proportionally. */
|
|
103
|
+
interface LogScale extends ContinuousScale {
|
|
104
|
+
readonly kind: 'log';
|
|
105
|
+
readonly base: number;
|
|
106
|
+
}
|
|
107
|
+
/** A logarithmic scale from `domain`, whose ends must both be above zero, onto `range`. */
|
|
108
|
+
declare function logScale(opts: LogScaleOptions): LogScale;
|
|
109
|
+
|
|
110
|
+
/** Options for {@link bandScale}. */
|
|
111
|
+
interface BandScaleOptions {
|
|
112
|
+
/** The categories, one band each, in order. */
|
|
113
|
+
domain: readonly string[];
|
|
114
|
+
range: readonly [number, number];
|
|
115
|
+
/** The share of each step left empty between bands, 0 to 1. Default 0.2. */
|
|
116
|
+
paddingInner?: number;
|
|
117
|
+
/** The room before the first band and after the last, in steps. Default half of `paddingInner`. */
|
|
118
|
+
paddingOuter?: number;
|
|
119
|
+
}
|
|
120
|
+
/** A scale that cuts its range into equal bands, one per category, as a bar chart's category axis does. */
|
|
121
|
+
interface BandScale extends Scale<string> {
|
|
122
|
+
readonly kind: 'band';
|
|
123
|
+
readonly domain: readonly string[];
|
|
124
|
+
/** The width of each band. */
|
|
125
|
+
readonly bandwidth: number;
|
|
126
|
+
/** From one band's start to the next's. */
|
|
127
|
+
readonly step: number;
|
|
128
|
+
/** Where `key`'s band starts, or `NaN` for a key not in the domain. */
|
|
129
|
+
start(key: string): number;
|
|
130
|
+
/** The key whose band is nearest `at`; `undefined` for an empty domain. */
|
|
131
|
+
invert(at: number): string | undefined;
|
|
132
|
+
}
|
|
133
|
+
/** A band scale over `domain`. */
|
|
134
|
+
declare function bandScale(opts: BandScaleOptions): BandScale;
|
|
135
|
+
|
|
136
|
+
/** Options for {@link timeScale}. */
|
|
137
|
+
interface TimeScaleOptions {
|
|
138
|
+
/** Milliseconds since the epoch, as `Date.getTime` gives them. */
|
|
139
|
+
domain: readonly [number, number];
|
|
140
|
+
range: readonly [number, number];
|
|
141
|
+
}
|
|
142
|
+
/** A scale over instants, whose ticks fall on whole seconds, minutes, hours, days, months or years, in UTC. */
|
|
143
|
+
interface TimeScale extends ContinuousScale {
|
|
144
|
+
readonly kind: 'time';
|
|
145
|
+
}
|
|
146
|
+
type Unit = 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year';
|
|
147
|
+
/** `t` written to the precision of `unit`. */
|
|
148
|
+
declare function formatInstant(t: number, unit: Unit): string;
|
|
149
|
+
/** A time scale from `domain`, in milliseconds since the epoch, onto `range`. */
|
|
150
|
+
declare function timeScale(opts: TimeScaleOptions): TimeScale;
|
|
151
|
+
|
|
152
|
+
/** Options for {@link ordinalScale}. */
|
|
153
|
+
interface OrdinalScaleOptions<T> {
|
|
154
|
+
/** The keys, in order. */
|
|
155
|
+
domain: readonly string[];
|
|
156
|
+
/** What each key maps to, in domain order, wrapping when there are fewer than keys. */
|
|
157
|
+
range: readonly T[];
|
|
158
|
+
}
|
|
159
|
+
/** A scale from keys to values in turn, as a series' colors are chosen. */
|
|
160
|
+
interface OrdinalScale<T> {
|
|
161
|
+
readonly kind: 'ordinal';
|
|
162
|
+
readonly domain: readonly string[];
|
|
163
|
+
readonly range: readonly T[];
|
|
164
|
+
/** `key`'s value; a key not in the domain takes the next value after the last, and joins the domain. */
|
|
165
|
+
map(key: string): T;
|
|
166
|
+
/** The keys a legend lists. */
|
|
167
|
+
ticks(): string[];
|
|
168
|
+
format(key: string): string;
|
|
169
|
+
}
|
|
170
|
+
/** An ordinal scale from `domain` to `range`. Throws on an empty range. */
|
|
171
|
+
declare function ordinalScale<T>(opts: OrdinalScaleOptions<T>): OrdinalScale<T>;
|
|
172
|
+
|
|
173
|
+
/** The kinds of mark a chart is drawn with. */
|
|
174
|
+
type MarkKind = 'bar' | 'span' | 'line' | 'area' | 'point' | 'arc' | 'ribbon' | 'rule' | 'text';
|
|
175
|
+
/** The value a mark stands for, as plain fields: a series and index, a category, a value. */
|
|
176
|
+
type PlotDatum = Readonly<Record<string, string | number | boolean>>;
|
|
177
|
+
/** What a mark's scene data says about it: its kind, and the datum it draws. */
|
|
178
|
+
interface PlotMarkTrait {
|
|
179
|
+
kind: MarkKind;
|
|
180
|
+
datum?: PlotDatum;
|
|
181
|
+
}
|
|
182
|
+
/** A solid paint, as the kit's painters read one. */
|
|
183
|
+
interface SolidFill {
|
|
184
|
+
paint: {
|
|
185
|
+
color: string;
|
|
186
|
+
opacity?: number;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** A solid stroke, as the kit's painters read one. */
|
|
190
|
+
interface SolidStroke {
|
|
191
|
+
paint: {
|
|
192
|
+
color: string;
|
|
193
|
+
};
|
|
194
|
+
width: number;
|
|
195
|
+
dash?: number[];
|
|
196
|
+
cap?: 'butt' | 'round' | 'square';
|
|
197
|
+
join?: 'miter' | 'round' | 'bevel';
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A mark's scene data: the trait under `plotMark`, and the fields the kit's
|
|
201
|
+
* painters draw it from — `path` for a shape, a line or a region, `text` for
|
|
202
|
+
* a label.
|
|
203
|
+
*/
|
|
204
|
+
interface PlotMarkData {
|
|
205
|
+
plotMark: PlotMarkTrait;
|
|
206
|
+
path?: Path;
|
|
207
|
+
fill?: SolidFill;
|
|
208
|
+
stroke?: SolidStroke;
|
|
209
|
+
text?: string;
|
|
210
|
+
style?: {
|
|
211
|
+
fontFamily: string;
|
|
212
|
+
fontSize: number;
|
|
213
|
+
align?: 'left' | 'center' | 'right';
|
|
214
|
+
fontWeight?: number;
|
|
215
|
+
};
|
|
216
|
+
verticalAlign?: 'top' | 'center' | 'bottom';
|
|
217
|
+
}
|
|
218
|
+
/** A box, in the plot's own coordinates: from its root's corner. */
|
|
219
|
+
interface PlotBox {
|
|
220
|
+
x: number;
|
|
221
|
+
y: number;
|
|
222
|
+
width: number;
|
|
223
|
+
height: number;
|
|
224
|
+
/** Radians about the box's center. */
|
|
225
|
+
rotation?: number;
|
|
226
|
+
}
|
|
227
|
+
/** One mark, ready to be a scene node: a key unique within its plot, where it is drawn, and its data. */
|
|
228
|
+
interface PlotMark {
|
|
229
|
+
key: string;
|
|
230
|
+
pose: PlotBox;
|
|
231
|
+
data: PlotMarkData;
|
|
232
|
+
}
|
|
233
|
+
/** A point in the plot's coordinates. */
|
|
234
|
+
interface PlotPoint {
|
|
235
|
+
x: number;
|
|
236
|
+
y: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Options for {@link polarScale}. */
|
|
240
|
+
interface PolarScaleOptions {
|
|
241
|
+
center: PlotPoint;
|
|
242
|
+
/** The radius the domain's ends sit at: inner, then outer. */
|
|
243
|
+
radius: readonly [number, number];
|
|
244
|
+
domain: readonly [number, number];
|
|
245
|
+
/** How many spokes share the turn, evenly. */
|
|
246
|
+
axes: number;
|
|
247
|
+
/** Axis 0's angle, radians clockwise from twelve o'clock. Default 0. */
|
|
248
|
+
startAngle?: number;
|
|
249
|
+
}
|
|
250
|
+
/** A scale over spokes from a center, as a radar chart's axes are: a value along each of `axes` evenly spaced spokes. */
|
|
251
|
+
interface PolarScale {
|
|
252
|
+
readonly kind: 'polar';
|
|
253
|
+
readonly center: PlotPoint;
|
|
254
|
+
readonly radius: readonly [number, number];
|
|
255
|
+
readonly domain: readonly [number, number];
|
|
256
|
+
readonly axes: number;
|
|
257
|
+
/** Axis `i`'s angle, radians clockwise from twelve o'clock, as `arcMark`'s are. */
|
|
258
|
+
angle(i: number): number;
|
|
259
|
+
/** How far from the center `value` sits on every axis. */
|
|
260
|
+
radiusAt(value: number): number;
|
|
261
|
+
/** Where `value` sits on axis `i`. */
|
|
262
|
+
point(i: number, value: number): PlotPoint;
|
|
263
|
+
/** The value of the point on axis `i` nearest `at`, clamped to the domain. */
|
|
264
|
+
valueAt(i: number, at: PlotPoint): number;
|
|
265
|
+
/** The distance between ticks when about `count` are asked for. */
|
|
266
|
+
tickStep(count?: number): number;
|
|
267
|
+
/** Round values across the domain, about `count` of them. */
|
|
268
|
+
ticks(count?: number): number[];
|
|
269
|
+
/** `value` as a tick label reads it. */
|
|
270
|
+
format(value: number): string;
|
|
271
|
+
}
|
|
272
|
+
/** A polar scale: values from `domain` out along `axes` spokes from `center`, `radius[0]` to `radius[1]` away. */
|
|
273
|
+
declare function polarScale(opts: PolarScaleOptions): PolarScale;
|
|
274
|
+
|
|
275
|
+
export { logScale as A, type BandScale as B, type ContinuousScale as C, niceDomain as D, niceStep as E, ordinalScale as F, polarScale as G, stepTicks as H, tickDecimals as I, tickStep as J, timeScale as K, type LinearScale as L, type MarkKind as M, type OrdinalScale as O, type PlotDatum as P, type Scale as S, type TimeScale as T, type PlotMark as a, type PlotPoint as b, type PolarScale as c, type PlotMarkData as d, type PlotMarkTrait as e, type PlotBox as f, type BandScaleOptions as g, type ContinuousScaleFactory as h, type LinearScaleOptions as i, type LogScale as j, type LogScaleOptions as k, type OrdinalScaleOptions as l, type PolarScaleOptions as m, type SolidFill as n, type SolidStroke as o, type SpacedTickOptions as p, type TickFormatCtx as q, type TickFormatter as r, type TickSet as s, type TimeScaleOptions as t, bandScale as u, decimalsOf as v, formatInstant as w, formatNumber as x, formatTick as y, linearScale as z };
|
package/dist/scales.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { bandScale, decimalsOf, formatInstant, formatNumber, formatTick, linearScale, logScale, niceDomain, niceStep, ordinalScale, polarScale, stepTicks, tickDecimals, tickStep, timeScale } from './chunk-HA77BIQF.js';
|
|
2
|
+
//# sourceMappingURL=scales.js.map
|
|
3
|
+
//# sourceMappingURL=scales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"scales.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/plot",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.15.1",
|
|
4
|
+
"description": "Charts on weasel's scene graph: scales, axes, and marks that keep their data, and chart specs compiled to them, edited by dragging the marks.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./scales": {
|
|
17
|
+
"import": "./dist/scales.js",
|
|
18
|
+
"types": "./dist/scales.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"author": "orochi235",
|
|
23
|
+
"homepage": "https://orochi235.github.io/weasel/",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/orochi235/weasel.git",
|
|
27
|
+
"directory": "packages/plot"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/orochi235/weasel/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@weasel-js/geom": "1.15.1",
|
|
45
|
+
"@weasel-js/text": "1.15.1",
|
|
46
|
+
"@weasel-js/theme": "1.15.1"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@weasel-js/core": "1.15.1",
|
|
50
|
+
"react": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public",
|
|
54
|
+
"provenance": true
|
|
55
|
+
}
|
|
56
|
+
}
|