@@ -17,74 +17,45 @@ var Lib = require('../../lib');
17
17
var subTypes = require ( '../scatter/subtypes' ) ;
18
18
var calcColorscale = require ( '../scatter/colorscale_calc' ) ;
19
19
20
- var dataArrays = [ 'a' , 'b' , 'c' ] ;
21
- var arraysToFill = { a : [ 'b' , 'c' ] , b : [ 'a' , 'c' ] , c : [ 'a' , 'b' ] } ;
22
-
20
+ var dataArrays = [ 'a' , 'b' ] ;
23
21
24
22
module . exports = function calc ( gd , trace ) {
25
- var i , j , dataArray , newArray , fillArray1 , fillArray2 , trace ;
23
+ var i , j , dataArray , newArray , fillArray1 , fillArray2 , carpet ;
26
24
27
- for ( i = 0 ; i < gd . traces . length ; i ++ ) {
28
- if ( gd . traces [ i ] . carpetid === trace . carpetid ) {
29
- trace = gd . traces [ i ] ;
25
+ for ( i = 0 ; i < gd . _fullData . length ; i ++ ) {
26
+ if ( gd . _fullData [ i ] . carpetid === trace . carpetid && gd . _fullData [ i ] . type === 'carpet' ) {
27
+ carpet = gd . _fullData [ i ] ;
30
28
break ;
31
29
}
32
30
}
33
31
34
- if ( ! trace ) return ;
35
-
36
- console . log ( 'trace:' , trace ) ;
32
+ if ( ! carpet ) return ;
37
33
38
- return ;
34
+ // Transfer this over from carpet before plotting since this is a necessary
35
+ // condition in order for cartesian to actually plot this trace:
36
+ trace . xaxis = carpet . xaxis ;
37
+ trace . yaxis = carpet . yaxis ;
39
38
40
- var ternary = gd . _fullLayout [ trace . subplot ] ,
41
- displaySum = ternary . sum ,
39
+ var displaySum = carpet . sum ,
42
40
normSum = trace . sum || displaySum ;
43
41
44
- // fill in one missing component
45
- for ( i = 0 ; i < dataArrays . length ; i ++ ) {
46
- dataArray = dataArrays [ i ] ;
47
- if ( trace [ dataArray ] ) continue ;
48
-
49
- fillArray1 = trace [ arraysToFill [ dataArray ] [ 0 ] ] ;
50
- fillArray2 = trace [ arraysToFill [ dataArray ] [ 1 ] ] ;
51
- newArray = new Array ( fillArray1 . length ) ;
52
- for ( j = 0 ; j < fillArray1 . length ; j ++ ) {
53
- newArray [ j ] = normSum - fillArray1 [ j ] - fillArray2 [ j ] ;
54
- }
55
- trace [ dataArray ] = newArray ;
56
- }
57
-
58
42
// make the calcdata array
59
43
var serieslen = trace . a . length ;
60
44
var cd = new Array ( serieslen ) ;
61
- var a , b , c , norm , x , y ;
45
+ var a , b , norm , x , y ;
62
46
for ( i = 0 ; i < serieslen ; i ++ ) {
63
47
a = trace . a [ i ] ;
64
48
b = trace . b [ i ] ;
65
- c = trace . c [ i ] ;
66
- if ( isNumeric ( a ) && isNumeric ( b ) && isNumeric ( c ) ) {
67
- a = + a ;
68
- b = + b ;
69
- c = + c ;
70
- norm = displaySum / ( a + b + c ) ;
71
- if ( norm !== 1 ) {
72
- a *= norm ;
73
- b *= norm ;
74
- c *= norm ;
75
- }
76
- // map a, b, c onto x and y where the full scale of y
77
- // is [0, sum], and x is [-sum, sum]
78
- // TODO: this makes `a` always the top, `b` the bottom left,
79
- // and `c` the bottom right. Do we want options to rearrange
80
- // these?
81
- y = a ;
82
- x = c - b ;
83
- cd [ i ] = { x : x , y : y , a : a , b : b , c : c } ;
49
+ if ( isNumeric ( a ) && isNumeric ( b ) ) {
50
+ var xy = carpet . ab2xy ( + a , + b ) ;
51
+ cd [ i ] = { x : xy [ 0 ] , y : xy [ 1 ] , a : a , b : b } ;
84
52
}
85
53
else cd [ i ] = { x : false , y : false } ;
86
54
}
87
55
56
+ cd [ 0 ] . carpet = carpet ;
57
+ cd [ 0 ] . trace = trace ;
58
+
88
59
// fill in some extras
89
60
var marker , s ;
90
61
if ( subTypes . hasMarkers ( trace ) ) {
0 commit comments