|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | var Plotly = require('@lib/index'); |
| 4 | +var Lib = require('@src/lib'); |
| 5 | +var d3 = require('d3'); |
4 | 6 |
|
5 | 7 | // contourgl is not part of the dist plotly.js bundle initially |
6 | 8 | Plotly.register( |
@@ -82,18 +84,106 @@ var plotData = { |
82 | 84 | } |
83 | 85 | }; |
84 | 86 |
|
| 87 | +function transpose(a) { |
| 88 | + return a[0].map(function(ignore, columnIndex) {return a.map(function(row) {return row[columnIndex];});}); |
| 89 | +} |
| 90 | + |
| 91 | +function jitter(n) { |
| 92 | + return n + (Math.random() - 0.5) / 2; |
| 93 | +} |
| 94 | + |
| 95 | +function rotate(rad, point) { |
| 96 | + return { |
| 97 | + x: point.x * Math.cos(rad) - point.y * Math.sin(rad), |
| 98 | + y: point.x * Math.sin(rad) + point.y * Math.cos(rad) |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +function generator() { |
| 103 | + var x = d3.range(-12, 13, 1); // left closed, right open interval |
| 104 | + var y = d3.range(-12, 13, 1); // left closed, right open interval |
| 105 | + var i, j, p, z = new Array(x.length); |
| 106 | + for(i = 0; i < x.length; i++) { |
| 107 | + z[i] = new Array(y.length); |
| 108 | + for(j = 0; j < y.length; j++) { |
| 109 | + p = rotate(Math.PI / 4, {x: x[i], y: -y[j]}) |
| 110 | + z[i][j] = jitter(Math.pow(p.x, 2) / (10 * 10) + Math.pow(p.y, 2) / (4 * 4)) |
| 111 | + } |
| 112 | + } |
| 113 | + return {x: x, y: y, z: z} // looking forward to the ES2015 return {x, y, z} |
| 114 | +} |
| 115 | + |
| 116 | +var model = generator(); |
| 117 | + |
| 118 | +// equivalent to the new example case in gl-contour2d |
| 119 | +var plotDataCircular = { |
| 120 | + "data": [ |
| 121 | + { |
| 122 | + "type": "contourgl", |
| 123 | + "x": model.x.map(jitter), |
| 124 | + "y": model.y.map(jitter), |
| 125 | + "z": transpose(model.z), // gl-vis is column-major order while ploly is row-major order |
| 126 | + "colorscale": "Jet", |
| 127 | + "contours": { |
| 128 | + "start": 0, |
| 129 | + "end": 2, |
| 130 | + "size": 0.1, |
| 131 | + "coloring": "lines" |
| 132 | + }, |
| 133 | + "uid": "ad5624", |
| 134 | + "zmin": 0, |
| 135 | + "zmax": 2 |
| 136 | + } |
| 137 | + ], |
| 138 | + "layout": { |
| 139 | + "xaxis": { |
| 140 | + "range": [ |
| 141 | + -10, |
| 142 | + 10 |
| 143 | + ], |
| 144 | + "autorange": true |
| 145 | + }, |
| 146 | + "yaxis": { |
| 147 | + "range": [ |
| 148 | + -10, |
| 149 | + 10 |
| 150 | + ], |
| 151 | + "autorange": true |
| 152 | + }, |
| 153 | + "height": 600, |
| 154 | + "width": 600, |
| 155 | + "autosize": true |
| 156 | + } |
| 157 | +}; |
| 158 | + |
| 159 | + |
85 | 160 | function makePlot(gd, mock) { |
86 | 161 | return Plotly.plot(gd, mock.data, mock.layout); |
87 | 162 | } |
88 | 163 |
|
89 | 164 | fdescribe('contourgl plots', function() { |
90 | 165 |
|
| 166 | + // this dataset is a special case, very forgiving to the contour renderer, as it's convex, |
| 167 | + // contains no inflexion points etc. |
91 | 168 | it('render without raising an error', function(done) { |
92 | 169 | withSetupTeardown(done, function(gd) { |
93 | | - return makePlot(gd, plotData) |
94 | | - .then(function(gd) { |
95 | | - //debugger; |
96 | | - }) |
| 170 | + return makePlot(gd, plotData); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + // this dataset is less forgiving because it uses a noisy surface (random, will look different on each run) |
| 175 | + it('render without raising an error (coloring: "lines")', function(done) { |
| 176 | + withSetupTeardown(done, function(gd) { |
| 177 | + return makePlot(gd, plotDataCircular); |
| 178 | + }); |
| 179 | + }); |
| 180 | + |
| 181 | + // same with fill |
| 182 | + fit('render without raising an error (coloring: "fill")', function(done) { |
| 183 | + var mock = Lib.extendDeep({}, plotDataCircular); |
| 184 | + mock.data[0].contours.coloring = "fill"; // or delete property - fill is the default |
| 185 | + withSetupTeardown(done, function(gd) { |
| 186 | + return makePlot(gd, mock); |
97 | 187 | }); |
98 | 188 | }); |
99 | 189 |
|
|
0 commit comments