Skip to content

Commit

Permalink
Merge pull request #59 from danchitnis/log10
Browse files Browse the repository at this point in the history
Log10
  • Loading branch information
danchitnis authored Jan 2, 2021
2 parents 312ff6f + f4037f7 commit 7683cd5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
10 changes: 10 additions & 0 deletions dist/webglplot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ export default class WebGLPlot {
* @default = 0
*/
gOffsetY: number;
/**
* Global log10 of x-axis
* @default = false
*/
gLog10X: boolean;
/**
* Global log10 of y-axis
* @default = false
*/
gLog10Y: boolean;
/**
* collection of data lines in the plot
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/webglplot.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion dist/webglplot.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ class WebGLPlot {
this.gXYratio = 1;
this.gOffsetX = 0;
this.gOffsetY = 0;
this.gLog10X = false;
this.gLog10Y = false;
// Clear the color
this.webgl.clear(this.webgl.COLOR_BUFFER_BIT);
// Set the view port
Expand Down Expand Up @@ -383,6 +385,8 @@ class WebGLPlot {
]));
const uoffset = webgl.getUniformLocation(this.progThinLine, "uoffset");
webgl.uniform2fv(uoffset, new Float32Array([line.offsetX + this.gOffsetX, line.offsetY + this.gOffsetY]));
const isLog = webgl.getUniformLocation(this.progThinLine, "is_log");
webgl.uniform2iv(isLog, new Int32Array([this.gLog10X ? 1 : 0, this.gLog10Y ? 1 : 0]));
const uColor = webgl.getUniformLocation(this.progThinLine, "uColor");
webgl.uniform4fv(uColor, [line.color.r, line.color.g, line.color.b, line.color.a]);
webgl.bufferData(webgl.ARRAY_BUFFER, line.xy, webgl.STREAM_DRAW);
Expand Down Expand Up @@ -432,8 +436,13 @@ class WebGLPlot {
attribute vec2 coordinates;
uniform mat2 uscale;
uniform vec2 uoffset;
uniform ivec2 is_log;
void main(void) {
gl_Position = vec4(uscale*coordinates + uoffset, 0.0, 1.0);
float x = (is_log[0]==1) ? log(coordinates.x) : coordinates.x;
float y = (is_log[1]==1) ? log(coordinates.y) : coordinates.y;
vec2 line = vec2(x, y);
gl_Position = vec4(uscale*line + uoffset, 0.0, 1.0);
}`;
// Create a vertex shader object
const vertShader = this.webgl.createShader(this.webgl.VERTEX_SHADER);
Expand Down
11 changes: 10 additions & 1 deletion dist/webglplot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/webglplot.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7683cd5

Please sign in to comment.