Skip to content

Commit 592ad45

Browse files
committed
allow number format in color bar
1 parent 8700c0f commit 592ad45

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

webgpu/colormap.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ class Colorbar(Renderer):
153153
n_vertices: int = 3
154154

155155
def __init__(
156-
self, colormap: Colormap | None = None, position=(-0.9, 0.9), width=1, height=0.05
156+
self,
157+
colormap: Colormap | None = None,
158+
position=(-0.9, 0.9),
159+
width=1,
160+
height=0.05,
161+
number_format=None,
157162
):
158163
super().__init__()
159164
self.colormap = colormap or Colormap()
165+
self.number_format = number_format
160166
self.labels = Labels([], [], font_size=14, h_align="center", v_align="top")
161167
self.uniforms = None
162168

@@ -217,7 +223,7 @@ def update(self, options: RenderOptions):
217223
self.n_instances = 2 * self.colormap.n_colors
218224

219225
self.labels.labels = [
220-
format_number(v)
226+
format_number(v, self.number_format)
221227
for v in [
222228
self.colormap.minval + i / 4 * (self.colormap.maxval - self.colormap.minval)
223229
for i in range(6)

webgpu/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,9 @@ def max_bounding_box(boxes):
560560
return (pmin, pmax)
561561

562562

563-
def format_number(n):
563+
def format_number(n, format=None):
564+
if format is not None:
565+
return format % n
564566
if n == 0:
565567
return "0"
566568
abs_n = abs(n)

0 commit comments

Comments
 (0)