Skip to content

Commit 7ec1634

Browse files
committed
closes #615 - something else in this PR fixed it, just nailing a test
1 parent d15e541 commit 7ec1634

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/jasmine/tests/contour_test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
var Plotly = require('@lib/index');
12
var Plots = require('@src/plots/plots');
23
var Lib = require('@src/lib');
34

45
var Contour = require('@src/traces/contour');
56
var makeColorMap = require('@src/traces/contour/make_color_map');
67
var colorScales = require('@src/components/colorscale/scales');
78

9+
var fail = require('../assets/fail_test');
10+
var createGraphDiv = require('../assets/create_graph_div');
11+
var destroyGraphDiv = require('../assets/destroy_graph_div');
812
var customMatchers = require('../assets/custom_matchers');
913

14+
var d3 = require('d3');
15+
1016

1117
describe('contour defaults', function() {
1218
'use strict';
@@ -344,3 +350,54 @@ describe('contour calc', function() {
344350
});
345351
});
346352
});
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

Comments
 (0)