JetBrains / lets-plot-kotlin

Grammar of Graphics for Kotlin
https://lets-plot.org/kotlin/
MIT License
430 stars 36 forks source link

Kotlin/JS support? #66

Closed sureshg closed 2 years ago

sureshg commented 3 years ago

Are there any plans to make this library multiplatform, so that it can be used in Kotlin/JS based web applications?

alshan commented 3 years ago

We were not planning that. So far the use-case in mind was that most of the data wrangling is done on (JVM) backend and only the rendering is done by webapps frontend. So the Lets-Plot kotlin API is only available for JVM apps. Would you wish to use this API to build plots in the client entirely?

sureshg commented 3 years ago

Would you wish to use this API to build plots in the client entirely?

Yes, using it as a plot/charting library (because it's 100% kotlin) for a kotlin/js application.

alshan commented 3 years ago

Good proposal.

alshan commented 3 years ago

Pls, take a look: https://github.com/JetBrains/lets-plot-kotlin/discussions/73

sureshg commented 3 years ago

@alshan Awesome..will check it.

alshan commented 3 years ago

Kotlin/JS support added in v3.0.0.

sureshg commented 3 years ago

@alshan I am getting following error on the latest release. Any hint on what's wrong here?

* What went wrong:
Could not determine the dependencies of task ':packageJson'.
> Could not resolve all dependencies for configuration ':npm'.
   > Could not resolve org.jetbrains.lets-plot:lets-plot-kotlin-js:3.0.1.
     Required by:
         project :
      > No matching variant of org.jetbrains.lets-plot:lets-plot-kotlin-js:3.0.1 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
          - Variant 'jsApiElements-published' capability org.jetbrains.lets-plot:lets-plot-kotlin-js:3.0.1 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.js.compiler' with value 'legacy' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir'
          - Variant 'jsRuntimeElements-published' capability org.jetbrains.lets-plot:lets-plot-kotlin-js:3.0.1 declares a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.js.compiler' with value 'legacy' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir'
          - Variant 'metadataApiElements-published' capability org.jetbrains.lets-plot:lets-plot-kotlin-js:3.0.1:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
              - Other compatible attribute:
                  - Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
plugins {
    kotlin("js") version "1.5.20"
    kotlin("plugin.serialization") version "1.5.20"
}

kotlin {
    js(IR) {
        browser {
            distribution {
                directory = File("$projectDir/docs")
            }

            commonWebpackConfig {
                cssSupport.enabled = true
                outputFileName = "app.js"
            }

            testTask {
                useKarma {
                    useChromeHeadless()
                }
            }
        }
        binaries.executable()
        compilations.all { kotlinOptions {} }
    }
}
...

dependencies {
   ...
   implementation("org.jetbrains.lets-plot:lets-plot-kotlin-js:3.0.1")
}
alshan commented 3 years ago

Hi @sureshg , turned out that Lets-plot library v3.0.1 is not compatible with new Kotlin/JS compiler IR backend.

We will migrate to IR in the next release. Meanwhile, the only option it seems is to use the legacy (default) compiler backend.

sureshg commented 3 years ago

@alshan Thanks, will wait for the next IR release then.

alshan commented 3 years ago

Update: in v3.0.2 we haven't manage to generate Kotlin/JS IR artifacts due to one issue (at least): KJS / IR: "NullPointerException: Parameter specified as non-null is null".

It seems like this issue affects not only Kotlin v1.5.21 but v1.5.30-M1 as well.

alshan commented 2 years ago

Hi @sureshg , it took a while, Kotlin/JS IR compiler is finally supported in v3.1.0

Here is an example of a simple Kotlin/JS IR app.