|
22 | 22 | )
|
23 | 23 |
|
24 | 24 | import ipywidgets
|
| 25 | +import numpy as np |
25 | 26 | import traitlets
|
26 |
| -from arro3.core import Table |
| 27 | +from arro3.core import Array, ChunkedArray, Table |
27 | 28 | from arro3.core.types import ArrowStreamExportable
|
28 | 29 |
|
29 | 30 | from lonboard._base import BaseExtension, BaseWidget
|
|
38 | 39 | from lonboard._serialization import infer_rows_per_chunk
|
39 | 40 | from lonboard._utils import auto_downcast as _auto_downcast
|
40 | 41 | from lonboard._utils import get_geometry_column_index, remove_extension_kwargs
|
| 42 | +from lonboard.layer_extension import DataFilterExtension |
41 | 43 | from lonboard.traits import (
|
42 | 44 | ArrowTableTrait,
|
43 | 45 | ColorAccessor,
|
@@ -409,9 +411,55 @@ def quak(self) -> quak.Widget:
|
409 | 411 | import quak
|
410 | 412 | import sqlglot
|
411 | 413 |
|
| 414 | + if not any(isinstance(ext, DataFilterExtension) for ext in self.extensions): |
| 415 | + self.add_extension(DataFilterExtension(category_size=1)) |
| 416 | + |
| 417 | + table: Table = self.table |
| 418 | + num_rows = table.num_rows |
| 419 | + if num_rows <= np.iinfo(np.uint8).max: |
| 420 | + row_index = Array.from_numpy(np.arange(num_rows, dtype=np.uint8)) |
| 421 | + filter_arr = np.ones(num_rows, dtype=np.float32) |
| 422 | + elif num_rows <= np.iinfo(np.uint16).max: |
| 423 | + row_index = Array.from_numpy(np.arange(num_rows, dtype=np.uint16)) |
| 424 | + filter_arr = np.ones(num_rows, dtype=np.float32) |
| 425 | + elif num_rows <= np.iinfo(np.uint32).max: |
| 426 | + row_index = Array.from_numpy(np.arange(num_rows, dtype=np.uint32)) |
| 427 | + filter_arr = np.ones(num_rows, dtype=np.float32) |
| 428 | + else: |
| 429 | + row_index = Array.from_numpy(np.arange(num_rows, dtype=np.uint64)) |
| 430 | + filter_arr = np.ones(num_rows, dtype=np.float32) |
| 431 | + |
| 432 | + table_with_row_index = table.append_column( |
| 433 | + "_row_index", ChunkedArray(row_index) |
| 434 | + ) |
| 435 | + quak_widget = quak.Widget(table_with_row_index) |
| 436 | + |
| 437 | + def row_index_callback(change): |
| 438 | + global test |
| 439 | + test = change |
| 440 | + |
| 441 | + sql = sqlglot.parse_one(quak_widget.sql, dialect="duckdb") |
| 442 | + sql.set("expressions", [sqlglot.column("_row_index")]) |
| 443 | + row_index_table = quak_widget._conn.query(sql.sql(dialect="duckdb")).arrow() |
| 444 | + |
| 445 | + # Reset all to 2. We don't use zero because there might be a bug with 0 |
| 446 | + filter_arr[:] = 2 |
| 447 | + |
| 448 | + # Set the desired _row_index to 1 |
| 449 | + filter_arr[row_index_table["_row_index"]] = 1 |
| 450 | + |
| 451 | + self.get_filter_category = filter_arr # type: ignore |
| 452 | + self.filter_categories = [1] # type: ignore |
| 453 | + |
| 454 | + quak_widget.observe(row_index_callback, names="sql") |
| 455 | + |
| 456 | + return quak_widget |
412 | 457 | pass
|
413 | 458 |
|
414 | 459 |
|
| 460 | +test = None |
| 461 | + |
| 462 | + |
415 | 463 | class BitmapLayer(BaseLayer):
|
416 | 464 | """
|
417 | 465 | The `BitmapLayer` renders a bitmap (e.g. PNG, JPEG, or WebP) at specified
|
|
0 commit comments