11
11
var createRegl = require ( 'regl' ) ;
12
12
var createMatrix = require ( 'regl-scattermatrix' ) ;
13
13
14
- var ScatterGl = require ( '../scattergl ' ) ;
14
+ var Lib = require ( '../../lib ' ) ;
15
15
var AxisIDs = require ( '../../plots/cartesian/axis_ids' ) ;
16
16
17
17
var calcMarkerSize = require ( '../scatter/calc' ) . calcMarkerSize ;
18
18
var calcAxisExpansion = require ( '../scatter/calc' ) . calcAxisExpansion ;
19
19
var calcColorscales = require ( '../scatter/colorscale_calc' ) ;
20
+ var convertMarkerStyle = require ( '../scattergl/convert' ) . convertMarkerStyle ;
20
21
21
- var TOO_MANY_POINTS = 1e5 ;
22
+ var BADNUM = require ( '../../constants/numerical' ) . BADNUM ;
23
+ var TOO_MANY_POINTS = require ( '../scattergl/constants' ) . TOO_MANY_POINTS ;
22
24
23
25
function calc ( gd , trace ) {
24
26
var stash = { } ;
25
27
var opts = { } ;
26
- var i ;
28
+ var i , xa , ya ;
27
29
28
30
var dimLength = trace . dimensions . length ;
29
31
var hasTooManyPoints = ( dimLength * trace . _commonLength ) > TOO_MANY_POINTS ;
30
- opts . data = new Array ( dimLength ) ;
31
-
32
- var markerOptions = { } ;
32
+ var matrix = opts . data = new Array ( dimLength ) ;
33
33
34
34
for ( i = 0 ; i < dimLength ; i ++ ) {
35
- var xa = AxisIDs . getFromId ( gd , trace . xaxes [ i ] ) ;
36
- var ya = AxisIDs . getFromId ( gd , trace . yaxes [ i ] ) ;
37
-
38
35
// using xa or ya should make no difference here
39
- var vals = opts . data [ i ] = makeCalcdata ( xa , trace , trace . dimensions [ i ] ) ;
36
+ xa = AxisIDs . getFromId ( gd , trace . xaxes [ i ] ) ;
37
+ matrix [ i ] = makeCalcdata ( xa , trace , trace . dimensions [ i ] ) ;
38
+ }
39
+
40
+ calcColorscales ( trace ) ;
41
+ Lib . extendFlat ( opts , convertMarkerStyle ( trace ) ) ;
42
+
43
+ for ( i = 0 ; i < dimLength ; i ++ ) {
44
+ xa = AxisIDs . getFromId ( gd , trace . xaxes [ i ] ) ;
45
+ ya = AxisIDs . getFromId ( gd , trace . yaxes [ i ] ) ;
40
46
41
47
// Re-use SVG scatter axis expansion routine except
42
48
// for graph with very large number of points where it
@@ -45,40 +51,109 @@ function calc(gd, trace) {
45
51
// and an average size for array marker.size inputs.
46
52
var ppad ;
47
53
if ( hasTooManyPoints ) {
48
- ppad = 2 * ( markerOptions . sizeAvg || Math . max ( markerOptions . size , 3 ) ) ;
49
- } else if ( markerOptions ) {
50
- ppad = calcMarkerSize ( trace , trace . _length ) ;
54
+ ppad = 2 * ( opts . sizeAvg || Math . max ( opts . size , 3 ) ) ;
55
+ } else {
56
+ ppad = calcMarkerSize ( trace , trace . _commonLength ) ;
51
57
}
52
- calcAxisExpansion ( gd , trace , xa , ya , vals , vals , ppad ) ;
58
+ calcAxisExpansion ( gd , trace , xa , ya , matrix [ i ] , matrix [ i ] , ppad ) ;
53
59
}
54
60
55
- // TODO
56
- // - marker / line options
57
- // - colorscale
58
-
59
- var scene = stash . scene = { } ;
60
- scene . scatterOpts = opts ;
61
-
62
- scene . matrix = true ;
61
+ var scene = stash . scene = sceneUpdate ( gd , stash ) ;
62
+ if ( ! scene . matrix ) scene . matrix = true ;
63
+ scene . matrixOptions = opts ;
63
64
64
65
return [ { x : false , y : false , t : stash , trace : trace } ] ;
65
66
}
66
67
67
68
function makeCalcdata ( ax , trace , dim ) {
69
+ var i ;
70
+
68
71
var cdata = ax . makeCalcdata ( {
69
72
v : dim . values ,
70
73
vcalendar : trace . calendar
71
74
} , 'v' ) ;
72
75
76
+ for ( i = 0 ; i < cdata . length ; i ++ ) {
77
+ cdata [ i ] = cdata [ i ] === BADNUM ? NaN : cdata [ i ] ;
78
+ }
79
+
73
80
if ( ax . type === 'log' ) {
74
- for ( var i = 0 ; i < cdata . length ; i ++ ) {
81
+ for ( i = 0 ; i < cdata . length ; i ++ ) {
75
82
cdata [ i ] = ax . c2l ( cdata [ i ] ) ;
76
83
}
77
84
}
78
85
79
86
return cdata ;
80
87
}
81
88
89
+ function sceneUpdate ( gd , stash ) {
90
+ var scene = stash . _scene ;
91
+
92
+ var reset = {
93
+ dirty : true ,
94
+ opts : null
95
+ } ;
96
+
97
+ var first = {
98
+ selectBatch : null ,
99
+ unselectBatch : null ,
100
+ // regl- component stubs, initialized in dirty plot call
101
+ matrix : false ,
102
+ select : null
103
+ } ;
104
+
105
+ if ( ! scene ) {
106
+ scene = stash . _scene = Lib . extendFlat ( { } , reset , first ) ;
107
+
108
+ scene . update = function update ( opt ) {
109
+ if ( scene . matrix ) scene . matrix . update ( opt ) ;
110
+ scene . draw ( ) ;
111
+ } ;
112
+
113
+ scene . draw = function draw ( ) {
114
+ if ( scene . matrix ) scene . matrix . draw ( ) ;
115
+
116
+ // TODO selection stuff
117
+
118
+ scene . dirty = false ;
119
+ } ;
120
+
121
+ // make sure canvas is clear
122
+ scene . clear = function clear ( ) {
123
+ // TODO
124
+ } ;
125
+
126
+ // remove selection
127
+ scene . clearSelect = function clearSelect ( ) {
128
+ if ( ! scene . selectBatch ) return ;
129
+ scene . selectBatch = null ;
130
+ scene . unselectBatch = null ;
131
+ scene . matrix . update ( scene . opts ) ;
132
+ scene . clear ( ) ;
133
+ scene . draw ( ) ;
134
+ } ;
135
+
136
+ // remove scene resources
137
+ scene . destroy = function destroy ( ) {
138
+ if ( scene . matrix ) scene . matrix . destroy ( ) ;
139
+
140
+ scene . opts = null ;
141
+ scene . selectBatch = null ;
142
+ scene . unselectBatch = null ;
143
+
144
+ stash . _scene = null ;
145
+ } ;
146
+ }
147
+
148
+ // In case if we have scene from the last calc - reset data
149
+ if ( ! scene . dirty ) {
150
+ Lib . extendFlat ( scene , reset ) ;
151
+ }
152
+
153
+ return scene ;
154
+
155
+ }
156
+
82
157
function plot ( gd , _ , cdata ) {
83
158
if ( ! cdata . length ) return ;
84
159
@@ -103,28 +178,30 @@ function plot(gd, _, cdata) {
103
178
104
179
var regl = fullLayout . _glcanvas . data ( ) [ 0 ] . regl ;
105
180
106
- var opts = scene . scatterOpts ;
107
181
var dimLength = trace . dimensions . length ;
108
- opts . ranges = new Array ( dimLength ) ;
109
- opts . domains = new Array ( dimLength ) ;
182
+ var viewOpts = {
183
+ ranges : new Array ( dimLength ) ,
184
+ domains : new Array ( dimLength )
185
+ } ;
110
186
111
187
for ( var i = 0 ; i < dimLength ; i ++ ) {
112
188
var xa = AxisIDs . getFromId ( gd , trace . xaxes [ i ] ) ;
113
189
var ya = AxisIDs . getFromId ( gd , trace . yaxes [ i ] ) ;
114
- opts . ranges [ i ] = [ xa . range [ 0 ] , ya . range [ 0 ] , xa . range [ 1 ] , ya . range [ 1 ] ] ;
115
- opts . domains [ i ] = [ xa . domain [ 0 ] , ya . domain [ 0 ] , xa . domain [ 1 ] , ya . domain [ 1 ] ] ;
190
+ viewOpts . ranges [ i ] = [ xa . range [ 0 ] , ya . range [ 0 ] , xa . range [ 1 ] , ya . range [ 1 ] ] ;
191
+ viewOpts . domains [ i ] = [ xa . domain [ 0 ] , ya . domain [ 0 ] , xa . domain [ 1 ] , ya . domain [ 1 ] ] ;
116
192
}
117
193
118
- scene . scatterOpts . viewport = [ 0 , 0 , fullLayout . width , fullLayout . height ] ;
119
- scene . scatterOpts . padding = [ gs . l , gs . t , gs . r , gs . b ] ;
194
+ viewOpts . viewport = [ 0 , 0 , fullLayout . width , fullLayout . height ] ;
195
+ viewOpts . padding = [ gs . l , gs . t , gs . r , gs . b ] ;
120
196
121
197
if ( scene . matrix === true ) {
122
198
scene . matrix = createMatrix ( regl ) ;
123
199
}
124
200
if ( scene . matrix ) {
125
- scene . matrix . update ( scene . scatterOpts ) ;
126
- scene . matrix . draw ( ) ;
201
+ scene . matrix . update ( scene . matrixOptions ) ;
127
202
}
203
+
204
+ scene . update ( viewOpts ) ;
128
205
}
129
206
130
207
// TODO splom 'needs' the grid component, register it here?
0 commit comments