Skip to content

Commit

Permalink
gridlines default to infinite grid and fix typo
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Lai <oscar@tinyiu.com>
  • Loading branch information
soraxas committed Jun 25, 2023
1 parent bc49abc commit b3bec6b
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions vispy/visuals/gridlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

from __future__ import division

import numpy as np

from .image import ImageVisual
from ..color import Color
from .shaders import Function


_GRID_COLOR = """
uniform vec4 u_gridlines_bounds;
uniform float u_boarder_width;
uniform float u_border_width;
vec4 grid_color(vec2 pos) {
vec4 px_pos = $map_to_doc(vec4(pos, 0, 1));
Expand Down Expand Up @@ -67,9 +69,9 @@
if (any(lessThan(local_pos.xy, u_gridlines_bounds.xz)) ||
any(greaterThan(local_pos.xy, u_gridlines_bounds.yw))) {
// inside the defined bouarder width
if (all(greaterThan(local_pos.xy, u_gridlines_bounds.xz - u_boarder_width)) &&
all(lessThan(local_pos.xy, u_gridlines_bounds.yw + u_boarder_width))) {
// inside the defined border width
if (all(greaterThan(local_pos.xy, u_gridlines_bounds.xz - u_border_width)) &&
all(lessThan(local_pos.xy, u_gridlines_bounds.yw + u_border_width))) {
alpha = 1;
} else {
discard;
Expand All @@ -94,8 +96,9 @@ class GridLinesVisual(ImageVisual):
channel modified.
"""

def __init__(self, scale=(1, 1), color='w', bounds=(-1e3, 1e3, -1e3, 1e3),
boarder_width=2):
def __init__(self, scale=(1, 1), color='w',
bounds=(-np.inf, np.inf, -np.inf, np.inf),
border_width=2):
# todo: PlaneVisual should support subdivide/impostor methods from
# image and gridlines should inherit from plane instead.
self._grid_color_fn = Function(_GRID_COLOR)
Expand All @@ -108,7 +111,7 @@ def __init__(self, scale=(1, 1), color='w', bounds=(-1e3, 1e3, -1e3, 1e3),
self.shared_program.frag['color_transform'] = cfun
self.unfreeze()
self.bounds = bounds
self.boarder_width = boarder_width
self.border_width = border_width
self.freeze()

@property
Expand All @@ -122,13 +125,13 @@ def bounds(self, value):
self.update()

@property
def boarder_width(self):
return self._boarder_width
def border_width(self):
return self._border_width

@boarder_width.setter
def boarder_width(self, value):
self.shared_program['u_boarder_width'] = value
self._boarder_width = value
@border_width.setter
def border_width(self, value):
self.shared_program['u_border_width'] = value
self._border_width = value
self.update()

@property
Expand Down

0 comments on commit b3bec6b

Please sign in to comment.