fish-bone-master.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @fileOverview
  3. *
  4. * 鱼骨图主骨架布局
  5. *
  6. * @author: techird
  7. * @copyright: Baidu FEX, 2014
  8. */
  9. define(function(require, exports, module) {
  10. var kity = require('../core/kity');
  11. var Layout = require('../core/layout');
  12. Layout.register('fish-bone-master', kity.createClass('FishBoneMasterLayout', {
  13. base: Layout,
  14. doLayout: function(parent, children, round) {
  15. var upPart = [],
  16. downPart = [];
  17. var child = children[0];
  18. var pBox = parent.getContentBox();
  19. parent.setVertexOut(new kity.Point(pBox.right, pBox.cy));
  20. parent.setLayoutVectorOut(new kity.Vector(1, 0));
  21. if (!child) return;
  22. var cBox = child.getContentBox();
  23. var pMarginRight = parent.getStyle('margin-right');
  24. var cMarginLeft = child.getStyle('margin-left');
  25. var cMarginTop = child.getStyle('margin-top');
  26. var cMarginBottom = child.getStyle('margin-bottom');
  27. children.forEach(function(child, index) {
  28. child.setLayoutTransform(new kity.Matrix());
  29. var cBox = child.getContentBox();
  30. if (index % 2) {
  31. downPart.push(child);
  32. child.setVertexIn(new kity.Point(cBox.left, cBox.top));
  33. child.setLayoutVectorIn(new kity.Vector(1, 1));
  34. }
  35. else {
  36. upPart.push(child);
  37. child.setVertexIn(new kity.Point(cBox.left, cBox.bottom));
  38. child.setLayoutVectorIn(new kity.Vector(1, -1));
  39. }
  40. });
  41. this.stack(upPart, 'x');
  42. this.stack(downPart, 'x');
  43. this.align(upPart, 'bottom');
  44. this.align(downPart, 'top');
  45. var xAdjust = pBox.right + pMarginRight + cMarginLeft;
  46. var yAdjustUp = pBox.cy - cMarginBottom - parent.getStyle('margin-top');
  47. var yAdjustDown = pBox.cy + cMarginTop + parent.getStyle('margin-bottom');
  48. this.move(upPart, xAdjust, yAdjustUp);
  49. this.move(downPart, xAdjust + cMarginLeft, yAdjustDown);
  50. }
  51. }));
  52. });