|  | 
| 1 | 1 | var Plotly = require('@lib'); | 
|  | 2 | +var Lib = require('@src/lib'); | 
|  | 3 | +var supplyDefaults = require('@src/traces/mesh3d').supplyDefaults; | 
| 2 | 4 | var createGraphDiv = require('../assets/create_graph_div'); | 
| 3 | 5 | var destroyGraphDiv = require('../assets/destroy_graph_div'); | 
| 4 | 6 | var failTest = require('../assets/fail_test'); | 
| 5 | 7 | 
 | 
| 6 | 8 | describe('Test mesh3d', function() { | 
| 7 | 9 |     'use strict'; | 
| 8 | 10 | 
 | 
|  | 11 | +    describe('supplyDefaults', function() { | 
|  | 12 | +        var defaultColor = '#444'; | 
|  | 13 | +        var layout = {_dfltTitle: {colorbar: 'cb'}}; | 
|  | 14 | + | 
|  | 15 | +        var traceIn, traceOut; | 
|  | 16 | + | 
|  | 17 | +        beforeEach(function() { | 
|  | 18 | +            traceOut = {}; | 
|  | 19 | +        }); | 
|  | 20 | + | 
|  | 21 | +        it('should set \'visible\' to false if \'x\' isn\'t provided', function() { | 
|  | 22 | +            traceIn = { | 
|  | 23 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 24 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 25 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 26 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 27 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 28 | +            }; | 
|  | 29 | + | 
|  | 30 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 31 | +            expect(traceOut.visible).toBe(false); | 
|  | 32 | +        }); | 
|  | 33 | + | 
|  | 34 | +        it('should set \'visible\' to false if \'y\' isn\'t provided', function() { | 
|  | 35 | +            traceIn = { | 
|  | 36 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 37 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 38 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 39 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 40 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 41 | +            }; | 
|  | 42 | + | 
|  | 43 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 44 | +            expect(traceOut.visible).toBe(false); | 
|  | 45 | +        }); | 
|  | 46 | + | 
|  | 47 | +        it('should set \'visible\' to false if \'z\' isn\'t provided', function() { | 
|  | 48 | +            traceIn = { | 
|  | 49 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 50 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 51 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 52 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 53 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 54 | +            }; | 
|  | 55 | + | 
|  | 56 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 57 | +            expect(traceOut.visible).toBe(false); | 
|  | 58 | +        }); | 
|  | 59 | + | 
|  | 60 | +        it('should set \'visible\' to false if \'i\' isn\'t provided', function() { | 
|  | 61 | +            traceIn = { | 
|  | 62 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 63 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 64 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 65 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 66 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 67 | +            }; | 
|  | 68 | + | 
|  | 69 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 70 | +            expect(traceOut.visible).toBe(false); | 
|  | 71 | +        }); | 
|  | 72 | + | 
|  | 73 | +        it('should set \'visible\' to false if \'j\' isn\'t provided', function() { | 
|  | 74 | +            traceIn = { | 
|  | 75 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 76 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 77 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 78 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 79 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 80 | +            }; | 
|  | 81 | + | 
|  | 82 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 83 | +            expect(traceOut.visible).toBe(false); | 
|  | 84 | +        }); | 
|  | 85 | + | 
|  | 86 | +        it('should set \'visible\' to false if \'k\' isn\'t provided', function() { | 
|  | 87 | +            traceIn = { | 
|  | 88 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 89 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 90 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 91 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 92 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3] | 
|  | 93 | +            }; | 
|  | 94 | + | 
|  | 95 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 96 | +            expect(traceOut.visible).toBe(false); | 
|  | 97 | +        }); | 
|  | 98 | + | 
|  | 99 | +        it('should coerce contour style attributes if contour line is enabled', function() { | 
|  | 100 | +            traceIn = { | 
|  | 101 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 102 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 103 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 104 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 105 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 106 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2], | 
|  | 107 | +                contour: { | 
|  | 108 | +                    show: true | 
|  | 109 | +                } | 
|  | 110 | +            }; | 
|  | 111 | + | 
|  | 112 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 113 | +            expect(traceOut.contour.color).toEqual('#444'); | 
|  | 114 | +            expect(traceOut.contour.width).toEqual(2); | 
|  | 115 | +        }); | 
|  | 116 | + | 
|  | 117 | +        it('should not coerce contour attributes when contour line is disabled', function() { | 
|  | 118 | +            traceIn = { | 
|  | 119 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 120 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 121 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 122 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 123 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 124 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2], | 
|  | 125 | +                contour: { | 
|  | 126 | +                    show: false | 
|  | 127 | +                } | 
|  | 128 | +            }; | 
|  | 129 | + | 
|  | 130 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 131 | +            expect(traceOut.contour.color).toBeUndefined(); | 
|  | 132 | +            expect(traceOut.contour.width).toBeUndefined(); | 
|  | 133 | +        }); | 
|  | 134 | + | 
|  | 135 | +        it('should coerce colorscale and colorbar attributes when intensity is present', function() { | 
|  | 136 | +            traceIn = { | 
|  | 137 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 138 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 139 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 140 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 141 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 142 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2], | 
|  | 143 | +                intensity: [1, 2, 3, 4, 5, 6, 7, 8] | 
|  | 144 | +            }; | 
|  | 145 | + | 
|  | 146 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 147 | +            expect(traceOut.cauto).toBe(true); | 
|  | 148 | +            expect(traceOut.cmin).toBeUndefined(); | 
|  | 149 | +            expect(traceOut.cmax).toBeUndefined(); | 
|  | 150 | +            expect(traceOut.colorscale).toEqual([ | 
|  | 151 | +                [0, 'rgb(5,10,172)'], | 
|  | 152 | +                [0.35, 'rgb(106,137,247)'], | 
|  | 153 | +                [0.5, 'rgb(190,190,190)'], | 
|  | 154 | +                [0.6, 'rgb(220,170,132)'], | 
|  | 155 | +                [0.7, 'rgb(230,145,90)'], | 
|  | 156 | +                [1, 'rgb(178,10,28)'] | 
|  | 157 | +            ]); | 
|  | 158 | +            expect(traceOut.reversescale).toBe(false); | 
|  | 159 | +            expect(traceOut.showscale).toBe(true); | 
|  | 160 | +            expect(traceOut.colorbar).toBeDefined(); | 
|  | 161 | +        }); | 
|  | 162 | + | 
|  | 163 | +        it('should not coerce colorscale and colorbar attributes when intensity is not present', function() { | 
|  | 164 | +            traceIn = { | 
|  | 165 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 166 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 167 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 168 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 169 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 170 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 171 | +            }; | 
|  | 172 | + | 
|  | 173 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 174 | +            expect(traceOut.cauto).toBeUndefined(); | 
|  | 175 | +            expect(traceOut.cmin).toBeUndefined(); | 
|  | 176 | +            expect(traceOut.cmax).toBeUndefined(); | 
|  | 177 | +            expect(traceOut.colorscale).toBeUndefined(); | 
|  | 178 | +            expect(traceOut.reversescale).toBeUndefined(); | 
|  | 179 | +            expect(traceOut.showscale).toBe(false); | 
|  | 180 | +            expect(traceOut.colorbar).toBeUndefined(); | 
|  | 181 | +        }); | 
|  | 182 | + | 
|  | 183 | +        it('should inherit layout.calendar', function() { | 
|  | 184 | +            traceIn = { | 
|  | 185 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 186 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 187 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 188 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 189 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 190 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2] | 
|  | 191 | +            }; | 
|  | 192 | +            supplyDefaults(traceIn, traceOut, defaultColor, Lib.extendFlat({calendar: 'islamic'}, layout)); | 
|  | 193 | + | 
|  | 194 | +            // we always fill calendar attributes, because it's hard to tell if | 
|  | 195 | +            // we're on a date axis at this point. | 
|  | 196 | +            expect(traceOut.xcalendar).toBe('islamic'); | 
|  | 197 | +            expect(traceOut.ycalendar).toBe('islamic'); | 
|  | 198 | +            expect(traceOut.zcalendar).toBe('islamic'); | 
|  | 199 | +        }); | 
|  | 200 | + | 
|  | 201 | +        it('should take its own calendars', function() { | 
|  | 202 | +            var traceIn = { | 
|  | 203 | +                x: [0, 1, 0, 1, 0, 1, 0, 1], | 
|  | 204 | +                y: [0, 0, 1, 1, 0, 0, 1, 1], | 
|  | 205 | +                z: [0, 0, 0, 0, 1, 1, 1, 1], | 
|  | 206 | +                i: [0, 3, 4, 7, 0, 6, 1, 7, 0, 5, 2, 7], | 
|  | 207 | +                j: [1, 2, 5, 6, 2, 4, 3, 5, 4, 1, 6, 3], | 
|  | 208 | +                k: [3, 0, 7, 4, 6, 0, 7, 1, 5, 0, 7, 2], | 
|  | 209 | +                xcalendar: 'coptic', | 
|  | 210 | +                ycalendar: 'ethiopian', | 
|  | 211 | +                zcalendar: 'mayan' | 
|  | 212 | +            }; | 
|  | 213 | + | 
|  | 214 | +            supplyDefaults(traceIn, traceOut, defaultColor, layout); | 
|  | 215 | +            expect(traceOut.xcalendar).toBe('coptic'); | 
|  | 216 | +            expect(traceOut.ycalendar).toBe('ethiopian'); | 
|  | 217 | +            expect(traceOut.zcalendar).toBe('mayan'); | 
|  | 218 | +        }); | 
|  | 219 | +    }); | 
|  | 220 | + | 
| 9 | 221 |     describe('restyle', function() { | 
| 10 | 222 |         afterEach(destroyGraphDiv); | 
| 11 | 223 | 
 | 
|  | 
0 commit comments