Skip to content

Commit

Permalink
additional protection around incoming dataformat
Browse files Browse the repository at this point in the history
adds some extra checks around the incoming data so it doesn't throw out
if toDataFrame returns something unexpected from a particular source.

repackaged at ver 1.1.3
  • Loading branch information
andymchugh committed Feb 17, 2024
1 parent f65ec66 commit 2d4fd6c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flow",
"version": "1.1.2",
"version": "1.1.3",
"description": "Svg flowchart visualization",
"scripts": {
"build": "webpack -c ./webpack.config.ts --env production",
Expand Down
44 changes: 23 additions & 21 deletions src/components/TimeSeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,34 @@ export function seriesExtend(tsData: TimeSeriesData, timeMin: number, timeMax: n
// This transforms the data so we have name-indexable sets of time and value.
// i.e.:
// - series: [fields: [{name, values}]] => Map<string, TimeSeries>
export function seriesTransform(series: any, timeMin: number, timeMax: number): TimeSeriesData {
export function seriesTransform(series: any[], timeMin: number, timeMax: number): TimeSeriesData {
const timeSeries = new Map<string, TimeSeries>();

series.forEach((frame: any) => {
let tsTime = null;
let tsNamed: Record<string, any> = {};

frame.fields.forEach(function(ts: any) {
if (ts.name === 'time') {
// The index is stored alongside the ts because it has potential to be shared
// and if so, only has to be calculated once.
tsTime = {valuesIndex: null, values: ts.values};
if (tsTime.values.length > 0) {
const maxInd = tsTime.values.length - 1;
timeMin = Math.min(timeMin ?? tsTime.values[0], tsTime.values[0]);
timeMax = Math.max(timeMax ?? tsTime.values[maxInd], tsTime.values[maxInd]);
if (('fields' in frame) && Array.isArray(frame.fields)) {
let tsTime = null;
let tsNamed: Record<string, any> = {};

frame.fields.forEach(function(ts: any) {
if (ts.name === 'time') {
// The index is stored alongside the ts because it has potential to be shared
// and if so, only has to be calculated once.
tsTime = {valuesIndex: null, values: ts.values};
if (tsTime.values.length > 0) {
const maxInd = tsTime.values.length - 1;
timeMin = Math.min(timeMin ?? tsTime.values[0], tsTime.values[0]);
timeMax = Math.max(timeMax ?? tsTime.values[maxInd], tsTime.values[maxInd]);
}
}
else {
tsNamed[ts.name] = {values: ts.values, time: null};
}
});
// Embed a time shallow copy against each ts in the frame and export to holder
for (const [name, ts] of Object.entries<any>(tsNamed)) {
ts.time = tsTime;
timeSeries.set(name, ts);
}
else {
tsNamed[ts.name] = {values: ts.values, time: null};
}
});
// Embed a time shallow copy against each ts in the frame and export to holder
for (const [name, ts] of Object.entries<any>(tsNamed)) {
ts.time = tsTime;
timeSeries.set(name, ts);
}
});

Expand Down

0 comments on commit 2d4fd6c

Please sign in to comment.