Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffa0af7

Browse files
committed
lint (gl-vis -> plotly.js formatting)
1 parent 4f037ee commit ffa0af7

File tree

1 file changed

+127
-112
lines changed

1 file changed

+127
-112
lines changed

src/traces/surface/convert.js

Lines changed: 127 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,68 @@ var str2RgbaArray = require('../../lib/str2rgbarray');
2020

2121
var MIN_RESOLUTION = 128;
2222

23+
2324
function SurfaceTrace(scene, surface, uid) {
24-
this.scene = scene;
25-
this.uid = uid;
26-
this.surface = surface;
27-
this.data = null;
28-
this.showContour = [false,false,false];
29-
this.dataScale = 1.0;
25+
this.scene = scene;
26+
this.uid = uid;
27+
this.surface = surface;
28+
this.data = null;
29+
this.showContour = [false, false, false];
30+
this.dataScale = 1.0;
3031
}
3132

3233
var proto = SurfaceTrace.prototype;
3334

3435
proto.handlePick = function(selection) {
35-
if(selection.object === this.surface) {
36-
var selectIndex = [
37-
Math.min(Math.round(selection.data.index[0]/this.dataScale-1)|0, this.data.z[0].length-1),
38-
Math.min(Math.round(selection.data.index[1]/this.dataScale-1)|0, this.data.z.length-1) ];
39-
var traceCoordinate = [0,0,0];
40-
if(Array.isArray(this.data.x[0])) {
41-
traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
42-
} else {
43-
traceCoordinate[0] = this.data.x[selectIndex[0]];
44-
}
45-
if(Array.isArray(this.data.y[0])) {
46-
traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
47-
} else {
48-
traceCoordinate[1] = this.data.y[selectIndex[1]];
49-
}
50-
traceCoordinate[2] = this.data.z[selectIndex[1]][selectIndex[0]];
51-
selection.traceCoordinate = traceCoordinate;
52-
53-
var sceneLayout = this.scene.fullSceneLayout;
54-
selection.dataCoordinate = [
55-
sceneLayout.xaxis.d2l(traceCoordinate[0])*this.scene.dataScale[0],
56-
sceneLayout.yaxis.d2l(traceCoordinate[1])*this.scene.dataScale[1],
57-
sceneLayout.zaxis.d2l(traceCoordinate[2])*this.scene.dataScale[2]
58-
];
59-
60-
var text = this.data.text;
61-
if(text && text[selectIndex[1]] && text[selectIndex[1]][selectIndex[0]]!==undefined) {
62-
selection.textLabel = text[selectIndex[1]][selectIndex[0]];
63-
}
64-
else selection.textLabel = '';
36+
if(selection.object === this.surface) {
37+
var selectIndex = [
38+
Math.min(
39+
Math.round(selection.data.index[0]/this.dataScale-1)|0,
40+
this.data.z[0].length-1
41+
),
42+
Math.min(
43+
Math.round(selection.data.index[1]/this.dataScale-1)|0,
44+
this.data.z.length-1
45+
)
46+
];
47+
var traceCoordinate = [0,0,0];
48+
49+
if(Array.isArray(this.data.x[0])) {
50+
traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
51+
} else {
52+
traceCoordinate[0] = this.data.x[selectIndex[0]];
53+
}
54+
if(Array.isArray(this.data.y[0])) {
55+
traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
56+
} else {
57+
traceCoordinate[1] = this.data.y[selectIndex[1]];
58+
}
59+
60+
traceCoordinate[2] = this.data.z[selectIndex[1]][selectIndex[0]];
61+
selection.traceCoordinate = traceCoordinate;
6562

66-
selection.data.dataCoordinate = selection.dataCoordinate.slice();
63+
var sceneLayout = this.scene.fullSceneLayout;
64+
selection.dataCoordinate = [
65+
sceneLayout.xaxis.d2l(traceCoordinate[0]) * this.scene.dataScale[0],
66+
sceneLayout.yaxis.d2l(traceCoordinate[1]) * this.scene.dataScale[1],
67+
sceneLayout.zaxis.d2l(traceCoordinate[2]) * this.scene.dataScale[2]
68+
];
6769

68-
this.surface.highlight(selection.data);
70+
var text = this.data.text;
71+
if(text && text[selectIndex[1]] && text[selectIndex[1]][selectIndex[0]]!==undefined) {
72+
selection.textLabel = text[selectIndex[1]][selectIndex[0]];
73+
}
74+
else selection.textLabel = '';
6975

70-
//Snap spikes to data coordinate
71-
this.scene.glplot.spikes.position = selection.dataCoordinate;
76+
selection.data.dataCoordinate = selection.dataCoordinate.slice();
7277

73-
return true;
74-
}
78+
this.surface.highlight(selection.data);
79+
80+
// Snap spikes to data coordinate
81+
this.scene.glplot.spikes.position = selection.dataCoordinate;
82+
83+
return true;
84+
}
7585
};
7686

