@@ -72,36 +72,38 @@ charts or filled areas).
72
72
horizontal = s . bars . horizontal ,
73
73
withbottom = ps > 2 && ( horizontal ? datapoints . format [ 2 ] . x : datapoints . format [ 2 ] . y ) ,
74
74
withsteps = withlines && s . lines . steps ,
75
- fromgap = true ,
76
75
keyOffset = horizontal ? 1 : 0 ,
77
76
accumulateOffset = horizontal ? 0 : 1 ,
78
77
i = 0 , j = 0 , l , m ;
79
78
80
79
while ( true ) {
81
- if ( i >= points . length )
80
+ if ( i >= points . length && j >= otherpoints . length )
82
81
break ;
83
82
84
83
l = newpoints . length ;
85
84
86
- if ( points [ i ] == null ) {
85
+ if ( i < points . length && points [ i ] == null ) {
87
86
// copy gaps
88
87
for ( m = 0 ; m < ps ; ++ m )
89
88
newpoints . push ( points [ i + m ] ) ;
90
89
i += ps ;
91
90
}
91
+ else if ( i >= points . length ) {
92
+ // take the remaining points from the previous series
93
+ for ( m = 0 ; m < ps ; ++ m )
94
+ newpoints . push ( otherpoints [ j + m ] ) ;
95
+ if ( withbottom )
96
+ newpoints [ l + 2 ] = otherpoints [ j + accumulateOffset ] ;
97
+ j += otherps ;
98
+ }
92
99
else if ( j >= otherpoints . length ) {
93
- // for lines, we can't use the rest of the points
94
- if ( ! withlines ) {
95
- for ( m = 0 ; m < ps ; ++ m )
96
- newpoints . push ( points [ i + m ] ) ;
97
- }
100
+ // take the remaining points from the current series
101
+ for ( m = 0 ; m < ps ; ++ m )
102
+ newpoints . push ( points [ i + m ] ) ;
98
103
i += ps ;
99
104
}
100
- else if ( otherpoints [ j ] == null ) {
101
- // oops, got a gap
102
- for ( m = 0 ; m < ps ; ++ m )
103
- newpoints . push ( null ) ;
104
- fromgap = true ;
105
+ else if ( j < otherpoints . length && otherpoints [ j ] == null ) {
106
+ // ignore point
105
107
j += otherps ;
106
108
}
107
109
else {
@@ -123,9 +125,15 @@ charts or filled areas).
123
125
j += otherps ;
124
126
}
125
127
else if ( px > qx ) {
128
+ // take the point from the previous series so that next series will correctly stack
129
+ if ( i == 0 ) {
130
+ for ( m = 0 ; m < ps ; ++ m )
131
+ newpoints . push ( otherpoints [ j + m ] ) ;
132
+ bottom = qy ;
133
+ }
126
134
// we got past point below, might need to
127
135
// insert interpolated extra point
128
- if ( withlines && i > 0 && points [ i - ps ] != null ) {
136
+ if ( i > 0 && points [ i - ps ] != null ) {
129
137
intery = py + ( points [ i - ps + accumulateOffset ] - py ) * ( qx - px ) / ( points [ i - ps + keyOffset ] - px ) ;
130
138
newpoints . push ( qx ) ;
131
139
newpoints . push ( intery + qy ) ;
@@ -137,18 +145,12 @@ charts or filled areas).
137
145
j += otherps ;
138
146
}
139
147
else { // px < qx
140
- if ( fromgap && withlines ) {
141
- // if we come from a gap, we just skip this point
142
- i += ps ;
143
- continue ;
144
- }
145
-
146
148
for ( m = 0 ; m < ps ; ++ m )
147
149
newpoints . push ( points [ i + m ] ) ;
148
150
149
151
// we might be able to interpolate a point below,
150
152
// this can give us a better y
151
- if ( withlines && j > 0 && otherpoints [ j - otherps ] != null )
153
+ if ( j > 0 && otherpoints [ j - otherps ] != null )
152
154
bottom = qy + ( otherpoints [ j - otherps + accumulateOffset ] - qy ) * ( px - qx ) / ( otherpoints [ j - otherps + keyOffset ] - qx ) ;
153
155
154
156
newpoints [ l + accumulateOffset ] += bottom ;
@@ -159,7 +161,7 @@ charts or filled areas).
159
161
fromgap = false ;
160
162
161
163
if ( l != newpoints . length && withbottom )
162
- newpoints [ l + 2 ] + = bottom ;
164
+ newpoints [ l + 2 ] = bottom ;
163
165
}
164
166
165
167
// maintain the line steps invariant
0 commit comments