|
1 | | -// var Plotly = require('@lib/index'); |
| 1 | +var Plotly = require('@lib/index'); |
2 | 2 | var Plots = require('@src/plots/plots'); |
3 | | -// var Lib = require('@src/lib'); |
| 3 | +var Lib = require('@src/lib'); |
4 | 4 |
|
5 | 5 | var Carpet = require('@src/traces/carpet'); |
6 | 6 | var smoothFill2D = require('@src/traces/carpet/smooth_fill_2d_array'); |
7 | 7 | var smoothFill = require('@src/traces/carpet/smooth_fill_array'); |
8 | | -// var calc = require('@src/traces/carpet/calc'); |
9 | 8 |
|
| 9 | +var d3 = require('d3'); |
10 | 10 | var customMatchers = require('../assets/custom_matchers'); |
11 | | - |
12 | | -// var d3 = require('d3'); |
13 | | -// var createGraphDiv = require('../assets/create_graph_div'); |
14 | | -// var destroyGraphDiv = require('../assets/destroy_graph_div'); |
15 | | -// var customMatchers = require('../assets/custom_matchers'); |
16 | | - |
17 | | -var test = { |
18 | | - supplyDefaults: false, |
19 | | - smoothFill2D: true |
20 | | -}; |
| 11 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 12 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 13 | +var fail = require('../assets/fail_test'); |
21 | 14 |
|
22 | 15 | describe('carpet supplyDefaults', function() { |
23 | | - if(!test.supplyDefaults) return; |
24 | 16 | 'use strict'; |
25 | 17 |
|
26 | 18 | var traceIn, |
@@ -55,7 +47,6 @@ describe('carpet supplyDefaults', function() { |
55 | 47 | expect(traceOut.db).toBeUndefined(); |
56 | 48 | expect(traceOut.a0).toBeUndefined(); |
57 | 49 | expect(traceOut.b0).toBeUndefined(); |
58 | | - expect(traceOut.visible).toBe(true); |
59 | 50 | }); |
60 | 51 |
|
61 | 52 | it('sets a0/da when a not provided', function() { |
@@ -222,7 +213,6 @@ describe('supplyDefaults visibility check', function() { |
222 | 213 | }); |
223 | 214 |
|
224 | 215 | describe('carpet smooth_fill_2d_array', function() { |
225 | | - if(!test.smoothFill2D) return; |
226 | 216 | var _; |
227 | 217 |
|
228 | 218 | beforeAll(function() { jasmine.addMatchers(customMatchers); }); |
@@ -389,7 +379,6 @@ describe('carpet smooth_fill_2d_array', function() { |
389 | 379 | }); |
390 | 380 |
|
391 | 381 | describe('smooth_fill_array', function() { |
392 | | - if(!test.smoothFill2D) return; |
393 | 382 | var _; |
394 | 383 |
|
395 | 384 | beforeAll(function() { jasmine.addMatchers(customMatchers); }); |
@@ -430,3 +419,96 @@ describe('smooth_fill_array', function() { |
430 | 419 | .toBeCloseToArray([0, 1, 2, 3]); |
431 | 420 | }); |
432 | 421 | }); |
| 422 | + |
| 423 | +describe('Test carpet interactions:', function() { |
| 424 | + var gd; |
| 425 | + |
| 426 | + beforeEach(function() { |
| 427 | + gd = createGraphDiv(); |
| 428 | + }); |
| 429 | + |
| 430 | + afterEach(destroyGraphDiv); |
| 431 | + |
| 432 | + function countCarpets() { |
| 433 | + return d3.select(gd).selectAll('.carpetlayer').selectAll('.trace').size(); |
| 434 | + } |
| 435 | + |
| 436 | + function countContourTraces() { |
| 437 | + return d3.select(gd).selectAll('.contour').size(); |
| 438 | + } |
| 439 | + |
| 440 | + it('should restyle visible attribute properly', function(done) { |
| 441 | + var mock = Lib.extendDeep({}, require('@mocks/cheater.json')); |
| 442 | + |
| 443 | + Plotly.plot(gd, mock) |
| 444 | + .then(function() { |
| 445 | + expect(countCarpets()).toEqual(1); |
| 446 | + expect(countContourTraces()).toEqual(3); |
| 447 | + |
| 448 | + return Plotly.restyle(gd, 'visible', false, [2, 3]); |
| 449 | + }) |
| 450 | + .then(function() { |
| 451 | + expect(countCarpets()).toEqual(1); |
| 452 | + expect(countContourTraces()).toEqual(1); |
| 453 | + |
| 454 | + return Plotly.restyle(gd, 'visible', true); |
| 455 | + }) |
| 456 | + .then(function() { |
| 457 | + expect(countCarpets()).toEqual(1); |
| 458 | + expect(countContourTraces()).toEqual(3); |
| 459 | + |
| 460 | + return Plotly.restyle(gd, 'visible', false); |
| 461 | + }) |
| 462 | + .then(function() { |
| 463 | + expect(countCarpets()).toEqual(0); |
| 464 | + expect(countContourTraces()).toEqual(0); |
| 465 | + }) |
| 466 | + .catch(fail) |
| 467 | + .then(done); |
| 468 | + }); |
| 469 | + |
| 470 | + it('should add/delete trace properly', function(done) { |
| 471 | + var mock = Lib.extendDeep({}, require('@mocks/cheater.json')); |
| 472 | + var trace1 = Lib.extendDeep({}, mock.data[1]); |
| 473 | + |
| 474 | + Plotly.plot(gd, mock) |
| 475 | + .then(function() { |
| 476 | + expect(countCarpets()).toEqual(1); |
| 477 | + expect(countContourTraces()).toEqual(3); |
| 478 | + |
| 479 | + return Plotly.deleteTraces(gd, [1]); |
| 480 | + }) |
| 481 | + .then(function() { |
| 482 | + expect(countCarpets()).toEqual(1); |
| 483 | + expect(countContourTraces()).toEqual(2); |
| 484 | + |
| 485 | + return Plotly.addTraces(gd, trace1); |
| 486 | + }) |
| 487 | + .then(function() { |
| 488 | + expect(countCarpets()).toEqual(1); |
| 489 | + expect(countContourTraces()).toEqual(3); |
| 490 | + |
| 491 | + return Plotly.deleteTraces(gd, [0, 1, 2, 3]); |
| 492 | + }) |
| 493 | + .then(function() { |
| 494 | + expect(countCarpets()).toEqual(0); |
| 495 | + expect(countContourTraces()).toEqual(0); |
| 496 | + }) |
| 497 | + .catch(fail) |
| 498 | + .then(done); |
| 499 | + }); |
| 500 | + |
| 501 | + it('should respond to relayout properly', function(done) { |
| 502 | + var mock = Lib.extendDeep({}, require('@mocks/cheater.json')); |
| 503 | + |
| 504 | + Plotly.plot(gd, mock) |
| 505 | + .then(function() { |
| 506 | + return Plotly.relayout(gd, 'xaxis.range', [0, 1]); |
| 507 | + }) |
| 508 | + .then(function() { |
| 509 | + return Plotly.relayout(gd, 'yaxis.range', [7, 8]); |
| 510 | + }) |
| 511 | + .catch(fail) |
| 512 | + .then(done); |
| 513 | + }); |
| 514 | +}); |
0 commit comments