88
99'use strict' ;
1010
11- var createScatterPlot = require ( 'gl-scatter3d' ) ;
1211var conePlot = require ( 'gl-cone3d' ) ;
1312var createConeMesh = require ( 'gl-cone3d' ) . createConeMesh ;
1413
@@ -19,14 +18,13 @@ function Cone(scene, uid) {
1918 this . scene = scene ;
2019 this . uid = uid ;
2120 this . mesh = null ;
22- this . pts = null ;
2321 this . data = null ;
2422}
2523
2624var proto = Cone . prototype ;
2725
2826proto . handlePick = function ( selection ) {
29- if ( selection . object === this . pts ) {
27+ if ( selection . object === this . mesh ) {
3028 var selectIndex = selection . index = selection . data . index ;
3129 var xx = this . data . x [ selectIndex ] ;
3230 var yy = this . data . y [ selectIndex ] ;
@@ -61,7 +59,6 @@ function zip3(x, y, z) {
6159}
6260
6361var axisName2scaleIndex = { xaxis : 0 , yaxis : 1 , zaxis : 2 } ;
64- var sizeMode2sizeKey = { scaled : 'coneSize' , absolute : 'absoluteConeSize' } ;
6562var anchor2coneOffset = { tip : 1 , tail : 0 , cm : 0.25 , center : 0.5 } ;
6663var anchor2coneSpan = { tip : 1 , tail : 1 , cm : 0.75 , center : 0.5 } ;
6764
@@ -90,17 +87,23 @@ function convert(scene, trace) {
9087
9188 coneOpts . colormap = parseColorScale ( trace . colorscale ) ;
9289 coneOpts . vertexIntensityBounds = [ trace . cmin / trace . _normMax , trace . cmax / trace . _normMax ] ;
93-
94- coneOpts [ sizeMode2sizeKey [ trace . sizemode ] ] = trace . sizeref ;
9590 coneOpts . coneOffset = anchor2coneOffset [ trace . anchor ] ;
9691
97- var meshData = conePlot ( coneOpts ) ;
92+ if ( trace . sizemode === 'scaled' ) {
93+ // unitless sizeref
94+ coneOpts . coneSize = trace . sizeref || 0.5 ;
95+ } else {
96+ // sizeref here has unit of velocity
97+ coneOpts . coneSize = trace . sizeref && trace . _normMax ?
98+ trace . sizeref / trace . _normMax :
99+ 0.5 ;
100+ }
98101
99- // stash positions for gl-scatter3d 'hover' trace
100- meshData . _pts = coneOpts . positions ;
102+ var meshData = conePlot ( coneOpts ) ;
101103
102104 // pass gl-mesh3d lighting attributes
103- meshData . lightPosition = [ trace . lightposition . x , trace . lightposition . y , trace . lightposition . z ] ;
105+ var lp = trace . lightposition ;
106+ meshData . lightPosition = [ lp . x , lp . y , lp . z ] ;
104107 meshData . ambient = trace . lighting . ambient ;
105108 meshData . diffuse = trace . lighting . diffuse ;
106109 meshData . specular = trace . lighting . specular ;
@@ -109,8 +112,7 @@ function convert(scene, trace) {
109112 meshData . opacity = trace . opacity ;
110113
111114 // stash autorange pad value
112- trace . _pad = anchor2coneSpan [ trace . anchor ] * meshData . vectorScale * trace . sizeref ;
113- if ( trace . sizemode === 'scaled' ) trace . _pad *= trace . _normMax ;
115+ trace . _pad = anchor2coneSpan [ trace . anchor ] * meshData . vectorScale * meshData . coneScale * trace . _normMax ;
114116
115117 return meshData ;
116118}
@@ -119,14 +121,10 @@ proto.update = function(data) {
119121 this . data = data ;
120122
121123 var meshData = convert ( this . scene , data ) ;
122-
123124 this . mesh . update ( meshData ) ;
124- this . pts . update ( { position : meshData . _pts } ) ;
125125} ;
126126
127127proto . dispose = function ( ) {
128- this . scene . glplot . remove ( this . pts ) ;
129- this . pts . dispose ( ) ;
130128 this . scene . glplot . remove ( this . mesh ) ;
131129 this . mesh . dispose ( ) ;
132130} ;
@@ -137,21 +135,11 @@ function createConeTrace(scene, data) {
137135 var meshData = convert ( scene , data ) ;
138136 var mesh = createConeMesh ( gl , meshData ) ;
139137
140- var pts = createScatterPlot ( {
141- gl : gl ,
142- position : meshData . _pts ,
143- project : false ,
144- opacity : 0
145- } ) ;
146-
147138 var cone = new Cone ( scene , data . uid ) ;
148139 cone . mesh = mesh ;
149- cone . pts = pts ;
150140 cone . data = data ;
151141 mesh . _trace = cone ;
152- pts . _trace = cone ;
153142
154- scene . glplot . add ( pts ) ;
155143 scene . glplot . add ( mesh ) ;
156144
157145 return cone ;
0 commit comments