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).
To create a Reactive Widget
import { ReactiveWidget } from "@john-guerra/reactive-widgets"
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;
}
Here are some other examples that follow (at least in part) the idea of reactive visualization widgets