Hi Pekka,
Thanks for creating this component it has been extremely useful to us.
A couple of comments, we had a minor snag with logging whereby when we added the Canvas POM into our SpringBoot project our application failed to start due to multiple log configurations and Spring having been given/selected slf4j-simple. This required an exclusion to be added to our POM but perhaps the log implementation should be removed from the Canvas POM? Also, for fun I experimented with enhancing the Canvas to support a click event, I have attached the relevant code snippets.
Paul
Hi Paul.
Thanks for the feedback!
It looks like the slf4j dependency should be test-scoped, so it doesn’t get included for users of the addon. This was changed in the project template after I have created my canvas project. I fixed this issue now (not released yet).
About click events: I can’t see your attachment (maybe a problem in this comment functionality).
Anyway, if you’d like to have that feature, feel free to open a pull request directly in GitHub and contribute to this open source project: https://github.com/pekam/vaadin-flow-canvas
(if you wish)
public class ClickEvent extends ComponentEvent<Heatmap> {
private static final long serialVersionUID = -7238174239206292297L;
// CHECKSTYLE:OFF encapsulate
public final int coordX;
public final int coordY;
// CHECKSTYLE:ON
public ClickEvent(Heatmap source, int coordX, int coordY) {
super(source, false);
this.coordX = coordX;
this.coordY = coordY;
}
}
/* Code for Canvas constructor */
{
getElement()
.addEventListener("click", eventListener())
.addEventData("event.pageX").addEventData("event.pageY").addEventData("element.offsetLeft").addEventData("element.offsetTop");
}
private DomEventListener eventListener() {
return e -> {
double pageX = e.getEventData().getNumber("event.pageX");
double pageY = e.getEventData().getNumber("event.pageY");
double offsetLeft = e.getEventData().getNumber("element.offsetLeft");
double offsetTop = e.getEventData().getNumber("element.offsetTop");
int coordX = convertX(pageX - offsetLeft);
int coordY = convertY(pageY - offsetTop);
fireEvent(new ClickEvent(Heatmap.this, coordX, coordY));
};
}
/**
* @param listener The ClickEvent listener
* @return The registration through which a listener may be removed
*/
public Registration addChangeListener(ComponentEventListener<ClickEvent> listener) {
return addListener(ClickEvent.class, listener);
}
18086439.txt (1.58 KB)
I think that implementing the ClickNotifier
interface provides all the same functionality (and more) out of the box with its default implementation. Thanks anyway! I try to add it at some point.