Skip to content

Commit

Permalink
fix load same file again; fix hovering
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Li <[email protected]>
  • Loading branch information
lixun910 committed Dec 8, 2023
1 parent b34ac84 commit 0430e9c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/actions/src/vis-state-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ export type NextFileBatchUpdaterAction = {
/* eslint-disable no-undef */
gen: AsyncGenerator<FileContent>;
fileName: string;
fileLastModified?: number;
progress?: any;
accumulated?: any;
onFinish: (result: any) => any;
Expand Down
5 changes: 1 addition & 4 deletions src/layers/src/layer-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ export function getHoveredObjectFromArrow(
const field = fieldAccessor(dataContainer);
const encoding = field?.metadata?.get('ARROW:extension:name');

const hoveredFeature = parseGeometryFromArrow({
encoding,
data: rawGeometry
});
const hoveredFeature = parseGeometryFromArrow(rawGeometry, encoding);

const properties = dataContainer.rowAsArray(objectInfo.index).reduce((prev, cur, i) => {
const fieldName = dataContainer?.getField?.(i).name;
Expand Down
7 changes: 6 additions & 1 deletion src/processors/src/file-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const JSON_LOADER_OPTIONS = {
export type ProcessFileDataContent = {
data: unknown;
fileName: string;
lastModified?: number;
length?: number;
progress?: {rowCount?: number; rowCountInBatch?: number; percent?: number};
/** metadata e.g. for arrow data, metadata could be the schema.fields */
Expand Down Expand Up @@ -215,11 +216,15 @@ export function processFileData({
fileCache: FileCacheItem[];
}): Promise<FileCacheItem[]> {
return new Promise((resolve, reject) => {
let {fileName, data} = content;
let {fileName, data, lastModified} = content;
let format: string | undefined;
let processor: Function | undefined;

// generate unique id with length of 4 using fileName string
// attach lastModified to fileName if its not undefined
if (lastModified) {
fileName = `${fileName}-${lastModified}`;
}
const id = generateHashIdFromString(fileName);

if (isArrowData(data)) {
Expand Down
58 changes: 31 additions & 27 deletions src/reducers/src/vis-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2228,9 +2228,13 @@ export function makeLoadFileTask(file, fileCache, loaders: Loader[] = [], loadOp
nextFileBatch({
gen,
fileName: file.name,
fileLastModified: file.lastModified,
onFinish: result =>
processFileContent({
content: result,
content: {
...result,
fileLastModified: file.lastModified
},
fileCache
})
}),
Expand Down Expand Up @@ -2300,39 +2304,39 @@ export function loadBatchDataSuccessUpdater(
export const nextFileBatchUpdater = (
state: VisState,
{
payload: {gen, fileName, progress, accumulated, onFinish}
payload: {gen, fileName, fileLastModified, progress, accumulated, onFinish}
}: VisStateActions.NextFileBatchUpdaterAction
): VisState => {
const stateWithProgress = updateFileLoadingProgressUpdater(state, {
fileName,
progress: parseProgress(state.fileLoadingProgress[fileName], progress)
});

return withTask(
stateWithProgress, [
...(fileName.endsWith('arrow') && accumulated && accumulated.data?.length > 0
? [
PROCESS_FILE_DATA({content: accumulated, fileCache: []}).bimap(
result => loadBatchDataSuccess({fileName, fileCache: result}),
err => loadFilesErr(fileName, err)
)
]
: []),
UNWRAP_TASK(gen.next()).bimap(
({value, done}) => {
return done
? onFinish(accumulated)
: nextFileBatch({
gen,
fileName,
progress: value.progress,
accumulated: value,
onFinish
});
},
err => loadFilesErr(fileName, err)
)
]);
return withTask(stateWithProgress, [
...(fileName.endsWith('arrow') && accumulated && accumulated.data?.length > 1
? [
PROCESS_FILE_DATA({content: {...accumulated, fileLastModified}, fileCache: []}).bimap(
result => loadBatchDataSuccess({fileName, fileCache: result}),
err => loadFilesErr(fileName, err)
)
]
: []),
UNWRAP_TASK(gen.next()).bimap(
({value, done}) => {
return done
? onFinish(accumulated)
: nextFileBatch({
gen,
fileName,
fileLastModified,
progress: value.progress,
accumulated: value,
onFinish
});
},
err => loadFilesErr(fileName, err)
)
]);
};

/**
Expand Down

0 comments on commit 0430e9c

Please sign in to comment.