Skip to content

Commit fed224c

Browse files
authored
Merge pull request #1033 from monfera/date-resolution-3
Preserving 64 bit floats for WebGL 2D plotting
2 parents ad864c4 + d528fa7 commit fed224c

File tree

6 files changed

+113
-50
lines changed

6 files changed

+113
-50
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@
5959
"es6-promise": "^3.0.2",
6060
"fast-isnumeric": "^1.1.1",
6161
"gl-contour2d": "^1.1.2",
62-
"gl-error2d": "^1.0.0",
62+
"gl-error2d": "^1.2.0",
6363
"gl-error3d": "^1.0.0",
6464
"gl-heatmap2d": "^1.0.2",
65-
"gl-line2d": "^1.3.0",
65+
"gl-line2d": "^1.4.0",
6666
"gl-line3d": "^1.1.0",
6767
"gl-mat4": "^1.1.2",
6868
"gl-mesh3d": "^1.2.0",
6969
"gl-plot2d": "^1.1.9",
7070
"gl-plot3d": "^1.5.1",
7171
"gl-pointcloud2d": "^1.0.0",
72-
"gl-scatter2d": "^1.0.5",
73-
"gl-scatter2d-fancy": "^1.1.1",
72+
"gl-scatter2d": "^1.2.0",
73+
"gl-scatter2d-fancy": "^1.2.0",
7474
"gl-scatter3d": "^1.0.4",
7575
"gl-select-box": "^1.0.1",
7676
"gl-shader": "4.2.0",

src/lib/float32_truncate.js

-21
This file was deleted.

