SciProgCentre / plotly.kt

An interactive Kotlin wrapper for plotly visualization tools
https://sciprogcentre.github.io/plotly.kt/
Apache License 2.0
150 stars 21 forks source link

Text annotations #23

Closed weidenka closed 4 years ago

weidenka commented 4 years ago

Is it possible to add some text annotations to the plots? Probably similar to the following snippet:

  plt.plot(1, 8) {
        trace(trace)
        text { 
            x=0.4
            y=0.9
            text = "asdfsafdasfdasdf"
        }
        layout {
            title = plot_title
            xaxis { title = xlabel }
            yaxis { title = ylabel }
        }
    }
altavir commented 4 years ago

Hi, It is definitely possible. Plotly defines annotations in a layout section: https://plot.ly/javascript/text-and-annotations/#simple-annotation. Once we add builders for that, it is quite easy to add an extension to a plot builder. I will try to add it in a few days if there will be no problems with migration to new version of Kotlin and DataForge-core.

Plotly did not get a lot of love lately, but we plan a significant upgrade this summer by the way.

weidenka commented 4 years ago

Thank you so much! Great to hear that you are working on major upgrade.

altavir commented 4 years ago

I'll leave it open. I tried to implement the feature today, but encountered a problem with enums due to https://youtrack.jetbrains.com/issue/KT-37503. As soon as I think of something to do about it, I will implement the feature. Right now it could be done via unsupported feature (https://github.com/mipt-npm/plotly.kt/blob/master/examples/src/main/kotlin/unsupportedFeature.kt) but it is really cumbersome.

altavir commented 4 years ago

Implemented in 0.2.0-dev-1. The example is here: https://github.com/mipt-npm/plotly.kt/blob/dev/examples/src/main/kotlin/annotation/plotWithAnnotation.kt.

I will leave the issue until release. @weidenka please write if you need any specific customization.

weidenka commented 4 years ago

That looks perfekt! Thank you so much.