Adding XML-Library with PlugIn to embedded mode

110 views
Skip to first unread message

Thiya

unread,
Mar 16, 2017, 7:03:45 AM3/16/17
to draw.io
Hey,

hope it is ok to ask this many questions, but you are such a big help and it seems i cant manage alone.

I try to load a library i created in the scratchpad of www.draw.io and exported it as xml in a plugin to my embedded draw.io.

I saw the example in plugins/p1.js and try to write something similar. But there are only images imported.
I saw in google+ community that it is possible to load an xml library in two ways. I tried both but i m not able to get it to work:
1)sidebar.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Title')

 For the first solution i tried it like this:

var myCell = new mxCell('http://192.168...../url/to/my/file.xml', new mxGeometry(0, 0, 120, 60), 'shape=component;align=left');
myCell.vertex = true;

ui.sidebar.addPalette('name', 'name',true,function(content){
    content.appendChild(ui.sidebar.createVertexTemplateFromCell([myCell],100,100);
});

But it doesn't load, so i think i created the myCell in the wrong way. I also tried to create the cell like this:
var doc = mxUtils.createXmlDocument();
var myCell = doc.createElement('xml')
myCell
.setAttribute('xml', 'http://192.168...../url/to/my/file.xml');

ui.sidebar.addPalette('name', 'name',true,function(content){
    content.appendChild(ui.sidebar.createVertexTemplateFromCell([myCell.getAttribute('xml')],100,100);
});


2) ui.sidebar.addPalette('name', 'name',true,function(content){
              mxUtils.get('http://192.168...../url/to/my/file.xml',function(req)
                {
                ui.sidebar.loadLibrary(new LocalLibrary(this, req.getText(), file.xml));
                });
});

But this one also doesn't work out this way. I tried also:

ui.sidebar.addStencilPalette('name', 'NAME','http://192.168...../url/to/my/file.xml');


But none of the solutions worked for me. Is one of them implemented in the right way and there is a mistake in my file.xml or do i have to do it in an other way?

I also tried to use the URL parameter clib=Uhttps%3A%2F%2F192.168....%2Furl%2Fto%2Fmy%2Ffile%2Ffile.xml but this didn't work either, and it is also not my preferred way to do it.

Thanks again for your amazing support. It really helps me a lot.

Best Thiya


Thiya

unread,
Mar 21, 2017, 5:33:32 AM3/21/17
to draw.io
Since I posted this question on Thursday i m trying to figure out what could be the reason why i dont get one of this options to work. Finally i found a solution.
I really have no idea what was going on, because i tried the final Solution too often and it never worked, but now it does.
So for everyone, who is struggeling with the same problem, this is the whole plugin:

Draw.loadPlugin(function(ui) {

var url = ''http://....../url/to/my/file.xml';
mxUtils.get(url, function(req){
          ui.loadLibrary(new LocalLibrary(this, req.getText(),url));
           });
});

file.xml is a Library i created via the scratchpad in online-draw.io and downloaded it.


Reply all
Reply to author
Forward
0 new messages