|
244 | 244 |
|
245 | 245 | var progressGraph = getProgressGraphKernel; |
246 | 246 |
|
| 247 | + /** |
| 248 | + * @param {Object} gpu GPU.js instance |
| 249 | + * @param {Object} dimensions Dimensions of Graph |
| 250 | + * @param {String} progressiveAxis The axis which progresses. |
| 251 | + * @param {Number} xOffset |
| 252 | + * @param {Number} yOffset |
| 253 | + * @param {Float32Array} axesColor |
| 254 | + * @param {Float32Array} bgColor |
| 255 | + */ |
| 256 | + function getSqueezeGraphKernel(gpu, dimensions, progressiveAxis, xOffset, yOffset, axesColor, bgColor) { |
| 257 | + return gpu.createKernel(function(graphPixels, scalingFactor) { |
| 258 | + const outX = this.output.x, outY = this.output.y; |
| 259 | + const X = Math.floor(outY * (this.constants.xOffset / 100)); |
| 260 | + const Y = Math.floor(outX * (this.constants.yOffset / 100)); |
| 261 | + |
| 262 | + if ( |
| 263 | + (Math.floor(this.thread.x * (1 - this.constants.progressiveAxis) / scalingFactor) >= outX) || |
| 264 | + (Math.floor(this.thread.y * this.constants.progressiveAxis / scalingFactor) >= outY) |
| 265 | + ) { |
| 266 | + if (this.thread.x === Y || this.thread.y === X) return this.constants.axesColor; |
| 267 | + else return this.constants.bgColor; |
| 268 | + } |
| 269 | + else { |
| 270 | + const newY = this.constants.progressiveAxis == 1 ? Math.floor(this.thread.y / scalingFactor) : Math.floor(this.thread.y); |
| 271 | + const newX = this.constants.progressiveAxis == 0 ? Math.floor(this.thread.x / scalingFactor) : Math.floor(this.thread.x); |
| 272 | + |
| 273 | + return graphPixels[newY][newX]; |
| 274 | + } |
| 275 | + }, |
| 276 | + { |
| 277 | + output: dimensions, |
| 278 | + pipeline: true, |
| 279 | + constants: { |
| 280 | + progressiveAxis: progressiveAxis == 'y' ? 1 : 0, |
| 281 | + xOffset, |
| 282 | + yOffset, |
| 283 | + axesColor, |
| 284 | + bgColor |
| 285 | + }, |
| 286 | + constantTypes: { |
| 287 | + progressiveAxis: 'Integer', |
| 288 | + xOffset: 'Float', |
| 289 | + yOffset: 'Float', |
| 290 | + axesColor: 'Array(3)', |
| 291 | + bgColor: 'Array(3)' |
| 292 | + } |
| 293 | + }) |
| 294 | + } |
| 295 | + |
| 296 | + var squeezeGraph = getSqueezeGraphKernel; |
| 297 | + |
247 | 298 | /** |
248 | 299 | * |
249 | 300 | * @param {Object} gpu |
|
258 | 309 | * @param {Number} lineColor |
259 | 310 | * @param {String} progressiveAxis |
260 | 311 | */ |
261 | | - function getAddDataKernel(gpu, dimensions, brushSize, brushColor, xScaleFactor, yScaleFactor, xOffset, yOffset, lineThickness, lineColor, progressiveAxis) { |
262 | | - return gpu.createKernel(function(graphPixels, value, dataIndex, lastData, numProgress) { |
| 312 | + function getAddDataKernel(gpu, dimensions, brushSize, brushColor, xOffset, yOffset, lineThickness, lineColor, progressiveAxis) { |
| 313 | + return gpu.createKernel(function(graphPixels, value, dataIndex, lastData, numProgress, xScaleFactor, yScaleFactor) { |
263 | 314 | const x = this.thread.x + numProgress * Math.abs(this.constants.progressiveAxis - 1), |
264 | 315 | y = this.thread.y + numProgress * this.constants.progressiveAxis; |
265 | 316 |
|
|
268 | 319 |
|
269 | 320 | const outX = this.output.x, outY = this.output.y; |
270 | 321 |
|
271 | | - const X = x / this.constants.xScaleFactor - (outX * (this.constants.yOffset / 100)) / this.constants.xScaleFactor; |
272 | | - const Y = y / this.constants.yScaleFactor - (outY * (this.constants.xOffset / 100)) / this.constants.yScaleFactor; |
| 322 | + const X = x / xScaleFactor - (outX * (this.constants.yOffset / 100)) / xScaleFactor; |
| 323 | + const Y = y / yScaleFactor - (outY * (this.constants.xOffset / 100)) / yScaleFactor; |
273 | 324 |
|
274 | | - const xDist = (X - dataIndex) * this.constants.xScaleFactor; |
275 | | - const yDist = (Y - val) * this.constants.yScaleFactor; |
| 325 | + const xDist = (X - dataIndex) * xScaleFactor; |
| 326 | + const yDist = (Y - val) * yScaleFactor; |
276 | 327 |
|
277 | 328 | const dist = Math.sqrt(xDist*xDist + yDist*yDist); |
278 | 329 |
|
|
297 | 348 | brushColor, |
298 | 349 | lineThickness, |
299 | 350 | lineColor, |
300 | | - xScaleFactor, |
301 | | - yScaleFactor, |
302 | 351 | xOffset, |
303 | 352 | yOffset, |
304 | 353 | progressiveAxis: progressiveAxis == 'y' ? 1 : 0 |
|
308 | 357 | brushSize: 'Float', |
309 | 358 | lineThickness: 'Float', |
310 | 359 | lineColor: 'Array(3)', |
311 | | - xScaleFactor: 'Float', |
312 | | - yScaleFactor: 'Float', |
313 | 360 | xOffset: 'Float', |
314 | 361 | yOffset: 'Float', |
315 | 362 | progressiveAxis: 'Integer' |
|
337 | 384 | // *****DEFAULTS***** |
338 | 385 |
|
339 | 386 | this._progressGraph = progressGraph(this.gpu, this.dimensions, this.progressiveAxis, this.xOffset, this.yOffset, this.axesColor, this.bgColor); |
| 387 | + this._squeezeGraph = squeezeGraph(this.gpu, this.dimensions, this.progressiveAxis, this.xOffset, this.yOffset, this.axesColor, this.bgColor); |
340 | 388 | this._lastProgress = 0; // Time when the graph last progressed. Internal variable |
341 | 389 | this._numProgress = 0; // Number of times the graph has progressed |
342 | 390 |
|
343 | 391 | this._dataIndex = 1; // Number of plots |
344 | 392 | this._lastData = [0]; // (Value) To display lines |
345 | 393 |
|
346 | | - this._addData = addData(this.gpu, this.dimensions, this.brushSize, this.brushColor, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset, this.lineThickness, this.lineColor, this.progressiveAxis); |
| 394 | + this._addData = addData(this.gpu, this.dimensions, this.brushSize, this.brushColor, this.xOffset, this.yOffset, this.lineThickness, this.lineColor, this.progressiveAxis); |
347 | 395 |
|
348 | 396 | this.limits = { // Final ranges of x and y |
349 | 397 | x: [ |
|
360 | 408 | addData(value) { |
361 | 409 | if (!isNaN(parseFloat(value))) value = [parseFloat(value)]; |
362 | 410 | else if (!value.texture) throw 'Input invalid.'; |
363 | | - |
364 | | - console.log(value, this._lastData); |
365 | 411 |
|
366 | | - this.graphPixels = this._addData(this._cloneTexture(this.graphPixels), value, this._dataIndex++, this._lastData, this._numProgress); |
| 412 | + this.graphPixels = this._addData(this._cloneTexture(this.graphPixels), value, this._dataIndex++, this._lastData, this._numProgress, this.xScaleFactor, this.yScaleFactor); |
367 | 413 | this._lastData = value; |
368 | 414 |
|
369 | 415 | // Overflow |
370 | | - if (this._dataIndex >= this.limits.x[1] && this.progressionMode != 'continous') { |
| 416 | + if (this._dataIndex >= this.limits.x[1] && this.progressionMode == 'overflow') { |
371 | 417 | let progress = Math.ceil(this.progressiveAxis == 'y' ? this.yScaleFactor : this.xScaleFactor); |
372 | 418 |
|
373 | 419 | this.graphPixels = this._progressGraph( |
|
387 | 433 | } |
388 | 434 | } |
389 | 435 |
|
| 436 | + // Squeeze |
| 437 | + if (this._dataIndex >= this.limits.x[1] && this.progressionMode == 'squeeze') { |
| 438 | + const scalingFactor = (this._dataIndex / (this._dataIndex + 1)); |
| 439 | + |
| 440 | + this.graphPixels = this._squeezeGraph( |
| 441 | + this._cloneTexture(this.graphPixels), |
| 442 | + scalingFactor |
| 443 | + ); |
| 444 | + |
| 445 | + |
| 446 | + if (this.progressiveAxis == 'x') { |
| 447 | + this.xScaleFactor *= scalingFactor; |
| 448 | + this.limits.x[1] /= scalingFactor; |
| 449 | + } |
| 450 | + else { |
| 451 | + this.yScaleFactor *= scalingFactor; |
| 452 | + this.limits.y[1] /= scalingFactor; |
| 453 | + } |
| 454 | + } |
| 455 | + |
390 | 456 | this._display(this.graphPixels); |
391 | 457 | return this; |
392 | 458 | } |
|
423 | 489 | this._lastProgress = 0; |
424 | 490 | this._numProgress = 0; |
425 | 491 |
|
| 492 | + this.xScaleFactor = options.xScaleFactor || 10; |
| 493 | + this.yScaleFactor = options.yScaleFactor || 1; |
| 494 | + |
426 | 495 | this.limits = { // Final ranges of x and y |
427 | 496 | x: [ |
428 | 497 | 0 - (this.yOffset / 100) * (this.dimensions[0] / this.xScaleFactor), // lower limit |
|
723 | 792 | this._plotComplexPersistent = plotComplex(this.gpu, this.dimensions, this.brushSize, this.brushColor, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset); |
724 | 793 | this.Complex = complex; |
725 | 794 |
|
726 | | - this.interpolate = interpolate(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset, this.lineThickness, this.lineColor); |
| 795 | + this._interpolateKernel = interpolate(this.gpu, this.dimensions, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset, this.lineThickness, this.lineColor); |
727 | 796 | } |
728 | 797 |
|
729 | 798 | /** |
|
757 | 826 | } |
758 | 827 |
|
759 | 828 | _interpolate(graphPixels, n1, n2) { |
760 | | - graphPixels = this.interpolate(this._cloneTexture(graphPixels), [n1.x, n1.y], [n2.x, n2.y]); |
| 829 | + graphPixels = this._interpolateKernel(this._cloneTexture(graphPixels), [n1.x, n1.y], [n2.x, n2.y]); |
761 | 830 |
|
762 | 831 | return graphPixels; |
763 | 832 | } |
|
0 commit comments