| 80 | */ |
| 81 | @customElement('embeddings-module') |
| 82 | export class EmbeddingsModule extends LitModule { |
| 83 | static override title = 'Embeddings'; |
| 84 | static override infoMarkdown = |
| 85 | `Pan, zoom, rotate, and click to visualize datapoints in the latent space |
| 86 | of your model, in order to find clusters or patterns in the data.<br> |
| 87 | [Learn more.](https://pair-code.github.io/lit/documentation/components.md#embedding-projector)`; |
| 88 | static override template = |
| 89 | (model: string, selectionServiceIndex: number, shouldReact: number) => { |
| 90 | return html` |
| 91 | <embeddings-module model=${model} .shouldReact=${shouldReact} |
| 92 | selectionServiceIndex=${selectionServiceIndex}> |
| 93 | </embeddings-module>`; |
| 94 | }; |
| 95 | |
| 96 | static override get styles() { |
| 97 | return [sharedStyles, styles]; |
| 98 | } |
| 99 | |
| 100 | static override duplicateForModelComparison = false; |
| 101 | |
| 102 | private readonly projectorChoices: {[key: string]: ProjectorOptions} = {}; |
| 103 | |
| 104 | static override numCols = 3; |
| 105 | |
| 106 | @observable private isLoading = false; |
| 107 | |
| 108 | // Selection of one of the above configs. |
| 109 | @observable private projectorName = ''; |
| 110 | @computed get projector(): ProjectorOptions { |
| 111 | return this.projectorChoices[this.projectorName]; |
| 112 | } |
| 113 | |
| 114 | // Actual projected points. |
| 115 | @observable.ref private projectedPoints: Point3D[] = []; |
| 116 | |
| 117 | @observable private spriteImage?: HTMLImageElement|string = undefined; |
| 118 | |
| 119 | private readonly colorService = app.getService(ColorService); |
| 120 | private readonly focusService = app.getService(FocusService); |
| 121 | private readonly dataService = app.getService(DataService); |
| 122 | private readonly pinnedSelectionService = |
| 123 | app.getService(SelectionService, 'pinned'); |
| 124 | private readonly resizeObserver = new ResizeObserver(() => { |
| 125 | // Protect against resize when container isn't rendered, which can happen |
| 126 | // during model switching. |
| 127 | const resultsArea = this.shadowRoot!.querySelector('.module-results-area'); |
| 128 | const container = this.shadowRoot!.getElementById('scatter-gl-container'); |
| 129 | if (resultsArea == null || container == null) {return;} |
| 130 | |
| 131 | /** |
| 132 | * While investigating the jitter, we found that this callback function was |
| 133 | * being called twice for every selection change. After the first call, the |
| 134 | * `container.offsetHeight` would always be less than |
| 135 | * `resultsArea.offsetHeight`, and after the second they would be the same. |
| 136 | * We were unable to figure out why this is happening because of the |
| 137 | * opqueness of the ResizeObserver API's triggers. |
| 138 | * |
| 139 | * Thus we added this guard to only resize ScatterGL when the heights are |
nothing calls this directly
no test coverage detected