Index of every page on this site: llms.txt
All skills
luxalgo avatar

/using-vela-drawing-tools

@3d2179b
by luxalgoluxalgo/vela1.4k stars
285
Run it yourself

Works with the interactive drawing tools of Vela charts (@luxalgo/vela) - trend lines, horizontal lines, boxes, Fibonacci and Gann tools, pitchforks, patterns, annotations, positions and price-action zones - configuring the drawing toolbar, placing and editing drawings from code with chart.drawings, saving and restoring them, following drawing events, and adding a new drawing tool to Vela itself. Use when a Vela chart needs drawings shown, hidden, limited, created programmatically or persisted, when building a custom drawing toolbar, or when a new drawing tool is requested.

Use this Skill: https://skilld.dev/gh/luxalgo/vela/using-vela-drawing-tools

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈152 tokens for metadata: the name and description. ≈1.8k when used: this file.

Description uses 7.6% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈607 characters, or 7.6%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Using Vela drawing tools

Drawings are a model the chart owns: each one is plain JSON (type, time-and-price anchors, style), so it saves, restores, undoes and syncs without the renderer. Users place them from the drawing toolbar; code uses chart.drawings (in a workspace, ws.chart.drawings for the active cell).

The toolbar

new Vela('#chart', { data: bars, drawings: false });                              // no toolbar, API still works
new Vela('#chart', { data: bars, drawings: { tools: ['trendline', 'hline', 'box', 'fibretracement'] } });
new Vela('#chart', { data: bars, drawings: { groups: [{ id: 'mine', label: 'Mine', tools: ['trendline', 'ray'] }] } });

groups replaces the whole toolbar (and wins over tools when both are given). In a VelaWorkspace the same drawings option drives the one shared toolbar, and drawingToolbar: false hides that bar. Type keys are lowercase and fixed: lines (trendline, ray, hline, vline, extendedline), shapes (box is the rectangle, ellipse, triangle, polyline), annotations (text, note, callout, pricelabel), Fibonacci (fibretracement, fibextension), measure (datepricerange, and position, one tool for long and short positions), patterns (xabcd, headshoulders), price action (fairvaluegap, orderblock, liquidity). The full catalogue is in docs/user/drawing-tools.md.

Drawings from code

const d = chart.drawings;

// Place one: anchors are { time (epoch ms), price }. Returns the drawing, or null.
const line = d.add('trendline', {
    anchors: [{ time: bars[10]!.time, price: bars[10]!.low }, { time: bars[60]!.time, price: bars[60]!.low }],
    style: { lineColor: '#2962ff', lineWidth: 2, lineStyle: 'dashed', extendRight: true },
});
d.add('hline', {
    anchors: [{ time: bars.at(-1)!.time, price: 64000 }],
    text: { value: 'Resistance', size: 'normal', hAlign: 'right', vAlign: 'top' },
});

d.setTool('fibretracement');   // the user's next clicks place one; setTool(null) disarms
if (line) d.lock(line.id);
d.undo();

const off = chart.on('drawing:created', ({ id }) => console.log('drew', id));

Interactive methods (add, setTool, select, the toolbar) need a renderer that paints drawings: check chart.drawings.supported. Reading, fromJSON, update, remove and undo always work. A lock stops the user's gestures only: remove from code deletes a locked drawing. Drawings carry no owner field: to replace "the ones my code drew", keep their ids.

Saving and restoring

localStorage.setItem('drawings', JSON.stringify(chart.drawings.toJSON()));
chart.drawings.fromJSON(JSON.parse(localStorage.getItem('drawings') ?? 'null')); // untrusted input is safe

