- TypeScript 73.1%
- Python 21.5%
- JavaScript 3.1%
- HTML 2.3%
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> |
||
|---|---|---|
| demo | ||
| docs | ||
| editor | ||
| python | ||
| samples | ||
| schema | ||
| scripts | ||
| src | ||
| .gitignore | ||
| esbuild.mjs | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
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.jsonand 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). Noschema:mode to switch into, no secondEcon*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.