fish-bone-slave.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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-slave', kity.createClass('FishBoneSlaveLayout', {
  13. base: Layout,
  14. doLayout: function (parent, children, round) {
  15. var layout = this;
  16. var abs = Math.abs;
  17. var GOLD_CUT = 1 - 0.618;
  18. var pBox = parent.getContentBox();
  19. var vi = parent.getLayoutVectorIn();
  20. parent.setLayoutVectorOut(vi);
  21. var goldX = pBox.left + pBox.width * GOLD_CUT;
  22. var pout = new kity.Point(goldX, vi.y > 0 ? pBox.bottom : pBox.top);
  23. parent.setVertexOut(pout);
  24. var child = children[0];
  25. if (!child) return;
  26. var cBox = child.getContentBox();
  27. children.forEach(function(child, index) {
  28. child.setLayoutTransform(new kity.Matrix());
  29. child.setLayoutVectorIn(new kity.Vector(1, 0));
  30. child.setVertexIn(new kity.Point(cBox.left, cBox.cy));
  31. });
  32. this.stack(children, 'y');
  33. this.align(children, 'left');
  34. var xAdjust = 0, yAdjust = 0;
  35. xAdjust += pout.x;
  36. if (parent.getLayoutVectorOut().y < 0) {
  37. yAdjust -= this.getTreeBox(children).bottom;
  38. yAdjust += parent.getContentBox().top;
  39. yAdjust -= parent.getStyle('margin-top');
  40. yAdjust -= child.getStyle('margin-bottom');
  41. } else {
  42. yAdjust += parent.getContentBox().bottom;
  43. yAdjust += parent.getStyle('margin-bottom');
  44. yAdjust += child.getStyle('margin-top');
  45. }
  46. this.move(children, xAdjust, yAdjust);
  47. if (round == 2) {
  48. children.forEach(function(child) {
  49. var m = child.getLayoutTransform();
  50. var cbox = child.getContentBox();
  51. var pin = m.transformPoint(new kity.Point(cbox.left, 0));
  52. layout.move([child], abs(pin.y - pout.y), 0);
  53. });
  54. }
  55. }
  56. }));
  57. });