Skip to content

Commit a276f6b

Browse files
committed
Retain double float resolution of position data
1 parent 10d6836 commit a276f6b

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"gl-plot2d": "^1.1.6",
6969
"gl-plot3d": "^1.5.1",
7070
"gl-pointcloud2d": "^1.0.0",
71-
"gl-scatter2d": "^1.0.5",
71+
"gl-scatter2d": "monfera/gl-scatter2d#64-bit",
7272
"gl-scatter2d-fancy": "^1.1.1",
7373
"gl-scatter3d": "^1.0.4",
7474
"gl-select-box": "^1.0.1",

src/lib/float32_truncate.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@
88

99
'use strict';
1010

11+
function truncateFloat32(arrayIn, len) {
12+
var arrayOut = new Float32Array(len);
13+
for(var i = 0; i < len; i++) arrayOut[i] = arrayIn[i];
14+
return arrayOut;
15+
}
16+
17+
function truncateFloat64(arrayIn, len) {
18+
var arrayOut = new Float64Array(len);
19+
for(var i = 0; i < len; i++) arrayOut[i] = arrayIn[i];
20+
return arrayOut;
21+
}
22+
1123
/**
12-
* Truncate a Float32Array to some length. A wrapper to support environments
13-
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
24+
* Truncate a typed array to some length.
25+
* For some reason, ES2015 Float32Array.prototype.slice takes
26+
* 2x as long, therefore we aren't checking for its existence
1427
*/
15-
module.exports = function truncate(float32ArrayIn, len) {
16-
// for some reason, ES2015 Float32Array.prototype.slice takes 2x as long...
17-
// therefore we aren't checking for its existence
18-
var float32ArrayOut = new Float32Array(len);
19-
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
20-
return float32ArrayOut;
28+
module.exports = function truncate(arrayIn, len) {
29+
if(arrayIn instanceof Float32Array) return truncateFloat32(arrayIn, len);
30+
if(arrayIn instanceof Float64Array) return truncateFloat64(arrayIn, len);
31+
throw new Error('This array type is not yet supported by `truncate`.');
2132
};

src/traces/scattergl/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ proto.updateFast = function(options) {
265265

266266
var len = x.length,
267267
idToIndex = new Array(len),
268-
positions = new Float32Array(2 * len),
268+
positions = new Float64Array(2 * len),
269269
bounds = this.bounds,
270270
pId = 0,
271271
ptr = 0;

0 commit comments

Comments
 (0)