Kotlin / kandy

Kotlin plotting library.
https://kotlin.github.io/kandy/
Apache License 2.0
535 stars 11 forks source link

Swing app example ? #272

Open bric3 opened 6 months ago

bric3 commented 6 months ago

In the annoucement https://blog.jetbrains.com/kotlin/2023/12/kandy-the-new-kotlin-plotting-library-by-jetbrains/ there is written

Charts are rendered directly in the notebook cell outputs using Swing, and they are interactive

I understand this is limited to the proprietary kotlin notebook plugin, but is it possible to have an example with a simple Swing application.

AndreiKingsley commented 6 months ago

Hello! At the moment we don't have direct support for Swing. However, you can use Kandy plot in Swing in two ways 1) Simple but less efficient - you can create a BufferedImage (using this function) and add it to Swing. But image is raster and there's no interactions with plot (i.e. tooltips) 2) Convert Kandy Plot to Lets-Plot Plot and then use it in Swing, see https://github.com/JetBrains/lets-plot-kotlin/blob/master/USAGE_BATIK_JFX_JS.md.

bric3 commented 6 months ago

OK I'll give it a try. Thanks for the feedback.

I remember mentions of tooltips (and maybe some sort interactivity with the graph), do you know if let's plot support that ?

AndreiKingsley commented 6 months ago

You mean in Swing? Yes!

AndreiKingsley commented 6 months ago

Created a small example with Swing based on Lets-plot Swing example https://github.com/AndreiKingsley/kandy-swing-app-example

bric3 commented 6 months ago

@AndreiKingsley Thank you, it is very interesting. This should definitely be in the examples !

I'll need to check what can be accessed from a mouse event, i.e. if a data point like the hovered bar or the (x;y) can be accessed.