cptpiepmatz / nu-jupyter-kernel

📓 A wip jupyter raw kernel for nu
MIT License
28 stars 2 forks source link

nu_plugin_plotters should have a way to set axis labels #3

Open drbrain opened 1 day ago

drbrain commented 1 day ago

When plotting data from a time series from the nu_plugin_prometheus plugin:

'rate(unpoller_device_port_transmit_bytes_total{port_id="some-port-id"}[5m])'
| prometheus query range -s home --start ((date now) - 1hr) --end (date now) --step 5min
| get values
| flatten
| rename y x
y x
75867.61893734452 1728150300
121664.27478666068 1728150600
60296.01729080339 1728150900
96637.246886853 1728151200
113744.3007772066 1728151500
77804.2022084753 1728151800
78611.33469707123 1728152100
114471.74035087718 1728152400
333646.5026033993 1728152700
102914.6110389838 1728153000
80590.20828362502 1728153300
107095.817733316 1728153600
82750.42104672216 1728153900

The x axis values are seconds from the UNIX epoch. Plotting them as the raw value is not very useful for knowing the time span the plot covers.

It would be nice to attach an x (and y) label to a series that plotters-rs could use to give the axis labels as shown in several of the examples, perhaps:

# above command
| upsert x_label {|r|
  ($r.x | into int ) * 1_000_000_000
  | into datetime
  | format date "%+"
}
y x x_label
103804.44004673732 1728150697 2024-10-05T17:51:37+00:00
119285.249122807 1728150997 2024-10-05T17:56:37+00:00
55978.62157771563 1728151297 2024-10-05T18:01:37+00:00
75475.46051015754 1728151597 2024-10-05T18:06:37+00:00
78608.26529215892 1728151897 2024-10-05T18:11:37+00:00
98761.50626146942 1728152197 2024-10-05T18:16:37+00:00
148210.41477338516 1728152497 2024-10-05T18:21:37+00:00
299929.763187166 1728152797 2024-10-05T18:26:37+00:00
83996.41052631578 1728153097 2024-10-05T18:31:37+00:00
59713.041159526045 1728153397 2024-10-05T18:36:37+00:00
129653.7883944674 1728153697 2024-10-05T18:41:37+00:00
106094.0097469238 1728153997 2024-10-05T18:46:37+00:00
64033.876479793405 1728154297 2024-10-05T18:51:37+00:00
cptpiepmatz commented 1 day ago

I dislike the x_label proposal, it gets hard to get it right when you use multiple series and each series could come with an x_label. I think a better alternative altogether would be to pass the chart a closure that formats the labels on the x-axis.