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

does lets-plot support embeded in java and scala #267

Open
mullerhai opened this issue Dec 20, 2024 · 4 comments
Open

does lets-plot support embeded in java and scala #267

mullerhai opened this issue Dec 20, 2024 · 4 comments

Comments

@mullerhai
Copy link

lets-plot is very powerful, but I write scala code almost ,so I wanna know does lets-plot is support kotlin/scala mixed code project

@alshan
Copy link
Collaborator

alshan commented Dec 27, 2024

Hi, since both Kotlin and Scala run on the JVM and have good interoperability, you can, technically, use it in mixed projects.

However, some of Kotlin's DSL-style syntax will be lost in scale (like the "+" operator).
So a simple plot in Kotlin:

letsPlot(data) + geomPoint {
    x = "hwy"
    y = "cty"
    color = "make"
}

Becomes more verbose in Scala:

letsPlot(data).plus(new geomPoint(
  mapping = { mapping =>  // In Kotlin this would be a function with receiver: PointMapping.() -> Unit.
        // Not even sure Scala will pickup the receiver type form Kotlin's functional type with receiver.
    mapping.x = "hwy"      
    mapping.y = "cty"
    mapping.color = "make"
  }
))

@mullerhai
Copy link
Author

Hi, since both Kotlin and Scala run on the JVM and have good interoperability, you can, technically, use it in mixed projects.

However, some of Kotlin's DSL-style syntax will be lost in scale (like the "+" operator). So a simple plot in Kotlin:

letsPlot(data) + geomPoint {
    x = "hwy"
    y = "cty"
    color = "make"
}

Becomes more verbose in Scala:

letsPlot(data).plus(new geomPoint(
  mapping = { mapping =>  // In Kotlin this would be a function with receiver: PointMapping.() -> Unit.
        // Not even sure Scala will pickup the receiver type form Kotlin's functional type with receiver.
    mapping.x = "hwy"      
    mapping.y = "cty"
    mapping.color = "make"
  }
))

thanks ,if I use lets-plot in scala-sbt project, could you tell me which lets-plot module package dependencies should use ,because to many module

@alshan
Copy link
Collaborator

alshan commented Dec 28, 2024

You will need to add lets-plot-kotlin-jvm and lets-plot-batik dependencies as shown here: https://github.com/JetBrains/lets-plot-kotlin/blob/master/USAGE_BATIK_JFX_JS.md#jvm-swing-batik .

To get started, it might be a good idea to check out the lets-plot-mini-apps and try running a simple app here: https://github.com/alshan/lets-plot-mini-apps/blob/main/jvm-swing-batik-app/build.gradle.kts .

@mullerhai
Copy link
Author

You will need to add lets-plot-kotlin-jvm and lets-plot-batik dependencies as shown here: https://github.com/JetBrains/lets-plot-kotlin/blob/master/USAGE_BATIK_JFX_JS.md#jvm-swing-batik .

To get started, it might be a good idea to check out the lets-plot-mini-apps and try running a simple app here: https://github.com/alshan/lets-plot-mini-apps/blob/main/jvm-swing-batik-app/build.gradle.kts .

Ok ,Very thanks, I will try it

@alshan alshan transferred this issue from JetBrains/lets-plot Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants