freegroup / draw2d

Create Visio like drawings, diagrams or workflows with JavaScript and HTML5
https://freegroup.github.io/draw2d/#/examples
MIT License
738 stars 227 forks source link

can't marshal ports data from json. #159

Closed ThreeLambs closed 3 years ago

ThreeLambs commented 3 years ago
 var topPortLocator = draw2d.layout.locator.PortLocator.extend({
     init: function() {
         this._super();
     },
     relocate: function(index, figure) {
         var p = figure.getParent();
         this.applyConsiderRotation(figure, p.getWidth() / 2, 0);
     }
 });
...

var myfigure = draw2d.shape.basic.Rectangle.extend({
     NAME: "myfigure",
     init: function(attr, setter, getter) { 
         this._super(extend({ bgColor: _nodeColor, color: _nodeColor, width: 100, height: 40, radius: 5 }, attr), setter, getter); 

         this.createPort("hybrid", new topPortLocator());
         this.createPort("hybrid", new bottomPortLocator());
         this.createPort("hybrid", new leftPortLocator());
         this.createPort("hybrid", new rightPortLocator());

         this.label = new draw2d.shape.basic.Label({ text: "text", color: _nodeColor, fontColor: "#fff" }); 
         this.add(this.label, new draw2d.layout.locator.CenterLocator());
       }
}

 var reader = new draw2d.io.json.Reader();
     reader.unmarshal(canvas, json);
Error: <ellipse> attribute cx: Expected length, "NaN".

it can't marshal ports data from json. when i delete ports data , is ok.

shaffee commented 3 years ago

I'have exact same problem, Any suggestion or solution ?

ThreeLambs commented 3 years ago

I'have exact same problem, Any suggestion or solution ?

add NAME property

  NAME: "draw2d.layout.locator.MyTopLocator",
shaffee commented 3 years ago

It's not resolving the problem.

ThreeLambs commented 3 years ago

It's not resolving the problem.

?? you can also use system built-in locator instead of custom ports.

         this.createPort("hybrid", new draw2d.layout.locator.TopLocator());
         this.createPort("hybrid", new draw2d.layout.locator.BottomLocator());
         this.createPort("hybrid", new draw2d.layout.locator.LeftLocator());
         this.createPort("hybrid", new draw2d.layout.locator.RightLocator());