Skip to content

Commit 1c167ef

Browse files
author
HarshKhandeparkar
committed
v0.3.0
1 parent 23c4212 commit 1c167ef

File tree

3 files changed

+88
-19
lines changed

3 files changed

+88
-19
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,57 @@
244244

245245
var progressGraph = getProgressGraphKernel;
246246

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+
247298
/**
248299
*
249300
* @param {Object} gpu
@@ -258,8 +309,8 @@
258309
* @param {Number} lineColor
259310
* @param {String} progressiveAxis
260311
*/
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) {
263314
const x = this.thread.x + numProgress * Math.abs(this.constants.progressiveAxis - 1),
264315
y = this.thread.y + numProgress * this.constants.progressiveAxis;
265316

@@ -268,11 +319,11 @@
268319

269320
const outX = this.output.x, outY = this.output.y;
270321

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;
273324

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;
276327

277328
const dist = Math.sqrt(xDist*xDist + yDist*yDist);
278329

@@ -297,8 +348,6 @@
297348
brushColor,
298349
lineThickness,
299350
lineColor,
300-
xScaleFactor,
301-
yScaleFactor,
302351
xOffset,
303352
yOffset,
304353
progressiveAxis: progressiveAxis == 'y' ? 1 : 0
@@ -308,8 +357,6 @@
308357
brushSize: 'Float',
309358
lineThickness: 'Float',
310359
lineColor: 'Array(3)',
311-
xScaleFactor: 'Float',
312-
yScaleFactor: 'Float',
313360
xOffset: 'Float',
314361
yOffset: 'Float',
315362
progressiveAxis: 'Integer'
@@ -337,13 +384,14 @@
337384
// *****DEFAULTS*****
338385

339386
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);
340388
this._lastProgress = 0; // Time when the graph last progressed. Internal variable
341389
this._numProgress = 0; // Number of times the graph has progressed
342390

343391
this._dataIndex = 1; // Number of plots
344392
this._lastData = [0]; // (Value) To display lines
345393

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);
347395

348396
this.limits = { // Final ranges of x and y
349397
x: [
@@ -360,14 +408,12 @@
360408
addData(value) {
361409
if (!isNaN(parseFloat(value))) value = [parseFloat(value)];
362410
else if (!value.texture) throw 'Input invalid.';
363-
364-
console.log(value, this._lastData);
365411

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);
367413
this._lastData = value;
368414

369415
// Overflow
370-
if (this._dataIndex >= this.limits.x[1] && this.progressionMode != 'continous') {
416+
if (this._dataIndex >= this.limits.x[1] && this.progressionMode == 'overflow') {
371417
let progress = Math.ceil(this.progressiveAxis == 'y' ? this.yScaleFactor : this.xScaleFactor);
372418

373419
this.graphPixels = this._progressGraph(
@@ -387,6 +433,26 @@
387433
}
388434
}
389435

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+
390456
this._display(this.graphPixels);
391457
return this;
392458
}
@@ -423,6 +489,9 @@
423489
this._lastProgress = 0;
424490
this._numProgress = 0;
425491

492+
this.xScaleFactor = options.xScaleFactor || 10;
493+
this.yScaleFactor = options.yScaleFactor || 1;
494+
426495
this.limits = { // Final ranges of x and y
427496
x: [
428497
0 - (this.yOffset / 100) * (this.dimensions[0] / this.xScaleFactor), // lower limit
@@ -723,7 +792,7 @@
723792
this._plotComplexPersistent = plotComplex(this.gpu, this.dimensions, this.brushSize, this.brushColor, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
724793
this.Complex = complex;
725794

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);
727796
}
728797

729798
/**
@@ -757,7 +826,7 @@
757826
}
758827

759828
_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]);
761830

762831
return graphPixels;
763832
}

0 commit comments

Comments
 (0)