Can we add a custom tooltip (content from a component) for a node in Diagram

Hi Syncfusion Team,

I have a question.

I want to display a custom tooltip when click a node in diagram. That tooltip has content from a component. Maybe it just likes when we hover a point in chart, and a tooltip is displayed, but it only has some simple information.

For example, I've created a basic project.

https://stackblitz.com/edit/angular-11-new-swasxd?file=src%2Fapp%2Fapp.component.ts

In this project, what I want is that: when we click a node, the right side bar is displayed as a tooltip (or maybe like a dialog) and that tooltip look exactly the right side bar in the right of that page. That tooltip will give some useful information to user about the node we've clicked; and its position will be flexible, I mean most of the time, it will be on the right of that node, but if the node is too close to the right of the page, the tooltip will be on the left.
And don't forget to add the arrow icon. The position of this icon is flexible too, just like its behaviour in tooltip.Image_9357_1700063002778
Tell me if you need any further information.

Kind Regards,

Nguyen


8 Replies

VG Vivisa Ganesan Syncfusion Team November 16, 2023 03:38 PM UTC

Hi,

We have created the sample as per your requirement. We have bind the syncfusion tooltip component to render the tooltip on the click event. Refer the below sample.

Sample:

https://stackblitz.com/edit/angular-wfvzqu-kyiwgy?file=src%2Fapp.component.html,src%2Fapp.component.ts


Regards,

Vivisa




NH nguyen hoang phuong November 16, 2023 04:14 PM UTC

Hi,

Maybe you misunderstood my requirement.

In my example project with the link above, what I want is that when I click a node, a tooltip appears with the content of the right-side-bar component.

What I have done in my real project is that, I created a dialog (with the same content from the right-side-bar component) and set its position due to the node position. And when I click a node, that dialog is displayed. But this is not an ideal implementation, because we have to set some static value to the dialog's position; and it just works fine with some nodes; and with some other nodes, it looks a little bit weird.

As you can see in the image, the dialog is displayed next to the node, just like a tooltip, but it's not a tooltip, because I used the DialogComponent for it.

Do you have any perfect idea for this?


Kind Regards,

Nguyen



NH nguyen hoang phuong replied to Vivisa Ganesan November 17, 2023 08:52 AM UTC

Hi,

I can give you a short video about what I've done. Sorry for blurring the video because it contains sensitive information.

Like I said before, I don't use the TooltipComponent because I canot bind a component to the tooltip's content. I created a dialog and set its position according to node's position. 

this.openDialog.emit({

          positionX: node.offsetX,

          positionY: node.offsetY,

        });

and in the dialog component:

public open(event: any): void {

    this.position = {

      X: event.positionX + 200 + 160,

      Y: event.positionY

    };

    this.dialog.show();

    this.arrowRef.nativeElement.style.display = 'block';

  }

This's not an ideal implementation. Because we have to hard code for the position of that dialog (+200 + 160); and if the node is close to the right of the page (for example: offsetX > 900), I have to set the positionX again so that the dialog can be displayed on the right of the node (like in the video). I think there are many cases that I cannot control enough. And I also created a div to draw a arrow icon:

<div #arrowRef class="triangle-arrow"></div>


what I want is like this: Image_6373_1700211093784

but sometimes, it looks weird:Image_7801_1700211093784               Image_4879_1700211093784                                 Image_7218_1700211093784

This is only a temporary solution. 

I hope you can understand my requirement and reply soon.

Regards,

Nguyen


Attachment: demo_8e410855.rar


VG Vivisa Ganesan Syncfusion Team November 17, 2023 02:45 PM UTC

Hi,

We have created the sample in which we have render the dialog on clicking the node. Refer the below code-snippet and sample:


onClickEvent(event: MouseEvent) {

    let dialog = document.getElementById('dialog');

    if (this.diagram.selectedItems.nodes && this.diagram.selectedItems.nodes.length > 0) {

      var diagram = (document.getElementById('diagram') as any) .ej2_instances[0];

      let node = this.diagram.selectedItems.nodes[0];

      let Targetnode = document .getElementById(node.id + '_groupElement') .getBoundingClientRect();

      dialog.style.left = Targetnode.left + 'px';

      dialog.style.top =

        Targetnode.top - this.diagram.selectedItems.nodes[0].height + 'px';

      this.dialog.visible = true;

    } else {

      this.dialog.visible = false;

    }

  }

 


Sample:https://stackblitz.com/edit/angular-wfvzqu-yfvaur?file=src%2Fapp.component.html,src%2Fapp.component.ts

Regards,

Vivisa



NH nguyen hoang phuong replied to Vivisa Ganesan November 19, 2023 02:47 PM UTC

Hi,

There are 2 points from your sample:

1. I want the dialog to be displayed to the right of the node; And when it is too close to the right margin of the diagram and does not display all the content, the dialog will be displayed to the left of the node. And if it's too close to the top margin of the diagram and might be missing content, I want it to automatically be displayed a little lower so that the dialog's content is fully visible.

2. Maybe you forgot the arrow icon that is displayed between the node and the dialog. It is necessary for showing the relationship between  the node and the dialog.

I hope to hear from you soon.

Regards,

Nguyen



VG Vivisa Ganesan Syncfusion Team November 20, 2023 04:31 PM UTC

Hi

We don't have collision option in dialog component and the tip pointer is not available for dialog control. You can render HTML elements with the tooltip using template option and tip pointer is available for tooltip control. So, you can use tooltip control to achieve your requirement.


Sample:https://stackblitz.com/edit/angular-ruv7j2-qumnz5?file=app.component.ts,app.component.html

Regards,

Vivisa



NH nguyen hoang phuong November 21, 2023 07:22 AM UTC

Hi,


Thank you for all your assistance. With your suggestion about using " getBoundingClientRect", I can use it for my  requirement. From now, I can handle it by myself.


Regards,
Nguyen



PR Preethi Rajakandham Syncfusion Team November 22, 2023 06:23 AM UTC

Hi Nguyen,

Thank you for the update. 

Please let us know if you require any further assistance on this, we will be happy to assist you. 

Regards,

Preethi R


Loader.
Up arrow icon