From 8d7e02c4770faffc369af755fafa4e12a6689be6 Mon Sep 17 00:00:00 2001 From: TienHao Date: Fri, 27 May 2022 18:00:20 +0800 Subject: [PATCH] Thchang/1546 exporting full resolution data in the spatial profiler (#1865) * exporting original data when showing decimated data in the plotting of Spatial Profiler * modified change log * modified property name * minor refactoring * minor refactoring --- CHANGELOG.md | 1 + .../Shared/LinePlot/LinePlotComponent.tsx | 6 ++++-- .../SpatialProfiler/SpatialProfilerComponent.tsx | 14 +++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c12f0f96f..2f225347f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added missing vector overlay and image fitting options in the View menu ([#1848](https://github.com/CARTAvis/carta-frontend/issues/1848)). * Hide code snippet option in the View menu when code snippet is disabled in the preferences ([#1856](https://github.com/CARTAvis/carta-frontend/issues/1856)). * 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)) ## [3.0.0-beta.3] diff --git a/src/components/Shared/LinePlot/LinePlotComponent.tsx b/src/components/Shared/LinePlot/LinePlotComponent.tsx index d58f816908..e3bca2ed91 100644 --- a/src/components/Shared/LinePlot/LinePlotComponent.tsx +++ b/src/components/Shared/LinePlot/LinePlotComponent.tsx @@ -70,7 +70,7 @@ export interface LinePlotInsideTextMarker { export class LinePlotComponentProps { width?: number; height?: number; - data?: {x: number; y: number; z?: number}[]; + data?: Point2D[]; comments?: string[]; xMin?: number; xMax?: number; @@ -122,6 +122,7 @@ export class LinePlotComponentProps { insideTexts?: LinePlotInsideTextMarker[]; order?: number; multiPlotPropsMap?: Map; + fullResolutionData?: Point2D[]; } // Maximum time between double clicks @@ -660,7 +661,8 @@ export class LinePlotComponent extends React.Component { // data part rows.push("# x\ty"); const useScientificForm = plotName === "histogram" || this.props.tickTypeX === TickType.Scientific; - rows = rows.concat(this.props.data.map(o => (useScientificForm ? `${toExponential(o.x, 10)}\t${toExponential(o.y, 10)}` : `${o.x}\t${toExponential(o.y, 10)}`))); + const data = this.props.fullResolutionData?.length > 0 ? this.props.fullResolutionData : this.props.data; + rows = rows.concat(data.map(o => (useScientificForm ? `${toExponential(o.x, 10)}\t${toExponential(o.y, 10)}` : `${o.x}\t${toExponential(o.y, 10)}`))); exportTsvFile(imageName, plotName, `${comment}\n${rows.join("\n")}\n`); } diff --git a/src/components/SpatialProfiler/SpatialProfilerComponent.tsx b/src/components/SpatialProfiler/SpatialProfilerComponent.tsx index fcc7014a58..76d5a7f604 100644 --- a/src/components/SpatialProfiler/SpatialProfilerComponent.tsx +++ b/src/components/SpatialProfiler/SpatialProfilerComponent.tsx @@ -73,7 +73,7 @@ export class SpatialProfilerComponent extends React.Component { } } - @computed get plotData(): {values: Array; smoothingValues: Array; xMin: number; xMax: number; yMin: number; yMax: number; yMean: number; yRms: number} { + @computed get plotData(): {values: Array; fullResolutionValues: Array; smoothingValues: Array; xMin: number; xMax: number; yMin: number; yMax: number; yMean: number; yRms: number} { if (!this.frame || !this.width || !this.profileStore) { return null; } @@ -115,13 +115,15 @@ export class SpatialProfilerComponent extends React.Component { let ySum2 = 0; let yCount = 0; - let values: Array<{x: number; y: number}>; + let values: Array; + let fullResolutionValues: Array; let smoothingValues: Array<{x: number; y: number}>; let N: number; if (this.lineAxis) { N = coordinateData.values.length; values = new Array(N); + fullResolutionValues = new Array(N); let xArray: number[] = new Array(N); const numPixels = this.width; const decimationFactor = Math.round(N / numPixels); @@ -144,6 +146,8 @@ export class SpatialProfilerComponent extends React.Component { xArray[i] = x; if (decimationFactor <= 1) { values[i] = {x, y}; + } else { + fullResolutionValues[i] = {x, y}; } } if (decimationFactor > 1) { @@ -192,8 +196,10 @@ export class SpatialProfilerComponent extends React.Component { } } else { // Decimated data + fullResolutionValues = new Array(N); for (let i = 0; i < N; i++) { const val = coordinateData.values[i + xMin]; + const x = coordinateData.start + i + xMin; if (isFinite(val)) { yMin = Math.min(yMin, val); yMax = Math.max(yMax, val); @@ -201,6 +207,7 @@ export class SpatialProfilerComponent extends React.Component { ySum += val; ySum2 += val * val; } + fullResolutionValues[i] = {x, y: val}; } values = this.widgetStore.smoothingStore.getDecimatedPoint2DArray(xArray, coordinateData.values, decimationFactor, xMin, xMax); } @@ -223,7 +230,7 @@ export class SpatialProfilerComponent extends React.Component { yMax += range * VERTICAL_RANGE_PADDING; } - return {values: values, smoothingValues, xMin, xMax, yMin, yMax, yMean, yRms}; + return {values: values, fullResolutionValues, smoothingValues, xMin, xMax, yMin, yMax, yMean, yRms}; } } @@ -488,6 +495,7 @@ export class SpatialProfilerComponent extends React.Component { const currentPlotData = this.plotData; if (currentPlotData) { linePlotProps.data = currentPlotData.values; + linePlotProps.fullResolutionData = currentPlotData.fullResolutionValues; // set line color let primaryLineColor = getColorForTheme(widgetStore.primaryLineColor);