Skip to content

Commit 553975d

Browse files
committed
abstracted out truncate
1 parent 0deaccc commit 553975d

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

Diff for: src/lib/float32_truncate.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
/**
12+
* Truncate a Float32Array to some length. A wrapper to support environments
13+
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
14+
*/
15+
module.exports = function truncate(float32ArrayIn, len) {
16+
if(Float32Array.slice === undefined) {
17+
var float32ArrayOut = new Float32Array(len);
18+
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
19+
return float32ArrayOut;
20+
}
21+
22+
return float32ArrayIn.slice(0, len);
23+
};

Diff for: src/traces/pointcloud/convert.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var createpointcloud = require('gl-pointcloud2d');
1212
var isNumeric = require('fast-isnumeric');
1313

1414
var str2RGBArray = require('../../lib/str2rgbarray');
15+
var truncate = require('../../lib/float32_truncate');
1516
var getTraceColor = require('../scatter/get_trace_color');
1617

1718
var AXES = ['xaxis', 'yaxis'];
@@ -67,20 +68,6 @@ proto.handlePick = function(pickResult) {
6768
};
6869
};
6970

70-
/**
71-
* Truncate a Float32Array to some length. A wrapper to support environments
72-
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
73-
*/
74-
function truncate(float32ArrayIn, len) {
75-
if(Float32Array.slice === undefined) {
76-
var float32ArrayOut = new Float32Array(len);
77-
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
78-
return float32ArrayOut;
79-
}
80-
81-
return float32ArrayIn.slice(0, len);
82-
}
83-
8471
proto.update = function(options) {
8572

8673
this.textLabels = options.text;

Diff for: src/traces/scattergl/convert.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var Lib = require('../../lib');
1919
var Axes = require('../../plots/cartesian/axes');
2020
var ErrorBars = require('../../components/errorbars');
2121
var str2RGBArray = require('../../lib/str2rgbarray');
22+
var truncate = require('../../lib/float32_truncate');
2223
var formatColor = require('../../lib/gl_format_color');
2324
var subTypes = require('../scatter/subtypes');
2425
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
@@ -218,20 +219,6 @@ function _convertColor(colors, opacities, count) {
218219
return result;
219220
}
220221

221-
/**
222-
* Truncate a Float32Array to some length. A wrapper to support environments
223-
* (e.g. node-webkit) that do not implement Float32Array.prototype.slice
224-
*/
225-
function truncate(float32ArrayIn, len) {
226-
if(Float32Array.slice === undefined) {
227-
var float32ArrayOut = new Float32Array(len);
228-
for(var i = 0; i < len; i++) float32ArrayOut[i] = float32ArrayIn[i];
229-
return float32ArrayOut;
230-
}
231-
232-
return float32ArrayIn.slice(0, len);
233-
}
234-
235222
/* Order is important here to get the correct laying:
236223
* - lines
237224
* - errorX

0 commit comments

Comments
 (0)