Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed5e520

Browse files
authored
Merge pull request plotly#1440 from plotly/clear-parcoords-canvas-of-zero-panels
Clear parcoords canvas specially if no panels exist
2 parents 0cf2ee1 + bbd0d8c commit ed5e520

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/traces/parcoords/lines.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ module.exports = function(canvasGL, lines, canvasWidth, canvasHeight, initialDim
365365
}
366366
}
367367

368+
if(panelCount === 0) {
369+
// clear canvas here, as the panel iteration below will not enter the loop body
370+
clear(regl, 0, 0, canvasWidth, canvasHeight);
371+
}
372+
368373
for(I = 0; I < panelCount; I++) {
369374
var panel = panels[I];
370375
var dim1 = panel.dim1;
@@ -396,10 +401,23 @@ module.exports = function(canvasGL, lines, canvasWidth, canvasHeight, initialDim
396401
return pickPixel;
397402
}
398403

404+
function readPixels(canvasX, canvasY, width, height) {
405+
var pixelArray = new Uint8Array(4 * width * height);
406+
regl.read({
407+
x: canvasX,
408+
y: canvasY,
409+
width: width,
410+
height: height,
411+
data: pixelArray
412+
});
413+
return pixelArray;
414+
}
415+
399416
return {
400417
setColorDomain: setColorDomain,
401418
render: renderGLParcoords,
402419
readPixel: readPixel,
420+
readPixels: readPixels,
403421
destroy: regl.destroy
404422
};
405423
};

src/traces/parcoords/parcoords.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ function model(layout, d, i) {
127127
canvasOverdrag: c.overdrag * c.canvasPixelRatio
128128
});
129129

130-
var groupWidth = width * (domain.x[1] - domain.x[0]);
131-
var groupHeight = layout.height * (domain.y[1] - domain.y[0]);
130+
var groupWidth = Math.floor(width * (domain.x[1] - domain.x[0]));
131+
var groupHeight = Math.floor(layout.height * (domain.y[1] - domain.y[0]));
132132

133133
var pad = layout.margin || {l: 80, r: 80, t: 100, b: 80};
134134
var rowContentWidth = groupWidth;
43 Bytes
Loading

test/jasmine/tests/parcoords_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,36 @@ describe('parcoords', function() {
792792
});
793793
});
794794

795+
it('Calling `Plotly.restyle` with zero panels left should erase lines', function(done) {
796+
797+
var mockCopy = Lib.extendDeep({}, mock2);
798+
var gd = createGraphDiv();
799+
Plotly.plot(gd, mockCopy.data, mockCopy.layout);
800+
801+
function restyleDimension(key, dimIndex, setterValue) {
802+
var value = Lib.isArray(setterValue) ? setterValue[0] : setterValue;
803+
return function() {
804+
return Plotly.restyle(gd, 'dimensions[' + dimIndex + '].' + key, setterValue).then(function() {
805+
expect(gd.data[0].dimensions[dimIndex][key]).toEqual(value, 'for dimension attribute \'' + key + '\'');
806+
});
807+
};
808+
}
809+
810+
restyleDimension('values', 1, [[]])()
811+
.then(function() {
812+
d3.selectAll('.parcoords-lines').each(function(d) {
813+
var imageArray = d.lineLayer.readPixels(0, 0, d.model.canvasWidth, d.model.canvasHeight);
814+
var foundPixel = false;
815+
var i = 0;
816+
do {
817+
foundPixel = foundPixel || imageArray[i++] !== 0;
818+
} while(!foundPixel && i < imageArray.length);
819+
expect(foundPixel).toEqual(false);
820+
});
821+
done();
822+
});
823+
});
824+
795825
describe('Having two datasets', function() {
796826

797827
it('Two subsequent calls to Plotly.plot should create two parcoords rows', function(done) {

0 commit comments

Comments
 (0)