Skip to content

Commit

Permalink
fix arrowlayer filtering performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lixun910 committed Oct 25, 2023
1 parent 41fb3b1 commit 3914b67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/layers/src/arrow-layer/arrow-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ export default class ArrowLayer extends GeoJsonLayer {
encoding: col.metadata?.get(GEOARROW_COLUMN_METADATA_KEY),
data: rawGeometry
});
const properties = this.dataContainer.rowAsArray(objectInfo.index).reduce((prev, cur, i) => {
if (i !== geojson.fieldIdx) prev[this.dataContainer.getColumn(i).name] = cur;
return prev;
}, {});
return {
...hoveredFeature,
properties: {
...properties,
index: objectInfo.index
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/reducers/src/layer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export function getLayerHoverProp({
// deckgl layer to kepler-gl layer
const layer = layers[overlay.props.idx];

if (object && layer && layer.getHoverData && layersToRender[layer.id]) {
// TODO: for binary format GeojsonLayer, deck will return object=null but hoverInfo.index >= 0
if ((object || hoverInfo.index >= 0) && layer && layer.getHoverData && layersToRender[layer.id]) {
// if layer is visible and have hovered data
const {
config: {dataId}
Expand All @@ -190,7 +191,7 @@ export function getLayerHoverProp({
return null;
}
const {dataContainer, fields} = datasets[dataId];
const data: DataRow | null = layer.getHoverData(object, dataContainer, fields);
const data: DataRow | null = layer.getHoverData(object || hoverInfo.index, dataContainer, fields);
if (!data) {
return null;
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/src/arrow-data-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function* columnIterator(dataContainer: DataContainerInterface, columnIndex: num
*/
export class ArrowDataContainer implements DataContainerInterface {
_cols: ArrowColumn[];
_colData: any[][];
_numColumns: number;
_numRows: number;

Expand All @@ -68,6 +69,8 @@ export class ArrowDataContainer implements DataContainerInterface {
}

this._cols = data.cols;
// cache column data to make valueAt() faster
this._colData = data.cols.map(c => c.toArray());
this._numColumns = data.cols.length;
this._numRows = data.cols[0].length;
}
Expand All @@ -81,7 +84,7 @@ export class ArrowDataContainer implements DataContainerInterface {
}

valueAt(rowIndex: number, columnIndex: number): any {
return this._cols[columnIndex].get(rowIndex);
return this._colData[columnIndex][rowIndex];
}

row(rowIndex: number, sharedRow?: SharedRowOptions): DataRow {
Expand All @@ -95,7 +98,7 @@ export class ArrowDataContainer implements DataContainerInterface {
}

rowAsArray(rowIndex: number): any[] {
return this._cols.map(col => col.get(rowIndex));
return this._colData.map(col => col[rowIndex]);
}

rows(sharedRow: SharedRowOptions) {
Expand Down

0 comments on commit 3914b67

Please sign in to comment.