jpc_helper_area.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. let JV = require('../jpc_value_define');
  2. let JpcAreaHelper = {
  3. outputArea: function(areaNode, band, unitFactor, rowAmount, rowIdx, colAmount, colIdx, multipleDispCol, multipleColIdx,syncHeight, syncWidth) {
  4. let rst = {}, maxMultiColumns = 3;
  5. if (multipleDispCol > 0 && multipleDispCol <= maxMultiColumns) {
  6. //1. calculate left/right
  7. let areaWidth = 1.0 * (band[JV.PROP_RIGHT] - band[JV.PROP_LEFT]) / multipleDispCol;
  8. areaWidth = areaWidth / colAmount;
  9. let innerLeft = 0.0, innerRight = areaWidth;
  10. //
  11. if (typeof areaNode[JV.PROP_H_CALCULATION] === "string") {
  12. switch (areaNode[JV.PROP_H_CALCULATION]) {
  13. case JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE] :
  14. innerLeft = (1.0 * areaNode[JV.PROP_LEFT] * areaWidth / JV.HUNDRED_PERCENT);
  15. innerRight = (1.0 * areaNode[JV.PROP_RIGHT] * areaWidth / JV.HUNDRED_PERCENT);
  16. break;
  17. case JV.CAL_TYPE[JV.CAL_TYPE_ABSTRACT] :
  18. innerLeft = 1.0 * areaNode[JV.PROP_LEFT] * unitFactor;
  19. innerRight = 1.0 * areaNode[JV.PROP_RIGHT] * unitFactor;
  20. break;
  21. }
  22. } else {
  23. //颗粒度更加细化的控制,可能左右两边的计算坐标方式都不同
  24. if (areaNode[JV.PROP_H_CALCULATION][JV.PROP_LEFT] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
  25. innerLeft = (1.0 * areaNode[JV.PROP_LEFT] * areaWidth / JV.HUNDRED_PERCENT);
  26. } else {
  27. innerLeft = 1.0 * areaNode[JV.PROP_LEFT] * unitFactor;
  28. }
  29. if (areaNode[JV.PROP_H_CALCULATION][JV.PROP_RIGHT] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
  30. innerRight = (1.0 * areaNode[JV.PROP_RIGHT] * areaWidth / JV.HUNDRED_PERCENT);
  31. } else {
  32. innerRight = 1.0 * areaNode[JV.PROP_RIGHT] * unitFactor;
  33. }
  34. }
  35. //2. calculate top/bottom
  36. let areaHeight = 1.0 * (band[JV.PROP_BOTTOM] - band[JV.PROP_TOP]);
  37. areaHeight = areaHeight / rowAmount;
  38. let innerTop = 0.0, innerBottom = areaHeight;
  39. if (typeof areaNode[JV.PROP_V_CALCULATION] === "string") {
  40. switch (areaNode[JV.PROP_V_CALCULATION]) {
  41. case JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE] :
  42. innerTop = (1.0 * areaNode[JV.PROP_TOP] * areaHeight / JV.HUNDRED_PERCENT);
  43. innerBottom = (1.0 * areaNode[JV.PROP_BOTTOM] * areaHeight / JV.HUNDRED_PERCENT);
  44. break;
  45. case JV.CAL_TYPE[JV.CAL_TYPE_ABSTRACT] :
  46. innerTop = 1.0 * areaNode[JV.PROP_TOP] * unitFactor;
  47. innerBottom = 1.0 * areaNode[JV.PROP_BOTTOM] * unitFactor;
  48. break;
  49. }
  50. } else {
  51. //颗粒度更加细化的控制,可能上下两边的计算坐标方式都不同
  52. if (areaNode[JV.PROP_V_CALCULATION][JV.PROP_TOP] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
  53. innerTop = (1.0 * areaNode[JV.PROP_TOP] * areaHeight / JV.HUNDRED_PERCENT);
  54. } else {
  55. innerTop = 1.0 * areaNode[JV.PROP_TOP] * unitFactor;
  56. }
  57. if (areaNode[JV.PROP_V_CALCULATION][JV.PROP_BOTTOM] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
  58. innerBottom = (1.0 * areaNode[JV.PROP_BOTTOM] * areaHeight / JV.HUNDRED_PERCENT);
  59. } else {
  60. innerBottom = 1.0 * areaNode[JV.PROP_BOTTOM] * unitFactor;
  61. }
  62. }
  63. //
  64. let rstLeft = 0.0, rstRight = 0.0, rstTop = 0.0, rstBottom = 0.0;
  65. if (syncHeight) {
  66. rstBottom = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * (rowIdx + 1) + innerTop);
  67. } else {
  68. rstBottom = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * rowIdx + innerBottom);
  69. }
  70. if (syncWidth) {
  71. rstRight = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * (colIdx + 1) + innerLeft + multipleColIdx * areaWidth);
  72. } else {
  73. rstRight = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * colIdx + innerRight + multipleColIdx * areaWidth);
  74. }
  75. rstLeft = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * colIdx + innerLeft + multipleColIdx * areaWidth);
  76. rstTop = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * rowIdx + innerTop);
  77. rst[JV.PROP_LEFT] = rstLeft;
  78. rst[JV.PROP_RIGHT] = rstRight;
  79. rst[JV.PROP_TOP] = rstTop;
  80. rst[JV.PROP_BOTTOM] = rstBottom;
  81. }
  82. return rst;
  83. }
  84. };
  85. module.exports = JpcAreaHelper;