Reactive widgets allow you to build your visualization application in a more modular way, facilitating reusability and replicability of experiments.
Think of them as interactive building blocks for your visualizations!
A Reactive Visualization widget displays data and allows users to directly interact with it (e.g., select a bar in a bar chart π). It then emits events based on these interactions (e.g., signaling which bars are selected).
TL;DR Usage
To use within observable just
import { ReactiveWidget } from "@john-guerra/reactive-widgets"
// Outside of observable the easiest is to copy and pase
function MyWidget(
data, { value = 0 } = {}
) {
let widget;
const element = htl.html``; // β
Add here the code that creates your widget as an HTML element
function showValue() {
/* β
Add here the code that updates the current selection */
}
// π§° Then wrap your visualization (html element) with the reactive value
// and input events
let widget = ReactiveWidget(element.node(), { value, showValue });
// π§° Show the initial value
showValue();
// π§° Finally return the html element
return widget;
}