@@ -49,8 +49,13 @@ function LineWithMarkers(scene, uid) {
49
49
this . idToIndex = [ ] ;
50
50
this . bounds = [ 0 , 0 , 0 , 0 ] ;
51
51
52
+ this . isVisible = false ;
52
53
this . hasLines = false ;
53
- this . lineOptions = {
54
+ this . hasErrorX = false ;
55
+ this . hasErrorY = false ;
56
+ this . hasMarkers = false ;
57
+
58
+ this . line = this . initObject ( createLine , {
54
59
positions : new Float64Array ( 0 ) ,
55
60
color : [ 0 , 0 , 0 , 1 ] ,
56
61
width : 1 ,
@@ -61,34 +66,25 @@ function LineWithMarkers(scene, uid) {
61
66
[ 0 , 0 , 0 , 1 ] ,
62
67
[ 0 , 0 , 0 , 1 ] ] ,
63
68
dashes : [ 1 ]
64
- } ;
65
- this . line = createLine ( scene . glplot , this . lineOptions ) ;
66
- this . line . _trace = this ;
69
+ } ) ;
67
70
68
- this . hasErrorX = false ;
69
- this . errorXOptions = {
71
+ this . errorX = this . initObject ( createError , {
70
72
positions : new Float64Array ( 0 ) ,
71
73
errors : new Float64Array ( 0 ) ,
72
74
lineWidth : 1 ,
73
75
capSize : 0 ,
74
76
color : [ 0 , 0 , 0 , 1 ]
75
- } ;
76
- this . errorX = createError ( scene . glplot , this . errorXOptions ) ;
77
- this . errorX . _trace = this ;
77
+ } ) ;
78
78
79
- this . hasErrorY = false ;
80
- this . errorYOptions = {
79
+ this . errorY = this . initObject ( createError , {
81
80
positions : new Float64Array ( 0 ) ,
82
81
errors : new Float64Array ( 0 ) ,
83
82
lineWidth : 1 ,
84
83
capSize : 0 ,
85
84
color : [ 0 , 0 , 0 , 1 ]
86
- } ;
87
- this . errorY = createError ( scene . glplot , this . errorYOptions ) ;
88
- this . errorY . _trace = this ;
85
+ } ) ;
89
86
90
- this . hasMarkers = false ;
91
- this . scatterOptions = {
87
+ var scatterOptions0 = {
92
88
positions : new Float64Array ( 0 ) ,
93
89
sizes : [ ] ,
94
90
colors : [ ] ,
@@ -100,16 +96,48 @@ function LineWithMarkers(scene, uid) {
100
96
borderSize : 1 ,
101
97
borderColor : [ 0 , 0 , 0 , 1 ]
102
98
} ;
103
- this . scatter = createScatter ( scene . glplot , this . scatterOptions ) ;
104
- this . scatter . _trace = this ;
105
- this . fancyScatter = createFancyScatter ( scene . glplot , this . scatterOptions ) ;
106
- this . fancyScatter . _trace = this ;
107
99
108
- this . isVisible = false ;
100
+ this . scatter = this . initObject ( createScatter , scatterOptions0 ) ;
101
+ this . fancyScatter = this . initObject ( createFancyScatter , scatterOptions0 ) ;
109
102
}
110
103
111
104
var proto = LineWithMarkers . prototype ;
112
105
106
+ proto . initObject = function ( createFn , options ) {
107
+ var _this = this ;
108
+ var glplot = _this . scene . glplot ;
109
+ var options0 = Lib . extendFlat ( { } , options ) ;
110
+ var obj = null ;
111
+
112
+ // TODO how to handle ordering ???
113
+
114
+ function update ( ) {
115
+ if ( ! obj ) {
116
+ obj = createFn ( glplot , options ) ;
117
+ obj . _trace = _this ;
118
+ }
119
+ obj . update ( options ) ;
120
+ return obj ;
121
+ }
122
+
123
+ function clear ( ) {
124
+ if ( obj ) obj . update ( options0 ) ;
125
+ return obj ;
126
+ }
127
+
128
+ function dispose ( ) {
129
+ if ( obj ) obj . dispose ( ) ;
130
+ return obj ;
131
+ }
132
+
133
+ return {
134
+ options : options ,
135
+ update : update ,
136
+ clear : clear ,
137
+ dispose : dispose
138
+ } ;
139
+ } ;
140
+
113
141
proto . handlePick = function ( pickResult ) {
114
142
var index = pickResult . pointId ;
115
143
@@ -233,6 +261,7 @@ function _convertColor(colors, opacities, count) {
233
261
* - markers
234
262
*/
235
263
proto . update = function ( options ) {
264
+
236
265
if ( options . visible !== true ) {
237
266
this . isVisible = false ;
238
267
this . hasLines = false ;
@@ -255,7 +284,11 @@ proto.update = function(options) {
255
284
this . connectgaps = ! ! options . connectgaps ;
256
285
257
286
if ( ! this . isVisible ) {
258
- this . clear ( ) ;
287
+ this . line . clear ( ) ;
288
+ this . errorX . clear ( ) ;
289
+ this . errorY . clear ( ) ;
290
+ this . scatter . clear ( ) ;
291
+ this . fancyScatter . clear ( ) ;
259
292
}
260
293
else if ( this . isFancy ( options ) ) {
261
294
this . updateFancy ( options ) ;
@@ -292,22 +325,6 @@ function allFastTypesLikely(a) {
292
325
return true ;
293
326
}
294
327
295
- proto . clear = function ( ) {
296
- this . lineOptions . positions = new Float64Array ( 0 ) ;
297
- this . line . update ( this . lineOptions ) ;
298
-
299
- this . errorXOptions . positions = new Float64Array ( 0 ) ;
300
- this . errorX . update ( this . errorXOptions ) ;
301
-
302
- this . errorYOptions . positions = new Float64Array ( 0 ) ;
303
- this . errorY . update ( this . errorYOptions ) ;
304
-
305
- this . scatterOptions . positions = new Float64Array ( 0 ) ;
306
- this . scatterOptions . glyphs = [ ] ;
307
- this . scatter . update ( this . scatterOptions ) ;
308
- this . fancyScatter . update ( this . scatterOptions ) ;
309
- } ;
310
-
311
328
proto . updateFast = function ( options ) {
312
329
var x = this . xData = this . pickXData = options . x ;
313
330
var y = this . yData = this . pickYData = options . y ;
@@ -363,34 +380,30 @@ proto.updateFast = function(options) {
363
380
var markerSize ;
364
381
365
382
if ( this . hasMarkers ) {
366
- this . scatterOptions . positions = positions ;
383
+ this . scatter . options . positions = positions ;
367
384
368
385
var markerColor = str2RGBArray ( options . marker . color ) ,
369
386
borderColor = str2RGBArray ( options . marker . line . color ) ,
370
387
opacity = ( options . opacity ) * ( options . marker . opacity ) ;
371
388
372
389
markerColor [ 3 ] *= opacity ;
373
- this . scatterOptions . color = markerColor ;
390
+ this . scatter . options . color = markerColor ;
374
391
375
392
borderColor [ 3 ] *= opacity ;
376
- this . scatterOptions . borderColor = borderColor ;
393
+ this . scatter . options . borderColor = borderColor ;
377
394
378
395
markerSize = options . marker . size ;
379
- this . scatterOptions . size = markerSize ;
380
- this . scatterOptions . borderSize = options . marker . line . width ;
396
+ this . scatter . options . size = markerSize ;
397
+ this . scatter . options . borderSize = options . marker . line . width ;
381
398
382
- this . scatter . update ( this . scatterOptions ) ;
399
+ this . scatter . update ( ) ;
383
400
}
384
401
else {
385
- this . scatterOptions . positions = new Float64Array ( 0 ) ;
386
- this . scatterOptions . glyphs = [ ] ;
387
- this . scatter . update ( this . scatterOptions ) ;
402
+ this . scatter . clear ( ) ;
388
403
}
389
404
390
405
// turn off fancy scatter plot
391
- this . scatterOptions . positions = new Float64Array ( 0 ) ;
392
- this . scatterOptions . glyphs = [ ] ;
393
- this . fancyScatter . update ( this . scatterOptions ) ;
406
+ this . fancyScatter . clear ( ) ;
394
407
395
408
// add item for autorange routine
396
409
this . expandAxesFast ( bounds , markerSize ) ;
@@ -464,16 +477,16 @@ proto.updateFancy = function(options) {
464
477
var sizes ;
465
478
466
479
if ( this . hasMarkers ) {
467
- this . scatterOptions . positions = positions ;
480
+ this . scatter . options . positions = positions ;
468
481
469
482
// TODO rewrite convert function so that
470
483
// we don't have to loop through the data another time
471
484
472
- this . scatterOptions . sizes = new Array ( pId ) ;
473
- this . scatterOptions . glyphs = new Array ( pId ) ;
474
- this . scatterOptions . borderWidths = new Array ( pId ) ;
475
- this . scatterOptions . colors = new Array ( pId * 4 ) ;
476
- this . scatterOptions . borderColors = new Array ( pId * 4 ) ;
485
+ this . scatter . options . sizes = new Array ( pId ) ;
486
+ this . scatter . options . glyphs = new Array ( pId ) ;
487
+ this . scatter . options . borderWidths = new Array ( pId ) ;
488
+ this . scatter . options . colors = new Array ( pId * 4 ) ;
489
+ this . scatter . options . borderColors = new Array ( pId * 4 ) ;
477
490
478
491
var markerSizeFunc = makeBubbleSizeFn ( options ) ,
479
492
markerOpts = options . marker ,
@@ -490,28 +503,24 @@ proto.updateFancy = function(options) {
490
503
for ( i = 0 ; i < pId ; ++ i ) {
491
504
index = idToIndex [ i ] ;
492
505
493
- this . scatterOptions . sizes [ i ] = 4.0 * sizes [ index ] ;
494
- this . scatterOptions . glyphs [ i ] = glyphs [ index ] ;
495
- this . scatterOptions . borderWidths [ i ] = 0.5 * borderWidths [ index ] ;
506
+ this . scatter . options . sizes [ i ] = 4.0 * sizes [ index ] ;
507
+ this . scatter . options . glyphs [ i ] = glyphs [ index ] ;
508
+ this . scatter . options . borderWidths [ i ] = 0.5 * borderWidths [ index ] ;
496
509
497
510
for ( j = 0 ; j < 4 ; ++ j ) {
498
- this . scatterOptions . colors [ 4 * i + j ] = colors [ 4 * index + j ] ;
499
- this . scatterOptions . borderColors [ 4 * i + j ] = borderColors [ 4 * index + j ] ;
511
+ this . scatter . options . colors [ 4 * i + j ] = colors [ 4 * index + j ] ;
512
+ this . scatter . options . borderColors [ 4 * i + j ] = borderColors [ 4 * index + j ] ;
500
513
}
501
514
}
502
515
503
- this . fancyScatter . update ( this . scatterOptions ) ;
516
+ this . fancyScatter . update ( ) ;
504
517
}
505
518
else {
506
- this . scatterOptions . positions = new Float64Array ( 0 ) ;
507
- this . scatterOptions . glyphs = [ ] ;
508
- this . fancyScatter . update ( this . scatterOptions ) ;
519
+ this . fancyScatter . clear ( ) ;
509
520
}
510
521
511
522
// turn off fast scatter plot
512
- this . scatterOptions . positions = new Float64Array ( 0 ) ;
513
- this . scatterOptions . glyphs = [ ] ;
514
- this . scatter . update ( this . scatterOptions ) ;
523
+ this . scatter . clear ( ) ;
515
524
516
525
// add item for autorange routine
517
526
this . expandAxesFancy ( x , y , sizes ) ;
@@ -535,61 +544,60 @@ proto.updateLines = function(options, positions) {
535
544
}
536
545
}
537
546
538
- this . lineOptions . positions = linePositions ;
547
+ this . line . options . positions = linePositions ;
539
548
540
549
var lineColor = convertColor ( options . line . color , options . opacity , 1 ) ,
541
- lineWidth = Math . round ( 0.5 * this . lineOptions . width ) ,
550
+ lineWidth = Math . round ( 0.5 * this . line . options . width ) ,
542
551
dashes = ( DASHES [ options . line . dash ] || [ 1 ] ) . slice ( ) ;
543
552
544
553
for ( i = 0 ; i < dashes . length ; ++ i ) dashes [ i ] *= lineWidth ;
545
554
546
555
switch ( options . fill ) {
547
556
case 'tozeroy' :
548
- this . lineOptions . fill = [ false , true , false , false ] ;
557
+ this . line . options . fill = [ false , true , false , false ] ;
549
558
break ;
550
559
case 'tozerox' :
551
- this . lineOptions . fill = [ true , false , false , false ] ;
560
+ this . line . options . fill = [ true , false , false , false ] ;
552
561
break ;
553
562
default :
554
- this . lineOptions . fill = [ false , false , false , false ] ;
563
+ this . line . options . fill = [ false , false , false , false ] ;
555
564
break ;
556
565
}
557
566
558
567
var fillColor = str2RGBArray ( options . fillcolor ) ;
559
568
560
- this . lineOptions . color = lineColor ;
561
- this . lineOptions . width = 2.0 * options . line . width ;
562
- this . lineOptions . dashes = dashes ;
563
- this . lineOptions . fillColor = [ fillColor , fillColor , fillColor , fillColor ] ;
569
+ this . line . options . color = lineColor ;
570
+ this . line . options . width = 2.0 * options . line . width ;
571
+ this . line . options . dashes = dashes ;
572
+ this . line . options . fillColor = [ fillColor , fillColor , fillColor , fillColor ] ;
573
+
574
+ this . line . update ( ) ;
564
575
}
565
576
else {
566
- this . lineOptions . positions = new Float64Array ( 0 ) ;
577
+ this . line . clear ( ) ;
567
578
}
568
-
569
- this . line . update ( this . lineOptions ) ;
570
579
} ;
571
580
572
581
proto . updateError = function ( axLetter , options , positions , errors ) {
573
582
var errorObj = this [ 'error' + axLetter ] ,
574
- errorOptions = options [ 'error_' + axLetter . toLowerCase ( ) ] ,
575
- errorObjOptions = this [ 'error' + axLetter + 'Options' ] ;
583
+ errorOptions = options [ 'error_' + axLetter . toLowerCase ( ) ] ;
576
584
577
585
if ( axLetter . toLowerCase ( ) === 'x' && errorOptions . copy_ystyle ) {
578
586
errorOptions = options . error_y ;
579
587
}
580
588
581
589
if ( this [ 'hasError' + axLetter ] ) {
582
- errorObjOptions . positions = positions ;
583
- errorObjOptions . errors = errors ;
584
- errorObjOptions . capSize = errorOptions . width ;
585
- errorObjOptions . lineWidth = errorOptions . thickness / 2 ; // ballpark rescaling
586
- errorObjOptions . color = convertColor ( errorOptions . color , 1 , 1 ) ;
590
+ errorObj . options . positions = positions ;
591
+ errorObj . options . errors = errors ;
592
+ errorObj . options . capSize = errorOptions . width ;
593
+ errorObj . options . lineWidth = errorOptions . thickness / 2 ; // ballpark rescaling
594
+ errorObj . options . color = convertColor ( errorOptions . color , 1 , 1 ) ;
595
+
596
+ errorObj . update ( ) ;
587
597
}
588
598
else {
589
- errorObjOptions . positions = new Float64Array ( 0 ) ;
599
+ errorObj . clear ( ) ;
590
600
}
591
-
592
- errorObj . update ( errorObjOptions ) ;
593
601
} ;
594
602
595
603
proto . expandAxesFast = function ( bounds , markerSize ) {
0 commit comments