| 150 | } |
| 151 | |
| 152 | updateBackground(data: number[][], discretize: boolean): void { |
| 153 | let dx = data[0].length; |
| 154 | let dy = data.length; |
| 155 | |
| 156 | if (dx !== this.numSamples || dy !== this.numSamples) { |
| 157 | throw new Error( |
| 158 | "The provided data matrix must be of size " + |
| 159 | "numSamples X numSamples"); |
| 160 | } |
| 161 | |
| 162 | // Compute the pixel colors; scaled by CSS. |
| 163 | let context = (this.canvas.node() as HTMLCanvasElement).getContext("2d"); |
| 164 | let image = context.createImageData(dx, dy); |
| 165 | |
| 166 | for (let y = 0, p = -1; y < dy; ++y) { |
| 167 | for (let x = 0; x < dx; ++x) { |
| 168 | let value = data[x][y]; |
| 169 | if (discretize) { |
| 170 | value = (value >= 0 ? 1 : -1); |
| 171 | } |
| 172 | let c = d3.rgb(this.color(value)); |
| 173 | image.data[++p] = c.r; |
| 174 | image.data[++p] = c.g; |
| 175 | image.data[++p] = c.b; |
| 176 | image.data[++p] = 160; |
| 177 | } |
| 178 | } |
| 179 | context.putImageData(image, 0, 0); |
| 180 | } |
| 181 | |
| 182 | private updateCircles(container, points: Example2D[]) { |
| 183 | // Keep only points that are inside the bounds. |