-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-components): add l4e datasource
- Loading branch information
1 parent
415c9e0
commit 2947002
Showing
36 changed files
with
1,116 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/react-components/src/components/anomaly-widget/hooks/useDataSet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useMemo } from 'react'; | ||
import { AnomalyData } from '../../../data'; | ||
import { barHeight, barHeightEncoding } from '../constants'; | ||
|
||
const datasetFromData = (data: AnomalyData) => { | ||
if (Array.isArray(data)) { | ||
return data.map((d) => ({ | ||
...d, | ||
[barHeightEncoding]: barHeight, | ||
})); | ||
} | ||
return { | ||
...data, | ||
[barHeightEncoding]: data.timestamp.map(() => barHeight), | ||
}; | ||
}; | ||
|
||
export const useDataSet = ({ data }: { data: AnomalyData | undefined }) => { | ||
return useMemo(() => { | ||
if (!data) return; | ||
return { | ||
dataset: [ | ||
{ | ||
source: datasetFromData(data), | ||
}, | ||
{ | ||
// Transform using echarts so we don't need to care | ||
// about the format of the data | ||
transform: [ | ||
{ | ||
type: 'sort', | ||
config: { dimension: 'timestamp', order: 'asc' }, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
}, [data]); | ||
}; |
38 changes: 38 additions & 0 deletions
38
packages/react-components/src/components/anomaly-widget/hooks/useSeries.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useMemo } from 'react'; | ||
import { ANOMALY_SERIES } from '../constants'; | ||
import { AnomalyDescription } from '../../../data'; | ||
|
||
export const useSeries = ({ | ||
description, | ||
}: { | ||
description: AnomalyDescription | undefined; | ||
}) => { | ||
return useMemo(() => { | ||
if (!description) { | ||
return { | ||
series: [...ANOMALY_SERIES.series], | ||
}; | ||
} | ||
const diagnosticSeries = description.diagnostics.map((d) => { | ||
return { | ||
id: d.id, | ||
name: d.name, | ||
encode: { | ||
x: 'timestamp', | ||
y: d.id, | ||
}, | ||
type: 'line', | ||
step: 'start', | ||
xAxisIndex: 1, | ||
yAxisIndex: 1, | ||
datasetIndex: 1, | ||
areaStyle: {}, | ||
stack: 'Total', | ||
}; | ||
}); | ||
|
||
return { | ||
series: [...ANOMALY_SERIES.series, ...diagnosticSeries], | ||
}; | ||
}, [description]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 24 additions & 19 deletions
43
...onents/src/components/l4eWidget/index.tsx → ...s/src/components/anomaly-widget/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/react-components/src/components/anomaly-widget/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { HistoricalViewport } from '@iot-app-kit/core'; | ||
import type { FixedLengthArray } from 'type-fest'; | ||
import { AnomalyObjectDataSource } from '../../data/transformers/anomaly/object/datasource'; | ||
|
||
type AnomalyWidgetDataSources = AnomalyObjectDataSource; | ||
export type AnomalyWidgetOptions = { | ||
title?: string; | ||
mode?: 'light' | 'dark'; | ||
decimalPlaces?: number; | ||
datasources: FixedLengthArray<AnomalyWidgetDataSources, 1>; | ||
viewport: HistoricalViewport; | ||
tooltipSort?: 'value' | 'alphabetical'; | ||
}; |
Oops, something went wrong.