fromJSON replaces every drawing and keeps their ids; a missing or invalid document restores an empty chart. It clears the undo history and fires no drawing:* event.

  • A VelaWorkspace with persist: true saves drawings, tool settings and saved styles for you.

  • Drawings belong to the chart, not the symbol. They stay through a symbol switch. To keep a set per symbol, track the symbol yourself (chart.market already names the next one while it loads) and swap on market:changed, which also fires on a timeframe-only switch:

    let symbol = chart.market.symbol ?? '';
    const key = (s: string) => `drawings:${s}`;
    chart.on('market:changed', ({ symbol: next }) => {
        if (next === symbol) return;                               // a timeframe switch
        localStorage.setItem(key(symbol), JSON.stringify(chart.drawings.toJSON()));
        symbol = next;
        chart.drawings.fromJSON(JSON.parse(localStorage.getItem(key(symbol)) ?? 'null'));
    });
  • A drawing's showOn (timeframe bands) limits the timeframes it shows on: d.update(id, { showOn: [...] }).

A toolbar of your own

Hide Vela's bar (drawings: { toolbar: false }), call setTool(type) from your buttons, and mirror the state from the events: drawing:tool (armed tool), drawing:snap (magnet), drawing:stay (stay in drawing mode), drawing:mode (measure or eraser), drawing:selected. Show your shortcuts in Vela's flyouts with d.setToolShortcuts({ trendline: 'Alt+T' }).

Adding a new drawing tool

A new tool is added to Vela's source, in the Vela repository. registerDrawingType is exported, but it takes only the existing type keys (a closed union), the base classes a tool extends are internal, and the native painter draws only the families it knows: a host application cannot add a working tool through the public API. Instead:

  • marks users do not edit (signals, zones computed from data): draw them from an indicator (lines, boxes and labels in a native indicator's output; the adding-vela-indicators skill);
  • a house style for a zone users place: the box tool with a fill and text, offered through d.setToolDefaults(...) or a saved style (d.setToolTemplates(...));
  • a genuinely new tool: contribute it to the Vela repository, in five steps.

The five steps, all under src/core/drawings/:

  1. Key: add the type's string to the DrawingTypeKey union in Drawing.ts.

  2. Class in types/: extend the closest base, so the leaf only states what is unique:

    Base For The leaf supplies
    SegmentDrawing multi-line tools (channels, pitchforks) geometry(proj): segments and an optional fill
    FibRatios Fibonacci tools defaultLevels(), entryLines(proj)
    PatternDrawing / HarmonicPattern labelled vertex patterns vertexLabels() / patternName() and ranges()
    CalloutBase, PinnedLabel, GlyphStamp annotations and stamps the type, a default label or glyph
    Drawing a shape like no other every geometry method and schema()
  3. Register in registry.ts: registerDrawingType({ type, group, label, icon, defaultStyle, create }). One call makes both the factory and the toolbar entry; group picks the toolbar group.

  4. Export the class from index.ts.

  5. Paint only a new look: a type extending an existing family is painted already; a new visual needs a branch in src/renderers/native/drawings/DrawingPainter.ts.

Keep the class free of renderer imports and pixels: anchors are time and price, geometry is computed through the Projector it is given. Interaction (placementMode()), the settings panel (schema()), persistence, undo and copy-paste then work without more code. Add tests next to test/drawings-*.test.ts, a row to the catalogue in docs/user/drawing-tools.md, and run npm run i18n:extract for a label written with msg().

Check your work

  1. chart.drawings.all() holds the drawing with the anchors you gave, and chart.inspect() lists it among the generated drawings.
  2. Restore round trip: fromJSON(toJSON()) on a fresh chart gives the same all().
  3. In the browser, the drawing paints where its anchors are, its handles drag, and its settings panel opens on double-click.

Further reading

  • node_modules/@luxalgo/vela/docs/user/drawing-tools.md: every tool, toolbar behavior, keyboard shortcuts, depth in the stack.
  • node_modules/@luxalgo/vela/docs/user/api-reference.md (section chart.drawings): every method and event.
  • node_modules/@luxalgo/vela/docs/contributing/adding-a-drawing-tool.md: the seam in detail.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts16d3 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides instructions for managing interactive drawing tools within Vela charts using the @luxalgo/vela library. It includes examples for toolbar configuration, programmatic drawing creation, and local state persistence.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

Signed by skilld at 3d2179b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 3 weeks ago

README badge

README badge for luxalgo/vela/using-vela-drawing-tools