8
8
9
9
'use strict' ;
10
10
11
- var createScatterPlot = require ( 'gl-scatter3d' ) ;
12
11
var conePlot = require ( 'gl-cone3d' ) ;
13
12
var createConeMesh = require ( 'gl-cone3d' ) . createConeMesh ;
14
13
@@ -19,14 +18,13 @@ function Cone(scene, uid) {
19
18
this . scene = scene ;
20
19
this . uid = uid ;
21
20
this . mesh = null ;
22
- this . pts = null ;
23
21
this . data = null ;
24
22
}
25
23
26
24
var proto = Cone . prototype ;
27
25
28
26
proto . handlePick = function ( selection ) {
29
- if ( selection . object === this . pts ) {
27
+ if ( selection . object === this . mesh ) {
30
28
var selectIndex = selection . index = selection . data . index ;
31
29
var xx = this . data . x [ selectIndex ] ;
32
30
var yy = this . data . y [ selectIndex ] ;
@@ -61,7 +59,6 @@ function zip3(x, y, z) {
61
59
}
62
60
63
61
var axisName2scaleIndex = { xaxis : 0 , yaxis : 1 , zaxis : 2 } ;
64
- var sizeMode2sizeKey = { scaled : 'coneSize' , absolute : 'absoluteConeSize' } ;
65
62
var anchor2coneOffset = { tip : 1 , tail : 0 , cm : 0.25 , center : 0.5 } ;
66
63
var anchor2coneSpan = { tip : 1 , tail : 1 , cm : 0.75 , center : 0.5 } ;
67
64
@@ -90,17 +87,23 @@ function convert(scene, trace) {
90
87
91
88
coneOpts . colormap = parseColorScale ( trace . colorscale ) ;
92
89
coneOpts . vertexIntensityBounds = [ trace . cmin / trace . _normMax , trace . cmax / trace . _normMax ] ;
93
-
94
- coneOpts [ sizeMode2sizeKey [ trace . sizemode ] ] = trace . sizeref ;
95
90
coneOpts . coneOffset = anchor2coneOffset [ trace . anchor ] ;
96
91
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
+ }
98
101
99
- // stash positions for gl-scatter3d 'hover' trace
100
- meshData . _pts = coneOpts . positions ;
102
+ var meshData = conePlot ( coneOpts ) ;
101
103
102
104
// 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 ] ;
104
107
meshData . ambient = trace . lighting . ambient ;
105
108
meshData . diffuse = trace . lighting . diffuse ;
106
109
meshData . specular = trace . lighting . specular ;
@@ -109,8 +112,7 @@ function convert(scene, trace) {
109
112
meshData . opacity = trace . opacity ;
110
113
111
114
// 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 ;
114
116
115
117
return meshData ;
116
118
}
@@ -119,14 +121,10 @@ proto.update = function(data) {
119
121
this . data = data ;
120
122
121
123
var meshData = convert ( this . scene , data ) ;
122
-
123
124
this . mesh . update ( meshData ) ;
124
- this . pts . update ( { position : meshData . _pts } ) ;
125
125
} ;
126
126
127
127
proto . dispose = function ( ) {
128
- this . scene . glplot . remove ( this . pts ) ;
129
- this . pts . dispose ( ) ;
130
128
this . scene . glplot . remove ( this . mesh ) ;
131
129
this . mesh . dispose ( ) ;
132
130
} ;
@@ -137,21 +135,11 @@ function createConeTrace(scene, data) {
137
135
var meshData = convert ( scene , data ) ;
138
136
var mesh = createConeMesh ( gl , meshData ) ;
139
137
140
- var pts = createScatterPlot ( {
141
- gl : gl ,
142
- position : meshData . _pts ,
143
- project : false ,
144
- opacity : 0
145
- } ) ;
146
-
147
138
var cone = new Cone ( scene , data . uid ) ;
148
139
cone . mesh = mesh ;
149
- cone . pts = pts ;
150
140
cone . data = data ;
151
141
mesh . _trace = cone ;
152
- pts . _trace = cone ;
153
142
154
- scene . glplot . add ( pts ) ;
155
143
scene . glplot . add ( mesh ) ;
156
144
157
145
return cone ;
0 commit comments