Skip to content

Commit 83060bc

Browse files
committed
using loops instead of map in mesh3d convert
1 parent bf51940 commit 83060bc

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

src/traces/mesh3d/convert.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,43 @@ proto.handlePick = function(selection) {
5252
};
5353

5454
function parseColorArray(colors) {
55-
return colors.map(str2RgbaArray);
55+
var b = [];
56+
var len = colors.length;
57+
for(var i = 0; i < len; i++) {
58+
b[i] = str2RgbaArray(colors[i]);
59+
}
60+
return b;
61+
}
62+
63+
// Unpack position data
64+
function toDataCoords(axis, coord, scale, calendar) {
65+
var b = [];
66+
var len = coord.length;
67+
for(var i = 0; i < len; i++) {
68+
b[i] = axis.d2l(coord[i], 0, calendar) * scale;
69+
}
70+
return b;
71+
}
72+
73+
// round indices if passed as floats
74+
function toIndex(a) {
75+
var b = [];
76+
var len = a.length;
77+
for(var i = 0; i < len; i++) {
78+
b[i] = Math.round(a[i]);
79+
}
80+
return b;
81+
}
82+
83+
// create cells
84+
function delaunayCells(delaunayaxis, positions) {
85+
var d = ['x', 'y', 'z'].indexOf(delaunayaxis);
86+
var b = [];
87+
var len = positions.length;
88+
for(var i = 0; i < len; i++) {
89+
b[i] = [positions[i][(d + 1) % 3], positions[i][(d + 2) % 3]];
90+
}
91+
return triangulate(b);
5692
}
5793

5894
proto.update = function(data) {
@@ -61,13 +97,6 @@ proto.update = function(data) {
6197

6298
this.data = data;
6399

64-
// Unpack position data
65-
function toDataCoords(axis, coord, scale, calendar) {
66-
return coord.map(function(x) {
67-
return axis.d2l(x, 0, calendar) * scale;
68-
});
69-
}
70-
71100
var positions = zip3(
72101
toDataCoords(layout.xaxis, data.x, scene.dataScale[0], data.xcalendar),
73102
toDataCoords(layout.yaxis, data.y, scene.dataScale[1], data.ycalendar),
@@ -77,19 +106,16 @@ proto.update = function(data) {
77106
var cells;
78107
if(data.i && data.j && data.k) {
79108
cells = zip3(
80-
data.i.map(function(e) { return Math.round(e); }),
81-
data.j.map(function(e) { return Math.round(e); }),
82-
data.k.map(function(e) { return Math.round(e); })
109+
toIndex(data.i),
110+
toIndex(data.j),
111+
toIndex(data.k)
83112
);
84113
} else if(data.alphahull === 0) {
85114
cells = convexHull(positions);
86115
} else if(data.alphahull > 0) {
87116
cells = alphaShape(data.alphahull, positions);
88117
} else {
89-
var d = ['x', 'y', 'z'].indexOf(data.delaunayaxis);
90-
cells = triangulate(positions.map(function(c) {
91-
return [c[(d + 1) % 3], c[(d + 2) % 3]];
92-
}));
118+
cells = delaunayCells(data.delaunayaxis, positions);
93119
}
94120

95121
var config = {

0 commit comments

Comments
 (0)