tianpan.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @fileOverview
  3. *
  4. * 天盘模板
  5. *
  6. * @author: along
  7. * @copyright: bpd729@163.com, 2015
  8. */
  9. define(function(require, exports, module) {
  10. var kity = require('../core/kity');
  11. var Layout = require('../core/layout');
  12. var Minder = require('../core/minder');
  13. Layout.register('tianpan', kity.createClass({
  14. base: Layout,
  15. doLayout: function (parent, children) {
  16. if (children.length == 0) return;
  17. var layout = this;
  18. var pbox = parent.getContentBox();
  19. var x, y,box;
  20. var _theta = 5;
  21. var _r = Math.max(pbox.width, 50);
  22. children.forEach(function (child, index) {
  23. child.setLayoutTransform(new kity.Matrix());
  24. box = layout.getTreeBox(child);
  25. _r = Math.max(Math.max(box.width, box.height), _r);
  26. })
  27. _r = _r / 1.5 / Math.PI;
  28. children.forEach(function (child, index) {
  29. x = _r * (Math.cos(_theta) + Math.sin(_theta) * _theta);
  30. y = _r * (Math.sin(_theta) - Math.cos(_theta) * _theta);
  31. _theta += (0.9 - index * 0.02);
  32. child.setLayoutVectorIn(new kity.Vector(1, 0));
  33. child.setVertexIn(new kity.Point(pbox.cx, pbox.cy));
  34. child.setLayoutTransform(new kity.Matrix());
  35. layout.move([child], x, y);
  36. });
  37. },
  38. getOrderHint: function (node) {
  39. var hint = [];
  40. var box = node.getLayoutBox();
  41. var offset = 5;
  42. hint.push({
  43. type: 'up',
  44. node: node,
  45. area: {
  46. x: box.x,
  47. y: box.top - node.getStyle('margin-top') - offset,
  48. width: box.width,
  49. height: node.getStyle('margin-top')
  50. },
  51. path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
  52. });
  53. hint.push({
  54. type: 'down',
  55. node: node,
  56. area: {
  57. x: box.x,
  58. y: box.bottom + offset,
  59. width: box.width,
  60. height: node.getStyle('margin-bottom')
  61. },
  62. path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
  63. });
  64. return hint;
  65. }
  66. }));
  67. });