UNPKG

devexpress-reporting

Version:

DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.

213 lines (212 loc) 8 kB
/** * DevExpress HTML/JS Reporting (designer\bands\_bandUtils.js) * Version: 25.1.3 * Build date: Jun 26, 2025 * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * License: https://www.devexpress.com/Support/EULAs/universal.xml */ import { bandSurfaceCollapsedHeight } from './bandSurfaceCollapsedHeight'; import { detailLevel, groupLevel } from './metadata/bandsMetadata'; export function sortBands(band1, band2) { return getBandWeight(band1) - getBandWeight(band2); } export function setMarkerWidth(bandHolder, levelCount, currentLevel = 0) { if (bandHolder && bandHolder.bands().length !== 0) { bandHolder.bands().forEach((band) => { band.markerWidth(bandSurfaceCollapsedHeight * (levelCount - currentLevel)); setMarkerWidth(band.bandsHolder, levelCount, currentLevel + 1); }); bandHolder.verticalBandsContainer && bandHolder.verticalBandsContainer.markerWidth(bandSurfaceCollapsedHeight * (levelCount - currentLevel)); } } export function getLevelCount(bandHolder) { let result = 0, maxLevelCount = 0; if (!bandHolder) return result; if (bandHolder.bands().length !== 0) { bandHolder.bands().forEach((band) => { const levelCount = getLevelCount(band.bandsHolder); if (levelCount > maxLevelCount) { maxLevelCount = levelCount; } }); result = maxLevelCount + 1; } else if (bandHolder.verticalBandsContainer && bandHolder.verticalBandsContainer.visible) { result = maxLevelCount + 1; } return result; } export function insertBand(bands, newBand) { insertBandSorted(bands, newBand); } function insertBandSorted(bands, newBand) { if (newBand) { const cloneBands = bands().slice(0); const previousBandIndex = bands().indexOf(newBand); if (previousBandIndex === -1) { cloneBands.push(newBand); } cloneBands.sort(sortBands); const index = cloneBands.indexOf(newBand); if (previousBandIndex !== -1) { bands.splice(previousBandIndex, 1); } bands.splice(index, 0, newBand); } } const bandsWeight = { 'TopMarginBand': 100, 'ReportHeaderBand': 200, 'PageHeaderBand': 300, 'GroupHeaderBand': 400, 'DetailBand': 500, 'VerticalHeaderBand': 500, 'VerticalDetailBand': 600, 'VerticalTotalBand': 700, 'DetailReportBand': 800, 'GroupFooterBand': 900, 'ReportFooterBand': 1000, 'PageFooterBand': 1100, 'BottomMarginBand': 1200 }; function getBandWeight(band) { if (band.controlType === 'GroupHeaderBand') { return bandsWeight[band.controlType] - (band.level() || 0); } if (band.controlType === 'GroupFooterBand') { return bandsWeight[band.controlType] + (band.level() || 0); } if (band.controlType === 'DetailReportBand') { return bandsWeight[band.controlType] + (band.level() || -1); } return bandsWeight[band.controlType]; } function initGroupIndexes(largeGroupBandCollection, smallGroupBandCollection) { const replaces = {}; const busyIndexes = []; const findClosestIndex = (currentIndex) => { let index = currentIndex; const findClosestAvailableIndex = (currentIndex, inc) => { const newIndex = currentIndex + inc; if (newIndex === largeGroupBandCollection.length || newIndex === -1) { return undefined; } if (busyIndexes.indexOf(currentIndex + inc) !== -1) { return newIndex; } else { return findClosestAvailableIndex(newIndex, inc); } }; if (busyIndexes.indexOf(currentIndex) !== -1) { index = findClosestAvailableIndex(currentIndex, -1); if (index === undefined) index = findClosestAvailableIndex(currentIndex, 1); } return index; }; for (let i = 0; i < largeGroupBandCollection.length; i++) { const currentLevel = largeGroupBandCollection[i].level; if (!replaces[currentLevel()]) replaces[currentLevel()] = [i]; else { replaces[currentLevel()].push(i); } currentLevel(i); } for (let i = 0; i < smallGroupBandCollection.length; i++) { let index = i; const currentLevel = smallGroupBandCollection[i].level; if (replaces[currentLevel()] && replaces[currentLevel()].length > 0) { index = replaces[currentLevel()].splice(0, 1)[0]; } else if (currentLevel() < largeGroupBandCollection.length) { index = findClosestIndex(currentLevel()); } else { index = findClosestIndex(i); } currentLevel(index); busyIndexes.push(index); } } export function _getUnitAbsoluteRect(bandSurface, getPositionInParent) { const parentAbsoluteRect = bandSurface.parent && bandSurface.parent['_unitAbsoluteRect']; if (parentAbsoluteRect) { const _unitPosition = getPositionInParent(); return { top: parentAbsoluteRect.top + _unitPosition.y(), left: parentAbsoluteRect.left + _unitPosition.x(), right: parentAbsoluteRect.left + _unitPosition.x() + bandSurface._control.size.width(), bottom: parentAbsoluteRect.top + _unitPosition.y() + bandSurface._control.size.height(), width: bandSurface._control.size.width() - bandSurface['_getGrayArea'](), height: bandSurface._control.size.height() }; } else { return { top: 0, left: 0, right: bandSurface._control.size.width(), bottom: bandSurface._control.size.height(), width: bandSurface._control.size.width() - bandSurface['_getGrayArea'](), height: bandSurface._control.size.height() }; } } export const NEW_GROUPBAND_DEFAULT_LEVEL = groupLevel.defaultVal; export const NEW_DETAILBAND_DEFAULT_LEVEL = detailLevel.defaultVal; export const REMOVED_DETAILBAND_LEVEL = Number.MAX_VALUE; export function getFirstEmptyLevel(bands) { if (!bands || bands.length === 0) return NEW_GROUPBAND_DEFAULT_LEVEL; for (let i = 0; i < bands.length; i++) { if (bands[i].level() !== i) return i; } return bands.length; } export function getMaxLevel(parentBands) { if (!parentBands || parentBands.length === 0) return -1; return Math.max(...parentBands.map(b => b.level())); } export function isFirstInit(band) { return !band.parentModel().bands; } export function isBandInserting(band) { return !band.parentModel().bands()?.find(b => b === band); } export function levelSetup(band, newValue) { if (isFirstInit(band)) { const coercedNewValue = band.coerceDefaultLevelValue(newValue); band._level(coercedNewValue); return; } const maxLevel = getMaxLevel(band.getFilteredParentBands()); if (isBandInserting(band)) band.updateLevelsOnInsert(maxLevel, newValue); else band.reorderLevels(maxLevel, newValue); const parentBands = band.parentModel().bands; parentBands.sort(sortBands); } export function getExistedSameLevelBand(bands, level) { return bands.find(band => band.level() === level); } export function coerceNewLevelValueOnReordering(value, minValue, maxValue) { if (value > maxValue) return maxValue; if (value < minValue) return minValue; return value; } export function coerceNewLevelValueOnInserting(value, minValue, maxValue) { if (value >= 0 && value <= maxValue) return value; return maxValue; } export function changeLevels(bands, startIndex, endIndex) { let currentIndex = startIndex; const direction = startIndex < endIndex ? 1 : -1; while (currentIndex != endIndex) { const level = (bands[currentIndex]).level(); bands[currentIndex]._level(level + direction); currentIndex += direction; } }