function createAxisConfiguration(regl) {
const configureAxes = regl({
uniforms: {
view: regl.prop("view"),
viewInverse: regl.prop("viewInverse")
},
context: {
view: regl.prop("view"),
viewInverse: regl.prop("viewInverse")
},
scissor: {
enable: true,
box: {
x: ({ pixelRatio }, { xRange: [xmin, xmax] }) => xmin * pixelRatio,
y: ({ pixelRatio, framebufferHeight }, { yRange: [ymax, ymin] }) =>
framebufferHeight - ymax * pixelRatio,
width: ({ pixelRatio }, { xRange: [xmin, xmax] }) =>
(xmax - xmin) * pixelRatio,
height: ({ pixelRatio }, { yRange: [ymax, ymin] }) =>
(ymax - ymin) * pixelRatio
}
},
viewport: {
x: ({ pixelRatio }, { xRange: [xmin, xmax] }) => xmin * pixelRatio,
y: ({ pixelRatio, framebufferHeight }, { yRange: [ymax, ymin] }) =>
framebufferHeight - ymax * pixelRatio,
width: ({ pixelRatio }, { xRange: [xmin, xmax] }) =>
(xmax - xmin) * pixelRatio,
height: ({ pixelRatio }, { yRange: [ymax, ymin] }) =>
(ymax - ymin) * pixelRatio
}
});
const view = mat4create();
const viewInverse = mat4create();
return function (xScale, yScale, callback) {
mat4ortho(view, ...xScale.domain, ...yScale.domain, -1, 1);
mat4invert(viewInverse, view);
configureAxes(
{ view, viewInverse, xRange: xScale.range, yRange: yScale.range },
callback
);
};
}