@niekes/charts-3d 0.4.0 → 0.6.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/README.md +1 -1
- package/dist/index.d.ts +103 -49
- package/dist/index.js +1019 -743
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
</tr>
|
|
39
39
|
<tr style="background-color: #f6f8fa">
|
|
40
40
|
<td><a target="_blank" href="https://niekes.github.io/charts-3d/docs/components/surface-chart-3d"><img src="assets/examples/surface-chart-3d.png" alt="Surface Chart 3D"></a></td>
|
|
41
|
-
<td><a target="_blank" href="https://niekes.github.io/charts-3d/docs/components/
|
|
41
|
+
<td><a target="_blank" href="https://niekes.github.io/charts-3d/docs/components/area-chart-3d"><img src="assets/examples/area-chart-3d.png" alt="Area Chart 3D"></a></td>
|
|
42
42
|
</tr>
|
|
43
43
|
</table>
|
|
44
44
|
|
package/dist/index.d.ts
CHANGED
|
@@ -27,12 +27,11 @@ export type View3D = {
|
|
|
27
27
|
perspective?: number;
|
|
28
28
|
};
|
|
29
29
|
/** How the marks of a chart are drawn. The box, its labels, the tooltip and the legend are always SVG and HTML. */
|
|
30
|
-
export type Renderer3D = "svg" | "canvas";
|
|
30
|
+
export type Renderer3D = "svg" | "canvas" | "webgl";
|
|
31
31
|
/** Maps data values to the world box, which spans -1 to 1 on every axis, y up. */
|
|
32
32
|
export type World = Record<keyof AxesSpec, (value: number) => number>;
|
|
33
|
+
/** What a mark says while the pointer is on it, beside the pointer. */
|
|
33
34
|
export type Tooltip3D = {
|
|
34
|
-
/** The anchor in the units of the view box. */
|
|
35
|
-
at: Point2D;
|
|
36
35
|
title?: React.ReactNode;
|
|
37
36
|
items: {
|
|
38
37
|
label: React.ReactNode;
|
|
@@ -54,9 +53,10 @@ export type Mark3D = {
|
|
|
54
53
|
/** Shown while the pointer is over the mark. */
|
|
55
54
|
tooltip?: Tooltip3D;
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* The marks of the same element as this one: the faces of a bar, the
|
|
57
|
+
* segments of a flow. Pointing at a mark gives them an edge in the focus
|
|
58
|
+
* color - `--chart-3d-focus`, or their own fill lightened - until the
|
|
59
|
+
* pointer leaves the mark; the fill never changes on hover.
|
|
60
60
|
*/
|
|
61
61
|
groups?: string[];
|
|
62
62
|
};
|
|
@@ -80,7 +80,7 @@ type ChartContext3D = {
|
|
|
80
80
|
export declare function useChart3D(): ChartContext3D;
|
|
81
81
|
/** The actions a key triggers: each steps the camera, `help` opens the shortcut panel. */
|
|
82
82
|
export type KeyAction3D = "rotateLeft" | "rotateRight" | "rotateUp" | "rotateDown" | "panLeft" | "panRight" | "panUp" | "panDown" | "zoomIn" | "zoomOut" | "reset" | "help";
|
|
83
|
-
/** The gestures of the pointer
|
|
83
|
+
/** The gestures of the pointer, which `keymap` can turn off or rename but not rebind; the shortcut panel shows each with its modifier on the reader's platform. */
|
|
84
84
|
export type Gesture3D = "dragRotate" | "dragPan" | "wheelZoom" | "doubleClickReset";
|
|
85
85
|
/**
|
|
86
86
|
* The shortcuts of a chart over their defaults, per action: `false` turns an
|
|
@@ -124,9 +124,9 @@ export type ChartContainer3DProps = {
|
|
|
124
124
|
*/
|
|
125
125
|
legend?: boolean;
|
|
126
126
|
/**
|
|
127
|
-
* How the marks of the chart are drawn: "canvas" suits many marks.
|
|
128
|
-
* chart draws as SVG until the browser shows it has
|
|
129
|
-
* has none.
|
|
127
|
+
* How the marks of the chart are drawn: "canvas" suits many marks, "webgl" more.
|
|
128
|
+
* The chart draws as SVG until the browser shows it has the requested renderer,
|
|
129
|
+
* "webgl" falling back to "canvas", and where it has none, as SVG.
|
|
130
130
|
* @defaultValue "svg"
|
|
131
131
|
*/
|
|
132
132
|
renderer?: Renderer3D;
|
|
@@ -146,20 +146,31 @@ export type ChartContainer3DProps = {
|
|
|
146
146
|
* @defaultValue "bottom-left"
|
|
147
147
|
*/
|
|
148
148
|
gizmo?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | false;
|
|
149
|
+
/**
|
|
150
|
+
* The corner beside the pointer the tooltip sits at. Where the tooltip would
|
|
151
|
+
* leave the chart, it flips to the other side, on each axis alone.
|
|
152
|
+
* @defaultValue "top-right"
|
|
153
|
+
*/
|
|
154
|
+
tooltip?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
149
155
|
};
|
|
150
|
-
declare function ChartContainer3D({ id, config, defaultView, width, height, animationDuration, legend, renderer: requested, shortcuts, keymap, gizmo, className, children, "aria-label": ariaLabel, ...props }: React.ComponentProps<"div"> & ChartContainer3DProps): React.JSX.Element;
|
|
156
|
+
declare function ChartContainer3D({ id, config, defaultView, width, height, animationDuration, legend, renderer: requested, shortcuts, keymap, gizmo, tooltip, className, children, "aria-label": ariaLabel, ...props }: React.ComponentProps<"div"> & ChartContainer3DProps): React.JSX.Element;
|
|
151
157
|
/**
|
|
152
158
|
* Eases a chart into new data: the numbers of `values` glide from the ones
|
|
153
159
|
* on screen to these over the animationDuration of the container. A key
|
|
154
|
-
* that is new starts at `enter`, or where it ends; a key that is gone
|
|
155
|
-
*
|
|
160
|
+
* that is new starts at `enter`, or where it ends; a key that is gone glides
|
|
161
|
+
* back to `enter`, the mirror of its entering - without one it stands where
|
|
162
|
+
* it is - and leaves when the glide is done. Without time, or with reduced
|
|
163
|
+
* motion, the numbers jump.
|
|
156
164
|
*/
|
|
157
165
|
declare function useTween(values: Record<string, number>, enter?: number): Record<string, number>;
|
|
158
166
|
/**
|
|
159
167
|
* `spec` gliding into new data with the marks: the ends of every axis glide
|
|
160
168
|
* as `useTween` glides the numbers, where ends rounded from the numbers on
|
|
161
169
|
* screen would jump from one round number to the next, and the box with
|
|
162
|
-
* them. The ticks
|
|
170
|
+
* them. The ticks stay those of `spec`; labels of ticks outside the gliding
|
|
171
|
+
* ends fade out in `edgeLabels` instead of popping out of the range. The
|
|
172
|
+
* outermost ticks glide too, so the line of the axis grows to a new tick and
|
|
173
|
+
* shrinks from a dropped one instead of jumping when the glide is done.
|
|
163
174
|
*/
|
|
164
175
|
declare function useTweenAxes(spec: AxesSpec): AxesSpec;
|
|
165
176
|
/**
|
|
@@ -168,7 +179,7 @@ declare function useTweenAxes(spec: AxesSpec): AxesSpec;
|
|
|
168
179
|
*/
|
|
169
180
|
declare function Marks3D({ marks }: {
|
|
170
181
|
marks: Mark3D[];
|
|
171
|
-
}): React.JSX.Element
|
|
182
|
+
}): React.JSX.Element | null;
|
|
172
183
|
/**
|
|
173
184
|
* A label beside a mark, at `at` in the units of the view box. `toward`, a
|
|
174
185
|
* unit vector, lays the label on that side of `at`, touching it, and slides
|
|
@@ -181,8 +192,6 @@ export type Label3D = {
|
|
|
181
192
|
text: React.ReactNode;
|
|
182
193
|
anchor?: "start" | "middle" | "end";
|
|
183
194
|
toward?: Point2D;
|
|
184
|
-
/** The groups of the mark it names, so it fades with the mark out of focus. */
|
|
185
|
-
groups?: string[];
|
|
186
195
|
};
|
|
187
196
|
/**
|
|
188
197
|
* The labels of the marks of a chart, ringed by the background so that they
|
|
@@ -230,14 +239,79 @@ declare function intoWorld<Datum extends Point3D, T extends ShapeInstance<Datum>
|
|
|
230
239
|
* shade follows the theme variables.
|
|
231
240
|
*/
|
|
232
241
|
declare function shade(face: TransformedPoint<unknown>[], color: string): string;
|
|
233
|
-
/**
|
|
234
|
-
|
|
242
|
+
/**
|
|
243
|
+
* `color` at `opacity`, from 0 to 1: a CSS color-mix with transparent, so a
|
|
244
|
+
* mark fades on every renderer while its color stays in CSS. Rounded to a
|
|
245
|
+
* percent, so the renderers that resolve colors cache a bounded few. Fade
|
|
246
|
+
* after `shade`, which would mix a translucent color back towards opaque.
|
|
247
|
+
*/
|
|
248
|
+
declare function faded(color: string, opacity: number): string;
|
|
249
|
+
/**
|
|
250
|
+
* The entries of `data` and their series, for a chart that lays the entries
|
|
251
|
+
* out along x and the series along z, as the bar and the area chart do. The
|
|
252
|
+
* name of every entry comes from its `index` field, the series are `keys` or
|
|
253
|
+
* the keys of the config, and the `target` of every cell is keyed by the name
|
|
254
|
+
* of its entry and its series, so it follows its entry when the data
|
|
255
|
+
* reorders; a value that is not a number stands as 0. Each glides by name:
|
|
256
|
+
* `values` from 0, `rows` - the place of every entry - to where it stands, and
|
|
257
|
+
* `presence` from 0 to 1 as an entry comes and back as it goes, the gone ones
|
|
258
|
+
* still among them. `labels` name the ticks: the entry at a tick of x, through
|
|
259
|
+
* `format.x` - a tick of a gone entry fades out unnamed - and the series at a
|
|
260
|
+
* tick of z.
|
|
261
|
+
*/
|
|
262
|
+
declare function useSeries<T extends Record<string, unknown>>({ data, index, keys, format }: {
|
|
263
|
+
data: T[];
|
|
264
|
+
index: keyof T & string;
|
|
265
|
+
keys?: string[];
|
|
266
|
+
format?: {
|
|
267
|
+
x?: (label: string) => React.ReactNode;
|
|
268
|
+
y?: (value: number) => React.ReactNode;
|
|
269
|
+
};
|
|
270
|
+
}): {
|
|
271
|
+
series: string[];
|
|
272
|
+
target: {
|
|
273
|
+
[k: string]: number;
|
|
274
|
+
};
|
|
275
|
+
values: Record<string, number>;
|
|
276
|
+
rows: Record<string, number>;
|
|
277
|
+
presence: Record<string, number>;
|
|
278
|
+
labels: {
|
|
279
|
+
x: (i: number) => React.ReactNode;
|
|
280
|
+
y: ((value: number) => React.ReactNode) | undefined;
|
|
281
|
+
z: (j: number) => string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | Iterable<React.ReactNode> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | React.ReactPortal | null | undefined> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
235
284
|
/** The marks of a cube: its faces that look at the camera, shaded in `color`, each with `tooltip` on hover. */
|
|
236
285
|
declare function cubeMarks(id: string, faces: CubeFace[], color: string, tooltip: Tooltip3D): Mark3D[];
|
|
286
|
+
export type AreaChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
287
|
+
/** One entry per point along x, with a value per series. */
|
|
288
|
+
data: T[];
|
|
289
|
+
/** The field that names each entry, such as "year"; a point follows its name through updates, so the names should be unique. */
|
|
290
|
+
index: keyof T & string;
|
|
291
|
+
/**
|
|
292
|
+
* The fields that hold the series, one ribbon each.
|
|
293
|
+
* @defaultValue the keys of the chart config
|
|
294
|
+
*/
|
|
295
|
+
keys?: string[];
|
|
296
|
+
/** Formats the labels of the entries along x and the values along y. */
|
|
297
|
+
format?: {
|
|
298
|
+
x?: (label: string) => React.ReactNode;
|
|
299
|
+
y?: (value: number) => React.ReactNode;
|
|
300
|
+
};
|
|
301
|
+
/** The titles of the axes. */
|
|
302
|
+
titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Areas pushed back into ribbons: the entries of `data` along x, one ribbon
|
|
306
|
+
* per series along z, the area under its line reaching down to the floor of
|
|
307
|
+
* the box. The series are the keys of the chart config unless `keys` names
|
|
308
|
+
* them.
|
|
309
|
+
*/
|
|
310
|
+
export declare function AreaChart3D<T extends Record<string, unknown>>({ data, index, keys, format, titles }: AreaChart3DProps<T>): React.JSX.Element;
|
|
237
311
|
export type BarChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
238
312
|
/** One entry per row of bars, with a value per series. */
|
|
239
313
|
data: T[];
|
|
240
|
-
/** The field that names each entry, such as "month". */
|
|
314
|
+
/** The field that names each entry, such as "month"; a bar follows its name through updates, so the names should be unique. */
|
|
241
315
|
index: keyof T & string;
|
|
242
316
|
/**
|
|
243
317
|
* The fields that hold the series, one row of bars each.
|
|
@@ -272,6 +346,13 @@ export type ScatterChart3DProps<T extends Record<string, unknown> = Record<strin
|
|
|
272
346
|
y: keyof T & string;
|
|
273
347
|
/** The field of the position along z. */
|
|
274
348
|
z: keyof T & string;
|
|
349
|
+
/**
|
|
350
|
+
* The field that names an entry, so a point follows its name through
|
|
351
|
+
* updates: a new one grows, a gone one shrinks away, one that moves glides.
|
|
352
|
+
* The names should be unique.
|
|
353
|
+
* @defaultValue the position of the entry
|
|
354
|
+
*/
|
|
355
|
+
id?: keyof T & string;
|
|
275
356
|
/**
|
|
276
357
|
* The field whose value is the config key of the color of a point.
|
|
277
358
|
* @defaultValue the first key of the chart config for every point
|
|
@@ -291,7 +372,7 @@ export type ScatterChart3DProps<T extends Record<string, unknown> = Record<strin
|
|
|
291
372
|
* Points in the chart box, at the fields `x`, `y` and `z` of each entry.
|
|
292
373
|
* `series` names the field whose value is the config key of the color.
|
|
293
374
|
*/
|
|
294
|
-
export declare function ScatterChart3D<T extends Record<string, unknown>>({ data, x, y, z, series, radius, format, titles }: ScatterChart3DProps<T>): React.JSX.Element;
|
|
375
|
+
export declare function ScatterChart3D<T extends Record<string, unknown>>({ data, x, y, z, id, series, radius, format, titles }: ScatterChart3DProps<T>): React.JSX.Element;
|
|
295
376
|
export type SurfaceChart3DProps = {
|
|
296
377
|
/** The heights on the grid, `data[row][column]`. */
|
|
297
378
|
data: number[][];
|
|
@@ -322,32 +403,5 @@ export type SurfaceChart3DProps = {
|
|
|
322
403
|
* of the chart config, by default its first two.
|
|
323
404
|
*/
|
|
324
405
|
export declare function SurfaceChart3D({ data, domain, colors, format, titles }: SurfaceChart3DProps): React.JSX.Element;
|
|
325
|
-
export
|
|
326
|
-
/** One entry per flow. `source` and `target` are keys of the chart config, which names and colors the nodes. */
|
|
327
|
-
data: {
|
|
328
|
-
source: string;
|
|
329
|
-
target: string;
|
|
330
|
-
value: number;
|
|
331
|
-
}[];
|
|
332
|
-
/**
|
|
333
|
-
* The width of a node, as a share of the distance between two columns.
|
|
334
|
-
* @defaultValue 0.2
|
|
335
|
-
*/
|
|
336
|
-
nodeWidth?: number;
|
|
337
|
-
/**
|
|
338
|
-
* The gap between two nodes of a column, as a share of the height.
|
|
339
|
-
* @defaultValue 0.05
|
|
340
|
-
*/
|
|
341
|
-
nodePadding?: number;
|
|
342
|
-
/** Formats the values in the tooltip. */
|
|
343
|
-
format?: (value: number) => React.ReactNode;
|
|
344
|
-
};
|
|
345
|
-
/**
|
|
346
|
-
* Flows from left to right: every node a box in its column, as high as the
|
|
347
|
-
* larger of what flows in and what flows out, and every flow a band from node
|
|
348
|
-
* to node, as thick as its value, that turns from the color of its source to
|
|
349
|
-
* the color of its target.
|
|
350
|
-
*/
|
|
351
|
-
export declare function SankeyChart3D({ data, nodeWidth, nodePadding, format }: SankeyChart3DProps): React.JSX.Element;
|
|
352
|
-
export { Axes3D, ChartContainer3D, ChartLegend3D, Labels3D, Marks3D, axis, center, cubeMarks, intoWorld, linear, pad, shade, useTween, useTweenAxes, worldBox };
|
|
406
|
+
export { Axes3D, ChartContainer3D, ChartLegend3D, Labels3D, Marks3D, axis, cubeMarks, faded, intoWorld, linear, pad, shade, useSeries, useTween, useTweenAxes, worldBox };
|
|
353
407
|
//# sourceMappingURL=index.d.ts.map
|