piccolomo / plotext

plotting on terminal
MIT License
1.77k stars 82 forks source link

Feature request: clickable plots #175

Open 0100101110101001010110 opened 1 year ago

0100101110101001010110 commented 1 year ago

It would be really helpful to be able to click on a point in a scatter plot chart and then update a second chart to whatever was selected in the first chart. As outliers are what are of interest, the mouse click event handling wouldn't have to be very precise. Thoughts?

Great library and documentation, by the way. Thank you!

0100101110101001010110 commented 1 year ago

I'm going to do this myself and already have a nice prototype working. I'll put this here for anyone interested: I assign each plot point a unique RGB color value. I then use the python-xlib package to detect a mouse click and register the RGB value. I then update a second chart based on the data point clicked. I'll keep the RGB values in SQLite and create a dict while working with them.

piccolomo commented 1 year ago

Hi sorry, I have not involved in protext lately. I will eventually, but busy with work.

Also I got stuck in dealing with plotext docstrings with classes in spare time and it is taking time. I will be back but apologies to everyone for the absence of involvement.

On Fri, 30 Jun 2023 at 09:23, 0100101110101001010110 < @.***> wrote:

Closed #175 https://github.com/piccolomo/plotext/issues/175 as completed.

— Reply to this email directly, view it on GitHub https://github.com/piccolomo/plotext/issues/175#event-9685335684, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQQH6KNYEYKUZX6XKCXHVLXN2EH3ANCNFSM6AAAAAAZI7DCIA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

piccolomo commented 1 year ago

Hi @0100101110101001010110

sorry for late reply. Are you still interested? This would be a nice feature request (although not sure if I could pull this off). I reopen it. Any ideas welcomed.

All the best, Savino

0100101110101001010110 commented 1 year ago

I can offer ChatGPT's suggestions. :) I like my custom RGB value idea for its simplicity.

Adding mouse event awareness to elements in a Linux terminal plotting app involves using libraries or techniques that support capturing and handling mouse input. Here are various methods you can consider:

  1. Ncurses Library: Ncurses is a popular library for creating text-based user interfaces. It offers functions for handling mouse events within a terminal application.

  2. Curses-based Libraries with Mouse Support: Libraries like libtcod (for roguelike games) and pdcurses provide mouse event handling capabilities along with the standard curses functionality.

  3. Termbox: Termbox is a minimalistic library that simplifies terminal input and output. It supports mouse event handling and can be used to create simple terminal-based user interfaces.

  4. TUI Libraries: Libraries like tui-rs for Rust and urwid for Python provide higher-level abstractions for creating terminal user interfaces, including support for handling mouse events.

  5. Custom Mouse Event Handling: You can manually handle mouse events by reading input from the terminal and interpreting mouse control sequences, such as Xterm Mouse Tracking.

  6. Parsing ANSI Escape Codes: Some terminal emulators support mouse interaction through ANSI escape codes. You can parse these codes to detect mouse clicks and cursor movement.

  7. Terminal Emulator APIs: If your application is running inside a terminal emulator that supports mouse event forwarding, you might be able to use the terminal emulator's API to capture mouse events.

  8. Using a GUI Toolkit: Some GUI toolkits like GTK or Qt have terminal backends that can be used to create terminal-based applications with mouse event support.

  9. JavaScript-based Solutions: If your application runs in a browser-based terminal emulator (like xterm.js), you can use JavaScript to capture and handle mouse events.

  10. Interactive Shell Frameworks: For more complex interactions, you can use interactive shell frameworks like bash-it or fisherman to build command-line interfaces with mouse event support.

When implementing mouse event awareness in a terminal plotting app, consider the capabilities of the terminal emulator in use, as not all terminals support mouse interaction, and the level of support might vary. Choose the method that best fits your application's requirements and the programming language you are using.