hungtcs / mxgraph-type-definitions

mxgraph type definitions
https://www.npmjs.com/package/mxgraph-type-definitions
Apache License 2.0
20 stars 8 forks source link

Add support for more instance variables in mxGraph #13

Closed rajasaur closed 4 years ago

rajasaur commented 4 years ago

Hi, Thanks for creating the ts entries for mxGraph, Helps a lot with kickstarting an angular based project.

For some of my requirements, I need to customize things like popupMenuHandler etc, which seem to be created inside the createHandlers method which gets called as part of the constructor. So Im not able to use the createPopupMenuHandler or any of the other methods called inside createHandlers as all of them are called at constructor and there is no other way to override it.

If we instead add an instance variable like

    popupMenuHandler: mxPopupMenuHandler;

to mxGraph.d.ts, then we should be able to , say, use the popupHandler using the above variable. Right now, the other methods arent even called as they need to be defined at the time of constructing the mxGraph which doesnt seem possible.

Would you be open to taking patches for this ?

hungtcs commented 4 years ago

Hi @rajasaur ! Do you want to customize the popup menu? You can extends mxGraph and overwrite createPopupMenuHandler method, return a new instance of mxPopupMenuHandler with factory method, then use MyGraph instead of mxGraph in you project.

export class MyGraph extends mxGraph {
  public createPopupMenuHandler() {
    return new mxPopupMenuHandler(this, (handler: mxPopupMenuHandler, cell: mxCell, me: mxMouseEvent) => {
      if (cell) {
        handler.addItem('Delete Cell', null, () => {
          console.log('delete cell clicked!');
        });
      } else {

      }
    });
  }
}
hungtcs commented 4 years ago

@rajasaur Thank you very much for your feedback, I will add the missing types as soon as possible.

rajasaur commented 4 years ago

Thanks a lot for the workaround @hungtcs. I'll try and report back

hungtcs commented 4 years ago

Hi @rajasaur, fixed in 6680ea19ff4e3780633e107d7c9b995574bda1bd b38fc360a54c348c78f8189b45a6be426832996a

rajasaur commented 4 years ago

Thanks a lot for the quick turnaround on this. Super work will help us a lot.