Skip to content

Commit dd9707c

Browse files
author
Mr. X
committed
complete RealLineGraph
1 parent 5f77e9c commit dd9707c

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/renderers/RealLineGraph.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,54 @@ class RealLineGraph extends RealRenderer {
1111
this.progressiveAxis = this.progressiveAxis.toLowerCase();
1212
this.progressionMode = options.progressionMode || 'overflow'; // overflow -> Only progresses when completely filled; continous -> Always progresses;
1313
this.progressInterval = options.progressInterval || 1; // Progress once every interval time units; Only works with continous progressionMode
14+
1415
this.brushSize = options.brushSize || 2; // 1 unit radius
1516
this.brushColor = options.brushColor || [1, 1, 1];
17+
18+
this.lineThickness = options.lineThickness || 0.05;
19+
this.lineColor = options.lineColor || [0, 0.5, 0];
1620
// *****DEFAULTS*****
1721

1822
this._progressGraph = getProgressGraphKernel(this.gpu, this.dimensions, this.progressiveAxis, this.xOffset, this.yOffset, this.axesColor, this.bgColor);
1923
this._lastProgress = 0; // Time when the graph last progressed. Internal variable
24+
this._numProgress = 0; // Number of times the graph has progressed
2025

21-
this._dataIndex = 0; // Number of plots
26+
this._dataIndex = 1; // Number of plots
2227
this._lastData = 0; // (Value) To display lines
2328

24-
this._addData = getAddDataKernel(this.gpu, this.dimensions, this.brushSize, this.brushColor, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset);
29+
this._addData = getAddDataKernel(this.gpu, this.dimensions, this.brushSize, this.brushColor, this.xScaleFactor, this.yScaleFactor, this.xOffset, this.yOffset, this.lineThickness, this.lineColor);
30+
31+
this.limits = { // Final ranges of x and y
32+
x: [
33+
0 - (this.yOffset / 100) * (this.dimensions[0] / this.xScaleFactor), // lower limit
34+
this.dimensions[0] / this.xScaleFactor - (this.yOffset / 100) * (this.dimensions[0] / this.xScaleFactor) // upper limit
35+
],
36+
y: [
37+
0 - (this.xOffset / 100) * (this.dimensions[1] / this.yScaleFactor),
38+
this.dimensions[1] / this.yScaleFactor - (this.xOffset / 100) * (this.dimensions[1] / this.yScaleFactor)
39+
]
40+
}
2541
}
2642

2743
addData(value) {
28-
this.graphPixels = this._addData(this._cloneTexture(this.graphPixels), value, this._dataIndex++, this._lastData);
29-
this._display(this.graphPixels);
30-
44+
this.graphPixels = this._addData(this._cloneTexture(this.graphPixels), value, this._dataIndex++, this._lastData, this._numProgress);
3145
this._lastData = value;
46+
47+
// Overflow
48+
if (this._dataIndex >= this.limits.x[1] && this.progressionMode != 'continous') {
49+
this.graphPixels = this._progressGraph(this._cloneTexture(this.graphPixels), Math.ceil(this.xScaleFactor))
50+
this._numProgress += Math.ceil(this.xScaleFactor);
51+
}
52+
53+
this._display(this.graphPixels);
3254
return this;
3355
}
3456

3557
_drawFunc(graphPixels, time) {
3658
if (this.progressionMode == 'continous' && (time - this._lastProgress >= this.progressInterval)) {
3759
this._lastProgress = time;
38-
return this._progressGraph(this._cloneTexture(graphPixels));
60+
this._numProgress++;
61+
return this._progressGraph(this._cloneTexture(graphPixels), 1);
3962
}
4063
else return graphPixels;
4164
}

src/renderers/RealRenderer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class RealRenderer {
77
// *****DEFAULTS*****
88
this.canvasTag = options.canvasTag;
99
this.dimensions = options.dimensions || {x: 1000, y:1000};
10-
this.xScaleFactor = options.xScaleFactor || 1;
10+
this.xScaleFactor = options.xScaleFactor || 10;
1111
this.yScaleFactor = options.yScaleFactor || 1;
1212
this.bgColor = options.bgColor || [0, 0, 0];
1313
this.axesColor = options.axesColor || [1, 1, 1];
@@ -34,7 +34,8 @@ class RealRenderer {
3434

3535
this.gpu = new options.GPU({
3636
canvas: this.canvas,
37-
mode: 'gpu'
37+
mode: 'gpu',
38+
tactic: 'precision'
3839
})
3940

4041
this._blankGraph = getBlankGraphKernel(this.gpu, this.dimensions, this.xOffset, this.yOffset, this.bgColor, this.axesColor);

0 commit comments

Comments
 (0)