gridviz 2.0.50 → 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/README.md +1 -0
- package/dist/gridviz.js +58 -10
- package/dist/gridviz.min.js +1 -1
- package/package.json +1 -1
- package/src/App.js +9 -4
- package/src/style/TimeSeriesStyle.js +48 -5
package/package.json
CHANGED
package/src/App.js
CHANGED
|
@@ -111,7 +111,7 @@ export class App {
|
|
|
111
111
|
if (strong) dsc.updateViewCache(this.cg.extGeo)
|
|
112
112
|
|
|
113
113
|
//set layer alpha and blend mode
|
|
114
|
-
this.cg.ctx.globalAlpha = layer.alpha? layer.alpha(zf) : 1.0
|
|
114
|
+
this.cg.ctx.globalAlpha = layer.alpha ? layer.alpha(zf) : 1.0
|
|
115
115
|
this.cg.ctx.globalCompositeOperation = layer.blendOperation(zf)
|
|
116
116
|
|
|
117
117
|
//draw cells, style by style
|
|
@@ -124,14 +124,14 @@ export class App {
|
|
|
124
124
|
|
|
125
125
|
//set style alpha and blend mode
|
|
126
126
|
//TODO: multiply by layer alpha ?
|
|
127
|
-
this.cg.ctx.globalAlpha = s.alpha? s.alpha(zf) : 1.0
|
|
127
|
+
this.cg.ctx.globalAlpha = s.alpha ? s.alpha(zf) : 1.0
|
|
128
128
|
this.cg.ctx.globalCompositeOperation = s.blendOperation(zf)
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
s.draw(dsc.getViewCache(), dsc.getResolution(), this.cg)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
//add legend element
|
|
134
|
-
if (this.legend && strong)
|
|
134
|
+
if (this.legend && strong) {
|
|
135
135
|
for (const s of layer.styles) {
|
|
136
136
|
if (zf > s.maxZoom) continue
|
|
137
137
|
if (zf < s.minZoom) continue
|
|
@@ -157,6 +157,11 @@ export class App {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//restore default alpha and blend operation
|
|
163
|
+
this.cg.ctx.globalAlpha = 1.0
|
|
164
|
+
this.cg.ctx.globalCompositeOperation = "normal"
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
//draw boundary layer
|
|
@@ -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 =
|
|
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
|
-
|
|
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
|
+
|