|
| 1 | +import { getTimetableColumnAreaWidth } from "./tableHelper"; |
1 | 2 | interface TimeProps { |
2 | 3 | x: number; |
3 | 4 | y: number; |
@@ -88,53 +89,88 @@ export function getSelectedDatesWithSelectedArea( |
88 | 89 | selectedArea: TimeProps, |
89 | 90 | table: TimeProps, |
90 | 91 | startDate: Date, |
91 | | - currentTableIndex: number, |
92 | 92 | pageIndex: number |
93 | 93 | ) { |
94 | | - const { startIdx, endIdx } = getIndexesFromTable(selectedArea, table); |
| 94 | + const { startXIndex, endXIndex } = getXIndexesFromTable(selectedArea, table); |
| 95 | + const { startYIndex, endYIndex } = getYIndexesFromTable(selectedArea, table); |
| 96 | + |
95 | 97 | return getSelectedDates({ |
96 | | - startIdx, |
97 | | - endIdx, |
98 | | - startDate, |
99 | | - currentTableIndex, |
100 | 98 | pageIndex, |
| 99 | + startDate, |
| 100 | + startXIndex, |
| 101 | + endXIndex, |
| 102 | + startYIndex, |
| 103 | + endYIndex, |
101 | 104 | }); |
102 | 105 | } |
103 | 106 |
|
104 | | -function getIndexesFromTable(selectedArea: TimeProps, table: TimeProps) { |
| 107 | +function getXIndexesFromTable(selectedArea: TimeProps, timetable: TimeProps) { |
| 108 | + const GAP_SIZE = 1; |
| 109 | + |
| 110 | + const { x: selectedAreaX, w: selectedAreaWidth } = selectedArea; |
| 111 | + const { x: timetableX, w: timetableWidth } = timetable; |
| 112 | + |
| 113 | + const columnWidth = getTimetableColumnAreaWidth(timetableWidth); |
| 114 | + |
| 115 | + let startXIndex = 0; |
| 116 | + for (let index = 0; index < 7; index++) { |
| 117 | + const eachColumnXByIndex = |
| 118 | + timetableX + columnWidth * index + GAP_SIZE * index; |
| 119 | + //해당 인덱스의 컬럼의 x좌표와 선택영역의 x좌표가 소수점으로인해 다를수 있기에 반올림했음 |
| 120 | + if (Math.round(selectedAreaX - eachColumnXByIndex) === 0) { |
| 121 | + startXIndex = index; |
| 122 | + break; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + const endXIndex = |
| 127 | + Math.round(selectedAreaWidth / columnWidth) + startXIndex - 1; |
| 128 | + |
| 129 | + return { startXIndex, endXIndex }; |
| 130 | +} |
| 131 | + |
| 132 | +function getYIndexesFromTable(selectedArea: TimeProps, table: TimeProps) { |
105 | 133 | const fromTableToSelectedArea = selectedArea.y - table.y; |
106 | 134 | const GAP = 1; |
107 | 135 | const HEIGHT = |
108 | 136 | (table.h - GAP * (END_TIME - START_TIME - 1)) / (END_TIME - START_TIME); |
109 | 137 |
|
110 | | - const startIdx = Math.round(fromTableToSelectedArea / (HEIGHT + GAP)); |
111 | | - const endIdx = |
| 138 | + const startYIndex = Math.round(fromTableToSelectedArea / (HEIGHT + GAP)); |
| 139 | + const endYIndex = |
112 | 140 | Math.round((fromTableToSelectedArea + selectedArea.h) / (HEIGHT + GAP)) - 1; |
113 | | - return { startIdx, endIdx }; |
| 141 | + return { startYIndex, endYIndex }; |
114 | 142 | } |
115 | 143 |
|
116 | 144 | export function getSelectedDates({ |
117 | | - endIdx = 15, |
118 | | - startIdx = 0, |
119 | | - startDate, |
120 | | - currentTableIndex, |
121 | 145 | pageIndex, |
| 146 | + startDate, |
| 147 | + startXIndex, |
| 148 | + endXIndex = startXIndex, |
| 149 | + startYIndex = 0, |
| 150 | + endYIndex = 15, |
122 | 151 | startTime = 8, |
123 | 152 | }: { |
124 | | - endIdx?: number; |
125 | | - startIdx?: number; |
126 | | - startDate: Date; |
127 | | - currentTableIndex: number; |
128 | 153 | pageIndex: number; |
| 154 | + startDate: Date; |
| 155 | + startXIndex: number; |
| 156 | + endXIndex?: number; |
| 157 | + startYIndex?: number; |
| 158 | + endYIndex?: number; |
129 | 159 | startTime?: number; |
130 | 160 | }) { |
131 | | - if (endIdx - startIdx + 1 < 0) return []; |
132 | | - const selectedDates = new Array(endIdx - startIdx + 1).fill(0).map((_, idx) => |
133 | | - addDateAndTime(startDate, { |
134 | | - days: currentTableIndex + pageIndex * 7, |
135 | | - hours: startIdx + idx + startTime, |
136 | | - }) |
137 | | - ); |
| 161 | + if (endYIndex - startYIndex + 1 < 0) return []; |
| 162 | + let selectedDates: Date[] = []; |
| 163 | + for (let startIndex = startXIndex; startIndex <= endXIndex; startIndex++) { |
| 164 | + selectedDates = selectedDates.concat( |
| 165 | + new Array(endYIndex - startYIndex + 1).fill(0).map((_, idx) => |
| 166 | + addDateAndTime(startDate, { |
| 167 | + days: startIndex + pageIndex * 7, |
| 168 | + hours: startYIndex + idx + startTime, |
| 169 | + }) |
| 170 | + ) |
| 171 | + ); |
| 172 | + } |
| 173 | + console.log(selectedDates); |
138 | 174 | return selectedDates; |
139 | 175 | } |
140 | 176 |
|
|
0 commit comments