()
| 1832 | // This function is used to hide the rows which are not currently in view and |
| 1833 | // so reduce the performance cost of things like hit tests and scrolling. |
| 1834 | public syncHidden(): void { |
| 1835 | const isFlipped = this.view.userSettings.get("flipped"); |
| 1836 | const toHide = new Array<[HTMLElement, HTMLElement]>(); |
| 1837 | |
| 1838 | const sampleCell = this.view.divs.registers.children[1] as HTMLElement; |
| 1839 | const buffer = 2 * (isFlipped ? sampleCell.clientWidth : sampleCell.clientHeight); |
| 1840 | const min = (isFlipped ? this.view.divs.grid.offsetLeft + this.view.divs.grid.scrollLeft |
| 1841 | : this.view.divs.grid.offsetTop + this.view.divs.grid.scrollTop) |
| 1842 | - buffer; |
| 1843 | const max = (isFlipped ? min + this.view.divs.grid.clientWidth |
| 1844 | : min + this.view.divs.grid.clientHeight) |
| 1845 | + buffer; |
| 1846 | |
| 1847 | // The rows are grouped by being contained within a group div. This is so as to allow |
| 1848 | // groups of rows to easily be displayed and hidden with less of a performance cost. |
| 1849 | // Each row in the mainGroup div is matched with an equivalent placeholder row in |
| 1850 | // the placeholderGroup div that will be shown when mainGroup is hidden so as to maintain |
| 1851 | // the dimensions and scroll positions of the grid. |
| 1852 | |
| 1853 | const rangeGroups = this.view.divs.grid.children; |
| 1854 | for (let i = 1; i < rangeGroups.length; i += 2) { |
| 1855 | const mainGroup = rangeGroups[i] as HTMLElement; |
| 1856 | const placeholderGroup = rangeGroups[i - 1] as HTMLElement; |
| 1857 | const isHidden = mainGroup.classList.contains("range-hidden"); |
| 1858 | // The offsets are used to calculate whether the group is in view. |
| 1859 | const offsetMin = this.getOffset(mainGroup.firstChild as HTMLElement, |
| 1860 | placeholderGroup.firstChild as HTMLElement, isHidden, isFlipped); |
| 1861 | const offsetMax = this.getOffset(mainGroup.lastChild as HTMLElement, |
| 1862 | placeholderGroup.lastChild as HTMLElement, isHidden, isFlipped); |
| 1863 | |
| 1864 | if (offsetMax > min && offsetMin < max) { |
| 1865 | if (isHidden) { |
| 1866 | // Show the rows, hide the placeholders. |
| 1867 | mainGroup.classList.toggle("range-hidden", false); |
| 1868 | placeholderGroup.classList.toggle("range-hidden", true); |
| 1869 | } |
| 1870 | } else if (!isHidden) { |
| 1871 | // Only hide the rows once the new rows are shown so that scrollLeft is not lost. |
| 1872 | toHide.push([mainGroup, placeholderGroup]); |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | for (const [mainGroup, placeholderGroup] of toHide) { |
| 1877 | // Hide the rows, show the placeholders. |
| 1878 | mainGroup.classList.toggle("range-hidden", true); |
| 1879 | placeholderGroup.classList.toggle("range-hidden", false); |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | // This function is required to keep the axes labels in line with the grid |
| 1884 | // content when scrolling. |
no test coverage detected