Public
Edited
Jul 25, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gem = ({
//"meta": {"name": "All at once"},
staggerings: [
{
name: "a",
by: "year_in",
order: "ascending", // step ? "ascending" : "descending",
overlap: 0 //0.7
}
],
timeline: {
concat: [
...(step
? [
{
component: { mark: "layer_0_marks" }, // rect
change: {
data: false,
//data: { keys: ["year_in", "formula"] },
encode: {
update: { y: false, y2: false },
enter: false,
exit: false
}
},
timing: { duration: 200 }
}
]
: []),

{
component: { mark: "layer_0_marks" }, // rect
change: {
//data: { keys: ["year_in", "formula"] },
encode: {
update: { opacity: false }
// enter: true, // for now
//exit: true
}
},
timing: { staggering: "a", duration: { ratio: 1 } }
},

{
component: { mark: "layer_1_marks" },
timing: { duration: { ratio: 0.7 } }
},

{
component: { mark: "layer_2_marks" },
timing: { duration: { ratio: 0.7 } }
},

...(!step
? [
{
component: { mark: "layer_0_marks" }, // rect
change: {
data: false,
//data: { keys: ["year_in", "formula"] },
encode: {
update: { y: false, y2: false },
enter: false,
exit: false
}
},
timing: { duration: 200 }
}
]
: [])
]
},
totalDuration: 2200
})
Insert cell
{
if (step != mutable v0) {
console.log("RUNNING");
const animation = await gemini.animate(mapped[v0], mapped[step], gem);
await animation.play("#view");
setV0(step);
console.log("done");
}
}
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
Insert cell
Insert cell
gemini.animate(mapped[0], mapped[1], gem)
Insert cell
//gemini.animate(mapped[0], mapped[1], gem)
Insert cell
spec0.marks.map((d) => d.name)
Insert cell
viewof chart = embed("#view", mapped[v0], { renderer: "svg" })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable v0 = 0
Insert cell
v1 = step
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
introspection1 = await calculang.introspection("entrypoint.cul.js", fs1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
projection0_ = helpers.calcudata({
models: [model0],
outputs: ["premiums", "mclaims", "profit", "mΔreserve"],
input_domains: { year_in: _.range(0, 21 + 0.1, 1) },
input_cursors: [cursor, cursor] // for update in enter/exit/update pattern to match
//pivot: true
})
//.filter((d) => d.formula == "profit" || Math.abs(d.value) > 0.001)
Insert cell
projection0 = aq
.from(projection0_)
.groupby(["year_in", "formula"])
.orderby("input_cursor_id")
.derive({ A: (d) => aq.op.lag(d.value, 1, 0), B: (d) => d.value })
.filter((d) => d.input_cursor_id == 1)
.derive({
keep: (
d // =IF(C6<0,MIN(0,MAX(D6,C6)),IF(C6>0,MAX(0,MIN(D6,C6))))
) => {
if (d.A < 0) return Math.min(0, Math.max(d.A, d.B));
return Math.max(0, Math.min(d.A, d.B));
},
add: (d) => Math.max(0, d.B - d.A),
subtract: (d) => Math.max(0, d.A - d.B)
})
.fold(["A", "B", "keep", "add", "subtract"], { as: ["partition", "value"] })
Insert cell
projection1_ = helpers.calcudata({
models: [model0],
outputs: ["premiums", "mclaims", "profit", "mΔreserve"],
input_domains: { year_in: _.range(0, 21 + 0.1, 1) },
input_cursors: [cursor, { ...cursor, limit_in: 0 }] // for update in enter/exit/update pattern to match
//pivot: true
})
//.filter((d) => d.formula == "profit" || Math.abs(d.value) > 0.001)
Insert cell
Insert cell
cursor = ({ premiums_fn_in:() => premiums, claims_fn_in:() => claims, point_id_in: 0, adverse_reserve_factor_in:0, limit_in:10000 })
Insert cell
premiums = [0, ..._.range(0, 19.1).map((year) => 100 - year * 1.5)]
Insert cell
claims = [0, ..._.range(0, 19.1).map((year) => 1.35 ** year)]
Insert cell
mapped[0]
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more