(
seriesIndex: number,
newPointsOrData: DataPoint[] | OHLCDataPoint[] | Float32Array | Float64Array,
pointType?: 'xy' | 'ohlc'
)
| 1242 | |
| 1243 | // Implementation |
| 1244 | appendData( |
| 1245 | seriesIndex: number, |
| 1246 | newPointsOrData: DataPoint[] | OHLCDataPoint[] | Float32Array | Float64Array, |
| 1247 | pointType?: 'xy' | 'ohlc' |
| 1248 | ): void { |
| 1249 | if (this.isDisposed) { |
| 1250 | throw new ChartGPUWorkerError( |
| 1251 | 'Cannot appendData on disposed chart', |
| 1252 | 'DISPOSED', |
| 1253 | 'appendData', |
| 1254 | this.chartId |
| 1255 | ); |
| 1256 | } |
| 1257 | |
| 1258 | if (!Number.isInteger(seriesIndex) || seriesIndex < 0) { |
| 1259 | throw new ChartGPUWorkerError( |
| 1260 | `Invalid seriesIndex: ${seriesIndex}. Must be a non-negative integer.`, |
| 1261 | 'INVALID_ARGUMENT', |
| 1262 | 'appendData', |
| 1263 | this.chartId |
| 1264 | ); |
| 1265 | } |
| 1266 | |
| 1267 | // Handle typed array form (zero-copy transfer) |
| 1268 | if (newPointsOrData instanceof Float32Array || newPointsOrData instanceof Float64Array) { |
| 1269 | if (!pointType) { |
| 1270 | throw new ChartGPUWorkerError( |
| 1271 | 'pointType parameter is required when passing typed arrays', |
| 1272 | 'INVALID_ARGUMENT', |
| 1273 | 'appendData', |
| 1274 | this.chartId |
| 1275 | ); |
| 1276 | } |
| 1277 | |
| 1278 | const sourceArray = newPointsOrData; |
| 1279 | |
| 1280 | if (sourceArray.length === 0) { |
| 1281 | return; // No-op for empty arrays |
| 1282 | } |
| 1283 | |
| 1284 | // Determine expected format based on point type |
| 1285 | const floatsPerPoint = pointType === 'xy' ? 2 : 5; |
| 1286 | const pointCount = sourceArray.length / floatsPerPoint; |
| 1287 | const stride: StrideBytes = pointType === 'xy' ? XY_STRIDE : OHLC_STRIDE; |
| 1288 | |
| 1289 | // Validate that length is a multiple of floatsPerPoint |
| 1290 | if (sourceArray.length % floatsPerPoint !== 0) { |
| 1291 | throw new ChartGPUWorkerError( |
| 1292 | `Invalid typed array length: ${sourceArray.length}. Expected multiple of ${floatsPerPoint} for '${pointType}' points.`, |
| 1293 | 'INVALID_ARGUMENT', |
| 1294 | 'appendData', |
| 1295 | this.chartId |
| 1296 | ); |
| 1297 | } |
| 1298 | |
| 1299 | // CRITICAL: GPU buffers use Float32, so convert Float64Array to Float32Array |
| 1300 | let typedArray: Float32Array; |
| 1301 | if (sourceArray instanceof Float64Array) { |
nothing calls this directly
no test coverage detected