@@ -78,46 +78,41 @@ charts or filled areas).
78
78
i = 0 , j = 0 , l , m ;
79
79
80
80
while ( true ) {
81
- // browse all points from the current series and from the previous series
82
- if ( i >= points . length && j >= otherpoints . length )
81
+ if ( i >= points . length )
83
82
break ;
84
83
85
- // newpoints will replace current series with
86
- // as many points as different timestamps we have in the 2 (current & previous) series
87
84
l = newpoints . length ;
88
- px = points [ i + keyOffset ] ;
89
- py = points [ i + accumulateOffset ] ;
90
- qx = otherpoints [ j + keyOffset ] ;
91
- qy = otherpoints [ j + accumulateOffset ] ;
92
- bottom = 0 ;
93
-
94
- if ( i < points . length && px == null ) {
95
- // let's ignore null points from current series, nothing to do with them
85
+
86
+ if ( points [ i ] == null ) {
87
+ // copy gaps
88
+ for ( m = 0 ; m < ps ; ++ m )
89
+ newpoints . push ( points [ i + m ] ) ;
96
90
i += ps ;
97
91
}
98
- else if ( j < otherpoints . length && qx == null ) {
99
- // let's ignore null points from previous series, nothing to do with them
100
- j += otherps ;
92
+ 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
+ }
98
+ i += ps ;
101
99
}
102
- else if ( i >= points . length ) {
103
- // no more points in the current series, simply take the remaining points
104
- // from the previous series so that next series will correctly stack
100
+ else if ( otherpoints [ j ] == null ) {
101
+ // oops, got a gap
105
102
for ( m = 0 ; m < ps ; ++ m )
106
- newpoints . push ( otherpoints [ j + m ] ) ;
107
- bottom = qy ;
103
+ newpoints . push ( null ) ;
104
+ fromgap = true ;
108
105
j += otherps ;
109
106
}
110
- else if ( j >= otherpoints . length ) {
111
- // no more points in the previous series, of course let's take
112
- // the remaining points from the current series
113
- for ( m = 0 ; m < ps ; ++ m )
114
- newpoints . push ( points [ i + m ] ) ;
115
- i += ps ;
116
- }
117
107
else {
118
- // next available points from current and previous series have the same timestamp
108
+ // cases where we actually got two points
109
+ px = points [ i + keyOffset ] ;
110
+ py = points [ i + accumulateOffset ] ;
111
+ qx = otherpoints [ j + keyOffset ] ;
112
+ qy = otherpoints [ j + accumulateOffset ] ;
113
+ bottom = 0 ;
114
+
119
115
if ( px == qx ) {
120
- // so take the point from the current series and skip the previous' one
121
116
for ( m = 0 ; m < ps ; ++ m )
122
117
newpoints . push ( points [ i + m ] ) ;
123
118
@@ -127,39 +122,55 @@ charts or filled areas).
127
122
i += ps ;
128
123
j += otherps ;
129
124
}
130
- // next available point with the smallest timestamp is from the previous series
131
125
else if ( px > qx ) {
132
- // so take the point from the previous series so that next series will correctly stack
133
- for ( m = 0 ; m < ps ; ++ m )
134
- newpoints . push ( otherpoints [ j + m ] ) ;
135
-
136
- // we might be able to interpolate
137
- if ( i > 0 && points [ i - ps ] != null )
138
- newpoints [ l + accumulateOffset ] += py + ( points [ i - ps + accumulateOffset ] - py ) * ( qx - px ) / ( points [ i - ps + keyOffset ] - px ) ;
139
-
140
- bottom = qy ;
126
+ // we got past point below, might need to
127
+ // insert interpolated extra point
128
+ if ( withlines && i > 0 && points [ i - ps ] != null ) {
129
+ intery = py + ( points [ i - ps + accumulateOffset ] - py ) * ( qx - px ) / ( points [ i - ps + keyOffset ] - px ) ;
130
+ newpoints . push ( qx ) ;
131
+ newpoints . push ( intery + qy ) ;
132
+ for ( m = 2 ; m < ps ; ++ m )
133
+ newpoints . push ( points [ i + m ] ) ;
134
+ bottom = qy ;
135
+ }
141
136
142
137
j += otherps ;
143
138
}
144
- // (px < qx) next available point with the smallest timestamp is from the current series
145
- else {
146
- // so of course let's take the point from the current series
139
+ 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
+
147
146
for ( m = 0 ; m < ps ; ++ m )
148
147
newpoints . push ( points [ i + m ] ) ;
149
148
150
149
// we might be able to interpolate a point below,
151
150
// this can give us a better y
152
- if ( j > 0 && otherpoints [ j - otherps ] != null )
151
+ if ( withlines && j > 0 && otherpoints [ j - otherps ] != null )
153
152
bottom = qy + ( otherpoints [ j - otherps + accumulateOffset ] - qy ) * ( px - qx ) / ( otherpoints [ j - otherps + keyOffset ] - qx ) ;
154
153
155
154
newpoints [ l + accumulateOffset ] += bottom ;
156
155
157
156
i += ps ;
158
157
}
159
- }
160
158
161
- if ( l != newpoints . length && withbottom )
162
- newpoints [ l + 2 ] = bottom ;
159
+ fromgap = false ;
160
+
161
+ if ( l != newpoints . length && withbottom )
162
+ newpoints [ l + 2 ] += bottom ;
163
+ }
164
+
165
+ // maintain the line steps invariant
166
+ if ( withsteps && l != newpoints . length && l > 0
167
+ && newpoints [ l ] != null
168
+ && newpoints [ l ] != newpoints [ l - ps ]
169
+ && newpoints [ l + 1 ] != newpoints [ l - ps + 1 ] ) {
170
+ for ( m = 0 ; m < ps ; ++ m )
171
+ newpoints [ l + ps + m ] = newpoints [ l + m ] ;
172
+ newpoints [ l + 1 ] = newpoints [ l - ps + 1 ] ;
173
+ }
163
174
}
164
175
165
176
datapoints . points = newpoints ;
0 commit comments