Skip to content

Commit f18d07b

Browse files
committed
add wrapper function to truncate Float32Array,
to support environment (e.g. node-webkit) that don't implement Float32Array.prototype.slice
1 parent 1fb7aae commit f18d07b

File tree

1 file changed

+16
-2
lines changed
  • shelly/plotlyjs/static/plotlyjs/src/gl2d/scattergl

1 file changed

+16
-2
lines changed

shelly/plotlyjs/static/plotlyjs/src/gl2d/scattergl/convert.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ function _convertColor(colors, opacities, count) {
196196
return result;
197197
}
198198

199+
/**
200+
* Truncate a Float32Array to some length. A wrapper to support environments
201+
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
202+
*/
203+
function truncate(float32ArrayIn, len) {
204+
if(Float32Array.slice === undefined) {
205+
var float32ArrayOut = new Float32Array(len);
206+
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
207+
return float32ArrayOut;
208+
}
209+
210+
return float32ArrayIn.slice(0, len);
211+
}
212+
199213
/* Order is important here to get the correct laying:
200214
* - lines
201215
* - errorX
@@ -266,7 +280,7 @@ proto.updateFast = function(options) {
266280
bounds[3] = Math.max(bounds[3], yy);
267281
}
268282

269-
positions = positions.slice(0, ptr);
283+
positions = truncate(positions, ptr);
270284
this.idToIndex = idToIndex;
271285

272286
this.updateLines(options, positions);
@@ -368,7 +382,7 @@ proto.updateFancy = function(options) {
368382
bounds[3] = Math.max(bounds[3], yy + ey1);
369383
}
370384

371-
positions = positions.slice(0, ptr);
385+
positions = truncate(positions, ptr);
372386
this.idToIndex = idToIndex;
373387

374388
this.updateLines(options, positions);

0 commit comments

Comments
 (0)