angular/joint integration

example of how to update a joint shape using angular

HTML

<link rel="stylesheet" href="http://jointjs.com/css/style.css" />
<link rel="stylesheet" href="http://jointjs.com/css/joint.css" />        
<script src="http://jointjs.com/js/joint.js"></script>
<div ng-app>
  <div ng-controller="MyCtrl">
    <div id="paper"/>
    <div>
      <label>Type here:</label>
      <input type="text" ng-model="element.name"  />
    </div>
  </div>
</div>

JavaScript

function MyCtrl($scope) {

  //there is a problem with jointjs in the latest version of Chrome. This fixes it
  SVGElement.prototype.getTransformToElement = 
    SVGElement.prototype.getTransformToElement || function(toElement) {
    return toElement.getScreenCTM().inverse().multiply(this.getScreenCTM());
  };

  var graph = new joint.dia.Graph;
  var paper = new joint.dia.Paper({
      el: $('#paper'),
      width: 400,
      height: 400,
      model: graph,
      gridSize: 1,
      interactive: false
  });

  var element = new joint.shapes.basic.Rect({
      position: {x:100, y:30},
      attrs: {text: {text: 'edit my name'}},
      size: { height: 92.7051, width: 150}
  });

	$scope.element = element;

  graph.addCell(element);

  Object.defineProperty(joint.shapes.basic.Rect.prototype, 'name', {
      get: function () { return this.attr('text/text'); },
      set: function (value) { this.attr('text/text', value); }
  });

}