Skip to content

Commit

Permalink
fix(core): categorical data in "link" mark misbehaved
Browse files Browse the repository at this point in the history
Closes #231
  • Loading branch information
tuner committed Feb 20, 2024
1 parent 98feeaf commit 14a4d8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/marks/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ export default class LinkMark extends Mark {
attribInfo.divisor
) {
attribInfo.offset =
offset * this.arrays[attribute].numComponents * 4; // gl.FLOAT in bytes
offset *
this.arrays[attribute].numComponents *
this.bytesPerElement.get(attribute);
}
}
setBuffersAndAttributes(
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/marks/mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export default class Mark {
*/
this.bufferInfo = undefined;

/**
* TWGL's BufferInfo doesn't contain the number of bytes per element,
* so we need to keep track of it separately. This is mainly used by
* the instancing hack in the link mark.
*
* @type {Map<string, number>}
* @protected
*/
this.bytesPerElement = new Map();

/**
* @type {import("twgl.js").ProgramInfo}
* @protected
Expand Down Expand Up @@ -788,6 +798,15 @@ export default class Mark {
{ numElements: vertexData.vertexCount }
);
this.bufferInfo.allocatedVertices = vertexData.allocatedVertices;

for (const [attribute, attributeData] of Object.entries(
vertexData.arrays
)) {
this.bytesPerElement.set(
attribute,
attributeData.data.BYTES_PER_ELEMENT
);
}
}
}

Expand Down

0 comments on commit 14a4d8d

Please sign in to comment.