Guías
Canales matemáticos
Canales de fórmula que se comportan como columnas, una vista previa en el editor y persistencia en tu backend.
Qué es un canal
Un canal matemático es una fórmula con nombre sobre columnas existentes. Aparece en state.numericColumns y cualquier gráfico puede representarlo. Se evalúa por conjunto de datos, así que las funciones de ventana nunca cruzan el límite de un conjunto de datos.
| Familia | Funciones |
|---|---|
| Aritmética | + − × ÷, abs, sqrt, exp, log, trigonometría, min, max, round, mod |
| Condicional | if, nullif, clamp |
| Ventana | derivative, integral, movavg, lag, lead |
| Filtros | lowpass y highpass de Butterworth |
FUNCTION_REFERENCE lista todas las funciones con su firma y descripción, lista para el panel de ayuda de un editor.
Crear y editar
const ch = engine.mathChannels.create({ name: 'speed_kmh', formula: 'speed * 3.6', units: 'km/h' })
engine.mathChannels.update(ch.id, { formula: 'lowpass(speed, 5) * 3.6' })
engine.mathChannels.update(ch.id, { enabled: false })
engine.mathChannels.remove(ch.id)
await engine.mathChannels.importMany(channelsFromYourApi)
const { channels, errors } = await engine.mathChannels.importFile(file) // a JSON export
const blob = engine.mathChannels.exportBlob()Vista previa del editor
import { newMathChannel, parseFormula } from '@kymoscope/sdk'
const parsed = parseFormula(input.value)
if (!parsed.ok) showError(parsed.message)
const draft = newMathChannel({ name: 'draft', formula: input.value })
const result = engine.mathChannels.preview(draft) // null when nothing is plotted
// result.status: 'ok' | 'missing-inputs' | 'parse-error' | 'runtime-error' | 'disabled' | 'references-channel'
// result.values: (number | null)[], result.missingCols, result.messageAlmacenar canales
Sin almacén, los canales viven en memoria durante la sesión. Con un MathChannelStoreAdapter, el motor aplica cada cambio localmente y llama a tu almacén; tú le devuelves la lista autorizada con sync cada vez que cambia.
const engine = createEngine({
mathChannels: {
create: (channel) => api.createChannel(channel),
update: (id, patch) => api.updateChannel(id, patch),
remove: (id) => api.deleteChannel(id),
importMany: (channels) => api.importChannels(channels),
},
})
engine.mathChannels.sync(await api.listChannels())
api.onChannelsChanged((list) => engine.mathChannels.sync(list))Un create, update o remove rechazado se notifica como un evento error (la llamada al motor ya ha devuelto). importMany e importFile esperan al almacén y se rechazan si este lo hace.