@@ -13,47 +13,63 @@ var isNumeric = require('fast-isnumeric');
1313
1414var ScatterGl = require ( '../scattergl' ) ;
1515var calcColorscales = require ( '../scatter/colorscale_calc' ) ;
16+ var calcMarkerSize = require ( '../scatter/calc' ) . calcMarkerSize ;
17+ var convert = require ( '../scattergl/convert' ) ;
18+
19+ var Lib = require ( '../../lib' ) ;
1620var Axes = require ( '../../plots/cartesian/axes' ) ;
1721var makeHoverPointText = require ( '../scatterpolar/hover' ) . makeHoverPointText ;
18- var subTypes = require ( '../scatter/subtypes' ) ;
1922
2023var TOO_MANY_POINTS = require ( '../scattergl/constants' ) . TOO_MANY_POINTS ;
2124
22- function calc ( container , trace ) {
23- var layout = container . _fullLayout ;
25+ function calc ( gd , trace ) {
26+ var fullLayout = gd . _fullLayout ;
2427 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 ;
2730 var rArray = radialAxis . makeCalcdata ( trace , 'r' ) ;
2831 var thetaArray = angularAxis . makeCalcdata ( trace , 'theta' ) ;
32+ var len = trace . _length ;
2933 var stash = { } ;
3034
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 ) ;
3537
3638 stash . r = rArray ;
3739 stash . theta = thetaArray ;
3840
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 } ) ;
4053
4154 return [ { x : false , y : false , t : stash , trace : trace } ] ;
4255}
4356
44- function plot ( container , subplot , cdata ) {
57+ function plot ( gd , subplot , cdata ) {
58+ if ( ! cdata . length ) return ;
59+
4560 var radialAxis = subplot . radialAxis ;
4661 var angularAxis = subplot . angularAxis ;
62+ var scene = ScatterGl . sceneUpdate ( gd , subplot ) ;
4763
48- var scene = ScatterGl . sceneUpdate ( container , subplot ) ;
49-
50- cdata . forEach ( function ( cdscatter , traceIndex ) {
64+ cdata . forEach ( function ( cdscatter ) {
5165 if ( ! cdscatter || ! cdscatter [ 0 ] || ! cdscatter [ 0 ] . trace ) return ;
5266 var cd = cdscatter [ 0 ] ;
5367 var trace = cd . trace ;
5468 var stash = cd . t ;
69+ var len = trace . _length ;
5570 var rArray = stash . r ;
5671 var thetaArray = stash . theta ;
72+ var opts = stash . opts ;
5773 var i ;
5874
5975 var subRArray = rArray . slice ( ) ;
@@ -67,12 +83,11 @@ function plot(container, subplot, cdata) {
6783 }
6884 }
6985
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 ) ;
7489
75- for ( i = 0 ; i < count ; i ++ ) {
90+ for ( i = 0 ; i < len ; i ++ ) {
7691 var r = subRArray [ i ] ;
7792 var xx , yy ;
7893
@@ -88,54 +103,69 @@ function plot(container, subplot, cdata) {
88103 y [ i ] = positions [ i * 2 + 1 ] = yy ;
89104 }
90105
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-
100106 stash . tree = cluster ( positions ) ;
101107
102108 // 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 ;
105111 }
106112
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 ;
110115 }
111116
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+
128156 stash . x = x ;
129157 stash . y = y ;
130158 stash . rawx = x ;
131159 stash . rawy = y ;
132160 stash . r = rArray ;
133161 stash . theta = thetaArray ;
134162 stash . positions = positions ;
135- stash . count = count ;
163+ stash . _scene = scene ;
164+ stash . index = scene . count ;
165+ scene . count ++ ;
136166 } ) ;
137167
138- return ScatterGl . plot ( container , subplot , cdata ) ;
168+ return ScatterGl . plot ( gd , subplot , cdata ) ;
139169}
140170
141171function hoverPoints ( pointData , xval , yval , hovermode ) {
0 commit comments