Overlays have access to a specialized environment containing the current chart state.
$core
Contains core elements like data (full dataset), range, and view (visible range). It also provides layout for coordinate mapping.
draw() {
const layout = $core.layout
const data = $core.data
const view = $core.view
// Example: mapping data to coordinates
let x = layout.ti2x(p[0], i)
let y = layout.value2y(p[idx])
}
$props
Provides access to properties defined via prop(). If a property is passed via the props field of an OverlayObject, it overrides the script's default.
prop('color', { type: 'color', def: '#2d7b2f33' })
console.log($props.color) // #2d7b2f33
$lib
A collection of helper functions and primitives. For example, drawing candles:
$lib.candleWick(ctx, candleDescriptor, layout)
$lib.candleBody(ctx, candleDescriptor, layout)
$events
Used to interact with the MetaHub. For example, to lock or unlock scrolling:
$events.emit('scroll-lock', true) // Lock On
$events.emit('scroll-lock', false) // Lock Off
// Accessing $core in a draw loop
draw() {
const layout = $core.layout
const data = $core.data
const view = $core.view
// ...
}