Skip to content

Commit d2ef2c7

Browse files
committed
Added warnings & errors for bad correlation plots.
1 parent 843d98d commit d2ef2c7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/components/Content/PlotWidget/PlotWidget.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,12 @@ const PlotWidget: React.FC<PlotWidgetProps> = React.memo(
10841084
(meta) => meta.pulseId
10851085
);
10861086

1087+
const isXRaw = metaData.raw;
1088+
1089+
let combiningRawWithBinned = false;
1090+
let timestampsNotMatching = false;
1091+
let valuesLostInMapping = false;
1092+
10871093
for (let index = 0; index < curves.length; index++) {
10881094
if (index === xCurveIndex) continue;
10891095

@@ -1092,6 +1098,10 @@ const PlotWidget: React.FC<PlotWidgetProps> = React.memo(
10921098
const curveTimestamps = Object.keys(baseData);
10931099
const curveValues = Object.values(baseData);
10941100

1101+
if (isXRaw !== curve.curveData.curve.meta.raw) {
1102+
combiningRawWithBinned = true;
1103+
}
1104+
10951105
let i = 0,
10961106
j = 0;
10971107
const mergedX: number[] = [];
@@ -1119,6 +1129,16 @@ const PlotWidget: React.FC<PlotWidgetProps> = React.memo(
11191129
}
11201130
}
11211131

1132+
// Check if none of the timestamps match to signal to the user that there are bad curves
1133+
if (xTimestamps.length > 0 && mergedX.length === 0) {
1134+
timestampsNotMatching = true;
1135+
}
1136+
1137+
// Check if the curves are not of the same size to alert the user of data loss
1138+
if (xTimestamps.length != curveTimestamps.length) {
1139+
valuesLostInMapping = true;
1140+
}
1141+
11221142
const label = getLabelForCurve(curve);
11231143
const displayLabel =
11241144
curveAttributes.get(label)?.displayLabel;
@@ -1172,6 +1192,28 @@ const PlotWidget: React.FC<PlotWidgetProps> = React.memo(
11721192
line: { color: color, shape: shape },
11731193
} as Plotly.Data);
11741194
}
1195+
1196+
// Tell the user about anomalies
1197+
if (timestampsNotMatching) {
1198+
// Since this message is important and somewhat long, give it enough time (and increase if message expanded) such that it can be read.
1199+
let timeMs = 5000;
1200+
let message =
1201+
"Some curves have mismatching timestamps and cannot be correlated.";
1202+
if (combiningRawWithBinned) {
1203+
message +=
1204+
" Try disabling raw when sparse in the time-selector bar to get binned data for all curves.";
1205+
timeMs += 5000;
1206+
}
1207+
1208+
showSnackbarAndLog(message, "error", null, 10000);
1209+
}
1210+
if (valuesLostInMapping) {
1211+
// This is quite common and shouldnt impact ux negatively by popping up all the time, so lets put it into the console so it can be used for debugging bad plots
1212+
logToConsole(
1213+
"Some curves have different sizes, only values with matching timestamps have been correlated.",
1214+
"warning"
1215+
);
1216+
}
11751217
} else {
11761218
for (let index = 0; index < curves.length; index++) {
11771219
const curve = curves[index];

0 commit comments

Comments
 (0)