Public
Edited
Aug 8, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
basicStatefulTranslate = function(target_pos, state, make_position_interpolator) {
return function (d, i, nodes) {

const current_pos = state.pos
const interpolate_position = make_position_interpolator(current_pos, target_pos)
return t => {
const position = interpolate_position(t)
// Object.assign(pos_state, (({x,y}) => ({x,y}))(position))
state.pos = position

return `translate (${position.x}, ${position.y})`
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
multiStatefulTranslate = function(local, make_position_interpolator, target_position_accessor) {
return function (d, i, nodes) {
const current_position = local.get(this)
const interpolate_position = make_position_interpolator(current_position, target_position_accessor(d))
return t => {
const position = interpolate_position(t)
local.set(this, position)
return `translate (${position.x}, ${position.y})`
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
statefulTransition = function (
state_local,
interpolator_factory,
output_callback,
target_state_accessor = (d) => d
) {
return function (d, i, nodes) {
const initial_state = state_local.get(this);
const target_state = target_state_accessor(d)
const interpolate_state = interpolator_factory(
initial_state,
target_state,
);

return (t) => {
const interpolated_state = interpolate_state(t);
state_local.set(this, interpolated_state);
return output_callback(interpolated_state, initial_state, target_state);
// TODO: write up how including these extra parameters enables more flexible use e.g. with .tween
};
};
}
Insert cell
statefulTranslate = function (local, make_position_interpolator, target_position_accessor) {
const translateCallback = (position) => `translate (${position.x}, ${position.y})`
return statefulTransition(local, make_position_interpolator, translateCallback, target_position_accessor);
}
Insert cell
Insert cell
Insert cell
statefulTransition2 = function (
state_local,
interpolator_factory,
output_callback,
target_state_accessor = (d) => d
) {
return function (d, i, nodes) {
const initial_state = state_local.get(this);
const target_state = target_state_accessor(d)
const interpolate_state = interpolator_factory(
initial_state,
target_state,
);

return (t) => {
const interpolated_state = interpolate_state(t);
state_local.set(this, {initial: initial_state,
target: target_state,
t: t}
);
return output_callback(interpolated_state, initial_state, target_state);
};
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
timer = {
while (true) {
yield
await Promises.delay(1800)
}
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more