@grundyjs/algiviz 0.7.1 → 0.8.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/CHANGELOG.md +8 -0
- package/README.md +29 -3
- package/dist/canvas/index.d.ts +16 -3
- package/dist/canvas/index.js +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0 — 2026-10-19
|
|
4
|
+
|
|
5
|
+
- Add partial custom colors to the Canvas array renderer and its compatible alias,
|
|
6
|
+
with exported ArrayPalette, ArrayPaletteOverrides and ArrayRendererOptions types.
|
|
7
|
+
- Preserve theme defaults and isolate copied overrides per renderer instance.
|
|
8
|
+
- Add theme presets, six color controls and palette reset to Sorting lab without
|
|
9
|
+
restarting playback or changing the current frame.
|
|
10
|
+
|
|
3
11
|
## 0.7.1 — 2026-10-15
|
|
4
12
|
|
|
5
13
|
- Update package description and keywords for custom algorithm visualizations.
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ renderer help you get started.
|
|
|
28
28
|
|
|
29
29
|
Use it for educational demos, interactive articles and algorithm walkthroughs.
|
|
30
30
|
Algorithms and layouts belong to your application; AlgiViz provides the playback
|
|
31
|
-
and rendering API. This README describes version 0.
|
|
31
|
+
and rendering API. This README describes version 0.8.0.
|
|
32
32
|
|
|
33
33
|
## Start with one custom object
|
|
34
34
|
|
|
@@ -365,7 +365,33 @@ magnitude for bar height and retain their sign in labels; this is not a signed-a
|
|
|
365
365
|
plot. Dense charts hide labels. For recording, use a canvas with fixed export
|
|
366
366
|
dimensions. Rendering does not start an animation loop or record video.
|
|
367
367
|
|
|
368
|
-
|
|
368
|
+
#### Custom array colors (since 0.8.0)
|
|
369
|
+
|
|
370
|
+
Version 0.8.0 accepts partial palette overrides on both `createArrayRenderer`
|
|
371
|
+
and its compatible alias `createSortRenderer`:
|
|
372
|
+
|
|
373
|
+
```ts
|
|
374
|
+
import { createArrayRenderer, type ArrayPaletteOverrides } from '@grundyjs/algiviz/canvas';
|
|
375
|
+
const colors: ArrayPaletteOverrides = { background: '#ffffff', text: '#182230', active: '#e87900' };
|
|
376
|
+
const renderer = createArrayRenderer({ theme: 'light', colors });
|
|
377
|
+
renderer.render(ctx, currentFrame);
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
`ArrayPalette` defines six string roles: `background` (full canvas), `text`
|
|
381
|
+
(all labels), `bar` (ordinary bars), `sorted` (sorted prefix/suffix), `active`
|
|
382
|
+
(highlighted/compared/moved items), and `held` (the held item, taking precedence
|
|
383
|
+
over active and sorted). `ArrayPaletteOverrides` is its partial form;
|
|
384
|
+
`ArrayRendererOptions` describes the options object. Values are Canvas color
|
|
385
|
+
strings, passed through without CSS validation. Omitted or undefined roles use
|
|
386
|
+
the selected theme. Existing theme-only calls and default colors are unchanged.
|
|
387
|
+
|
|
388
|
+
Overrides are copied when creating a renderer. Changing the input object later
|
|
389
|
+
has no effect. To switch theme or palette, create a new renderer and render the
|
|
390
|
+
same current frame. This changes colors only, not playback, snapshots, layout or
|
|
391
|
+
bitmap/DPR handling. Try the theme presets, six color inputs and reset control
|
|
392
|
+
in [Sorting lab](examples/index.html).
|
|
393
|
+
|
|
394
|
+
## Memory and generation cost
|
|
369
395
|
|
|
370
396
|
Array operations copy the input, validate finite numbers and reject sparse inputs.
|
|
371
397
|
`defineArrayAlgorithm` performs this work on the first iterator `next()`;
|
|
@@ -499,7 +525,7 @@ candidate commit.
|
|
|
499
525
|
|
|
500
526
|
The [publish workflow](.github/workflows/npm-publish.yml) runs when a stable GitHub
|
|
501
527
|
Release is published. Drafts, prereleases and tag pushes alone do not publish.
|
|
502
|
-
Use `v` followed by the exact package version, such as `v0.
|
|
528
|
+
Use `v` followed by the exact package version, such as `v0.8.0`, at the tested commit.
|
|
503
529
|
|
|
504
530
|
The workflow uses Node.js 24 and npm 11, checks the version and packed consumer,
|
|
505
531
|
then publishes with provenance through npm trusted publishing (OIDC).
|
package/dist/canvas/index.d.ts
CHANGED
|
@@ -10,10 +10,23 @@ export type ArrayObjects = {
|
|
|
10
10
|
};
|
|
11
11
|
/** Adapts array identities to the same public scene contract used by custom objects. */
|
|
12
12
|
export declare function arrayScene(state: SortSnapshot): Scene<ArrayObjects>;
|
|
13
|
+
/** Canvas color strings for the semantic roles in the array renderer. */
|
|
14
|
+
export interface ArrayPalette {
|
|
15
|
+
readonly background: string;
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly bar: string;
|
|
18
|
+
readonly sorted: string;
|
|
19
|
+
readonly active: string;
|
|
20
|
+
readonly held: string;
|
|
21
|
+
}
|
|
22
|
+
/** Overrides are copied at renderer creation; omitted roles retain the theme color. */
|
|
23
|
+
export type ArrayPaletteOverrides = Partial<ArrayPalette>;
|
|
24
|
+
export interface ArrayRendererOptions {
|
|
25
|
+
readonly theme: "light" | "dark";
|
|
26
|
+
readonly colors?: ArrayPaletteOverrides;
|
|
27
|
+
}
|
|
13
28
|
export { createSortRenderer as createArrayRenderer };
|
|
14
29
|
/** Stateless full-frame renderer. Bitmap dimensions determine layout and video size. */
|
|
15
|
-
export declare function createSortRenderer(options: {
|
|
16
|
-
theme: "light" | "dark";
|
|
17
|
-
}): Readonly<{
|
|
30
|
+
export declare function createSortRenderer(options: ArrayRendererOptions): Readonly<{
|
|
18
31
|
render(ctx: CanvasRenderingContext2D, frame: SortFrame): void;
|
|
19
32
|
}>;
|
package/dist/canvas/index.js
CHANGED
|
@@ -36,7 +36,12 @@ function positions(state) {
|
|
|
36
36
|
}
|
|
37
37
|
/** Stateless full-frame renderer. Bitmap dimensions determine layout and video size. */
|
|
38
38
|
export function createSortRenderer(options) {
|
|
39
|
-
const colors = palettes[options.theme];
|
|
39
|
+
const colors = { ...palettes[options.theme] };
|
|
40
|
+
for (const key of Object.keys(colors)) {
|
|
41
|
+
const color = options.colors?.[key];
|
|
42
|
+
if (color !== undefined)
|
|
43
|
+
colors[key] = color;
|
|
44
|
+
}
|
|
40
45
|
const projectFrame = createSceneProjector(arrayScene);
|
|
41
46
|
return Object.freeze({
|
|
42
47
|
render(ctx, frame) {
|