MCPcopy Index your code
hub / github.com/plotly/plotly.js / drawMagnifiedPixelsOnCanvas

Function drawMagnifiedPixelsOnCanvas

src/traces/image/plot.js:91–122  ·  view source on GitHub ↗
(readPixel)

Source from the content-addressed store, hash-verified

89
90 // Create a new canvas and draw magnified pixels on it
91 function drawMagnifiedPixelsOnCanvas(readPixel) {
92 var canvas = document.createElement('canvas');
93 canvas.width = imageWidth;
94 canvas.height = imageHeight;
95 var context = canvas.getContext('2d', {willReadFrequently: true});
96
97 var ipx = function(i) {return Lib.constrain(Math.round(xa.c2p(x0 + i * dx) - left), 0, imageWidth);};
98 var jpx = function(j) {return Lib.constrain(Math.round(ya.c2p(y0 + j * dy) - top), 0, imageHeight);};
99
100 var cr = constants.colormodel[trace.colormodel];
101 var colormodel = (cr.colormodel || trace.colormodel);
102 var fmt = cr.fmt;
103 var c;
104 for(i = 0; i < cd0.w; i++) {
105 var ipx0 = ipx(i); var ipx1 = ipx(i + 1);
106 if(ipx1 === ipx0 || isNaN(ipx1) || isNaN(ipx0)) continue;
107 for(var j = 0; j < cd0.h; j++) {
108 var jpx0 = jpx(j); var jpx1 = jpx(j + 1);
109 if(jpx1 === jpx0 || isNaN(jpx1) || isNaN(jpx0) || !readPixel(i, j)) continue;
110 c = trace._scaler(readPixel(i, j));
111 if(c) {
112 context.fillStyle = colormodel + '(' + fmt(c).join(',') + ')';
113 } else {
114 // Return a transparent pixel
115 context.fillStyle = 'rgba(0,0,0,0)';
116 }
117 context.fillRect(ipx0, jpx0, ipx1 - ipx0, jpx1 - jpx0);
118 }
119 }
120
121 return canvas;
122 }
123
124 var image3 = plotGroup.selectAll('image')
125 .data([cd]);

Callers 1

plot.jsFile · 0.85

Calls 3

ipxFunction · 0.85
jpxFunction · 0.85
readPixelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…