Having some trouble using functions from Observable Plot example with a marimekko chart in my TypeScript project. I encountered an error on this particular line:
setXz(I.map((i) => sum.get(X[i])))
The code snippet causing the issue is as follows:
function marimekko({ x, y, z, inset = 0.5, ...options }) {
const [Xz, setXz] = lazyChannel(z)
const {
y1,
y2,
transform: stackY,
} = Plot.stackY({ offset: "expand", x, y: z })
const {
x1,
x2,
transform: stackX,
} = Plot.stackX({ offset: "expand", y, x: Xz })
return {
x1,
x2,
y1,
y2,
transform: (data, facets) => {
const I = d3.range(data.length)
const X = Plot.valueof(data, x)
const Z = Plot.valueof(data, z)
const sum = d3.rollup(
I,
(I) => d3.sum(I, (i) => Z[i]),
(i) => X[i]
)
setXz(I.map((i) => sum.get(X[i])))
stackX(data, facets)
stackY(data, facets)
return { data, facets }
},
inset,
...options,
}
}
function lazyChannel(source) {
let value
return [
{
transform: () => value,
label:
typeof source === "string"
? source
: source
? source.label
: undefined,
},
(v) => (value = v),
]
}
Could anyone suggest a solution to resolve this error?