mind.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. define(function(require, exports, module) {
  2. var kity = require('../core/kity');
  3. var Layout = require('../core/layout');
  4. var Minder = require('../core/minder');
  5. Layout.register('mind', kity.createClass({
  6. base: Layout,
  7. doLayout: function(node, children) {
  8. var layout = this;
  9. var half = Math.ceil(node.children.length / 2);
  10. var right = [];
  11. var left = [];
  12. children.forEach(function(child) {
  13. if (child.getIndex() < half) right.push(child);
  14. else left.push(child);
  15. });
  16. var leftLayout = Minder.getLayoutInstance('left');
  17. var rightLayout = Minder.getLayoutInstance('right');
  18. leftLayout.doLayout(node, left);
  19. rightLayout.doLayout(node, right);
  20. var box = node.getContentBox();
  21. node.setVertexOut(new kity.Point(box.cx, box.cy));
  22. node.setLayoutVectorOut(new kity.Vector(0, 0));
  23. },
  24. getOrderHint: function(node) {
  25. var hint = [];
  26. var box = node.getLayoutBox();
  27. var offset = 5;
  28. hint.push({
  29. type: 'up',
  30. node: node,
  31. area: new kity.Box({
  32. x: box.x,
  33. y: box.top - node.getStyle('margin-top') - offset,
  34. width: box.width,
  35. height: node.getStyle('margin-top')
  36. }),
  37. path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
  38. });
  39. hint.push({
  40. type: 'down',
  41. node: node,
  42. area: new kity.Box({
  43. x: box.x,
  44. y: box.bottom + offset,
  45. width: box.width,
  46. height: node.getStyle('margin-bottom')
  47. }),
  48. path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
  49. });
  50. return hint;
  51. }
  52. }));
  53. });