|
| 1 | +var supplyDefaults = require('@src/traces/heatmapgl').supplyDefaults; |
| 2 | +var Plots = require('@src/plots/plots'); |
| 3 | +var Plotly = require('@lib/index'); |
| 4 | +var schema = Plotly.PlotSchema.get(); |
| 5 | +var attributeList = Object.getOwnPropertyNames(schema.traces.heatmapgl.attributes); |
| 6 | + |
| 7 | +describe('heatmapgl supplyDefaults', function() { |
| 8 | + 'use strict'; |
| 9 | + |
| 10 | + var traceIn; |
| 11 | + var traceOut; |
| 12 | + |
| 13 | + var defaultColor = '#444'; |
| 14 | + var layout = { |
| 15 | + font: Plots.layoutAttributes.font, |
| 16 | + _dfltTitle: {colorbar: 'cb'}, |
| 17 | + _subplots: {cartesian: ['xy'], xaxis: ['x'], yaxis: ['y']} |
| 18 | + }; |
| 19 | + |
| 20 | + beforeEach(function() { |
| 21 | + traceOut = {}; |
| 22 | + }); |
| 23 | + |
| 24 | + it('should set visible to false when z is empty', function() { |
| 25 | + traceIn = { |
| 26 | + z: [] |
| 27 | + }; |
| 28 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 29 | + expect(traceOut.visible).toBe(false); |
| 30 | + |
| 31 | + traceIn = { |
| 32 | + z: [[]] |
| 33 | + }; |
| 34 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 35 | + expect(traceOut.visible).toBe(false); |
| 36 | + |
| 37 | + traceIn = { |
| 38 | + z: [[], [], []] |
| 39 | + }; |
| 40 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 41 | + expect(traceOut.visible).toBe(false); |
| 42 | + |
| 43 | + traceIn = { |
| 44 | + type: 'heatmapgl', |
| 45 | + z: [[1, 2], []] |
| 46 | + }; |
| 47 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 48 | + expect(traceOut.visible).toBe(false); |
| 49 | + |
| 50 | + traceIn = { |
| 51 | + type: 'heatmapgl', |
| 52 | + z: [[], [1, 2], [1, 2, 3]] |
| 53 | + }; |
| 54 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 55 | + expect(traceOut.visible).toBe(false); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should set visible to false when z is non-numeric', function() { |
| 59 | + traceIn = { |
| 60 | + type: 'heatmapgl', |
| 61 | + z: [['a', 'b'], ['c', 'd']] |
| 62 | + }; |
| 63 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 64 | + expect(traceOut.visible).toBe(false); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should set visible to false when z isn\'t column not a 2d array', function() { |
| 68 | + traceIn = { |
| 69 | + x: [1, 1, 1, 2, 2], |
| 70 | + y: [1, 2, 3, 1, 2], |
| 71 | + z: [1, ['this is considered a column'], 1, 2, 3] |
| 72 | + }; |
| 73 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 74 | + expect(traceOut.visible).not.toBe(false); |
| 75 | + |
| 76 | + traceIn = { |
| 77 | + x: [1, 1, 1, 2, 2], |
| 78 | + y: [1, 2, 3, 1, 2], |
| 79 | + z: [[0], ['this is not considered a column'], 1, ['nor 2d']] |
| 80 | + }; |
| 81 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 82 | + expect(traceOut.visible).toBe(false); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should only coerce attributes that are part of scheme', function() { |
| 86 | + traceIn = { |
| 87 | + type: 'heatmapgl', |
| 88 | + z: [[0, 1], [1, 0]] |
| 89 | + }; |
| 90 | + |
| 91 | + supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 92 | + var allKeys = Object.getOwnPropertyNames(traceOut); |
| 93 | + allKeys.forEach(function(key) { |
| 94 | + if(key[0] !== '_') { |
| 95 | + expect(attributeList.indexOf(key)).not.toBe(-1, key); |
| 96 | + } |
| 97 | + }); |
| 98 | + }); |
| 99 | +}); |
0 commit comments