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

Add API for background images #49

Open
Omnieboer opened this issue Sep 14, 2020 · 4 comments
Open

Add API for background images #49

Omnieboer opened this issue Sep 14, 2020 · 4 comments
Labels
feature New feature or request
Milestone

Comments

@Omnieboer
Copy link
Contributor

As in this plotly behaviour.

This would be greatly helpful, as I can see no other way at the moment to display a map behind a set of coordinates. If there is such a method in PlotlyKt, please tell me and feel free to close the issue.

Thank you.

@altavir
Copy link
Member

altavir commented Sep 14, 2020

Hi, @Omnieboer we did not add this feature because we believed it is rarely used. We will add it in the future (reference API page: https://plotly.com/javascript/images/). Meanwhile, you do not have to wait for it. You can use our "unsupported feature" feature and add a block, describing the image model directly.

Here is a working the code sample:

Plotly.plot {
    trace{
        x(1,2,3)
        y(1,2,3)
    }
    layout{
        config["images"] = listOf(
            Meta{
                "source" put "https://images.plot.ly/language-icons/api-home/python-logo.png"
                "xref" put "paper"
                "yref" put "paper"
                "x" put 0
                "y" put 1
                "sizex" put 0.2
                "sizey" put 0.2
                "xanchor" put "right"
                "yanchor" put "bottom"
            },
            Meta{
                "source" put "https://images.plot.ly/language-icons/api-home/js-logo.png"
                "xref" put "x"
                "yref" put "y"
                "x" put 1.5
                "y" put 2
                "sizex" put 1
                "sizey" put 1
                "xanchor" put "right"
                "yanchor" put "bottom"
            }
        )
    }
}

And here is the result:
newplot

You have to enter at least two elements, otherwise, the block is reduced to a single element and is not recognized by Plotly. If you need only one image, you can use Meta.EMPTY as second.

@Omnieboer
Copy link
Contributor Author

Thanks very much! I love the addition of a unsupported feature feature :D
Is there a way to make this work with local images, or would I have to host the wanted image such that a url can reach it?

Thanks for adding the image feature on the todo list!

@altavir
Copy link
Member

altavir commented Sep 14, 2020

It depends on where do you host the image. The image is not uploaded, so it must be accessible in the environment, where you plot your image. Local files should be OK for file plots. For a notebook, I am not sure, they could be blocked by browser security, but you can try.

@Omnieboer
Copy link
Contributor Author

For future reference, for a local file this works.

I ended up encoding the local image to Base64 like this:

"source" put "data:image/png;base64,${
Base64.getEncoder().encodeToString(File("src/main/resources/BigMap.PNG").readBytes())                                        
}"

Any other way didn't seem to load the image from an offline source.

@SPC-code SPC-code added this to the 0.5.3 milestone Mar 31, 2023
@SPC-code SPC-code mentioned this issue Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants