|
| 1 | +var Plotly = require('@lib/index'); |
1 | 2 | var Plots = require('@src/plots/plots');
|
2 | 3 | var Lib = require('@src/lib');
|
3 | 4 |
|
4 | 5 | var Contour = require('@src/traces/contour');
|
5 | 6 | var makeColorMap = require('@src/traces/contour/make_color_map');
|
6 | 7 | var colorScales = require('@src/components/colorscale/scales');
|
7 | 8 |
|
| 9 | +var fail = require('../assets/fail_test'); |
| 10 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 11 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
8 | 12 | var customMatchers = require('../assets/custom_matchers');
|
9 | 13 |
|
| 14 | +var d3 = require('d3'); |
| 15 | + |
10 | 16 |
|
11 | 17 | describe('contour defaults', function() {
|
12 | 18 | 'use strict';
|
@@ -344,3 +350,54 @@ describe('contour calc', function() {
|
344 | 350 | });
|
345 | 351 | });
|
346 | 352 | });
|
| 353 | + |
| 354 | +describe('contour edits', function() { |
| 355 | + var gd; |
| 356 | + |
| 357 | + beforeEach(function() { |
| 358 | + gd = createGraphDiv(); |
| 359 | + }); |
| 360 | + afterEach(destroyGraphDiv); |
| 361 | + |
| 362 | + function checkTicks(axLetter, vals, msg) { |
| 363 | + var selection = d3.selectAll('.' + axLetter + 'tick text'); |
| 364 | + expect(selection.size()).toBe(vals.length); |
| 365 | + selection.each(function(d, i) { |
| 366 | + expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i); |
| 367 | + }); |
| 368 | + } |
| 369 | + |
| 370 | + it('can restyle x/y to different types', function(done) { |
| 371 | + Plotly.newPlot(gd, [{ |
| 372 | + type: 'contour', |
| 373 | + x: [1, 2, 3], |
| 374 | + y: [3, 4, 5], |
| 375 | + z: [[10, 11, 12], [13, 14, 15], [17, 18, 19]] |
| 376 | + }], {width: 400, height: 400}) |
| 377 | + .then(function() { |
| 378 | + checkTicks('x', ['1', '1.5', '2', '2.5', '3'], 'linear x'); |
| 379 | + expect(gd._fullLayout.xaxis.type).toBe('linear'); |
| 380 | + checkTicks('y', ['3', '3.5', '4', '4.5', '5'], 'linear y'); |
| 381 | + expect(gd._fullLayout.yaxis.type).toBe('linear'); |
| 382 | + |
| 383 | + return Plotly.restyle(gd, {x: [['a', 'b', 'c']], y: [['2016-01', '2016-02', '2016-03']]}); |
| 384 | + }) |
| 385 | + .then(function() { |
| 386 | + checkTicks('x', ['a', 'b', 'c'], 'category x'); |
| 387 | + expect(gd._fullLayout.xaxis.type).toBe('category'); |
| 388 | + checkTicks('y', ['Jan 102016', 'Jan 24', 'Feb 7', 'Feb 21'], 'date y'); |
| 389 | + expect(gd._fullLayout.yaxis.type).toBe('date'); |
| 390 | + |
| 391 | + // should be a noop, but one that raises no errors! |
| 392 | + return Plotly.relayout(gd, {'xaxis.type': '-', 'yaxis.type': '-'}); |
| 393 | + }) |
| 394 | + .then(function() { |
| 395 | + checkTicks('x', ['a', 'b', 'c'], 'category x #2'); |
| 396 | + expect(gd._fullLayout.xaxis.type).toBe('category'); |
| 397 | + checkTicks('y', ['Jan 102016', 'Jan 24', 'Feb 7', 'Feb 21'], 'date y #2'); |
| 398 | + expect(gd._fullLayout.yaxis.type).toBe('date'); |
| 399 | + }) |
| 400 | + .catch(fail) |
| 401 | + .then(done); |
| 402 | + }); |
| 403 | +}); |
0 commit comments