7787
function parseColorScale (colorscale, alpha) {
@@ -88,42 +98,44 @@ function parseColorScale (colorscale, alpha) {
8898
});
8999
}
90100

91-
//Pad coords by +1
101+
// Pad coords by +1
92102
function padField(field) {
93-
var shape = field.shape;
94-
var nshape = [shape[0]+2, shape[1]+2];
95-
var nfield = ndarray(new Float32Array(nshape[0] * nshape[1]), nshape);
96-
97-
//Center
98-
ops.assign(nfield.lo(1, 1).hi(shape[0], shape[1]), field);
99-
100-
//Edges
101-
ops.assign(nfield.lo(1).hi(shape[0], 1),
102-
field.hi(shape[0], 1));
103-
ops.assign(nfield.lo(1, nshape[1]-1).hi(shape[0], 1),
104-
field.lo(0, shape[1]-1).hi(shape[0], 1));
105-
ops.assign(nfield.lo(0, 1).hi(1, shape[1]),
106-
field.hi(1));
107-
ops.assign(nfield.lo(nshape[0]-1, 1).hi(1, shape[1]),
108-
field.lo(shape[0]-1));
109-
110-
//Corners
111-
nfield.set(0, 0, field.get(0, 0));
112-
nfield.set(0, nshape[1]-1, field.get(0, shape[1]-1));
113-
nfield.set(nshape[0]-1, 0, field.get(shape[0]-1, 0));
114-
nfield.set(nshape[0]-1, nshape[1]-1, field.get(shape[0]-1, shape[1]-1));
115-
116-
return nfield;
103+
var shape = field.shape;
104+
var nshape = [shape[0]+2, shape[1]+2];
105+
var nfield = ndarray(new Float32Array(nshape[0] * nshape[1]), nshape);
106+
107+
// Center
108+
ops.assign(nfield.lo(1, 1).hi(shape[0], shape[1]), field);
109+
110+
// Edges
111+
ops.assign(nfield.lo(1).hi(shape[0], 1),
112+
field.hi(shape[0], 1));
113+
ops.assign(nfield.lo(1, nshape[1]-1).hi(shape[0], 1),
114+
field.lo(0, shape[1]-1).hi(shape[0], 1));
115+
ops.assign(nfield.lo(0, 1).hi(1, shape[1]),
116+
field.hi(1));
117+
ops.assign(nfield.lo(nshape[0]-1, 1).hi(1, shape[1]),
118+
field.lo(shape[0]-1));
119+
120+
// Corners
121+
nfield.set(0, 0, field.get(0, 0));
122+
nfield.set(0, nshape[1]-1, field.get(0, shape[1]-1));
123+
nfield.set(nshape[0]-1, 0, field.get(shape[0]-1, 0));
124+
nfield.set(nshape[0]-1, nshape[1]-1, field.get(shape[0]-1, shape[1]-1));
125+
126+
return nfield;
117127
}
118128

119129
function refine(coords) {
120130
var minScale = Math.max(coords[0].shape[0], coords[0].shape[1]);
131+
121132
if(minScale < MIN_RESOLUTION) {
122133
var scaleF = MIN_RESOLUTION / minScale;
123134
var nshape = [
124135
Math.floor((coords[0].shape[0]) * scaleF+1)|0,
125136
Math.floor((coords[0].shape[1]) * scaleF+1)|0 ];
126137
var nsize = nshape[0] * nshape[1];
138+
127139
for(var i = 0; i < 3; ++i) {
128140
var padImg = padField(coords[i]);
129141
var scaledImg = ndarray(new Float32Array(nsize), nshape);
@@ -132,20 +144,24 @@ function refine(coords) {
132144
0, 0, 1]);
133145
coords[i] = scaledImg;
134146
}
147+
135148
return scaleF;
136149
}
150+
137151
return 1.0;
138152
}
139153

