123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- let JV = require('../jpc_value_define');
- let JpcAreaHelper = {
- outputArea: function(areaNode, band, unitFactor, rowAmount, rowIdx, colAmount, colIdx, multipleDispCol, multipleColIdx,syncHeight, syncWidth) {
- let rst = {}, maxMultiColumns = 3;
- if (multipleDispCol > 0 && multipleDispCol <= maxMultiColumns) {
- //1. calculate left/right
- let areaWidth = 1.0 * (band[JV.PROP_RIGHT] - band[JV.PROP_LEFT]) / multipleDispCol;
- areaWidth = areaWidth / colAmount;
- let innerLeft = 0.0, innerRight = areaWidth;
- //
- if (typeof areaNode[JV.PROP_H_CALCULATION] === "string") {
- switch (areaNode[JV.PROP_H_CALCULATION]) {
- case JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE] :
- innerLeft = (1.0 * areaNode[JV.PROP_LEFT] * areaWidth / JV.HUNDRED_PERCENT);
- innerRight = (1.0 * areaNode[JV.PROP_RIGHT] * areaWidth / JV.HUNDRED_PERCENT);
- break;
- case JV.CAL_TYPE[JV.CAL_TYPE_ABSTRACT] :
- innerLeft = 1.0 * areaNode[JV.PROP_LEFT] * unitFactor;
- innerRight = 1.0 * areaNode[JV.PROP_RIGHT] * unitFactor;
- break;
- }
- } else {
- //颗粒度更加细化的控制,可能左右两边的计算坐标方式都不同
- if (areaNode[JV.PROP_H_CALCULATION][JV.PROP_LEFT] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
- innerLeft = (1.0 * areaNode[JV.PROP_LEFT] * areaWidth / JV.HUNDRED_PERCENT);
- } else {
- innerLeft = 1.0 * areaNode[JV.PROP_LEFT] * unitFactor;
- }
- if (areaNode[JV.PROP_H_CALCULATION][JV.PROP_RIGHT] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
- innerRight = (1.0 * areaNode[JV.PROP_RIGHT] * areaWidth / JV.HUNDRED_PERCENT);
- } else {
- innerRight = 1.0 * areaNode[JV.PROP_RIGHT] * unitFactor;
- }
- }
- //2. calculate top/bottom
- let areaHeight = 1.0 * (band[JV.PROP_BOTTOM] - band[JV.PROP_TOP]);
- areaHeight = areaHeight / rowAmount;
- let innerTop = 0.0, innerBottom = areaHeight;
- if (typeof areaNode[JV.PROP_V_CALCULATION] === "string") {
- switch (areaNode[JV.PROP_V_CALCULATION]) {
- case JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE] :
- innerTop = (1.0 * areaNode[JV.PROP_TOP] * areaHeight / JV.HUNDRED_PERCENT);
- innerBottom = (1.0 * areaNode[JV.PROP_BOTTOM] * areaHeight / JV.HUNDRED_PERCENT);
- break;
- case JV.CAL_TYPE[JV.CAL_TYPE_ABSTRACT] :
- innerTop = 1.0 * areaNode[JV.PROP_TOP] * unitFactor;
- innerBottom = 1.0 * areaNode[JV.PROP_BOTTOM] * unitFactor;
- break;
- }
- } else {
- //颗粒度更加细化的控制,可能上下两边的计算坐标方式都不同
- if (areaNode[JV.PROP_V_CALCULATION][JV.PROP_TOP] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
- innerTop = (1.0 * areaNode[JV.PROP_TOP] * areaHeight / JV.HUNDRED_PERCENT);
- } else {
- innerTop = 1.0 * areaNode[JV.PROP_TOP] * unitFactor;
- }
- if (areaNode[JV.PROP_V_CALCULATION][JV.PROP_BOTTOM] === JV.CAL_TYPE[JV.CAL_TYPE_PERCENTAGE]) {
- innerBottom = (1.0 * areaNode[JV.PROP_BOTTOM] * areaHeight / JV.HUNDRED_PERCENT);
- } else {
- innerBottom = 1.0 * areaNode[JV.PROP_BOTTOM] * unitFactor;
- }
- }
- //
- let rstLeft = 0.0, rstRight = 0.0, rstTop = 0.0, rstBottom = 0.0;
- if (syncHeight) {
- rstBottom = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * (rowIdx + 1) + innerTop);
- } else {
- rstBottom = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * rowIdx + innerBottom);
- }
- if (syncWidth) {
- rstRight = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * (colIdx + 1) + innerLeft + multipleColIdx * areaWidth);
- } else {
- rstRight = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * colIdx + innerRight + multipleColIdx * areaWidth);
- }
- rstLeft = Math.round(1.0 * band[JV.PROP_LEFT] + areaWidth * colIdx + innerLeft + multipleColIdx * areaWidth);
- rstTop = Math.round(1.0 * band[JV.PROP_TOP] + areaHeight * rowIdx + innerTop);
- rst[JV.PROP_LEFT] = rstLeft;
- rst[JV.PROP_RIGHT] = rstRight;
- rst[JV.PROP_TOP] = rstTop;
- rst[JV.PROP_BOTTOM] = rstBottom;
- }
- return rst;
- }
- };
- module.exports = JpcAreaHelper;
|