Skip to content

Commit 8dbaf00

Browse files
committed
fix(color_range): support scientific notation
1 parent 71bac0c commit 8dbaf00

2 files changed

Lines changed: 299 additions & 251 deletions

File tree

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
from trame.widgets import html, vuetify3 as v3
2+
3+
4+
def create_size_menu(name, config):
5+
with v3.VBtn(
6+
icon=True,
7+
density="compact",
8+
variant="plain",
9+
classes="mx-1",
10+
size="small",
11+
):
12+
v3.VIcon(
13+
"mdi-arrow-expand",
14+
size="x-small",
15+
style="transform: scale(-1, 1);",
16+
)
17+
with v3.VMenu(activator="parent"):
18+
with config.provide_as("config"):
19+
with v3.VList(density="compact"):
20+
v3.VListItem(
21+
subtitle="Full Screen",
22+
click=f"active_layout = '{name}'",
23+
)
24+
v3.VDivider()
25+
with v3.VListItem(
26+
subtitle="Line Break",
27+
click="config.break_row = !config.break_row",
28+
):
29+
with v3.Template(v_slot_append=True):
30+
v3.VSwitch(
31+
v_model="config.break_row",
32+
hide_details=True,
33+
density="compact",
34+
color="primary",
35+
)
36+
with v3.VListItem(subtitle="Offset"):
37+
v3.VBtn(
38+
"0",
39+
classes="text-none ml-2",
40+
size="small",
41+
variant="outined",
42+
click="config.offset = 0",
43+
active=("config.offset === 0",),
44+
)
45+
v3.VBtn(
46+
"1",
47+
classes="text-none ml-2",
48+
size="small",
49+
variant="outined",
50+
click="config.offset = 1",
51+
active=("config.offset === 1",),
52+
)
53+
v3.VBtn(
54+
"2",
55+
classes="text-none ml-2",
56+
size="small",
57+
variant="outined",
58+
click="config.offset = 2",
59+
active=("config.offset === 2",),
60+
)
61+
v3.VBtn(
62+
"3",
63+
classes="text-none ml-2",
64+
size="small",
65+
variant="outined",
66+
click="config.offset = 3",
67+
active=("config.offset === 3",),
68+
)
69+
v3.VBtn(
70+
"4",
71+
classes="text-none ml-2",
72+
size="small",
73+
variant="outined",
74+
click="config.offset = 4",
75+
active=("config.offset === 4",),
76+
)
77+
v3.VBtn(
78+
"5",
79+
classes="text-none ml-2",
80+
size="small",
81+
variant="outined",
82+
click="config.offset = 5",
83+
active=("config.offset === 5",),
84+
)
85+
v3.VDivider()
86+
87+
v3.VListItem(
88+
subtitle="Full width",
89+
click="active_layout = 'auto_layout';config.size = 12",
90+
)
91+
v3.VListItem(
92+
subtitle="1/2 width",
93+
click="active_layout = 'auto_layout';config.size = 6",
94+
)
95+
v3.VListItem(
96+
subtitle="1/3 width",
97+
click="active_layout = 'auto_layout';config.size = 4",
98+
)
99+
v3.VListItem(
100+
subtitle="1/4 width",
101+
click="active_layout = 'auto_layout';config.size = 3",
102+
)
103+
v3.VListItem(
104+
subtitle="1/6 width",
105+
click="active_layout = 'auto_layout';config.size = 2",
106+
)
107+
108+
109+
def create_bottom_bar(config, update_color_preset):
110+
with config.provide_as("config"):
111+
with html.Div(
112+
classes="bg-blue-grey-darken-2 d-flex align-center",
113+
style="height:1rem;position:relative;top:0;user-select:none;cursor:context-menu;",
114+
):
115+
with v3.VMenu(
116+
v_model="config.menu",
117+
activator="parent",
118+
location=(
119+
"active_layout !== 'auto_layout' || config.size == 12 ? 'top' : 'end'",
120+
),
121+
close_on_content_click=False,
122+
):
123+
with v3.VCard(style="max-width: 360px;"):
124+
with v3.VCardItem(classes="pb-0"):
125+
v3.VIconBtn(
126+
raw_attrs=[
127+
'''v-tooltip:bottom="config.color_blind ? 'Colorblind safe presets' : 'All color presets'"'''
128+
],
129+
icon=(
130+
"config.color_blind ? 'mdi-shield-check-outline' : 'mdi-palette'",
131+
),
132+
click="config.color_blind = !config.color_blind",
133+
size="small",
134+
text="Colorblind safe",
135+
variant="text",
136+
)
137+
v3.VIconBtn(
138+
raw_attrs=[
139+
'''v-tooltip:bottom="config.invert ? 'Inverted preset' : 'Normal preset'"'''
140+
],
141+
icon=(
142+
"config.invert ? 'mdi-invert-colors' : 'mdi-invert-colors-off'",
143+
),
144+
click="config.invert = !config.invert",
145+
size="small",
146+
text="Invert",
147+
variant="text",
148+
)
149+
v3.VIconBtn(
150+
raw_attrs=[
151+
'''v-tooltip:bottom="config.use_log_scale ? 'Use log scale' : 'Use linear scale'"'''
152+
],
153+
icon=(
154+
"config.use_log_scale ? 'mdi-math-log' : 'mdi-stairs'",
155+
),
156+
click="config.use_log_scale = !config.use_log_scale",
157+
size="small",
158+
text=(
159+
"config.use_log_scale ? 'Log scale' : 'Linear scale'",
160+
),
161+
variant="text",
162+
)
163+
v3.VIconBtn(
164+
raw_attrs=[
165+
'''v-tooltip:bottom="config.override_range ? 'Use custom range' : 'Use data range'"'''
166+
],
167+
icon=(
168+
"config.override_range ? 'mdi-arrow-expand-horizontal' : 'mdi-pencil'",
169+
),
170+
click="config.override_range = !config.override_range",
171+
size="small",
172+
text="Use data range",
173+
variant="text",
174+
)
175+
176+
with v3.Template(v_slot_append=True):
177+
v3.VLabel(
178+
"{{ config.preset }}",
179+
classes="mr-2 text-caption",
180+
)
181+
v3.VIconBtn(
182+
icon="mdi-close",
183+
size="small",
184+
text="Close",
185+
click="config.menu=false",
186+
)
187+
with v3.VCardItem(v_show="config.override_range", classes="py-0"):
188+
v3.VTextField(
189+
v_model="config.color_value_min",
190+
hide_details=True,
191+
density="compact",
192+
variant="outlined",
193+
flat=True,
194+
label="Min",
195+
classes="mt-2",
196+
error=("!config.color_value_min_valid",),
197+
)
198+
v3.VTextField(
199+
v_model="config.color_value_max",
200+
hide_details=True,
201+
density="compact",
202+
variant="outlined",
203+
flat=True,
204+
label="Max",
205+
classes="mt-2",
206+
error=("!config.color_value_max_valid",),
207+
)
208+
# v3.VNumberInput(
209+
# model_value=("config.color_range[1]",),
210+
# update_modelValue="config.color_range = [config.color_range[0], Number($event)]",
211+
# hide_details=True,
212+
# density="compact",
213+
# variant="outlined",
214+
# flat=True,
215+
# label="Max",
216+
# classes="mt-2",
217+
# control_variant="hidden",
218+
# precision=("15",),
219+
# step=(
220+
# "Math.max(0.0001, (config.color_range[1] - config.color_range[0]) / 255)",
221+
# ),
222+
# )
223+
v3.VDivider(classes="mt-2")
224+
with v3.VList(density="compact", max_height="40vh"):
225+
with v3.VListItem(
226+
v_for="url, name in (config.invert ? luts_inverted : luts_normal)",
227+
v_show="!config.color_blind || safe_color[name]",
228+
key="name",
229+
subtitle=("name",),
230+
click=(
231+
update_color_preset,
232+
"[name, config.invert, config.use_log_scale]",
233+
),
234+
active=("config.preset === name",),
235+
):
236+
html.Img(
237+
src=("url",),
238+
style="width:100%;min-width:20rem;height:1rem;",
239+
classes="rounded",
240+
)
241+
html.Div(
242+
"{{ utils.quickview.formatRange(config.color_range?.[0], config.use_log_scale) }}",
243+
classes="text-caption px-2 text-no-wrap",
244+
)
245+
with html.Div(classes="overflow-hidden rounded w-100", style="height:70%;"):
246+
html.Img(
247+
src=("config.preset_img",),
248+
style="width:100%;height:2rem;",
249+
draggable=False,
250+
)
251+
html.Div(
252+
"{{ utils.quickview.formatRange(config.color_range?.[1], config.use_log_scale) }}",
253+
classes="text-caption px-2 text-no-wrap",
254+
)

0 commit comments

Comments
 (0)