140154
proto.setContourLevels = function() {
141155
var nlevels = [[], [], []];
142156
var needsUpdate = false;
143-
for(var i=0; i<3; ++i) {
157+
158+
for(var i = 0; i < 3; ++i) {
144159
if(this.showContour[i]) {
145160
needsUpdate = true;
146161
nlevels[i] = this.scene.contourLevels[i];
147162
}
148163
}
164+
149165
if(needsUpdate) {
150166
this.surface.update({ levels: nlevels });
151167
}
@@ -218,20 +234,22 @@ proto.update = function(data) {
218234
this.dataScale = refine(coords);
219235

220236
var params = {
221-
colormap: colormap,
222-
levels: [[], [], []],
223-
showContour: [ true, true, true ],
224-
showSurface: !data.hidesurface,
225-
contourProject: [ [ false, false, false ],
226-
[ false, false, false ],
227-
[ false, false, false ] ],
228-
contourWidth: [ 1, 1, 1 ],
229-
contourColor: [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1] ],
230-
contourTint: [ 1, 1, 1 ],
231-
dynamicColor: [ [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1] ],
232-
dynamicWidth: [ 1, 1, 1 ],
233-
dynamicTint: [ 1, 1, 1 ],
234-
opacity: 1
237+
colormap: colormap,
238+
levels: [[], [], []],
239+
showContour: [true, true, true],
240+
showSurface: !data.hidesurface,
241+
contourProject: [
242+
[false, false, false],
243+
[false, false, false],
244+
[false, false, false]
245+
],
246+
contourWidth: [1, 1, 1],
247+
contourColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],
248+
contourTint: [1, 1, 1],
249+
dynamicColor: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],
250+
dynamicWidth: [1, 1, 1],
251+
dynamicTint: [1, 1, 1],
252+
opacity: 1,
235253
};
236254

237255

@@ -241,24 +259,23 @@ proto.update = function(data) {
241259
}
242260
}
243261

244-
var highlightEnable = [ true, true, true ];
245-
var contourEnable = [ true, true, true ];
246-
var axis = [ 'x', 'y', 'z' ];
262+
var highlightEnable = [true, true, true];
263+
var contourEnable = [true, true, true];
264+
var axis = ['x', 'y', 'z'];
247265

248266
for(i = 0; i < 3; ++i) {
249-
var contourParams = data.contours[axis[i]];
250-
highlightEnable[i] = contourParams.highlight;
251-
contourEnable[i] = contourParams.show;
267+
var contourParams = data.contours[axis[i]];
268+
highlightEnable[i] = contourParams.highlight;
269+
contourEnable[i] = contourParams.show;
252270

253-
params.showContour[i] = contourParams.show || contourParams.highlight;
254-
if (!params.showContour[i]) {
255-
continue;
256-
}
271+
params.showContour[i] = contourParams.show || contourParams.highlight;
272+
if(!params.showContour[i]) continue;
257273

258-
params.contourProject[i] = [
274+
params.contourProject[i] = [
259275
contourParams.project.x,
260276
contourParams.project.y,
261-
contourParams.project.z ];
277+
contourParams.project.z
278+
];
262279

263280
if (contourParams.show) {
264281
this.showContour[i] = true;
@@ -283,18 +300,18 @@ proto.update = function(data) {
283300
params.coords = coords;
284301
surface.update(params);
285302

286-
surface.highlightEnable = highlightEnable;
287-
surface.contourEnable = contourEnable;
288-
surface.visible = data.visible;
303+
surface.highlightEnable = highlightEnable;
304+
surface.contourEnable = contourEnable;
305+
surface.visible = data.visible;
289306

290307
surface.snapToData = true;
291308

292309
if ('lighting' in data) {
293-
surface.ambientLight = data.lighting.ambient;
294-
surface.diffuseLight = data.lighting.diffuse;
295-
surface.specularLight = data.lighting.specular;
296-
surface.roughness = data.lighting.roughness;
297-
surface.fresnel = data.lighting.fresnel;
310+
surface.ambientLight = data.lighting.ambient;
311+
surface.diffuseLight = data.lighting.diffuse;
312+
surface.specularLight = data.lighting.specular;
313+
surface.roughness = data.lighting.roughness;
314+
surface.fresnel = data.lighting.fresnel;
298315
}
299316

300317
if (alpha && alpha < 1) {
@@ -304,19 +321,17 @@ proto.update = function(data) {
304321

305322

306323
proto.dispose = function() {
307-
this.glplot.remove(this.surface);
308-
this.surface.dispose();
324+
this.glplot.remove(this.surface);
325+
this.surface.dispose();
309326
};
310327

311328
function createSurfaceTrace(scene, data) {
312-
var gl = scene.glplot.gl;
313-
var surface = createSurface({
314-
gl: gl
315-
});
316-
var result = new SurfaceTrace(scene, surface, data.uid);
317-
result.update(data);
318-
scene.glplot.add(surface);
319-
return result;
329+
var gl = scene.glplot.gl;
330+
var surface = createSurface({ gl: gl });
331+
var result = new SurfaceTrace(scene, surface, data.uid);
332+
result.update(data);
333+
scene.glplot.add(surface);
334+
return result;
320335
}
321336

322337
module.exports = createSurfaceTrace;

0 commit comments

Comments
 (0)