Skip to content

Feature: Plot layout images #520

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
wants to merge 10 commits into from
Closed

Feature: Plot layout images #520

wants to merge 10 commits into from

Conversation

mdtusz
Copy link
Contributor

@mdtusz mdtusz commented May 9, 2016

This PR adds the ability to add arbitrary images loaded from a url to a plot. Plot layout images follow a similar interface to shapes, but use a coordinate position with width and height rather than x0, x1, y0, y1. Additionally, there are three sizing modes - contain (the default), fill, and stretch.

The intended use of this feature is mainly for logos and non-data-specific images - for image data that is tied directly to data (e.g. satellite imagery) we should/will add a new trace type to accommodate for this and enable features such as toggling from the legend and ordering.

That said, images can be added to the plot area and be forced to keep their binding to the underlying cartesian plane by setting the xref and yref to their respective axes and setting the sizing property to stretch.

@mdtusz
Copy link
Contributor Author

mdtusz commented May 9, 2016

There is a fair bit of code to this PR, but the commits follow a logical progression, so that's probably the best way to review through it.



var containerIn = Array.isArray(layoutIn.images) ?
layoutIn.images : [layoutIn.images],
Copy link
Contributor

Choose a reason for hiding this comment

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

layout.images should only be coerced if it is an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok. I figured as a convenience we could accept a single object.

Strict is good though 👍

source: {
valType: 'string',
role: 'info',
description: [
Copy link
Contributor

@etpinard etpinard May 9, 2016

Choose a reason for hiding this comment

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

so, nothing is blocking users from inputting data:image/svg+xml;base6 as source ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep works fine!

I'm not 100% sure if there's a possibility for XSS here (or if it should be something that we worry about in plotly.js) but I couldn't manage to break anything or set any code to be executed - maybe I'm just not a good enough h4X0r though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool.

Yes, we don't worry about XSS (see PR #100).

Copy link
Contributor

@etpinard etpinard May 9, 2016

Choose a reason for hiding this comment

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

Maybe we should make things more convenient for folks wanting to use base64 strings.

Maybe we could add a sourcetype attribute with possible values 'link', 'png' or even 'svg'?

Copy link
Member

Choose a reason for hiding this comment

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

Personally I like that we use the same spec as HTML img src. Makes it easy to document, explain, and extend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants