Kotlin / kandy

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

add plot modification after declaration and initialization #219

Open devcrocod opened 1 year ago

devcrocod commented 1 year ago

I want to save my plot to a variable, and then add or change some parameters.

For example, I have a plot and I want to use it with different flavours

Right now, my code looks like this:

val myPlot = plot {
            line {
                x(listOf(1, 2, 3))
                y(listOf(5, 3, 1))
            }
        }

(plot.features as MutableMap)[FeatureName("layout")] = Layout(flavor = Flavor.DARCULA)
plot.save(...)

(plot.features as MutableMap)[FeatureName("layout")] = Layout(flavor = Flavor.HIGH_CONTRAST_LIGHT)
plot.save(...)
AndreiKingsley commented 1 year ago
fun myPlotWithFlavor(flavor: Flavor): Plot {
   plot {
      ....
      layout.flavor = flavor
   }
}

val plots = flavors.map { myPlotWithFlavor(it) }

devcrocod commented 1 year ago

This creates several plots

My request is specifically about changing the current one. I understand that it's necessary to limit changes to data and possibly existing layers

devcrocod commented 10 months ago

@AndreiKingsley can you describe about the design of the decision?

AndreiKingsley commented 10 months ago

Current design: Add Plot.configure {} extension, that allows to add new layers and modify the layout.