|
| 1 | +var Plots = require('@src/plots/plots'); |
| 2 | +var Parcoords = require('@src/traces/parcoords'); |
| 3 | +var attributes = require('@src/traces/parcoords/attributes'); |
| 4 | +var Lib = require('@src/lib'); |
| 5 | + |
| 6 | +describe('parcoords initialization tests', function() { |
| 7 | + |
| 8 | + 'use strict'; |
| 9 | + |
| 10 | + describe('parcoords defaults', function() { |
| 11 | + |
| 12 | + function _supply(traceIn) { |
| 13 | + var traceOut = { visible: true }, |
| 14 | + defaultColor = '#444', |
| 15 | + layout = { }; |
| 16 | + |
| 17 | + Parcoords.supplyDefaults(traceIn, traceOut, defaultColor, layout); |
| 18 | + |
| 19 | + return traceOut; |
| 20 | + } |
| 21 | + |
| 22 | + it('\'pad\' defaults should apply if missing', function() { |
| 23 | + var fullTrace = _supply({}); |
| 24 | + expect(fullTrace.pad).toEqual({t: 80, r: 80, b: 80, l: 80}); |
| 25 | + }); |
| 26 | + |
| 27 | + it('\'pad\' properties should be default where not specified', function() { |
| 28 | + var fullTrace = _supply({ pad: {t: 10, r: 20, b: 30} }); |
| 29 | + expect(fullTrace.pad).toEqual({t: 10, r: 20, b: 30, l: 80}); |
| 30 | + }); |
| 31 | + |
| 32 | + it('\'line\' specification should yield a default color', function() { |
| 33 | + var fullTrace = _supply({}); |
| 34 | + expect(fullTrace.line.color).toEqual('#444'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('\'colorscale\' should assume a default value if the \'color\' array is specified', function() { |
| 38 | + var fullTrace = _supply({ |
| 39 | + line: { |
| 40 | + color: [35, 63, 21, 42] |
| 41 | + }, |
| 42 | + dimensions: [ |
| 43 | + {values: [321, 534, 542, 674]}, |
| 44 | + {values: [562, 124, 942, 189]}, |
| 45 | + {values: [287, 183, 385, 884]}, |
| 46 | + {values: [113, 489, 731, 454]} |
| 47 | + ] |
| 48 | + }); |
| 49 | + expect(fullTrace.line).toEqual({ |
| 50 | + color: [35, 63, 21, 42], |
| 51 | + colorscale: attributes.line.colorscale.dflt, |
| 52 | + cauto: true, |
| 53 | + autocolorscale: false, |
| 54 | + reversescale: false, |
| 55 | + showscale: false |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + it('\'domain\' specification should have a default', function() { |
| 60 | + var fullTrace = _supply({}); |
| 61 | + expect(fullTrace.domain).toEqual({x: [0, 1], y: [0, 1]}); |
| 62 | + }); |
| 63 | + |
| 64 | + it('\'dimension\' specification should have a default of an empty array', function() { |
| 65 | + var fullTrace = _supply({}); |
| 66 | + expect(fullTrace.dimensions).toEqual([]); |
| 67 | + }); |
| 68 | + |
| 69 | + it('\'dimension\' should be ignored if `values` are unsupported', function() { |
| 70 | + var fullTrace = _supply({ |
| 71 | + dimensions: [{label: 'test dimension'}] |
| 72 | + }); |
| 73 | + expect(fullTrace.dimensions).toEqual([]); |
| 74 | + }); |
| 75 | + |
| 76 | + it('\'dimension\' should be used with default values where attributes are not provided', function() { |
| 77 | + var fullTrace = _supply({ |
| 78 | + dimensions: [{values: []}] |
| 79 | + }); |
| 80 | + expect(fullTrace.dimensions).toEqual([{values: [], visible: false, _index: 0}]); |
| 81 | + }); |
| 82 | + |
| 83 | + it('\'dimension.values\' should get truncated to a common shortest length', function() { |
| 84 | + var fullTrace = _supply({dimensions: [ |
| 85 | + {values: [321, 534, 542, 674]}, |
| 86 | + {values: [562, 124, 942]}, |
| 87 | + {values: [], visible: true}, // should be overwritten to false |
| 88 | + {values: [1, 2], visible: false} // shouldn't be truncated to as false |
| 89 | + ]}); |
| 90 | + expect(fullTrace.dimensions).toEqual([ |
| 91 | + {values: [321, 534, 542], visible: true, _index: 0}, |
| 92 | + {values: [562, 124, 942], visible: true, _index: 1}, |
| 93 | + {values: [], visible: false, _index: 2}, |
| 94 | + {values: [1, 2], visible: false, _index: 3} |
| 95 | + ]); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + describe('parcoords calc', function() { |
| 100 | + |
| 101 | + function _calc(trace) { |
| 102 | + var gd = { data: [trace] }; |
| 103 | + |
| 104 | + Plots.supplyDefaults(gd); |
| 105 | + |
| 106 | + var fullTrace = gd._fullData[0]; |
| 107 | + return Parcoords.calc(gd, fullTrace); |
| 108 | + } |
| 109 | + |
| 110 | + var base = { type: 'parcoords' }; |
| 111 | + |
| 112 | + it('\'colorscale\' should assume a default value if the \'color\' array is specified', function() { |
| 113 | + |
| 114 | + var fullTrace = _calc(Lib.extendDeep({}, base, { |
| 115 | + line: { |
| 116 | + color: [35, 63, 21, 42] |
| 117 | + }, |
| 118 | + dimensions: [ |
| 119 | + {values: [321, 534, 542, 674]}, |
| 120 | + {values: [562, 124, 942, 189]}, |
| 121 | + {values: [287, 183, 385, 884]}, |
| 122 | + {values: [113, 489, 731, 454]} |
| 123 | + ] |
| 124 | + })); |
| 125 | + |
| 126 | + expect(fullTrace[0].line).toEqual({ |
| 127 | + color: [35, 63, 21, 42], |
| 128 | + colorscale: attributes.line.colorscale.dflt, |
| 129 | + cauto: true, |
| 130 | + cmin: 21, |
| 131 | + cmax: 63, |
| 132 | + autocolorscale: false, |
| 133 | + reversescale: false, |
| 134 | + showscale: false |
| 135 | + }); |
| 136 | + }); |
| 137 | + |
| 138 | + it('use a singular \'color\' if it is not an array', function() { |
| 139 | + |
| 140 | + var fullTrace = _calc(Lib.extendDeep({}, base, { |
| 141 | + line: { |
| 142 | + color: '#444' |
| 143 | + }, |
| 144 | + dimensions: [ |
| 145 | + {values: [321, 534, 542, 674]}, |
| 146 | + {values: [562, 124, 942, 189]} |
| 147 | + ] |
| 148 | + })); |
| 149 | + |
| 150 | + expect(fullTrace[0].line).toEqual({ |
| 151 | + color: [0.5, 0.5, 0.5, 0.5], |
| 152 | + colorscale: [[0, '#444'], [1, '#444']], |
| 153 | + cmin: 0, |
| 154 | + cmax: 1 |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + it('use a singular \'color\' even if a \'colorscale\' is supplied', function() { |
| 159 | + |
| 160 | + var fullTrace = _calc(Lib.extendDeep({}, base, { |
| 161 | + line: { |
| 162 | + color: '#444', |
| 163 | + colorscale: 'Jet' |
| 164 | + }, |
| 165 | + dimensions: [ |
| 166 | + {values: [321, 534, 542, 674]}, |
| 167 | + {values: [562, 124, 942, 189]} |
| 168 | + ] |
| 169 | + })); |
| 170 | + |
| 171 | + expect(fullTrace[0].line).toEqual({ |
| 172 | + color: [0.5, 0.5, 0.5, 0.5], |
| 173 | + colorscale: [[0, '#444'], [1, '#444']], |
| 174 | + autocolorscale: false, |
| 175 | + showscale: false, |
| 176 | + reversescale: false, |
| 177 | + cauto: true, |
| 178 | + cmin: 0, |
| 179 | + cmax: 1 |
| 180 | + }); |
| 181 | + }); |
| 182 | + }); |
| 183 | +}); |
0 commit comments