• Joined on 2026-09-04

@jean/kerzwerk (0.1.1)

Published 2026-11-11 14:35:19 +00:00 by jean in jean/kerzwerk

Installation

@jean:registry=https://code.jeanavril.com/api/packages/jean/npm/
npm install @jean/kerzwerk@0.1.1
"@jean/kerzwerk": "0.1.1"

About this package

Price charts on canvas: candles, OHLC bars, lines, areas, histograms and bands on one time axis, with legend, scales, drawing tools and a Svelte 5 binding. No runtime dependencies.

kerzwerk

Price charts on canvas for Svelte 5 apps — and for any page, since the core knows no framework. Candles, OHLC bars, lines, areas, histograms and bands on one time axis; marks, levels, spans and custom primitives; a legend, linear, log, percent and indexed scales, linked charts, and ten drawing tools. No runtime dependencies: the core is about 24 kB gzip, the drawing tools 5.5 kB more.

Daily candles with lines, a zone, volume and a trade

Entry What
@jean/kerzwerk the core: createChart, aggregation, sync groups, all types
@jean/kerzwerk/svelte ChartView, the Svelte 5 binding
@jean/kerzwerk/tools drawing tools: createDrawingEditor and helpers
@jean/kerzwerk/theme.css default colours, light and dark

An app carries only what it imports.

Install

The package lives in the npm registry of Jean's Gitea and can be read without a token. In the app, an .npmrc next to package.json maps the scope:

@jean:registry=https://gitea.public.mgmt/api/packages/jean/npm/

Then:

npm install @jean/kerzwerk

A first chart (Svelte)

<script lang="ts">
	import '@jean/kerzwerk/theme.css';
	import { ChartView } from '@jean/kerzwerk/svelte';
	import type { ChartSpec } from '@jean/kerzwerk';

	// Columns as typed arrays: painters run over them without Svelte's proxies.
	let { times, open, high, low, close, volume }: Record<
		'times' | 'open' | 'high' | 'low' | 'close' | 'volume',
		Float64Array
	> = $props();

	const spec: ChartSpec = $derived({
		timeline: { kind: 'time', times, zone: 'America/New_York' },
		panes: [{ id: 'main', scales: [
			{ id: 'right', margins: { top: 0.08, bottom: 0.2 } },
			{ id: 'vol', side: 'none', margins: { top: 0.82, bottom: 0 } }
		] }],
		series: [
			{ id: 'price', kind: 'candles', open, high, low, close, title: 'ACME' },
			{ id: 'volume', kind: 'histogram', scale: 'vol', values: volume, color: '@neutral/40' }
		]
	});
</script>

<div style="height: 400px">
	<ChartView {spec} interactive legend crosshair="magnet" />
</div>

Without a class, ChartView fills its parent; give the parent a height. With a class, the class sets the size (class="h-96 w-full" in Tailwind). Later changes to spec go through update and leave the user's zoom alone; only a new timeline or a new view.key resets the visible range. bind:api gives the imperative handle (fit, showLast, setScaleMode, toImage, …).

Without Svelte

import { createChart } from '@jean/kerzwerk';

const chart = createChart(document.getElementById('chart')!, { interactive: true, legend: true });
chart.update(spec);
// …
chart.destroy();

The spec

A chart is a description, ChartSpec:

  • timeline — { kind: 'time', times, zone } with Unix seconds; daily bars carry 00:00 UTC of their day and keep the default zone UTC, so they show their own date; intraday bars use the exchange's zone. Or { kind: 'ordinal', length, label } for bars without dates.
  • panes — stacked areas, each with price scales (right, left, or side: 'none' for an overlay such as volume) and margins.
  • series — candles, ohlc, line (also step), area, histogram (colour per bar with colors), band (upper and lower edge). Values are columns of the timeline's length, NaN for a gap. rebase: true draws a series relative to the first series of its scale (comparison).
  • marks (arrows, dots, text at a bar), levels (horizontal lines with axis labels), spans (shaded time ranges) and primitives (your own painter, above or below the series).

Every bar has the same width whatever its time; nights, weekends and holidays take no room. Where bars are denser than pixels, the bars of one pixel column are folded into one — never skipped, so every spike stays.

Three panes: OHLC bars with two averages, volume, distance to the 50-day line

Five-minute bars on New York's clock, VWAP, and an index on a percent scale

Colours

