Jpc_Helper_Area.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var JV = require('../Jpc_ValueDefine');
  2. var JpcAreaHelper = {
  3. outputArea: function(areaNode, band, unitFactor, rowAmount, rowIdx, colAmount, colIdx, multipleDispCol, multipleColIdx,syncHeight, syncWidth) {
  4. var rst = {}, maxMultiColumns = 3;
  5. if (multipleDispCol > 0 && multipleDispCol <= maxMultiColumns) {
  6. //1. calculate left/right
  7. var areaWidth = 1.0 * (band[JV.PROP_RIGHT] - band[JV.PROP_LEFT]) / multipleDispCol;
  8. areaWidth = areaWidth / colAmount;
  9. var innerLeft = 0.0, innerRight = areaWidth;
  10. switch (areaNode[JV.PROP_H_CALCULATION]) {
  11. case JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE] :
  12. innerLeft = (1.0 * areaNode[JV.PROP_LEFT] * areaWidth / JV.HUNDRED_PERCENT);
  13. innerRight = (1.0 * areaNode[JV.PROP_RIGHT] * areaWidth / JV.HUNDRED_PERCENT) ;
  14. break;
  15. case JV.CAL_TYPE[JV.CAL_TYPE_ABSTRACT] :
  16. innerLeft = 1.0 * areaNode[JV.PROP_LEFT] * unitFactor;
  17. innerRight = 1.0 * areaNode[JV.PROP_RIGHT] * unitFactor ;
  18. break;
  19. }
  20. //2. calculate top/bottom
  21. var areaHeight = 1.0 * (band[JV.PROP_BOTTOM] - band[JV.PROP_TOP]);
  22. areaHeight = areaHeight / rowAmount;
  23. var innerTop = 0.0, innerBottom = areaHeight;
  24. switch (areaNode[JV.PROP_V_CALCULATION]) {
  25. case JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE] :
  26. innerTop = (1.0 * areaNode[JV.PROP_TOP] * areaHeight / JV.HUNDRED_PERCENT);
  27. innerBottom = (1.0 * areaNode[JV.PROP_BOTTOM] * areaHeight / JV.HUNDRED_PERCENT) ;
  28. break;
  29. case JV.CAL_TYPE[JV.CAL_TYPE_ABSTRACT] :
  30. innerTop = 1.0 * areaNode[JV.PROP_TOP] * unitFactor;
  31. innerBottom = 1.0 * areaNode[JV.PROP_BOTTOM] * unitFactor ;
  32. break;
  33. }
  34. //
  35. var rstLeft = 0.0, rstRight = 0.0, rstTop = 0.0, rstBottom = 0.0;
  36. if (syncHeight) {
  37. rstBottom = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * (rowIdx + 1) + innerTop);
  38. } else {
  39. rstBottom = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * rowIdx + innerBottom);
  40. }
  41. if (syncWidth) {
  42. rstRight = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * (colIdx + 1) + innerLeft + multipleColIdx * areaWidth);
  43. } else {
  44. rstRight = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * colIdx + innerRight + multipleColIdx * areaWidth);
  45. }
  46. rstLeft = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * colIdx + innerLeft + multipleColIdx * areaWidth);
  47. rstTop = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * rowIdx + innerTop);
  48. rst[JV.PROP_LEFT] = rstLeft;
  49. rst[JV.PROP_RIGHT] = rstRight;
  50. rst[JV.PROP_TOP] = rstTop;
  51. rst[JV.PROP_BOTTOM] = rstBottom;
  52. }
  53. return rst;
  54. }
  55. };
  56. module.exports = JpcAreaHelper;