-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.visidatarc
More file actions
378 lines (316 loc) · 12.2 KB
/
.visidatarc
File metadata and controls
378 lines (316 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/usr/bin/env python
import datetime # Allow additional datetime column formats
import dateutil
from visidata import BaseSheet, DirSheet, GraphSheet, Sheet, colors, options, vd
################################################################################
# visidata gruvbox dark theme configuration
# Gruvbox Dark color palette mapped to 256-color terminal codes
# Using the closest matches to original Gruvbox colors
# fmt: off
GRUVBOX = {
"bg0_h": 234, # #1d2021 (hard dark)
"bg0": 235, # #282828 (main dark)
"bg0_s": 236, # #32302f
"bg1": 237, # #3c3836
"bg2": 239, # #504945
"bg3": 241, # #665c54
"bg4": 243, # #7c6f64
"fg0": 229, # #fbf1c7 (hard light)
"fg": 223, # #ebdbb2 (main light)
"fg1": 223, # #ebdbb2 (main light)
"fg2": 250, # #d5c4a1
"fg3": 248, # #bdae93
"fg4": 246, # #a89984
"red": 124, # #cc241d (red)
"green": 106, # #98971a (green)
"yellow": 172, # #d79921 (yellow)
"blue": 66, # #458588 (blue)
"purple": 132, # #b16286 (purple)
"aqua": 108, # #689d6a (aqua)
"orange": 166, # #d65d0e (orange)
"bright_red": 167, # #fb4934 (bright red)
"bright_green": 142, # #b8bb26 (bright green)
"bright_yellow": 214, # #fabd2f (bright yellow)
"bright_blue": 109, # #83a598 (bright blue)
"bright_purple": 175, # #d3869b (bright purple)
"bright_aqua": 108, # #8ec07c (bright aqua)
"bright_orange": 208, # #fe8019 (bright orange)
"gray": 245, # #928374 (gray)
}
# fmt: on
# Plot colors for better visibility in graphs
PLOT_COLORS = {
"c1": 2, # green
"c2": 1, # red
"c3": 6, # cyan
"c4": 3, # yellow
"c5": 7, # white
"c6": 201,
"c7": 226,
"c8": 51,
"c9": 196,
"c10": 46,
"c11": 33,
"c12": 207,
"c13": 8, # gray
"c14": 19,
"c15": 220,
"c16": 88,
"c17": 45,
"c18": 22,
"c19": 141,
"c20": 118,
"c21": 39,
"c22": 208,
"c23": 52,
"c24": 156,
"c25": 213,
"c26": 224,
}
_plot_colors_str = " ".join(map(str, PLOT_COLORS.values()))
vd.themes["gruvbox-dark"] = dict(
# Base colors
color_default=f'{GRUVBOX["fg1"]} on {GRUVBOX["bg0"]}',
color_default_hdr=f'bold {GRUVBOX["bright_yellow"]} on {GRUVBOX["bg0_s"]}',
# Key column highlighting with good contrast
color_key_col=f'{GRUVBOX["bright_green"]} on {GRUVBOX["bg0"]}',
# Current column/row (cursor position)
color_current_row=f'bold {GRUVBOX["bg0"]} on {GRUVBOX["blue"]}', # Inverted for visibility
color_current_col=f'{GRUVBOX["bright_blue"]} on {GRUVBOX["bg0_s"]}',
color_current_cell=f'bold {GRUVBOX["bg0"]} on {GRUVBOX["bright_blue"]}',
# Selected rows - high contrast for readability
color_selected_row=f'{GRUVBOX["bg0"]} on {GRUVBOX["bright_green"]}', # Inverted green background
# Column separators
color_column_sep=f'{GRUVBOX["bg2"]} on {GRUVBOX["bg0"]}',
# Aggregator
color_aggregator=f'bold {GRUVBOX["fg0"]} on {GRUVBOX["bg0_h"]}',
# Status bars and messages
color_status=f'{GRUVBOX["fg1"]} on {GRUVBOX["bg0_h"]}',
color_active_status=f'{GRUVBOX["fg2"]} on {GRUVBOX["bg0_s"]}',
color_error=f'bold {GRUVBOX["bright_red"]} on {GRUVBOX["bg0_h"]}',
color_warning=f'{GRUVBOX["bright_yellow"]} on {GRUVBOX["bg0_h"]}',
# Sidebar
color_sidebar=f'{GRUVBOX["fg0"]} on {GRUVBOX["bg2"]}',
color_sidebar_title=f'{GRUVBOX["bright_orange"]} on {GRUVBOX["bg2"]}',
color_longname_guide=f'{GRUVBOX["fg4"]} on {GRUVBOX["bg2"]}',
color_heading=f'{GRUVBOX["bright_orange"]} on {GRUVBOX["bg2"]}',
# Cell content types
color_note_row=f'{GRUVBOX["bright_blue"]} on {GRUVBOX["bg0"]}',
# Graph colors
color_graph_hidden=f'{GRUVBOX["blue"]}',
plot_colors=_plot_colors_str,
# Bottom sheet colors
color_bottom_hdr=f'bold {GRUVBOX["bright_yellow"]} on {GRUVBOX["bg0_h"]}',
# Command palette and menus
color_cmdpalette=f'{GRUVBOX["fg1"]} on {GRUVBOX["bg3"]}',
color_menu=f'{GRUVBOX["fg1"]} on {GRUVBOX["bg3"]}',
color_menu_active=f'bold {GRUVBOX["bright_yellow"]} on {GRUVBOX["bg0_s"]}',
color_menu_help=f'italic {GRUVBOX["bg0_h"]} on {GRUVBOX["blue"]}',
# Hidden columns
color_hidden_col=f'{GRUVBOX["gray"]} on {GRUVBOX["bg0"]}',
# Add-on status colors
color_add_pending=f'{GRUVBOX["bright_yellow"]} on {GRUVBOX["bg0"]}',
color_change_pending=f'{GRUVBOX["bright_purple"]} on {GRUVBOX["bg0"]}',
color_delete_pending=f'{GRUVBOX["bright_red"]} on {GRUVBOX["bg0"]}',
disp_status_fmt="{sheet.sheetlist} ",
disp_rstatus_fmt="{sheet.threadStatus} {sheet.keystrokeStatus} {sheet.longname}[/] {sheet.nRows} {sheet.rowtype} {sheet.modifiedStatus}{sheet.selectedStatus}{vd.replayStatus} [:longname_status]{sheet.cursorRowIndex1}:{sheet.cursorVisibleColIndex1} {sheet.vertPos}[/] {vd.sidebarStatus}",
)
if options.theme == "":
options.theme = "gruvbox-dark"
################################################################################
# Set some UI preferences for better experience
options.motd_url = ""
vd.motd = ""
# Make @ use datetime instead of time
Sheet.addCommand(
"@",
"type-datetime",
'cursorCol.type=date; cursorCol.fmtstr="%Y-%m-%d %H:%M:%S"',
"set type of current column to datetime",
)
@Sheet.after
def afterLoad(_sheet):
options.numeric_binning = True
options.disp_date_fmt = "%Y-%m-%d"
options.disp_menu_boxchars = "││──╭╮╰╯├┤"
################################################################################
# Statusline variables
@Sheet.property
def cursorRowIndex1(sheet):
return sheet.cursorRowIndex + 1
@Sheet.property
def cursorVisibleColIndex1(sheet):
return sheet.cursorVisibleColIndex + 1
@Sheet.property
def vertPos(sheet):
if sheet.cursorRowIndex == 0:
return str(1) + "%"
return str(int((sheet.cursorRowIndex + 1) * 100 / sheet.nRows)) + "%"
################################################################################
# Key bindings
# Optional: Custom keybindings can be added here
# Example: bindkey('Alt+q', 'quit-sheet')
################################################################################
# Aggregators
def agg_range(values):
# Filter out invalid or incompatible values
valid = []
for v in values:
if v is None:
continue
# ignore arrays like [1] value
if isinstance(v, (list, tuple, dict)):
continue
valid.append(v)
if not valid:
return None
try:
diff = max(valid) - min(valid)
return diff
except Exception:
return None
def agg_non_empty(values):
return sum(1 for v in values if v is not None and v != "")
vd.aggregator("range", agg_range, "returns (max - min)", type=float)
vd.aggregator("non_empty", agg_non_empty, "returns non empty values")
@BaseSheet.api
def apply_aggregator_to_all_columns(sheet: BaseSheet) -> None:
agg = vd.input("Aggregator: ")
if agg:
sheet.addAggregators(
[col for col in sheet.visibleCols if vd.isNumeric(col)], [agg]
)
BaseSheet.addCommand(
"g+",
"add-aggregator-to-all-columns",
"apply_aggregator_to_all_columns()",
"add aggregator to all visible columns (prompt for name)",
)
################################################################################
# autotune.py
# https://gist.github.com/cool-RR/47d8ebb7afc636a995fccf889aada8e9
N_ROWS_FOR_TYPE_GUESSING = 100
DEFAULT_FLOAT_PRECISION = 5
DATE_FORMATS = [
"%Y-%m-%dT%H:%M:%S.%f%z",
"%Y-%m-%dT%H:%M:%S%z",
"%Y-%m-%dT%H:%M:%S.%f",
"%Y-%m-%d %H:%M:%S.%f",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d",
]
@GraphSheet.api
def guess_y_axis(graph_sheet: GraphSheet) -> None:
values = tuple(
column.getTypedValue(row)
for column in graph_sheet.ycols
for row in column.sheet.rows
)
min_value = min(values)
max_value = max(values)
if 0 <= min_value <= max_value <= 1:
graph_sheet.set_y("-0.1 1.1")
graph_sheet.extra_y_ticks = (0, 1)
elif -1 <= min_value <= max_value <= 1:
graph_sheet.set_y("-1.1 1.1")
graph_sheet.extra_y_ticks = (-1, 1)
def guess_column_types(sheet: BaseSheet) -> None:
if isinstance(sheet, DirSheet):
# These break for some reason.
return
for column in sheet.visibleCols:
if column.type not in (anytype, int):
continue
type_candidates = [int, float, date, anytype]
try:
values = tuple(
column.getValue(r) for r in sheet.rows[:N_ROWS_FOR_TYPE_GUESSING]
)
except Exception:
# I got an inexplicable `NameError` here while doing this on a `DirSheet`, so let's not
# guess a column when that happens.
continue
for value in values:
if value is None or value == "":
continue
if date in type_candidates:
if value is int or value is float:
type_candidates.remove(date)
else:
found = False
for datefmt in DATE_FORMATS:
try:
datetime.datetime.strptime(value, datefmt)
column.fmtstr = datefmt
found = True
break
except TypeError:
pass
except ValueError:
pass
if not found:
try:
date(value)
except dateutil.parser.ParserError:
type_candidates.remove(date)
if int in type_candidates:
try:
value_as_int = int(value)
except (ValueError, TypeError):
type_candidates.remove(int)
else:
if float(value) != value_as_int:
type_candidates.remove(int)
if float in type_candidates:
try:
float(value)
except (ValueError, TypeError):
type_candidates.remove(float)
column.type = type_candidates[0]
if column.type is float:
numbers = tuple(
column.getTypedValue(r) for r in sheet.rows[:N_ROWS_FOR_TYPE_GUESSING]
)
biggest_number = max(map(abs, numbers))
if biggest_number > 0:
for i in range(2, 6):
if 10 ** (-(i - 1)) < biggest_number:
if i != DEFAULT_FLOAT_PRECISION:
column.fmtstr = f"%.{i}f"
break
def guess_key_columns(sheet: BaseSheet) -> None:
if sheet.columns and sheet.columns[0].name in (
"generation",
"i_agent",
"time_step",
):
sheet.setKeys([sheet.columns[0]])
@BaseSheet.api
def autotune(sheet: BaseSheet) -> None:
if isinstance(sheet, GraphSheet):
guess_y_axis(sheet)
# Put selection box outside the plot:
sheet.cursorBox.xmin = sheet.visibleBox.xmin - 8 * sheet.cursorBox.w
else:
visidata.features.expand_cols.expand_cols_deep(
sheet, sheet.visibleCols, depth=0
)
guess_column_types(sheet)
guess_key_columns(sheet)
@BaseSheet.api
def autowidth(sheet: BaseSheet) -> None:
for column in sheet.visibleCols:
column: Column
if column.type is anytype:
try:
first_value = column.getValue(sheet.rows[0])
except Exception:
# I got an inexplicable `NameError` here while doing this on a `DirSheet`,
# so let's not guess a column when that happens.
continue
if isinstance(first_value, dict):
column.setWidth(len(column.name) + 5)
continue
column.setWidth(column.getMaxWidth(sheet.visibleRows))
BaseSheet.addCommand("b", "autotune", "autotune()")
BaseSheet.addCommand("Alt+=", "autowidth", "autowidth()")