(num_items)
| 330 | } |
| 331 | |
| 332 | set_area_dimensions(num_items) { |
| 333 | this.num_rows = this.model.get('rows'); |
| 334 | this.num_cols = this.model.get('cols'); |
| 335 | this.row_groups = this.model.get('row_groups'); |
| 336 | |
| 337 | if ( |
| 338 | this.num_cols !== undefined && |
| 339 | this.num_cols !== null && |
| 340 | this.num_cols !== 0 |
| 341 | ) { |
| 342 | // When the number of row groups is greater than 1, the number |
| 343 | // of columns has to be an odd number. This is to |
| 344 | // ensure the continuity of the waffles when groups are spread |
| 345 | // across multiple row groups |
| 346 | if (this.row_groups > 1 && this.num_cols % 2 === 0) { |
| 347 | this.num_cols++; |
| 348 | } |
| 349 | this.num_rows = Math.floor(num_items / this.num_cols); |
| 350 | this.num_rows = |
| 351 | num_items % this.num_cols === 0 ? this.num_rows : this.num_rows + 1; |
| 352 | } else if ( |
| 353 | this.num_rows !== undefined && |
| 354 | this.num_rows !== null && |
| 355 | this.num_rows !== 0 |
| 356 | ) { |
| 357 | this.num_cols = Math.floor(num_items / this.num_rows); |
| 358 | this.num_cols = |
| 359 | num_items % this.num_rows === 0 ? this.num_cols : this.num_cols + 1; |
| 360 | if (this.row_groups > 1 && this.num_cols % 2 === 0) { |
| 361 | this.num_cols++; |
| 362 | } |
| 363 | } else { |
| 364 | this.num_cols = Math.floor(Math.sqrt(num_items)); |
| 365 | if (this.row_groups > 1 && this.num_cols % 2 === 0) { |
| 366 | this.num_cols++; |
| 367 | } |
| 368 | this.num_rows = Math.floor(num_items / this.num_cols); |
| 369 | this.num_rows = |
| 370 | num_items % this.num_cols === 0 ? this.num_rows : this.num_rows + 1; |
| 371 | } |
| 372 | |
| 373 | // row_groups cannot be greater than the number of rows |
| 374 | this.row_groups = Math.min(this.row_groups, this.num_rows); |
| 375 | // if there is only one row_group, then the number of columns are |
| 376 | // not necessarily equal to the variable this.num_cols as we draw |
| 377 | // row first. So we need to adjust the this.num_cols variable |
| 378 | // according to the num_rows. |
| 379 | if (this.row_groups == 1) { |
| 380 | this.num_cols = Math.floor(num_items / this.num_rows); |
| 381 | this.num_cols = |
| 382 | num_items % this.num_rows === 0 ? this.num_cols : this.num_cols + 1; |
| 383 | } |
| 384 | // depending on the number of rows, we need to decide when to |
| 385 | // switch direction. The below functions tells us where to switch |
| 386 | // direction. |
| 387 | this.set_row_limits(); |
| 388 | } |
| 389 |
no test coverage detected