@@ -21,7 +21,8 @@ var plots = module.exports = {};
21
21
var modules = plots . modules = { } ,
22
22
allTypes = plots . allTypes = [ ] ,
23
23
allCategories = plots . allCategories = { } ,
24
- subplotsRegistry = plots . subplotsRegistry = { } ;
24
+ subplotsRegistry = plots . subplotsRegistry = { } ,
25
+ transformsRegistry = plots . transformsRegistry = { } ;
25
26
26
27
plots . attributes = require ( './attributes' ) ;
27
28
plots . attributes . type . values = allTypes ;
@@ -449,8 +450,7 @@ plots.supplyDefaults = function(gd) {
449
450
newData = gd . data || [ ] ,
450
451
modules = gd . _modules = [ ] ;
451
452
452
- var i , trace , fullTrace , _module , axList , ax ;
453
-
453
+ var i , trace , _module , axList , ax ;
454
454
455
455
// first fill in what we can of layout without looking at data
456
456
// because fullData needs a few things from layout
@@ -460,24 +460,7 @@ plots.supplyDefaults = function(gd) {
460
460
newFullLayout . _dataLength = newData . length ;
461
461
462
462
// then do the data
463
- for ( i = 0 ; i < newData . length ; i ++ ) {
464
- trace = newData [ i ] ;
465
-
466
- fullTrace = plots . supplyDataDefaults ( trace , i , newFullLayout ) ;
467
- newFullData . push ( fullTrace ) ;
468
-
469
- // detect plot type
470
- if ( plots . traceIs ( fullTrace , 'cartesian' ) ) newFullLayout . _hasCartesian = true ;
471
- else if ( plots . traceIs ( fullTrace , 'gl3d' ) ) newFullLayout . _hasGL3D = true ;
472
- else if ( plots . traceIs ( fullTrace , 'geo' ) ) newFullLayout . _hasGeo = true ;
473
- else if ( plots . traceIs ( fullTrace , 'pie' ) ) newFullLayout . _hasPie = true ;
474
- else if ( plots . traceIs ( fullTrace , 'gl2d' ) ) newFullLayout . _hasGL2D = true ;
475
- else if ( plots . traceIs ( fullTrace , 'ternary' ) ) newFullLayout . _hasTernary = true ;
476
- else if ( 'r' in fullTrace ) newFullLayout . _hasPolar = true ;
477
-
478
- _module = fullTrace . _module ;
479
- if ( _module && modules . indexOf ( _module ) === - 1 ) modules . push ( _module ) ;
480
- }
463
+ plots . supplyDataDefaults ( newData , newFullData , newFullLayout , modules ) ;
481
464
482
465
// special cases that introduce interactions between traces
483
466
for ( i = 0 ; i < modules . length ; i ++ ) {
@@ -609,7 +592,61 @@ function relinkPrivateKeys(toLayout, fromLayout) {
609
592
}
610
593
}
611
594
612
- plots . supplyDataDefaults = function ( traceIn , i , layout ) {
595
+ plots . supplyDataDefaults = function ( dataIn , dataOut , layout , modules ) {
596
+ var cnt = 0 ;
597
+
598
+ // push to array if item isn't already in array
599
+ function fill ( arr , item ) {
600
+ if ( item && arr . indexOf ( item ) === - 1 ) return arr . push ( item ) ;
601
+ }
602
+
603
+ // detect plot type
604
+ function detect ( trace ) {
605
+ if ( plots . traceIs ( trace , 'cartesian' ) ) layout . _hasCartesian = true ;
606
+ else if ( plots . traceIs ( trace , 'gl3d' ) ) layout . _hasGL3D = true ;
607
+ else if ( plots . traceIs ( trace , 'geo' ) ) layout . _hasGeo = true ;
608
+ else if ( plots . traceIs ( trace , 'pie' ) ) layout . _hasPie = true ;
609
+ else if ( plots . traceIs ( trace , 'gl2d' ) ) layout . _hasGL2D = true ;
610
+ else if ( plots . traceIs ( trace , 'ternary' ) ) layout . _hasTernary = true ;
611
+ else if ( 'r' in trace ) layout . _hasPolar = true ;
612
+ }
613
+
614
+ for ( var i = 0 ; i < dataIn . length ; i ++ ) {
615
+ var trace = dataIn [ i ] ;
616
+
617
+ var fullTrace = plots . supplyTraceDefaults ( trace , cnt , layout ) ;
618
+
619
+ // keep track of pre-transform _input
620
+ var traceIn = fullTrace . _input ;
621
+
622
+ if ( fullTrace . transforms && fullTrace . transforms . length ) {
623
+ var expandedTraces = applyTransforms ( fullTrace , dataOut , layout ) ;
624
+
625
+ for ( var j = 0 ; j < expandedTraces . length ; j ++ ) {
626
+ var expandedTrace = expandedTraces [ j ] ;
627
+ var fullExpandedTrace = plots . supplyTraceDefaults ( expandedTrace , cnt , layout ) ;
628
+
629
+ // copy refs
630
+ fullExpandedTrace . _input = traceIn ;
631
+ fullExpandedTrace . _fullTransforms = fullTrace . transforms ;
632
+ fullExpandedTrace . _index = i ;
633
+
634
+ dataOut . push ( fullExpandedTrace ) ;
635
+ fill ( modules , fullExpandedTrace . _module ) ;
636
+ detect ( fullExpandedTrace ) ;
637
+ cnt ++ ;
638
+ }
639
+ }
640
+ else {
641
+ dataOut . push ( fullTrace ) ;
642
+ fill ( modules , fullTrace . _module ) ;
643
+ detect ( trace ) ;
644
+ cnt ++ ;
645
+ }
646
+ }
647
+ } ;
648
+
649
+ plots . supplyTraceDefaults = function ( traceIn , i , layout ) {
613
650
var traceOut = { } ,
614
651
defaultColor = Color . defaults [ i % Color . defaults . length ] ;
615
652
@@ -666,6 +703,8 @@ plots.supplyDataDefaults = function(traceIn, i, layout) {
666
703
coerce ( 'showlegend' ) ;
667
704
coerce ( 'legendgroup' ) ;
668
705
}
706
+
707
+ supplyTransformDefaults ( traceIn , traceOut , layout ) ;
669
708
}
670
709
671
710
// NOTE: I didn't include fit info at all... for now I think it can stay
@@ -678,6 +717,42 @@ plots.supplyDataDefaults = function(traceIn, i, layout) {
678
717
return traceOut ;
679
718
} ;
680
719
720
+ function supplyTransformDefaults ( traceIn , traceOut , layout ) {
721
+ var containerIn = traceIn . transforms || [ ] ,
722
+ containerOut = traceOut . transforms = [ ] ;
723
+
724
+ for ( var i = 0 ; i < containerIn . length ; i ++ ) {
725
+ var transformIn = containerIn [ i ] ,
726
+ type = transformIn . type ,
727
+ _module = transformsRegistry [ type ] ;
728
+
729
+ var transformOut = _module . supplyDefaults ( transformIn , traceOut , layout ) ;
730
+ transformOut . type = type ;
731
+
732
+ containerOut . push ( transformOut ) ;
733
+ }
734
+ }
735
+
736
+ function applyTransforms ( fullTrace , fullData , layout ) {
737
+ var container = fullTrace . transforms ,
738
+ dataOut = [ fullTrace ] ;
739
+
740
+ for ( var i = 0 ; i < container . length ; i ++ ) {
741
+ var transform = container [ i ] ,
742
+ type = transform . type ,
743
+ _module = transformsRegistry [ type ] ;
744
+
745
+ dataOut = _module . transform ( dataOut , {
746
+ transform : transform ,
747
+ fullTrace : fullTrace ,
748
+ fullData : fullData ,
749
+ layout : layout
750
+ } ) ;
751
+ }
752
+
753
+ return dataOut ;
754
+ }
755
+
681
756
plots . supplyLayoutGlobalDefaults = function ( layoutIn , layoutOut ) {
682
757
function coerce ( attr , dflt ) {
683
758
return Lib . coerce ( layoutIn , layoutOut , plots . layoutAttributes , attr , dflt ) ;
0 commit comments