|
| 1 | +var Plotly = require('@lib'); |
1 | 2 | var Lib = require('@src/lib');
|
2 |
| -var supplyAllDefaults = require('../assets/supply_defaults'); |
3 | 3 | var Plots = require('@src/plots/plots');
|
| 4 | +var SUBPLOT_PATTERN = require('@src/plots/cartesian/constants').SUBPLOT_PATTERN; |
4 | 5 |
|
5 |
| -var Plotly = require('@lib'); |
| 6 | +var d3 = require('d3'); |
| 7 | +var supplyAllDefaults = require('../assets/supply_defaults'); |
6 | 8 | var createGraphDiv = require('../assets/create_graph_div');
|
7 | 9 | var destroyGraphDiv = require('../assets/destroy_graph_div');
|
8 | 10 | var failTest = require('../assets/fail_test');
|
@@ -404,4 +406,87 @@ describe('@gl Test splom interactions:', function() {
|
404 | 406 | .catch(failTest)
|
405 | 407 | .then(done);
|
406 | 408 | });
|
| 409 | + |
| 410 | + it('should update properly in-and-out of hasOnlyLargeSploms regime', function(done) { |
| 411 | + var figLarge = Lib.extendDeep({}, require('@mocks/splom_large.json')); |
| 412 | + var dimsLarge = figLarge.data[0].dimensions; |
| 413 | + var dimsSmall = dimsLarge.slice(0, 5); |
| 414 | + var cnt = 1; |
| 415 | + |
| 416 | + function _assert(exp) { |
| 417 | + var msg = ' - call #' + cnt; |
| 418 | + var subplots = d3.selectAll('g.cartesianlayer > g.subplot'); |
| 419 | + |
| 420 | + expect(subplots.size()) |
| 421 | + .toBe(exp.subplotCnt, '# of <g.subplot>' + msg); |
| 422 | + |
| 423 | + var failedSubplots = []; |
| 424 | + subplots.each(function(d, i) { |
| 425 | + var actual = this.children.length; |
| 426 | + var expected = typeof exp.innerSubplotNodeCnt === 'function' ? |
| 427 | + exp.innerSubplotNodeCnt(d, i) : |
| 428 | + exp.innerSubplotNodeCnt; |
| 429 | + if(actual !== expected) { |
| 430 | + failedSubplots.push([d, actual, 'vs', expected].join(' ')); |
| 431 | + } |
| 432 | + }); |
| 433 | + expect(failedSubplots) |
| 434 | + .toEqual([], '# of nodes inside <g.subplot>' + msg); |
| 435 | + |
| 436 | + expect(!!gd._fullLayout._splomGrid) |
| 437 | + .toBe(exp.hasSplomGrid, 'has regl-line2d splom grid' + msg); |
| 438 | + |
| 439 | + cnt++; |
| 440 | + } |
| 441 | + |
| 442 | + Plotly.plot(gd, figLarge).then(function() { |
| 443 | + _assert({ |
| 444 | + subplotCnt: 400, |
| 445 | + innerSubplotNodeCnt: 5, |
| 446 | + hasSplomGrid: true |
| 447 | + }); |
| 448 | + return Plotly.restyle(gd, 'dimensions', [dimsSmall]); |
| 449 | + }) |
| 450 | + .then(function() { |
| 451 | + _assert({ |
| 452 | + subplotCnt: 25, |
| 453 | + innerSubplotNodeCnt: 17, |
| 454 | + hasSplomGrid: false |
| 455 | + }); |
| 456 | + |
| 457 | + // make sure 'new' subplot layers are in order |
| 458 | + var gridIndex = -1; |
| 459 | + var xaxisIndex = -1; |
| 460 | + var subplot0 = d3.select('g.cartesianlayer > g.subplot').node(); |
| 461 | + for(var i in subplot0.children) { |
| 462 | + var cl = subplot0.children[i].classList; |
| 463 | + if(cl) { |
| 464 | + if(cl.contains('gridlayer')) gridIndex = +i; |
| 465 | + else if(cl.contains('xaxislayer-above')) xaxisIndex = +i; |
| 466 | + } |
| 467 | + } |
| 468 | + // from large -> small splom: |
| 469 | + // grid layer would be above xaxis layer, |
| 470 | + // if we didn't clear subplot children. |
| 471 | + expect(gridIndex).toBe(1, '<g.gridlayer> index'); |
| 472 | + expect(xaxisIndex).toBe(14, '<g.xaxislayer-above> index'); |
| 473 | + |
| 474 | + return Plotly.restyle(gd, 'dimensions', [dimsLarge]); |
| 475 | + }) |
| 476 | + .then(function() { |
| 477 | + _assert({ |
| 478 | + subplotCnt: 400, |
| 479 | + // from small -> large splom: |
| 480 | + // no need to clear subplots children in existing subplots, |
| 481 | + // new subplots though have reduced number of children. |
| 482 | + innerSubplotNodeCnt: function(d) { |
| 483 | + var p = d.match(SUBPLOT_PATTERN); |
| 484 | + return (p[1] > 5 || p[2] > 5) ? 5 : 17; |
| 485 | + }, |
| 486 | + hasSplomGrid: true |
| 487 | + }); |
| 488 | + }) |
| 489 | + .catch(failTest) |
| 490 | + .then(done); |
| 491 | + }); |
407 | 492 | });
|
0 commit comments