-
Notifications
You must be signed in to change notification settings - Fork 336
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
feat: Display image in a graphics_card #1817 #2373
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,19 @@ interface State { | |
* (Not the height of its coordinate system.) | ||
*/ | ||
height?: S | ||
/** | ||
* The path or URL or data URL of the background image, | ||
* e.g. `/foo.png` or `http://example.com/foo.png` or `data:image/png;base64,???`. | ||
*/ | ||
path?: S | ||
/** Background image data, base64-encoded. */ | ||
image?: S | ||
/** | ||
* The background image MIME subtype. One of `apng`, `bmp`, `gif`, `x-icon`, `jpeg`, `png`, `webp`. | ||
* Required only if `image` is set. | ||
*/ | ||
type?: S | ||
|
||
} | ||
|
||
const | ||
|
@@ -169,18 +182,27 @@ export const | |
}, | ||
render = () => { | ||
const | ||
{ view_box, width, height, stage, scene } = state, | ||
{ view_box, width, height, stage, scene, type, image, path } = state, | ||
stageEls = stage ? unpack<Recs>(stage).map(renderEl) : [], | ||
sceneEls = scene ? unpack<El[]>(scene).map(({ d, o }, i) => renderEl({ | ||
...(d ? JSON.parse(d) : {}), | ||
...(o ? JSON.parse(o) : {}), | ||
}, i)) : [] | ||
}, i)) : [], | ||
backgroundImageSrc = path | ||
? 'url('+path+')' | ||
: image ? `url(data:image/${type};base64,${image})` | ||
: undefined | ||
|
||
return ( | ||
<div data-test={name} className={css.card}> | ||
<svg viewBox={view_box} width={width} height={height}> | ||
<g>{stageEls}</g> | ||
<g>{sceneEls}</g> | ||
</svg> | ||
<div style={{ backgroundImage: `${backgroundImageSrc ? backgroundImageSrc : undefined}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this wrapper necessary? Wouldn't just adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mturoci, that was my original idea too. But the problem is that the existing I tried various things to adjust the styling of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I think the offset is fine though because even though the image in your current implementation would take up the whole card, the outer 15px wouldn't be reachable by graphics render, if I understood it correctly, which would be a problem especially when a user would want to highlight a certain part of the image with a rectangle for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @mturoci. So just to be clear, you are saying to remove the new parent div and instead put the background image on the existing div, which is defined with the 15px offset - right? This means the background image will not cover the entire card, as you can see in this screen shot. Please confirm that I'm understanding correctly. Thanks!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mturoci I made the changes as suggested. Removed the parent div and added the background-image stuff to the existing div. Here's a screen shot of the custom example I've been using: |
||
backgroundSize: `${backgroundImageSrc ? 'cover' : undefined}`, | ||
}}> | ||
<div data-test={name} className={css.card}> | ||
<svg viewBox={view_box} width={width} height={height}> | ||
<g>{stageEls}</g> | ||
<g>{sceneEls}</g> | ||
</svg> | ||
</div> | ||
</div> | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's replace this unit test with an entry in widgets section. The best place would probably be Widgets > Plots > Graphics or Widgets > Plots > AI (whatever makes more sense to you) and include 2 variations, a simple graphic and a simple graphic with a background image. That way, our documentation will be better and this functionality will be picked up by our visual regression testing suite.
Feel free to reach out in case you need help with any of the above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mturoci, question for you about this. Would it be better to add this to Guide > Graphics instead since that page already explains the
ui.graphics_card
? I could add a new section at the bottom to explain the new background image feature. That seems like a more logical place than Widgets > Plots, but maybe I'm overlooking something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guide > Graphics isn't picked up by visual regression testing suite + is more of a docs on how to work with graphics rather than how to display a widget and all its variations. The widget page should definitely have a link to the graphics guide though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mturoci, As requested, I removed the new test. For the documentation, I decided to add the new Graphics section at Widgets > Content > Graphics, just after the section for Image. The graphics stuff didn't seem to fit with the other information under Widgets > Plots, but it seemed to go well with the information under Widgets > Content. Let me know if you disagree and I can move it to wherever you prefer. I built the documentation and here's a short video showing the new page:
issue1817_doc-widget.mov