Skip to content

Commit

Permalink
Thchang/1831 fixed no updating of spatial profilers after region dele…
Browse files Browse the repository at this point in the history
…ting (#1869)

* fixed no updating of spatial profilers after region deleting

* removing the deleted region id from the regionIdMap of SpatialProfilerWidgetStore

* refactoring code of closing image and removing frame from RegionWidgetStore

* fixed issue of RegionStoreWidget when spatial matching

* updated CHANGELOG.md
  • Loading branch information
TienHao authored Jun 8, 2022
1 parent fca433e commit ec1edf5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed the rotation anchor offset of line regions ([#1739](https://github.com/CARTAvis/carta-frontend/issues/1739)).
* Fixed issue with exporting decimated data instead of full resolution data in spatial profiler ([#1546](https://github.com/CARTAvis/carta-frontend/issues/1546))
* Fixed larger position errors of projected contours, catalog overlays, and vector overlays near the border ([#1843](https://github.com/CARTAvis/carta-frontend/issues/1843)).
* Fixed no updating of spatial profile after region deleting ([#1831](https://github.com/CARTAvis/carta-frontend/issues/1831), [#1855](https://github.com/CARTAvis/carta-frontend/issues/1855)).

## [3.0.0-beta.3]

Expand Down
22 changes: 7 additions & 15 deletions src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,7 @@ export class AppStore {
const fileId = frame.frameInfo.fileId;

// adjust requirements for stores
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.statsWidgets, fileId);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.histogramWidgets, fileId);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spatialProfileWidgets, fileId);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spectralProfileWidgets, fileId);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.stokesAnalysisWidgets, fileId);
this.widgetsStore.removeFrameFromRegionWidgets(fileId);

// clear existing requirements for the frame
this.spectralRequirements.delete(fileId);
Expand Down Expand Up @@ -788,11 +784,7 @@ export class AppStore {
});
this.frames = [];
// adjust requirements for stores
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.statsWidgets);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.histogramWidgets);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spatialProfileWidgets);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.spectralProfileWidgets);
WidgetsStore.RemoveFrameFromRegionWidgets(this.widgetsStore.stokesAnalysisWidgets);
this.widgetsStore.removeFrameFromRegionWidgets();
}
};

Expand Down Expand Up @@ -2006,13 +1998,13 @@ export class AppStore {
@action deleteRegion = (region: RegionStore) => {
if (region) {
const frame = this.getFrame(region.fileId);
const regionId = region.regionId;
WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.statsWidgets, region.fileId, regionId);
WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.histogramWidgets, region.fileId, regionId);
WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.spectralProfileWidgets, region.fileId, regionId);
WidgetsStore.RemoveRegionFromRegionWidgets(this.widgetsStore.stokesAnalysisWidgets, region.fileId, regionId);
// adjust requirements for stores
this.widgetsStore.removeRegionFromRegionWidgets(region.fileId, region.regionId);
// delete region
if (frame) {
frame.secondarySpatialImages.forEach(image => {
this.widgetsStore.removeRegionFromRegionWidgets(image.frameInfo.fileId, region.regionId);
});
frame.regionSet.deleteRegion(region);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/stores/Frame/FrameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,8 @@ export class FrameStore {
for (const region of this.frameRegionSet.regions) {
this.frameRegionSet.deleteRegion(region);
}

AppStore.Instance.widgetsStore.removeRegionsFromRegionWidgetsByFrame(this.frameInfo.fileId);
return true;
};

Expand Down Expand Up @@ -2154,6 +2156,8 @@ export class FrameStore {
this.removeCatalogControlMap(frame);
});
this.catalogControlMaps.clear();

AppStore.Instance.widgetsStore.removeRegionsFromRegionWidgetsByFrame(this.frameInfo.fileId);
};

@action addSecondarySpatialImage = (frame: FrameStore) => {
Expand Down
56 changes: 37 additions & 19 deletions src/stores/WidgetsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,47 @@ export class WidgetsStore {
]
]);

public static RemoveFrameFromRegionWidgets(storeMap: Map<string, RegionWidgetStore>, fileId: number = ACTIVE_FILE_ID) {
if (fileId === ACTIVE_FILE_ID) {
storeMap.forEach(widgetStore => {
widgetStore.clearRegionMap();
widgetStore.setFileId(ACTIVE_FILE_ID);
});
} else {
storeMap.forEach(widgetStore => {
widgetStore.clearFrameEntry(fileId);
if (widgetStore.fileId === fileId) {
widgetStore.setFileId(ACTIVE_FILE_ID);
@action public removeFrameFromRegionWidgets(fileId: number = ACTIVE_FILE_ID) {
this.widgetsMap.forEach(widgets => {
widgets.forEach(widgetStore => {
if (widgetStore instanceof RegionWidgetStore) {
if (fileId === ACTIVE_FILE_ID) {
widgetStore.clearRegionMap();
widgetStore.setFileId(ACTIVE_FILE_ID);
} else {
widgetStore.clearFrameEntry(fileId);
if (widgetStore.fileId === fileId) {
widgetStore.setFileId(ACTIVE_FILE_ID);
}
}
}
});
}
});
}

public static RemoveRegionFromRegionWidgets = (storeMap: Map<string, RegionWidgetStore>, fileId, regionId: number) => {
storeMap.forEach(widgetStore => {
const selectedRegionId = widgetStore.regionIdMap.get(fileId);
// remove entry from map if it matches the deleted region
if (isFinite(selectedRegionId) && selectedRegionId === regionId) {
widgetStore.clearFrameEntry(fileId);
}
@action public removeRegionFromRegionWidgets = (fileId: number, regionId: number) => {
this.widgetsMap.forEach(widgets => {
widgets.forEach(widgetStore => {
if (widgetStore instanceof RegionWidgetStore) {
const selectedRegionId = widgetStore.regionIdMap.get(fileId);
// remove entry from map if it matches the deleted region
if (isFinite(selectedRegionId) && selectedRegionId === regionId) {
widgetStore.clearFrameEntry(fileId);
}
}
});
});
};

@action public removeRegionsFromRegionWidgetsByFrame = (fileId: number) => {
this.widgetsMap.forEach(widgets => {
widgets.forEach(widgetStore => {
if (widgetStore instanceof RegionWidgetStore) {
if (widgetStore.regionIdMap.has(fileId)) {
widgetStore.clearFrameEntry(fileId);
}
}
});
});
};

Expand Down

0 comments on commit ec1edf5

Please sign in to comment.