src/lib/typed_array_truncate.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
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+
23+
/**
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
27+
*/
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`.');
32+
};

src/traces/scattergl/convert.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Axes = require('../../plots/cartesian/axes');
2020
var autoType = require('../../plots/cartesian/axis_autotype');
2121
var ErrorBars = require('../../components/errorbars');
2222
var str2RGBArray = require('../../lib/str2rgbarray');
23-
var truncate = require('../../lib/float32_truncate');
23+
var truncate = require('../../lib/typed_array_truncate');
2424
var formatColor = require('../../lib/gl_format_color');
2525
var subTypes = require('../scatter/subtypes');
2626
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
@@ -51,7 +51,7 @@ function LineWithMarkers(scene, uid) {
5151

5252
this.hasLines = false;
5353
this.lineOptions = {
54-
positions: new Float32Array(0),
54+
positions: new Float64Array(0),
5555
color: [0, 0, 0, 1],
5656
width: 1,
5757
fill: [false, false, false, false],
@@ -67,8 +67,8 @@ function LineWithMarkers(scene, uid) {
6767

6868
this.hasErrorX = false;
6969
this.errorXOptions = {
70-
positions: new Float32Array(0),
71-
errors: new Float32Array(0),
70+
positions: new Float64Array(0),
71+
errors: new Float64Array(0),
7272
lineWidth: 1,
7373
capSize: 0,
7474
color: [0, 0, 0, 1]
@@ -78,8 +78,8 @@ function LineWithMarkers(scene, uid) {
7878

7979
this.hasErrorY = false;
8080
this.errorYOptions = {
81-
positions: new Float32Array(0),
82-
errors: new Float32Array(0),
81+
positions: new Float64Array(0),
82+
errors: new Float64Array(0),
8383
lineWidth: 1,
8484
capSize: 0,
8585
color: [0, 0, 0, 1]
@@ -89,7 +89,7 @@ function LineWithMarkers(scene, uid) {
8989

9090
this.hasMarkers = false;
9191
this.scatterOptions = {
92-
positions: new Float32Array(0),
92+
positions: new Float64Array(0),
9393
sizes: [],
9494
colors: [],
9595
glyphs: [],
@@ -291,7 +291,7 @@ proto.updateFast = function(options) {
291291

292292
var len = x.length,
293293
idToIndex = new Array(len),
294-
positions = new Float32Array(2 * len),
294+
positions = new Float64Array(2 * len),
295295
bounds = this.bounds,
296296
pId = 0,
297297
ptr = 0;
@@ -357,13 +357,13 @@ proto.updateFast = function(options) {
357357
this.scatter.update(this.scatterOptions);
358358
}
359359
else {
360-
this.scatterOptions.positions = new Float32Array(0);
360+
this.scatterOptions.positions = new Float64Array(0);
361361
this.scatterOptions.glyphs = [];
362362
this.scatter.update(this.scatterOptions);
363363
}
364364

365365
// turn off fancy scatter plot
366-
this.scatterOptions.positions = new Float32Array(0);
366+
this.scatterOptions.positions = new Float64Array(0);
367367
this.scatterOptions.glyphs = [];
368368
this.fancyScatter.update(this.scatterOptions);
369369

@@ -389,9 +389,9 @@ proto.updateFancy = function(options) {
389389

390390
var len = x.length,
391391
idToIndex = new Array(len),
392-
positions = new Float32Array(2 * len),
393-
errorsX = new Float32Array(4 * len),
394-
errorsY = new Float32Array(4 * len),
392+
positions = new Float64Array(2 * len),
393+
errorsX = new Float64Array(4 * len),
394+
errorsY = new Float64Array(4 * len),
395395
pId = 0,
396396
ptr = 0,
397397
ptrX = 0,
@@ -482,13 +482,13 @@ proto.updateFancy = function(options) {
482482
this.fancyScatter.update(this.scatterOptions);
483483
}
484484
else {
485-
this.scatterOptions.positions = new Float32Array(0);
485+
this.scatterOptions.positions = new Float64Array(0);
486486
this.scatterOptions.glyphs = [];
487487
this.fancyScatter.update(this.scatterOptions);
488488
}
489489

490490
// turn off fast scatter plot
491-
this.scatterOptions.positions = new Float32Array(0);
491+
this.scatterOptions.positions = new Float64Array(0);
492492
this.scatterOptions.glyphs = [];
493493
this.scatter.update(this.scatterOptions);
494494

@@ -506,7 +506,7 @@ proto.updateLines = function(options, positions) {
506506
var p = 0;
507507
var x = this.xData;
508508
var y = this.yData;
509-
linePositions = new Float32Array(2 * x.length);
509+
linePositions = new Float64Array(2 * x.length);
510510

511511
for(i = 0; i < x.length; ++i) {
512512
linePositions[p++] = x[i];
@@ -542,7 +542,7 @@ proto.updateLines = function(options, positions) {
542542
this.lineOptions.fillColor = [fillColor, fillColor, fillColor, fillColor];
543543
}
544544
else {
545-
this.lineOptions.positions = new Float32Array(0);
545+
this.lineOptions.positions = new Float64Array(0);
546546
}
547547

548548
this.line.update(this.lineOptions);
@@ -565,7 +565,7 @@ proto.updateError = function(axLetter, options, positions, errors) {
565565
errorObjOptions.color = convertColor(errorOptions.color, 1, 1);
566566
}
567567
else {
568-
errorObjOptions.positions = new Float32Array(0);
568+
errorObjOptions.positions = new Float64Array(0);
569569
}
570570

571571
errorObj.update(errorObjOptions);
@@ -588,7 +588,7 @@ proto.expandAxesFast = function(bounds, markerSize) {
588588
}
589589
};
590590

591-
// not quite on-par with 'scatter' (scatter fill in several other expand options),
591+
// not quite on-par with 'scatter' (scatter fill in several other expand options)
592592
// but close enough for now
593593
proto.expandAxesFancy = function(x, y, ppad) {
594594
var scene = this.scene,
865 Bytes
Loading

test/image/mocks/gl2d_date_axes.json

+58-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,68 @@
22
"data": [
33
{
44
"x": [
5-
"2013-10-04 22:23:00",
6-
"2013-11-04 22:23:00",
7-
"2013-12-04 22:23:00"
5+
"1970-10-25 22:23:00",
6+
"1970-10-25 22:23:00.001",
7+
"1970-10-25 22:23:00.002",
8+
"1970-10-25 22:23:00.003",
9+
"1970-10-25 22:23:00.004",
10+
"2016-10-25 22:23:00",
11+
"2016-10-25 22:23:00.001",
12+
"2016-10-25 22:23:00.002",
13+
"2016-10-25 22:23:00.003",
14+
"2016-10-25 22:23:00.004"
815
],
916
"y": [
17+
0,
1018
1,
19+
2,
1120
3,
12-
6
21+
4,
22+
5,
23+
6,
24+
7,
25+
8,
26+
9
1327
],
14-
"type": "scattergl"
28+
"type": "scattergl",
29+
"mode": "markers"
30+
},
31+
{
32+
"x": [
33+
"1970-10-25 22:23:00",
34+
"1970-10-25 22:23:00.001",
35+
"1970-10-25 22:23:00.002",
36+
"1970-10-25 22:23:00.003",
37+
"1970-10-25 22:23:00.004",
38+
"2016-10-25 22:23:00",
39+
"2016-10-25 22:23:00.001",
40+
"2016-10-25 22:23:00.002",
41+
"2016-10-25 22:23:00.003",
42+
"2016-10-25 22:23:00.004"
43+
],
44+
"y": [
45+
10,
46+
11,
47+
12,
48+
13,
49+
14,
50+
15,
51+
16,
52+
17,
53+
18,
54+
19
55+
],
56+
"type": "scattergl",
57+
"mode": "lines+markers"
58+
}
59+
],
60+
"layout": {
61+
"xaxis": {
62+
"range": [
63+
1477434179998,
64+
1477434180004
65+
],
66+
"autorange": false
1567
}
16-
]
68+
}
1769
}

0 commit comments

Comments
 (0)