Skip to content

Commit 7683cd5

Browse files
authored
Merge pull request #59 from danchitnis/log10
Log10
2 parents 312ff6f + f4037f7 commit 7683cd5

File tree

7 files changed

+67
-8
lines changed

7 files changed

+67
-8
lines changed

dist/webglplot.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ export default class WebGLPlot {
5252
* @default = 0
5353
*/
5454
gOffsetY: number;
55+
/**
56+
* Global log10 of x-axis
57+
* @default = false
58+
*/
59+
gLog10X: boolean;
60+
/**
61+
* Global log10 of y-axis
62+
* @default = false
63+
*/
64+
gLog10Y: boolean;
5565
/**
5666
* collection of data lines in the plot
5767
*/

dist/webglplot.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/webglplot.esm.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ class WebGLPlot {
353353
this.gXYratio = 1;
354354
this.gOffsetX = 0;
355355
this.gOffsetY = 0;
356+
this.gLog10X = false;
357+
this.gLog10Y = false;
356358
// Clear the color
357359
this.webgl.clear(this.webgl.COLOR_BUFFER_BIT);
358360
// Set the view port
@@ -383,6 +385,8 @@ class WebGLPlot {
383385
]));
384386
const uoffset = webgl.getUniformLocation(this.progThinLine, "uoffset");
385387
webgl.uniform2fv(uoffset, new Float32Array([line.offsetX + this.gOffsetX, line.offsetY + this.gOffsetY]));
388+
const isLog = webgl.getUniformLocation(this.progThinLine, "is_log");
389+
webgl.uniform2iv(isLog, new Int32Array([this.gLog10X ? 1 : 0, this.gLog10Y ? 1 : 0]));
386390
const uColor = webgl.getUniformLocation(this.progThinLine, "uColor");
387391
webgl.uniform4fv(uColor, [line.color.r, line.color.g, line.color.b, line.color.a]);
388392
webgl.bufferData(webgl.ARRAY_BUFFER, line.xy, webgl.STREAM_DRAW);
@@ -432,8 +436,13 @@ class WebGLPlot {
432436
attribute vec2 coordinates;
433437
uniform mat2 uscale;
434438
uniform vec2 uoffset;
439+
uniform ivec2 is_log;
440+
435441
void main(void) {
436-
gl_Position = vec4(uscale*coordinates + uoffset, 0.0, 1.0);
442+
float x = (is_log[0]==1) ? log(coordinates.x) : coordinates.x;
443+
float y = (is_log[1]==1) ? log(coordinates.y) : coordinates.y;
444+
vec2 line = vec2(x, y);
445+
gl_Position = vec4(uscale*line + uoffset, 0.0, 1.0);
437446
}`;
438447
// Create a vertex shader object
439448
const vertShader = this.webgl.createShader(this.webgl.VERTEX_SHADER);

dist/webglplot.js

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/webglplot.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)