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
[WIP] Imagemap #2739
base: main
Are you sure you want to change the base?
[WIP] Imagemap #2739
Conversation
Do we really want to add this kind of APIs to the |
Ok @martinRenou. I'm working on a MappedImage now, with a completely different approach, using |
Why not adding click events to the |
Yes, we could do that too. |
I feel like this kind of custom logic could be easily implemented, in Python, once the Image has click events with click coordinates. We might not want to add this to ipywidgets core though. |
@martinRenou Do you think the method |
The idea of using |
Oh sorry! I did not know about this |
The |
Yes, I've written a |
I feel like introducing a new widget for mapped images is not needed, because a And expanding the interactivity on the |
ipywidgets/widgets/widget_media.py
Outdated
self.name = name | ||
self.shape = shape | ||
self.coords = coords # a tuple of integers | ||
self.href = href |
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.
Those attributes could be traits
? Allowing to validate/observe/link values.
ipywidgets/widgets/widget_media.py
Outdated
self.name = name | ||
self.shape = shape | ||
self.coords = coords # a tuple of integers | ||
self.href = href |
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.
I wonder if href
is what we need, maybe an on_click
event would be easier to play with for users in Python?
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.
Similar to the Button API
ipywidgets/widgets/widget_media.py
Outdated
_view_name = Unicode('MappedImageView').tag(sync=True) | ||
_model_name = Unicode('MappedImageModel').tag(sync=True) | ||
|
||
map_name = Unicode("Map", help="The map name").tag(sync=True) |
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.
I wonder if the map_name
should be exposed to the user, as far as I understand this is an implementation detail and does not bring anything to the Python API.
Maybe we should set the map name to a random uuid? And not expose it to Python?
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.
Thanks @martinRenou
Yes, traits.
Yes, why not not expose map_name.
At the moment, I experience some difficulties in displaying the map areas. I could possible create a new HTMLElement widget, that would be like HTML, without its surrounding <div>
. Don't you think such an element would bring some flexibility?
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.
I am not sure I understand what you are saying.
But looking at the code I understand the ImageView
implementation should be changed in order for this to work, this.el
should be an HTMLDivElement
instead of an HTMLImageElement
. And it would contain the HTMLImageElement
and the HTMLMapElement
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.
I hesitate.
I guess having an <img>
without <div>
is there for a reason, in Image widget.
But I would like to use this HTMLElement
to create and display the map areas, and then the map itself.
Maybe such a strategy is too complicated. I want to test these things anyway, but if you tell me such an HTMLElement
(with arbitraty tag name, not necessarily 'div') would be useful / or not useful, that will help guiding my efforts anyway.
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.
I am not talking about a new HTMLElement
widget. I am talking about the html tags.
I was suggesting doing:
<div>
<img src="...">
<map>
<area ...>
<area ...>
</map>
</div>
instead of the current:
<img src="...">
In the Image
widget
ipywidgets/widgets/widget_string.py
Outdated
@@ -40,6 +40,19 @@ class HTML(_String): | |||
_view_name = Unicode('HTMLView').tag(sync=True) | |||
_model_name = Unicode('HTMLModel').tag(sync=True) | |||
|
|||
|
|||
@register | |||
class HTMLElement(_String): |
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.
I was not speaking about a new widget... I was speaking about https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement, or https://developer.mozilla.org/en-US/docs/Web/API/HTMLDivElement.
I made a new version, with no new widget in |
Returning the clicks also from an Image.
Passing click coordinates to the backend. For now, just for
Button
s.