@@ -14,9 +14,11 @@ var isNumeric = require('fast-isnumeric');
1414var ScatterGl = require ( '../scattergl' ) ;
1515var calcColorscales = require ( '../scatter/colorscale_calc' ) ;
1616var calcMarkerSize = require ( '../scatter/calc' ) . calcMarkerSize ;
17+ var convert = require ( '../scattergl/convert' ) ;
18+
19+ var Lib = require ( '../../lib' ) ;
1720var Axes = require ( '../../plots/cartesian/axes' ) ;
1821var makeHoverPointText = require ( '../scatterpolar/hover' ) . makeHoverPointText ;
19- var subTypes = require ( '../scatter/subtypes' ) ;
2022
2123var TOO_MANY_POINTS = require ( '../scattergl/constants' ) . TOO_MANY_POINTS ;
2224
@@ -36,13 +38,19 @@ function calc(gd, trace) {
3638 stash . r = rArray ;
3739 stash . theta = thetaArray ;
3840
39- // We could add TOO_MANY_POINTS logic like in Scattergl.calc,
40- // if users asks for scaterpolargl charts with > 1e5 pts
41- var ppad = calcMarkerSize ( trace , len ) ;
42- trace . _extremes . x = Axes . findExtremes ( radialAxis , rArray , { ppad : ppad } ) ;
43-
4441 calcColorscales ( trace ) ;
4542
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 } ) ;
53+
4654 return [ { x : false , y : false , t : stash , trace : trace } ] ;
4755}
4856
@@ -53,14 +61,15 @@ function plot(gd, subplot, cdata) {
5361 var angularAxis = subplot . angularAxis ;
5462 var scene = ScatterGl . sceneUpdate ( gd , subplot ) ;
5563
56- cdata . forEach ( function ( cdscatter , traceIndex ) {
64+ cdata . forEach ( function ( cdscatter ) {
5765 if ( ! cdscatter || ! cdscatter [ 0 ] || ! cdscatter [ 0 ] . trace ) return ;
5866 var cd = cdscatter [ 0 ] ;
5967 var trace = cd . trace ;
6068 var stash = cd . t ;
6169 var len = trace . _length ;
6270 var rArray = stash . r ;
6371 var thetaArray = stash . theta ;
72+ var opts = stash . opts ;
6473 var i ;
6574
6675 var subRArray = rArray . slice ( ) ;
@@ -94,50 +103,65 @@ function plot(gd, subplot, cdata) {
94103 y [ i ] = positions [ i * 2 + 1 ] = yy ;
95104 }
96105
97- var options = ScatterGl . sceneOptions ( container , subplot , trace , positions ) ;
98-
99- // set flags to create scene renderers
100- if ( options . fill && ! scene . fill2d ) scene . fill2d = true ;
101- if ( options . marker && ! scene . scatter2d ) scene . scatter2d = true ;
102- if ( options . line && ! scene . line2d ) scene . line2d = true ;
103- if ( ( options . errorX || options . errorY ) && ! scene . error2d ) scene . error2d = true ;
104- if ( options . text && ! scene . glText ) scene . glText = true ;
105-
106106 stash . tree = cluster ( positions ) ;
107107
108108 // FIXME: see scattergl.js#109
109- if ( options . marker && count >= TOO_MANY_POINTS ) {
110- options . marker . cluster = stash . tree ;
109+ if ( opts . marker && len >= TOO_MANY_POINTS ) {
110+ opts . marker . cluster = stash . tree ;
111111 }
112112
113- // bring positions to selected/unselected options
114- if ( subTypes . hasMarkers ( trace ) ) {
115- options . markerSel . positions = options . markerUnsel . positions = options . marker . positions ;
113+ if ( opts . marker ) {
114+ opts . markerSel . positions = opts . markerUnsel . positions = opts . marker . positions = positions ;
116115 }
117116
118- // save scene options batch
119- scene . lineOptions . push ( options . line ) ;
120- scene . errorXOptions . push ( options . errorX ) ;
121- scene . errorYOptions . push ( options . errorY ) ;
122- scene . fillOptions . push ( options . fill ) ;
123- scene . markerOptions . push ( options . marker ) ;
124- scene . markerSelectedOptions . push ( options . markerSel ) ;
125- scene . markerUnselectedOptions . push ( options . markerUnsel ) ;
126- scene . textOptions . push ( options . text ) ;
127- scene . textSelectedOptions . push ( options . textSel ) ;
128- scene . textUnselectedOptions . push ( options . textUnsel ) ;
129- scene . count = cdata . length ;
130-
131- // stash scene ref
132- stash . _scene = scene ;
133- 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+
134156 stash . x = x ;
135157 stash . y = y ;
136158 stash . rawx = x ;
137159 stash . rawy = y ;
138160 stash . r = rArray ;
139161 stash . theta = thetaArray ;
140162 stash . positions = positions ;
163+ stash . _scene = scene ;
164+ stash . index = scene . count ++ ;
141165 } ) ;
142166
143167 return ScatterGl . plot ( gd , subplot , cdata ) ;
0 commit comments