@@ -30,48 +30,6 @@ module.exports = function crossTraceCalc(gd, plotinfo) {
30
30
var groupOpts , interpolate , groupnorm , posAttr , valAttr ;
31
31
var hasAnyBlanks ;
32
32
33
- function insertBlank ( calcTrace , index , position , traceIndex ) {
34
- hasAnyBlanks [ traceIndex ] = true ;
35
- var newEntry = {
36
- i : null ,
37
- gap : true ,
38
- s : 0
39
- } ;
40
- newEntry [ posAttr ] = position ;
41
- calcTrace . splice ( index , 0 , newEntry ) ;
42
- // Even if we're not interpolating, if one trace has multiple
43
- // values at the same position and this trace only has one value there,
44
- // we just duplicate that one value rather than insert a zero.
45
- // We also make it look like a real point - because it's ambiguous which
46
- // one really is the real one!
47
- if ( index && position === calcTrace [ index - 1 ] [ posAttr ] ) {
48
- var prevEntry = calcTrace [ index - 1 ] ;
49
- newEntry . s = prevEntry . s ;
50
- // TODO is it going to cause any problems to have multiple
51
- // calcdata points with the same index?
52
- newEntry . i = prevEntry . i ;
53
- newEntry . gap = prevEntry . gap ;
54
- }
55
- else if ( interpolate ) {
56
- newEntry . s = getInterp ( calcTrace , index , position ) ;
57
- }
58
- if ( ! index ) {
59
- // t and trace need to stay on the first cd entry
60
- calcTrace [ 0 ] . t = calcTrace [ 1 ] . t ;
61
- calcTrace [ 0 ] . trace = calcTrace [ 1 ] . trace ;
62
- delete calcTrace [ 1 ] . t ;
63
- delete calcTrace [ 1 ] . trace ;
64
- }
65
- }
66
-
67
- function getInterp ( calcTrace , index , position ) {
68
- var pt0 = calcTrace [ index - 1 ] ;
69
- var pt1 = calcTrace [ index + 1 ] ;
70
- if ( ! pt1 ) return pt0 . s ;
71
- if ( ! pt0 ) return pt1 . s ;
72
- return pt0 . s + ( pt1 . s - pt0 . s ) * ( position - pt0 [ posAttr ] ) / ( pt1 [ posAttr ] - pt0 [ posAttr ] ) ;
73
- }
74
-
75
33
for ( var stackGroup in subplotStackOpts ) {
76
34
groupOpts = subplotStackOpts [ stackGroup ] ;
77
35
var indices = groupOpts . traceIndices ;
@@ -111,20 +69,20 @@ module.exports = function crossTraceCalc(gd, plotinfo) {
111
69
posj = cd [ j ] [ posAttr ] ;
112
70
for ( ; posj > allPositions [ k ] && k < allPositions . length ; k ++ ) {
113
71
// the current trace is missing a position from some previous trace(s)
114
- insertBlank ( cd , j , allPositions [ k ] , i ) ;
72
+ insertBlank ( cd , j , allPositions [ k ] , i , hasAnyBlanks , interpolate , posAttr ) ;
115
73
j ++ ;
116
74
}
117
75
if ( posj !== allPositions [ k ] ) {
118
76
// previous trace(s) are missing a position from the current trace
119
77
for ( i2 = 0 ; i2 < i ; i2 ++ ) {
120
- insertBlank ( calcTraces [ indices [ i2 ] ] , k , posj , i2 ) ;
78
+ insertBlank ( calcTraces [ indices [ i2 ] ] , k , posj , i2 , hasAnyBlanks , interpolate , posAttr ) ;
121
79
}
122
80
allPositions . splice ( k , 0 , posj ) ;
123
81
}
124
82
k ++ ;
125
83
}
126
84
for ( ; k < allPositions . length ; k ++ ) {
127
- insertBlank ( cd , j , allPositions [ k ] , i ) ;
85
+ insertBlank ( cd , j , allPositions [ k ] , i , hasAnyBlanks , interpolate , posAttr ) ;
128
86
j ++ ;
129
87
}
130
88
}
@@ -179,3 +137,45 @@ module.exports = function crossTraceCalc(gd, plotinfo) {
179
137
}
180
138
}
181
139
} ;
140
+
141
+ function insertBlank ( calcTrace , index , position , traceIndex , hasAnyBlanks , interpolate , posAttr ) {
142
+ hasAnyBlanks [ traceIndex ] = true ;
143
+ var newEntry = {
144
+ i : null ,
145
+ gap : true ,
146
+ s : 0
147
+ } ;
148
+ newEntry [ posAttr ] = position ;
149
+ calcTrace . splice ( index , 0 , newEntry ) ;
150
+ // Even if we're not interpolating, if one trace has multiple
151
+ // values at the same position and this trace only has one value there,
152
+ // we just duplicate that one value rather than insert a zero.
153
+ // We also make it look like a real point - because it's ambiguous which
154
+ // one really is the real one!
155
+ if ( index && position === calcTrace [ index - 1 ] [ posAttr ] ) {
156
+ var prevEntry = calcTrace [ index - 1 ] ;
157
+ newEntry . s = prevEntry . s ;
158
+ // TODO is it going to cause any problems to have multiple
159
+ // calcdata points with the same index?
160
+ newEntry . i = prevEntry . i ;
161
+ newEntry . gap = prevEntry . gap ;
162
+ }
163
+ else if ( interpolate ) {
164
+ newEntry . s = getInterp ( calcTrace , index , position , posAttr ) ;
165
+ }
166
+ if ( ! index ) {
167
+ // t and trace need to stay on the first cd entry
168
+ calcTrace [ 0 ] . t = calcTrace [ 1 ] . t ;
169
+ calcTrace [ 0 ] . trace = calcTrace [ 1 ] . trace ;
170
+ delete calcTrace [ 1 ] . t ;
171
+ delete calcTrace [ 1 ] . trace ;
172
+ }
173
+ }
174
+
175
+ function getInterp ( calcTrace , index , position , posAttr ) {
176
+ var pt0 = calcTrace [ index - 1 ] ;
177
+ var pt1 = calcTrace [ index + 1 ] ;
178
+ if ( ! pt1 ) return pt0 . s ;
179
+ if ( ! pt0 ) return pt1 . s ;
180
+ return pt0 . s + ( pt1 . s - pt0 . s ) * ( position - pt0 [ posAttr ] ) / ( pt1 [ posAttr ] - pt0 [ posAttr ] ) ;
181
+ }
0 commit comments