autobit-talisman
v0.0.1
Published
**Autobit Talisman** is a high-performance, modular charting and visualization library for the web. It is designed to be **event-driven** and **flexible**, allowing you to compose complex financial charts and data visualizations using a Registry-based arc
Readme
Autobit Talisman
Autobit Talisman is a high-performance, modular charting and visualization library for the web. It is designed to be event-driven and flexible, allowing you to compose complex financial charts and data visualizations using a Registry-based architecture.
Installation
npm install autobit-talismanQuick Start
Basic Usage
The easiest way to use Talisman is via the Runtime to bootstrap a chart from a simple configuration.
import { Runtime } from 'autobit-talisman';
// 1. Initialize Runtime with a container ID
const runtime = new Runtime('chart-container');
// 2. Define a Manifest (or load from JSON)
const manifest = {
objects: {
'MyChart': MyChartClass // Or a path string if using dynamic loading
},
scripts: {
'main': MyScriptClass
}
};
// 3. Boot
await runtime.boot('main', manifest);API Reference (src/index.ts)
Core
Runtime: The main entry point. Orchestrates theRegistry,PlaneManager, andInputManager. It handles booting the application from a manifest.Registry: A central repository for registering factory functions for Objects, Sources, and Triggers. Allows decoupling implementation from configuration.InputManager: Handles mouse and pointer events on the chart container, delegating them to thePlaneManagerand individual Render Objects.ALScriptEngine: An engine for executing AL (Algorithm Language) scripts (legacy/optional).
Planes & Rendering
PlaneManager: Manages multiplePlanelayers (canvases). It efficiently handles rendering only when needed (dirty-render pattern).createPlane(name, zIndex): Creates a new drawing layer.requestRender(): Triggers a render loop for the next animation frame.
Plane: A single canvas layer. Manages a list ofRenderObjects, coordinate spaces (Time/Price scales), and camera state (Zoom/Pan).RenderObject(Interface): The contract for anything drawn on the screen.render(ctx): Draw logic.hitTest(x, y): Interaction detection.
LineObject,TextObject: Primitive render implementations.
Data & Triggers
DataSource: Base class for data feeds (e.g., WebSocket, REST).TriggerChain: Manages a pipeline of triggers attempting to process data packets.
The Registry System (Detailed Demo)
The Registry is the heart of Talisman's modularity. It allows you to define "Blueprints" for your chart components and instantiate them dynamically. This is useful for building data-driven dashboards or saving/loading chart configurations.
1. Defining a Render Object
Create a class that implements RenderObject.
import { RenderObject, RenderContext, PlaneManager, Registry } from 'autobit-talisman';
export class MyCustomIndicator implements RenderObject {
id: string;
visible = true;
zIndex = 10;
constructor(id: string, private manager: PlaneManager, registry: Registry) {
this.id = id;
}
render(context: RenderContext) {
const { ctx, width, height } = context;
// Draw a red line across the screen
ctx.beginPath();
ctx.strokeStyle = 'red';
ctx.moveTo(0, height / 2);
ctx.lineTo(width, height / 2);
ctx.stroke();
}
}2. Registering the Object
Register the factory function with your Runtime's Registry.
// Ideally, do this in a manifest or setup phase
const manifest = {
objects: {
'CustomIndicator': MyCustomIndicator // Direct Class Reference
},
// ... sources, scripts
};3. Instantiating via Registry
You can now create instances of this object by string name. This is powerful for scripting or configuration files.
// Inside a Script or Setup function
const indicator = runtime.registry.createObject('CustomIndicator', 'my-indicator-1');
plane.addObject(indicator);4. Advanced: Dynamic Loading via Manifest
Talisman's Runtime can automatically scan a project or accept a JSON manifest to wire everything up.
manifest.json
{
"objects": {
"Candles": "./charts/CandleStick.ts",
"Volume": "./charts/Volume.ts"
},
"scripts": {
"init": "./scripts/Init.ts"
}
}Init.ts
export class Init {
run(context: any) {
const { registry } = context;
// Create objects defined in manifest
const candles = registry.createObject('Candles', 'main-candles');
return [candles]; // Return objects to add to the main plane
}
}This architecture allows you to build an entire trading platform where charts, indicators, and tools are just plugins in the Registry.
