Skip to content

Add Image support #271

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

Closed

Conversation

novakov-alexey-zz
Copy link

No description provided.

@novakov-alexey-zz
Copy link
Author

@alexarchambault Documentation tests seem not relevant for Image Trace due to outdated documentation fork. plotly-scala would require to update documentation to the latest Plotly.js state. However, Image trace is working fine:

import plotly.element.HoverInfo
import plotly.element.HoverInfo._

val z = Seq(
    Seq(Seq(0, 33, 50), Seq(0, 66, 50), Seq(0, 100, 50)),
    Seq(Seq(90, 33, 50), Seq(90, 66, 50), Seq(90, 100, 50)),
    Seq(Seq(180, 33, 50), Seq(180, 66, 50), Seq(180, 100, 50)),
    Seq(Seq(270, 33, 50), Seq(270, 66, 50), Seq(270, 100, 50)))

Image(
    z = z,
    x0=Some(0.05),
    y0=Some(0.05),
    hoverinfo = Some(HoverInfo(X, Y, Z)),
    colormodel = Some("rgb")
).plot()

@alexarchambault
Copy link
Owner

alexarchambault commented Mar 12, 2021

@novakov-alexey Thanks for opening this! I'm about to update the documentation sub-module, I should open a PR for it, either later today or in the coming days. That should allow to add tests for this.

Just ping me if I forget to come back here once it's done.

@novakov-alexey-zz
Copy link
Author

Great, looking forward to that!

Copy link
Owner

@alexarchambault alexarchambault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only left some minor comments.

I also updated the documentation sub-module in master, feel free to rebase, and enable relevant tests for images.

.gitignore Outdated
@@ -1,2 +1,3 @@
target/
.bsp/
.idea
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be added in a separate commit, to make the git history cleaner?

README.md Outdated
```scala
import $ivy.`org.plotly-scala::plotly-almond:0.8.0`
import $ivy.`org.plotly-scala::plotly-almond:0.8.1`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, let's edit the README in a separate commit too.

@novakov-alexey-zz
Copy link
Author

There is a small problem that I do not know how to resolve on JSON encoding level.

If we want to support 3-channel and 4 channel color models like RGB and RGBA, we might need to model colors in z property as some case classes. For example:

abstract class ZColor with ....
Color3(c1: Int, c2: Int, c3: Int) extends ZColor
// note that last property is Double, all other are Ints
Color4(c1: Int, c2: Int, c3: Int, alpha: Double) extends ZColor 

I tried to implement it, but failed to render these case classes without class name in the resulting JSON string. Currently, Trace encoder renders every type by printing all nested property type names/keys. That breaks z property. Expected JavaScript format of z is z: [[ [123,123,123], [.....] ]]

Latets API I came up with:

import plotly.element.HoverInfo._
import plotly.element.ColorModel._
import plotly.element.Element._

val colors = Seq(
    Seq(Seq(0d, 33d, 50d), Seq(0d, 66, 50), Seq(0d, 100, 50)),
    Seq(Seq(90d, 33d, 50d), Seq(90d, 66, 50), Seq(90d, 100, 50)),
    Seq(Seq(180d, 33d, 50d), Seq(180d, 66, 50), Seq(180d, 100, 50)),
    Seq(Seq(270d, 33d, 50d), Seq(270d, 66, 50), Seq(270d, 100, 50)))

Image(z = colors)
  .withX0(0.05)
  .withY0(0.05)
  .withHoverinfo(HoverInfo(X, Y, Z, HoverInfo.Color))
  .withColormodel(RGB)
  .plot()

It works, but requires Double numbers for RGB, which is weird.

@novakov-alexey-zz
Copy link
Author

New PR is here: #274

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

Successfully merging this pull request may close these issues.

2 participants