|
135 | 135 |
|
136 | 136 | function plotCells (ctx: CanvasRenderingContext2D, trialData: { [key: string]: CellPlus }) { |
137 | 137 | ctx.fillStyle = '#ffffff' |
138 | | - ctx.fillRect(0, 0, config.totalWidth, config.totalHeight) |
| 138 | + ctx.fillRect(0, 0, config.totalWidth + config.paddingLeft, config.totalHeight + config.paddingTop) |
139 | 139 |
|
140 | 140 | for (let r = 0; r < compProps.trial.layout.rows; r++) { |
141 | 141 | ctx.fillStyle = '#ffffff' |
|
165 | 165 | ctx.fillText(str, x + config.cellWidth / 2, config.paddingTop / 2) |
166 | 166 | } |
167 | 167 |
|
168 | | - Object.values(trialData).forEach(td => { |
169 | | - const row = td.row || 0 |
170 | | - const column = td.column || 0 |
| 168 | + for (let row = 0; row < compProps.trial.layout.rows; row++) { |
| 169 | + for (let column = 0; column < compProps.trial.layout.columns; column++) { |
| 170 | + let count = 0 |
| 171 | + // Determine the background color |
| 172 | + if (row % 2 === 0) { |
| 173 | + count++ |
| 174 | + } |
| 175 | + if (column % 2 === 0) { |
| 176 | + count++ |
| 177 | + } |
| 178 | + switch (count) { |
| 179 | + case 0: |
| 180 | + ctx.fillStyle = '#ffffff' |
| 181 | + break |
| 182 | + case 1: |
| 183 | + ctx.fillStyle = '#f2f2f2' |
| 184 | + break |
| 185 | + default: |
| 186 | + ctx.fillStyle = '#e0e0e0' |
| 187 | + break |
| 188 | + } |
171 | 189 |
|
172 | | - let count = 0 |
173 | | - // Determine the background color |
174 | | - if (row % 2 === 0) { |
175 | | - count++ |
176 | | - } |
177 | | - if (column % 2 === 0) { |
178 | | - count++ |
179 | | - } |
180 | | - switch (count) { |
181 | | - case 0: |
182 | | - ctx.fillStyle = '#ffffff' |
183 | | - break |
184 | | - case 1: |
185 | | - ctx.fillStyle = '#f2f2f2' |
186 | | - break |
187 | | - default: |
188 | | - ctx.fillStyle = '#e0e0e0' |
189 | | - break |
190 | | - } |
| 190 | + const x = column * config.cellWidth + config.paddingLeft |
| 191 | + const y = row * config.cellHeight + config.paddingTop |
| 192 | + ctx.fillRect(x, y, config.cellWidth, config.cellHeight) |
191 | 193 |
|
192 | | - const x = column * config.cellWidth + config.paddingLeft |
193 | | - const y = row * config.cellHeight + config.paddingTop |
194 | | - ctx.fillRect(x, y, config.cellWidth, config.cellHeight) |
195 | | - ctx.fillStyle = 'black' |
196 | | - ctx.fillText(td.displayName || '', x + config.cellWidth / 2, y + config.cellHeight / 2) |
197 | | - }) |
| 194 | + const td = trialData[`${row}|${column}`] |
| 195 | + if (td) { |
| 196 | + ctx.fillStyle = 'black' |
| 197 | + ctx.fillText(td.displayName || '', x + config.cellWidth / 2, y + config.cellHeight / 2) |
| 198 | + } |
| 199 | + } |
| 200 | + } |
198 | 201 |
|
199 | 202 | ctx.strokeRect(0, 0, config.totalWidth + config.paddingLeft - 1, config.totalHeight + config.paddingTop - 1) |
200 | 203 | } |
|
0 commit comments