MCPcopy Create free account
hub / github.com/microsoft/SandDance / markBitmaps

Function markBitmaps

docs/app/js/sanddance-app.js:138631–138650  ·  view source on GitHub ↗
($, avoidMarks, labelInside, isGroupArea)

Source from the content-addressed store, hash-verified

138629 ];
138630}
138631function markBitmaps($, avoidMarks, labelInside, isGroupArea) {
138632 // create canvas
138633 const width = $.width, height = $.height, border = labelInside || isGroupArea, context = (0, _vegaCanvas.canvas)(width, height).getContext("2d"); // render all marks to be avoided into canvas
138634 avoidMarks.forEach((items)=>draw(context, items, border)); // get canvas buffer, create bitmaps
138635 const buffer = new Uint32Array(context.getImageData(0, 0, width, height).data.buffer), layer1 = $.bitmap(), layer2 = border && $.bitmap(); // populate bitmap layers
138636 let x, y, u, v, alpha;
138637 for(y = 0; y < height; ++y)for(x = 0; x < width; ++x){
138638 alpha = buffer[y * width + x] & ALPHA_MASK;
138639 if (alpha) {
138640 u = $(x);
138641 v = $(y);
138642 if (!isGroupArea) layer1.set(u, v); // update interior bitmap
138643 if (border && alpha ^ INSIDE_OPACITY_IN_ALPHA) layer2.set(u, v); // update border bitmap
138644 }
138645 }
138646 return [
138647 layer1,
138648 layer2
138649 ];
138650}
138651function draw(context, items, interior) {
138652 if (!items.length) return;
138653 const type = items[0].mark.marktype;

Callers 1

labelLayoutFunction · 0.70

Calls 4

drawFunction · 0.70
$Function · 0.70
forEachMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected