@@ -13,47 +13,63 @@ var isNumeric = require('fast-isnumeric');
13
13
14
14
var ScatterGl = require ( '../scattergl' ) ;
15
15
var calcColorscales = require ( '../scatter/colorscale_calc' ) ;
16
+ var calcMarkerSize = require ( '../scatter/calc' ) . calcMarkerSize ;
17
+ var convert = require ( '../scattergl/convert' ) ;
18
+
19
+ var Lib = require ( '../../lib' ) ;
16
20
var Axes = require ( '../../plots/cartesian/axes' ) ;
17
21
var makeHoverPointText = require ( '../scatterpolar/hover' ) . makeHoverPointText ;
18
- var subTypes = require ( '../scatter/subtypes' ) ;
19
22
20
23
var TOO_MANY_POINTS = require ( '../scattergl/constants' ) . TOO_MANY_POINTS ;
21
24
22
- function calc ( container , trace ) {
23
- var layout = container . _fullLayout ;
25
+ function calc ( gd , trace ) {
26
+ var fullLayout = gd . _fullLayout ;
24
27
var subplotId = trace . subplot ;
25
- var radialAxis = layout [ subplotId ] . radialaxis ;
26
- var angularAxis = layout [ subplotId ] . angularaxis ;
28
+ var radialAxis = fullLayout [ subplotId ] . radialaxis ;
29
+ var angularAxis = fullLayout [ subplotId ] . angularaxis ;
27
30
var rArray = radialAxis . makeCalcdata ( trace , 'r' ) ;
28
31
var thetaArray = angularAxis . makeCalcdata ( trace , 'theta' ) ;
32
+ var len = trace . _length ;
29
33
var stash = { } ;
30
34
31
- if ( trace . _length < rArray . length ) rArray = rArray . slice ( 0 , trace . _length ) ;
32
- if ( trace . _length < thetaArray . length ) thetaArray = thetaArray . slice ( 0 , trace . _length ) ;
33
-
34
- calcColorscales ( trace ) ;
35
+ if ( len < rArray . length ) rArray = rArray . slice ( 0 , len ) ;
36
+ if ( len < thetaArray . length ) thetaArray = thetaArray . slice ( 0 , len ) ;
35
37
36
38
stash . r = rArray ;
37
39
stash . theta = thetaArray ;
38
40
39
- trace . _extremes . x = Axes . findExtremes ( radialAxis , rArray , { tozero : true } ) ;
41
+ calcColorscales ( trace ) ;
42
+
43
+ // only compute 'style' options in calc, as position options
44
+ // depend on the radial range and must be set in plot
45
+ var opts = stash . opts = convert . style ( gd , trace ) ;
46
+
47
+ // For graphs with very large number of points and array marker.size,
48
+ // use average marker size instead to speed things up.
49
+ var ppad = len < TOO_MANY_POINTS ?
50
+ calcMarkerSize ( trace , len ) :
51
+ 2 * ( opts . marker . sizeAvg || Math . max ( opts . marker . size , 3 ) ) ;
52
+ trace . _extremes . x = Axes . findExtremes ( radialAxis , rArray , { ppad : ppad } ) ;
40
53
41
54
return [ { x : false , y : false , t : stash , trace : trace } ] ;
42
55
}
43
56
44
- function plot ( container , subplot , cdata ) {
57
+ function plot ( gd , subplot , cdata ) {
58
+ if ( ! cdata . length ) return ;
59
+
45
60
var radialAxis = subplot . radialAxis ;
46
61
var angularAxis = subplot . angularAxis ;
62
+ var scene = ScatterGl . sceneUpdate ( gd , subplot ) ;
47
63
48
- var scene = ScatterGl . sceneUpdate ( container , subplot ) ;
49
-
50
- cdata . forEach ( function ( cdscatter , traceIndex ) {
64
+ cdata . forEach ( function ( cdscatter ) {
51
65
if ( ! cdscatter || ! cdscatter [ 0 ] || ! cdscatter [ 0 ] . trace ) return ;
52
66
var cd = cdscatter [ 0 ] ;
53
67
var trace = cd . trace ;
54
68
var stash = cd . t ;
69
+ var len = trace . _length ;
55
70
var rArray = stash . r ;
56
71
var thetaArray = stash . theta ;
72
+ var opts = stash . opts ;
57
73
var i ;
58
74
59
75
var subRArray = rArray . slice ( ) ;
@@ -67,12 +83,11 @@ function plot(container, subplot, cdata) {
67
83
}
68
84
}
69
85
70
- var count = rArray . length ;
71
- var positions = new Array ( count * 2 ) ;
72
- var x = Array ( count ) ;
73
- var y = Array ( count ) ;
86
+ var positions = new Array ( len * 2 ) ;
87
+ var x = Array ( len ) ;
88
+ var y = Array ( len ) ;
74
89
75
- for ( i = 0 ; i < count ; i ++ ) {
90
+ for ( i = 0 ; i < len ; i ++ ) {
76
91
var r = subRArray [ i ] ;
77
92
var xx , yy ;
78
93
@@ -88,54 +103,69 @@ function plot(container, subplot, cdata) {
88
103
y [ i ] = positions [ i * 2 + 1 ] = yy ;
89
104
}
90
105
91
- var options = ScatterGl . sceneOptions ( container , subplot , trace , positions ) ;
92
-
93
- // set flags to create scene renderers
94
- if ( options . fill && ! scene . fill2d ) scene . fill2d = true ;
95
- if ( options . marker && ! scene . scatter2d ) scene . scatter2d = true ;
96
- if ( options . line && ! scene . line2d ) scene . line2d = true ;
97
- if ( ( options . errorX || options . errorY ) && ! scene . error2d ) scene . error2d = true ;
98
- if ( options . text && ! scene . glText ) scene . glText = true ;
99
-
100
106
stash . tree = cluster ( positions ) ;
101
107
102
108
// FIXME: see scattergl.js#109
103
- if ( options . marker && count >= TOO_MANY_POINTS ) {
104
- options . marker . cluster = stash . tree ;
109
+ if ( opts . marker && len >= TOO_MANY_POINTS ) {
110
+ opts . marker . cluster = stash . tree ;
105
111
}
106
112
107
- // bring positions to selected/unselected options
108
- if ( subTypes . hasMarkers ( trace ) ) {
109
- options . markerSel . positions = options . markerUnsel . positions = options . marker . positions ;
113
+ if ( opts . marker ) {
114
+ opts . markerSel . positions = opts . markerUnsel . positions = opts . marker . positions = positions ;
110
115
}
111
116
112
- // save scene options batch
113
- scene . lineOptions . push ( options . line ) ;
114
- scene . errorXOptions . push ( options . errorX ) ;
115
- scene . errorYOptions . push ( options . errorY ) ;
116
- scene . fillOptions . push ( options . fill ) ;
117
- scene . markerOptions . push ( options . marker ) ;
118
- scene . markerSelectedOptions . push ( options . markerSel ) ;
119
- scene . markerUnselectedOptions . push ( options . markerUnsel ) ;
120
- scene . textOptions . push ( options . text ) ;
121
- scene . textSelectedOptions . push ( options . textSel ) ;
122
- scene . textUnselectedOptions . push ( options . textUnsel ) ;
123
- scene . count = cdata . length ;
124
-
125
- // stash scene ref
126
- stash . _scene = scene ;
127
- stash . index = traceIndex ;
117
+ if ( opts . line && positions . length > 1 ) {
118
+ Lib . extendFlat (
119
+ opts . line ,
120
+ convert . linePositions ( gd , trace , positions )
121
+ ) ;
122
+ }
123
+
124
+ if ( opts . text ) {
125
+ Lib . extendFlat (
126
+ opts . text ,
127
+ { positions : positions } ,
128
+ convert . textPosition ( gd , trace , opts . text , opts . marker )
129
+ ) ;
130
+ Lib . extendFlat (
131
+ opts . textSel ,
132
+ { positions : positions } ,
133
+ convert . textPosition ( gd , trace , opts . text , opts . markerSel )
134
+ ) ;
135
+ Lib . extendFlat (
136
+ opts . textUnsel ,
137
+ { positions : positions } ,
138
+ convert . textPosition ( gd , trace , opts . text , opts . markerUnsel )
139
+ ) ;
140
+ }
141
+
142
+ if ( opts . fill && ! scene . fill2d ) scene . fill2d = true ;
143
+ if ( opts . marker && ! scene . scatter2d ) scene . scatter2d = true ;
144
+ if ( opts . line && ! scene . line2d ) scene . line2d = true ;
145
+ if ( opts . text && ! scene . glText ) scene . glText = true ;
146
+
147
+ scene . lineOptions . push ( opts . line ) ;
148
+ scene . fillOptions . push ( opts . fill ) ;
149
+ scene . markerOptions . push ( opts . marker ) ;
150
+ scene . markerSelectedOptions . push ( opts . markerSel ) ;
151
+ scene . markerUnselectedOptions . push ( opts . markerUnsel ) ;
152
+ scene . textOptions . push ( opts . text ) ;
153
+ scene . textSelectedOptions . push ( opts . textSel ) ;
154
+ scene . textUnselectedOptions . push ( opts . textUnsel ) ;
155
+
128
156
stash . x = x ;
129
157
stash . y = y ;
130
158
stash . rawx = x ;
131
159
stash . rawy = y ;
132
160
stash . r = rArray ;
133
161
stash . theta = thetaArray ;
134
162
stash . positions = positions ;
135
- stash . count = count ;
163
+ stash . _scene = scene ;
164
+ stash . index = scene . count ;
165
+ scene . count ++ ;
136
166
} ) ;
137
167
138
- return ScatterGl . plot ( container , subplot , cdata ) ;
168
+ return ScatterGl . plot ( gd , subplot , cdata ) ;
139
169
}
140
170
141
171
function hoverPoints ( pointData , xval , yval , hovermode ) {
0 commit comments