SciProgCentre / plotly.kt

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

Setting unsupported hierarchical value (rangebreaks.enabled) #79

Closed ValeryNo closed 2 years ago

ValeryNo commented 3 years ago

Hi!

Trying to disable range breaks for dates based x-axis to avoid display of weekends. Supposedly setting rangebreaks.enabled should do (https://plotly.com/javascript/reference/#layout-xaxis-rangebreaks)

How can I do that?

PS. I'm using set(...) for other unsupported properties, but not sure if it can be used for setting hierarchical values like this one.

altavir commented 3 years ago

Indeed you can. You can either use set with dot-separated names like set("rangebreaks.value", listOf(2.0,3.0) or you can use hierarchical meta builder like:

            xaxis {
                title = "x axis name"
                set(
                    "rangebreaks",
                    listOf(
                        Meta {
                            "bounds" put listOf(2.0, 3.0)
                        },
                        Meta {
                            "bounds" put listOf(3.5, 4.5)
                        }
                    )
                )
            }

In case of rangebreaks I can't produce the result. The generated json seems to be fine, but I do not see changes in the picture. Complete plotly json example would help.

altavir commented 3 years ago

I've also found a minor bug in multiple node treatment (#80), which leads to additional field building and no array wrappings for single-element arrays. It will be fixed in the next release.

ValeryNo commented 3 years ago

Thank you!

This worked to skip weekends:

                    layout {
                        xaxis {
                            set("rangebreaks",
                                listOf(
                                    Meta { "enabled" put false },
                                    Meta { "bounds" put listOf("sat", "mon") }
                                )
                            )
                        }
...
altavir commented 3 years ago

Nice. Feel free to open an issue for this feature (with Plotly json space you want to achieve) or even contribute the solution.

ValeryNo commented 2 years ago

With dataforge 0.4 > 0.5 this part doesn't work anymore.

                            listOf(
                                ....
                                Meta { "bounds" put listOf("sat", "mon") }
                            )

Problem being "bounds" put listOf..." Basically it doesn't accept lists. Any idea how to work this around in a current version?

Thank you in advance!

altavir commented 2 years ago

Yes, there was a breaking change. The typing is now more strict. You should use ListValue() instead of listOf() like it is done here: https://github.com/mipt-npm/plotly.kt/blob/19efcb7e88541542e72edc169d85c07bc51fbc8f/examples/src/main/kotlin/unsupportedFeature.kt#L36.

I will see to adding a local extension to Plotly so we can add lists of Any as before to avoid breaking compatibility. The problem is accepting Any gives a number of bizarre runtime type errors that we would like to avoid.

ValeryNo commented 2 years ago

Appreciate quick reply. The example given should work just fine!