* Computes the `size` (width of a column, height of a row) and the `sumTo` * (width or height of the preceeding columns or rows) for each dot group.
(groups: GroupedExamples, colFeature: string,
rowFeature: string)
| 446 | * (width or height of the preceeding columns or rows) for each dot group. |
| 447 | */ |
| 448 | private matrixSizes(groups: GroupedExamples, colFeature: string, |
| 449 | rowFeature: string): GroupFeaturesSizes { |
| 450 | /** Stores size of the largest facet for the column and row features. */ |
| 451 | const sizes: GroupFeaturesSizes = {columns:{}, rows:{}}; |
| 452 | |
| 453 | // sorting the |
| 454 | const keys = Object.keys(groups).sort(keySorter); |
| 455 | for (const key of keys) { |
| 456 | const group = groups[key]; |
| 457 | const width = Math.ceil(Math.sqrt(group.data.length)); |
| 458 | const height = Math.ceil(group.data.length / width); |
| 459 | |
| 460 | for (const [feature, {displayVal}] of Object.entries(group.facets)) { |
| 461 | if (colFeature === rowFeature) { |
| 462 | if (sizes.columns[displayVal] == null) { |
| 463 | sizes.columns[displayVal] = {size: width, sumTo: 0}; |
| 464 | } else if (width > sizes.columns[displayVal].size) { |
| 465 | sizes.columns[displayVal].size = width; |
| 466 | } |
| 467 | |
| 468 | if (sizes.rows[displayVal] == null) { |
| 469 | sizes.rows[displayVal] = {size: height, sumTo: 0}; |
| 470 | } else if (height > sizes.rows[displayVal].size) { |
| 471 | sizes.rows[displayVal].size = height; |
| 472 | } |
| 473 | } else { |
| 474 | const size = colFeature === feature ? width : height; |
| 475 | const featureDimensions = |
| 476 | colFeature === feature ? sizes.columns : sizes.rows; |
| 477 | |
| 478 | if (featureDimensions[displayVal] == null) { |
| 479 | featureDimensions[displayVal] = {size, sumTo: 0}; |
| 480 | } else if (size > featureDimensions[displayVal].size) { |
| 481 | featureDimensions[displayVal].size = size; |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | let columnSum = 0; |
| 488 | for (const dimensions of Object.values(sizes.columns)) { |
| 489 | dimensions.sumTo = columnSum; |
| 490 | columnSum += dimensions.size; |
| 491 | } |
| 492 | |
| 493 | let rowSum = 0; |
| 494 | for (const dimensions of Object.values(sizes.rows)) { |
| 495 | dimensions.sumTo = rowSum; |
| 496 | rowSum += dimensions.size; |
| 497 | } |
| 498 | return sizes; |
| 499 | } |
| 500 | |
| 501 | /** Binds the labels and dots to the Megaplot scene. */ |
| 502 | private draw() { |