Colours are roles: @up, @down, @series-1, @up/45 (45 % opacity), or any CSS colour. A role @x reads the custom property --chart-x on the chart's element, so an app adds its own (--chart-ema21: #6246ea; and then color: '@ema21'). theme.css defines the roles the library uses, light under :root and dark under .dark or [data-theme='dark']; charts follow a switch by themselves. Without the stylesheet the same light colours come from a built-in fallback. Font: --chart-font, --chart-font-size.

Linked charts, aggregation, images

  • createSyncGroup() passed as sync to several charts shares crosshair, visible range and price-axis width — stacked charts line up.
  • aggregateDays (weeks, months) and aggregateMinutes (5–60 minutes, aligned to the session open) build larger bars from daily and minute bars.
  • api.toImage() gives a PNG of the chart; saveImage(api, 'chart.png') downloads it.

Drawing tools

import { createDrawingEditor, type Drawing } from '@jean/kerzwerk/tools';

const editor = createDrawingEditor(api, {
	onchange: ({ kind, drawing }) => save(kind, drawing), // 'add' | 'update' | 'remove'
	onselect: (drawing) => (selected = drawing)
});
spec.primitives = [editor.primitive]; // paints the drawings and the draft
editor.set(savedDrawings);
editor.setTool('trend');

A trend line, a level, a Fibonacci retracement, a long position and a note

Tools (ToolKind): hline, hray, vline, trend, ray, rect, fib, measure, long (a position with stop and target), text. Anchors are (time, price), so a drawing survives a change of timeframe. Escape cancels, Delete removes the selected drawing. Storing drawings is the app's business.

Working on the library and an app together

# in kerzwerk
npm run dev                 # svelte-package --watch, writes dist/
# in the app
npm install ../kerzwerk     # a link to the working copy

If Vite refuses to serve files from the linked folder, allow it in the app's vite.config.ts: server: { fs: { allow: ['../kerzwerk'] } }.

The first start after installing or updating the package can show an empty chart and an error in the console ("504 Outdated Optimize Dep", or Cannot read properties of undefined (reading 'call')): Vite has just pre-bundled the new dependency while the page loaded. Reload once. Back to the release: npm install @jean/kerzwerk@^0.1.0. Never commit the app with the link.

Releases

npm version patch           # or minor; writes the version and a tag
npm publish                 # runs check, tests and build first
git push --follow-tags

Publishing needs a Gitea token with package write access in your user npm config, once per machine — never in a repository:

npm config set -- //gitea.public.mgmt/api/packages/jean/npm/:_authToken "YOUR_TOKEN"

publishConfig sends the package to the Gitea registry only; it cannot end up on the public npm registry by mistake. Packages on Gitea take the visibility of their owner: while the user jean is public, anyone who reaches gitea.public.mgmt can install them, though the repository is private. Note user-visible changes in CHANGELOG.md.

Adding a series kind

A new kind (say a baseline) is a type in the contract and one case at each place that branches on s.kind: the type in core/types.ts (interface, entry in SeriesSpec), the accessors in core/series.ts (seriesLength, seriesRange, seriesHigh/Low, seriesValue, seriesValues, firstValue — autoscale, magnet, legend and percent base read only through them), the painter in core/paint/series.ts (paintSeries; visible bars only, positions through bx/by), the legend in core/legend.ts and the colour of the last value (seriesColor at the end of core/chart.ts). Several of these handle every series with values in their default; a kind with other columns needs its own case there — grep -n "case 'band'" lists them all. Add a painter test against the recorder (src/test/recorder.ts).

Development

npm install
npm test          # vitest, in Node, no browser (351 tests)
npm run check     # svelte-check
npm run build     # dist/

The pictures in this README are drawn by the library from made-up prices; docs/showcase/ holds the page that makes them and how to run it.

Design and history: feature 003 (the library) and feature 005 (this package) in the strategies repository, docu/feat/.

Dependencies

Development Dependencies

ID Version
@sveltejs/package ^3.0.2
@sveltejs/vite-plugin-svelte ^7.2.0
@types/node ^26.6.5
svelte ^5.57.1
svelte-check ^4.6.0
typescript ^6.0.3
vite ^8.3.0
vitest ^5.0.4

Peer Dependencies

ID Version
svelte ^5.0.0
Details
npm
2026-11-11 14:35:19 +00:00
3
UNLICENSED
96 KiB
Assets (1)
Versions (9) View all
0.5.3 2026-11-14
0.5.2 2026-11-12
0.5.1 2026-11-12
0.5.0 2026-11-12
0.4.0 2026-11-12