Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram not working properly, according to example #70

Closed
lobis opened this issue Mar 24, 2021 · 5 comments
Closed

Histogram not working properly, according to example #70

lobis opened this issue Mar 24, 2021 · 5 comments
Labels
bug Something isn't working fixed in dev Fixed in development version

Comments

@lobis
Copy link

lobis commented Mar 24, 2021

I believe there is an issue with the histogram examples (or perhaps with histograms itself). I have created a simple js histogram rendering using https://github.com/mipt-npm/plotly.kt/blob/master/examples/src/main/kotlin/histogram/BasicHistogram.kt as a reference. The code is the following: (version 0.3.1)

    document.addEventListener("DOMContentLoaded", {
        val element = document.getElementById("test") as? HTMLElement
            ?: error("Element with id 'test' not found on page")

        console.log("element loaded")

        val rnd = Random
        val values = List(500) { rnd.nextDouble() }

        element.plot {

            histogram {
                x.numbers = values
                name = "Random data"
            }

            layout {
                bargap = 0.1
                title {
                    text = "Basic Histogram"
                    font {
                        size = 20
                        color("black")
                    }
                }
                xaxis {
                    title {
                        text = "Value"
                        font {
                            size = 16
                        }
                    }
                }
                yaxis {
                    title {
                        text = "Count"
                        font {
                            size = 16
                        }
                    }
                }
            }
        }
    })

I believe this should produce a good looking histogram however what is produced is the following:

image

Also there is another issue in the examples, the usage of Random, which according to the documentation (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.random/-random/) should be called like Random.nextDouble() instead of Random().nextDouble() as it is written in the examples.

@altavir
Copy link
Member

altavir commented Mar 24, 2021

Thanks, I've reproduced it on JS (works perfectly fine on the JVM). For some reason, it ignores the trace type parameter when used directly from JS.

The Random is not the issue. Random() function creates a new generator with a random seed whereas Random singleton (companion object) represents the default generator that is created on start. In this context, there is no difference.

@lobis
Copy link
Author

lobis commented Mar 24, 2021

Thanks, I've reproduced it on JS (works perfectly fine on the JVM). For some reason, it ignores the trace type parameter when used directly from JS.

The Random is not the issue. Random() function creates a new generator with a random seed whereas Random singleton (companion object) represents the default generator that is created on start. In this context, there is no difference.

For some reason I couldn't get the Random() to work on my plot, I had to change it to Random as you see on the code in order to work. Probably some issue with dependencies on my side. (I imported import kotlin.random.Random to access Random).

@altavir
Copy link
Member

altavir commented Mar 24, 2021

Just for educational purposes. The problem is that I used the direct dynamic conversion of Kotlon structures to Json and the enum class is converted into structure instead of value. Like this:
image
I will fix that shortly.

@altavir
Copy link
Member

altavir commented Mar 24, 2021

Fixed and will be available in 0.4.0

@lobis lobis closed this as completed Mar 24, 2021
@altavir
Copy link
Member

altavir commented Mar 24, 2021

No, we need to migrate to a new version because there are some breaking changes and the package version change (kscience->space.kscience). I've published the 0.4.0-dev-2 to the dev repository. So you can use right now via

reposirories{
  maven("https://repo.kotlin.link")
}

depdendencies{
  implementation("space.kscience:plotlykt-core:0.4.0-dev-2")
}

There are breaking changes in package names, so be sure to check examples in dev branch.

@altavir altavir mentioned this issue Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in dev Fixed in development version
Projects
None yet
Development

No branches or pull requests

2 participants