No description
  • TypeScript 73.1%
  • Python 21.5%
  • JavaScript 3.1%
  • HTML 2.3%
Find a file
Bogac Celen ce73f52521
Add Bertrand–Edgeworth sample: capacity resolves the paradox
Companion to the pure Bertrand paradox: homogeneous goods, constant cost c,
demand Q = a - p, with a capacity limit on each firm. Capacity is set as a
share of the Cournot output q^C = (a-c)/3, so both firms' capacity always
binds and the market clears total capacity at p = a - K1 - K2 — a clean
pure-strategy equilibrium, no iteration. At full capacity (share = 1) price
equals the Cournot price (Kreps–Scheinkman); tightening capacity slides the
equilibrium up the demand curve toward the choke price.

Capping capacity at the Cournot quantity keeps the sim inside the region with
a pure-strategy equilibrium: the intermediate band (a-c)/3 < K < a-c has none
(Edgeworth cycles), and only K >= a-c restores the paradox. The sidebar names
both boundaries. Shows demand, the p=c line, the Cournot and paradox
reference points, the equilibrium, and each firm's profit rectangle split by
capacity.

Registered in the builder menu next to the other Bertrand samples; gallery
auto-includes it (30 samples). Verified headless: renders with no NaN and no
console errors; valid in the builder through every slider extreme; economics
checked numerically (share=1 -> Cournot price 53.3 at a=120,c=20).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-07 01:30:30 +00:00
demo Bertrand paradox: add best-response panel, minimum price increment 1 2026-07-17 06:12:10 +00:00
docs deployment.md: fix Caddy directive (encode, not encoding) 2026-07-20 01:18:26 +00:00
editor Add sequential-game (tree) builder mode + Stackelberg continuous sample 2026-07-19 14:48:53 +00:00
python Repeated-game builder mode + Python generators for the new library 2026-07-20 00:48:23 +00:00
samples Add Bertrand–Edgeworth sample: capacity resolves the paradox 2026-08-07 01:30:30 +00:00
schema Add 'annotation' object: LaTeX callouts anchored to data coordinates 2026-07-19 13:12:31 +00:00
scripts Manual: add 'Embedding & sharing' page 2026-07-19 12:49:42 +00:00
src Add Bertrand–Edgeworth sample: capacity resolves the paradox 2026-08-07 01:30:30 +00:00
.gitignore Deployment: static gallery site, self-contained per-graph export, user manual 2026-07-19 10:18:32 +00:00
esbuild.mjs Add 'Download standalone HTML' button to the builder and code editor 2026-07-19 10:47:22 +00:00
LICENSE Initial commit: spec-driven runtime, JSON spec contract, LinearDemand macro, migrated surplus and tr_mr_ar samples 2026-07-15 07:56:40 +00:00
package-lock.json Deployment: static gallery site, self-contained per-graph export, user manual 2026-07-19 10:18:32 +00:00
package.json Deployment: static gallery site, self-contained per-graph export, user manual 2026-07-19 10:18:32 +00:00
README.md Deployment: static gallery site, self-contained per-graph export, user manual 2026-07-19 10:18:32 +00:00
tsconfig.json Initial commit: spec-driven runtime, JSON spec contract, LinearDemand macro, migrated surplus and tr_mr_ar samples 2026-07-15 07:56:40 +00:00

kgjs-next

A spec-driven engine for interactive economics graphs. Clean-cut fork of Chris Makler's KineticGraphs, rebuilt around a single typed JSON spec, signal-based reactivity, and a modern build. Intended for teaching managerial economics and game theory.

Name is a working placeholder. Change it in package.json and this file.

What is different from the original

  • One language. There is a single list of primitive objects (curve, line, point, area, rectangle, arrow, segment, label). No schema: mode to switch into, no second Econ* vocabulary.
  • The spec is the contract. A small, versioned, JSON-Schema-validated graph spec is the only thing the runtime consumes. Authoring errors are surfaced, not swallowed to the console.
  • Reactivity is a real primitive. Params are signals; one effect rebuilds the scope and redraws through a single update path. No double-recompute, compiled expressions are cached.
  • No economics in the runtime. Domain conveniences are optional macros (e.g. LinearDemand) that expand to primitives before the runtime runs. Drop a macro and nothing economics-specific remains.
  • Modern toolchain. TypeScript (ES modules, strict), esbuild bundle, D3 v7, mathjs, KaTeX.

Build and run

npm install
npm run build      # -> dist/kg.js (global KG) and dist/kg.esm.js
npm run typecheck

Then open demo/index.html in a browser.

Authoring

A graph is a JSON object: params (adjustable variables), derived (expressions over params), axes or panels, objects, and an optional sidebar. Every numeric field may be an expression string over the flat scope. Interactivity is not a separate concept: a slider is any param with min/max, a drag is a draggable binding on a point. See schema/graph-spec.schema.json for the full contract and samples/ for worked examples.

Macros are optional, transparent sugar

LinearDemand expands to plain line primitives and injects the inverse-demand values (yIntercept, slope, xIntercept) as ordinary derived scope entries. It is opt-in and its output is documented, not a hidden schema. demo/tr_mr_ar.html is authored without it (everything explicit); demo/linear-demand.html shows the same idea with it.

Site and deployment

npm run site builds a static site into site/: a gallery of every graph, a fully self-contained HTML page per graph (engine + fonts + spec inlined, opens offline with no dependencies), the visual builder, the code editor, and the HTML user manual. Serve site/ on any static host (Forgejo pages, etc.). See docs/deployment.md for the publish steps, and docs/manual/ for the manual sources.

Status

Runtime, spec contract, validation, the macro layer, a full set of managerial-economics and game-theory samples, a Python/SymPy authoring layer that emits the same spec, a visual builder and code editor, and a deployable gallery + manual site. See claude/kgjs-fork-increment-*.md in the project for the build history.

Lineage and license

MIT. Forked from KineticGraphs (kgjs) by Chris Makler; original copyright retained in LICENSE.