gridviz 2.0.51 → 2.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gridviz",
3
- "version": "2.0.51",
3
+ "version": "2.0.52",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -21,6 +21,10 @@ export class TimeSeriesStyle extends Style {
21
21
  * @type {Array.<string>} */
22
22
  this.ts = opts.ts
23
23
 
24
+ /** A function specifying when a value should be considered as "no data" and thus not ignored. The line will have a break at these values.
25
+ * @type {function(string):boolean} */
26
+ this.noData = opts.noData || ((v) => v === undefined || v == "" || v === null || isNaN(+v))
27
+
24
28
  //x
25
29
  /** in geo unit
26
30
  * @type {function(import("../Dataset.js").Cell,number,number):number} */
@@ -112,7 +116,7 @@ export class TimeSeriesStyle extends Style {
112
116
  //in geo coordinates
113
117
  cg.setCanvasTransform()
114
118
 
115
- cg.ctx.lineCap = 'butt'
119
+ cg.ctx.lineCap = "butt"
116
120
  for (let c of cells) {
117
121
 
118
122
  //line width
@@ -185,23 +189,62 @@ export class TimeSeriesStyle extends Style {
185
189
  continue;
186
190
  }
187
191
 
192
+ /*/draw line
188
193
  if (val0 == undefined || isNaN(val0)) continue
189
-
190
- //draw line
191
194
  cg.ctx.beginPath()
192
195
  const sX = w / (nb - 1)
193
196
  for (let i = 0; i < nb; i++) {
194
197
  const val = c[this.ts[i]]
195
- if (val == undefined) break
198
+ if (val == undefined || isNaN(val)) break
196
199
  if (i == 0)
197
200
  cg.ctx.moveTo(c.x + i * sX + offX, c.y + y0 + (val - val0) * h / ampMax + offY)
198
201
  else
199
202
  cg.ctx.lineTo(c.x + i * sX + offX, c.y + y0 + (val - val0) * h / ampMax + offY)
200
203
  }
204
+ cg.ctx.stroke()*/
205
+
206
+
207
+ //draw line, segment by segment
208
+ const sX = w / (nb - 1)
209
+
210
+ //handle first point
211
+ let v0 = c[this.ts[0]]
212
+ if (!this.noData(v0)) {
213
+ cg.ctx.beginPath()
214
+ cg.ctx.moveTo(c.x + offX, c.y + y0 + (v0 - val0) * h / ampMax + offY)
215
+ }
216
+ //console.log(v0, isNaN(v0))
217
+
218
+ let v1
219
+ for (let i = 1; i < nb; i++) {
220
+ v1 = c[this.ts[i]]
201
221
 
202
- cg.ctx.stroke()
222
+ //draw segment from v0 to v1
223
+
224
+ //both points 'no data'
225
+ if (this.noData(v0) && this.noData(v1)) {
226
+
227
+ //second point 'no data'
228
+ } else if (!this.noData(v0) && this.noData(v1)) {
229
+ cg.ctx.stroke()
230
+
231
+ //first point 'no data'
232
+ } else if (this.noData(v0) && !this.noData(v1)) {
233
+ cg.ctx.beginPath()
234
+ cg.ctx.moveTo(c.x + i * sX + offX, c.y + y0 + (v1 - val0) * h / ampMax + offY)
235
+
236
+ //both points have data: trace line
237
+ } else {
238
+ cg.ctx.lineTo(c.x + i * sX + offX, c.y + y0 + (v1 - val0) * h / ampMax + offY)
239
+ //if it is the last point, stroke
240
+ if (i == nb - 1) cg.ctx.stroke()
241
+ }
242
+ v0 = v1
243
+ }
203
244
 
204
245
  }
205
246
 
206
247
  }
248
+
207
249
  }
250
+