caelum0x 08c95c7806 fix(chart-core): allow a descending output range in createScale
createScale ran checkDomain on the output range, which forbids min > max — so
world-viewer's trajectoryPlotGeometry (which passes an inverted Y range
{min: height-padding, max: padding} to flip SVG's downward Y) threw "invalid
domain" for EVERY input. A range is not a domain: it may legitimately descend to
flip an axis. Added checkRange (finite + non-zero span, order-agnostic) and used
it for the range argument; checkDomain stays strict for the domain.

Tests: a descending range maps domain-min -> range.min and domain-max ->
range.max (axis flip), and a zero-span range is still rejected. chart-core 10
pass.
2026-08-18 23:03:38 +03:00
..
2026-08-16 22:04:11 +03:00
2026-08-16 22:04:11 +03:00
2026-08-16 22:04:11 +03:00
2026-08-16 22:04:11 +03:00
2026-08-16 22:04:11 +03:00
2026-08-16 22:04:11 +03:00

@lawsynth/chart-core

chart-core is a dependency-free TypeScript package for turning LawSynth numerical output into validated, renderer-neutral chart data. It deliberately does not include a canvas, SVG, DOM, browser event system, or browser rendering adapter.

It provides:

  • validated trajectories and named data series;
  • deterministic Largest-Triangle-Three-Buckets decimation for large traces;
  • linear and logarithmic coordinate transforms, padded domains, and readable ticks;
  • chart models, annotations, brushes, pan/zoom domains, legends, tooltips, phase portraits, heatmap grids, and dependency graphs;
  • CSV/JSON data export.

Usage

import { createChartModel, normalizeTrajectory, seriesFromAllTrajectoryComponents } from "@lawsynth/chart-core";

const trajectory = normalizeTrajectory({
  variables: ["x"], times: [0, 1, 2], values: [[0], [1], [0.4]],
});
const model = createChartModel({
  title: "State", series: seriesFromAllTrajectoryComponents(trajectory),
  xLabel: "time (s)", yLabel: "x",
});

ChartModel is intentionally data only. A React, D3, Canvas, WebGL, or server renderer may consume it, but rendering is outside this package. Inputs containing non-finite values, duplicate variables/series, invalid grid dimensions, or unordered series are rejected at the boundary rather than silently repaired.

Run npm test from this package to compile and execute the invariant tests.