Skip to content

Commit

Permalink
Analysis: update scichart and tensorflow
Browse files Browse the repository at this point in the history
  • Loading branch information
miklschmidt committed Dec 29, 2024
1 parent 9519be3 commit d55171d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 85 deletions.
15 changes: 11 additions & 4 deletions src/app/analysis/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
XyySeriesInfo,
XyyDataSeries,
IDataSeries,
SplineLineRenderableSeries,
RolloverTooltipSvgAnnotation,
} from 'scichart';
import { useChart } from '@/app/analysis/hooks';
import { ChartTheme } from '@/app/analysis/chart-theme';
Expand Down Expand Up @@ -97,7 +99,7 @@ export const useADXLSignalChart = (axis: ADXLAxes) => {
const xAxis = new NumericAxis(surface.webAssemblyContext2D, {
id: SIGNAL_CHART_AXIS_SIGNAL_ID + axis,
autoRange: EAutoRange.Always,
maxAutoTicks: ADXL_STREAM_BUFFER_SIZE,
allowFastMath: true,
drawLabels: false,
drawMinorTickLines: false,
drawMajorTickLines: false,
Expand All @@ -111,6 +113,7 @@ export const useADXLSignalChart = (axis: ADXLAxes) => {
const xHistoryAxis = new NumericAxis(surface.webAssemblyContext2D, {
id: SIGNAL_CHART_AXIS_HISTORY_ID + axis,
autoRange: EAutoRange.Always,
allowFastMath: true,
drawLabels: false,
drawMinorGridLines: false,
drawMajorTickLines: false,
Expand Down Expand Up @@ -422,7 +425,11 @@ export const getPSDTooltipLegendTemplate = (seriesInfos: SeriesInfo[], svgAnnota
};

// Override the standard tooltip displayed by CursorModifier
export const psdRolloverTooltipTemplate: TRolloverTooltipSvgTemplate = (id, seriesInfo, rolloverTooltip) => {
export const psdRolloverTooltipTemplate: TRolloverTooltipSvgTemplate = (
id: string,
seriesInfo: SeriesInfo,
rolloverTooltip: RolloverTooltipSvgAnnotation,
) => {
let valuesBlock = '';
const tooltipProps = rolloverTooltip.tooltipProps;
const tooltipTitle = tooltipProps.tooltipTitle,
Expand All @@ -444,14 +451,14 @@ export const psdRolloverTooltipTemplate: TRolloverTooltipSvgTemplate = (id, seri
const width =
tooltipProps.width ??
calcTooltipWidth(
valuesWithLabels.reduce(function (prev, cur) {
valuesWithLabels.reduce(function (prev: number, cur: string) {
return cur.length > prev ? cur.length : prev;
}, 0),
);
// tooltip height
const height = tooltipProps.height ?? calcTooltipHeight(valuesWithLabels.length);
rolloverTooltip.updateSize(width, height);
valuesWithLabels.forEach(function (val, index) {
valuesWithLabels.forEach(function (val: string, index: number) {
valuesBlock += `<tspan x="8" dy="1.2em">${val}</tspan>`;
});
let blur = `<feGaussianBlur result="blurOut" in="offOut" stdDeviation="3" />`;
Expand Down
3 changes: 3 additions & 0 deletions src/app/analysis/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ export const useChart = <T,>(
padding: new Thickness(0, 0, 0, indent ? 300 : 0),
});
}
if (chart == null) {
throw new Error('Chart not initialized');
}
chart.sciChartSurface.watermarkPosition = EWatermarkPosition.BottomLeft;
chart.sciChartSurface.watermarkRelativeToCanvas = true;
surface.current = chart.sciChartSurface;
Expand Down
38 changes: 19 additions & 19 deletions src/app/analysis/realtime-analysis-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const useRealtimeAnalysisChart = (
await updateLoadingState.current(val);
}
const signalLength = xSignalChart.data.current?.signalData.count() ?? 0;
const psdLength = psdChart.surface.current?.renderableSeries.getById('total').dataSeries.count() ?? 0;
const psdLength = psdChart.surface.current?.renderableSeries.getById('total')?.dataSeries.count() ?? 0;
xSignalChart.data.current?.signalData.clear();
ySignalChart.data.current?.signalData.clear();
zSignalChart.data.current?.signalData.clear();
Expand Down Expand Up @@ -137,28 +137,28 @@ export const useRealtimeAnalysisChart = (
new Array(psdLength).fill(0).map((_, i) => i * (200 / psdLength)),
new Array(psdLength).fill(0),
);
psdChart.surface.current?.renderableSeries.getById('x').runAnimation(
psdChart.surface.current?.renderableSeries.getById('x')?.runAnimation(
new LineAnimation({
duration: 200,
ease: easing.inOutQuad,
dataSeries: animationDS.x,
}),
);
psdChart.surface.current?.renderableSeries.getById('y').runAnimation(
psdChart.surface.current?.renderableSeries.getById('y')?.runAnimation(
new LineAnimation({
duration: 200,
ease: easing.inOutQuad,
dataSeries: animationDS.y,
}),
);
psdChart.surface.current?.renderableSeries.getById('z').runAnimation(
psdChart.surface.current?.renderableSeries.getById('z')?.runAnimation(
new LineAnimation({
duration: 200,
ease: easing.inOutQuad,
dataSeries: animationDS.z,
}),
);
psdChart.surface.current?.renderableSeries.getById('total').runAnimation(
psdChart.surface.current?.renderableSeries.getById('total')?.runAnimation(
new MountainAnimation({
duration: 200,
ease: easing.inOutQuad,
Expand Down Expand Up @@ -222,27 +222,27 @@ export const useRealtimeAnalysisChart = (
`Total estimates and frequencies are not the same length (${res.total.estimates.length} vs ${res.total.frequencies.length})`,
);
}
if (res.x.frequencies.length !== surface.renderableSeries.getById('x').dataSeries.count()) {
if (res.x.frequencies.length !== surface.renderableSeries.getById('x')?.dataSeries.count()) {
getLogger().warn(
`X frequencies are not the same length as the data series (${res.x.estimates.length} vs ${surface.renderableSeries.getById('x').dataSeries.count()})`,
`X frequencies are not the same length as the data series (${res.x.estimates.length} vs ${surface.renderableSeries.getById('x')?.dataSeries.count()})`,
);
surface.renderableSeries.getById('x').dataSeries.clear();
surface.renderableSeries.getById('y').dataSeries.clear();
surface.renderableSeries.getById('z').dataSeries.clear();
surface.renderableSeries.getById('total').dataSeries.clear();
(surface.renderableSeries.getById('x').dataSeries as XyDataSeries).appendRange(
surface.renderableSeries.getById('x')?.dataSeries.clear();
surface.renderableSeries.getById('y')?.dataSeries.clear();
surface.renderableSeries.getById('z')?.dataSeries.clear();
surface.renderableSeries.getById('total')?.dataSeries.clear();
(surface.renderableSeries.getById('x')?.dataSeries as XyDataSeries | null)?.appendRange(
res.x.frequencies,
new Array(res.x.frequencies.length).fill(0),
);
(surface.renderableSeries.getById('y').dataSeries as XyDataSeries).appendRange(
(surface.renderableSeries.getById('y')?.dataSeries as XyDataSeries | null)?.appendRange(
res.y.frequencies,
new Array(res.y.frequencies.length).fill(0),
);
(surface.renderableSeries.getById('z').dataSeries as XyDataSeries).appendRange(
(surface.renderableSeries.getById('z')?.dataSeries as XyDataSeries | null)?.appendRange(
res.z.frequencies,
new Array(res.z.frequencies.length).fill(0),
);
(surface.renderableSeries.getById('total').dataSeries as XyDataSeries).appendRange(
(surface.renderableSeries.getById('total')?.dataSeries as XyDataSeries | null)?.appendRange(
res.total.frequencies,
new Array(res.total.frequencies.length).fill(0),
);
Expand All @@ -255,28 +255,28 @@ export const useRealtimeAnalysisChart = (
animationDS.y.appendRange(res.y.frequencies, res.y.estimates);
animationDS.z.appendRange(res.z.frequencies, res.z.estimates);
animationDS.total.appendRange(res.total.frequencies, res.total.estimates);
surface.renderableSeries.getById('x').runAnimation(
surface.renderableSeries.getById('x')?.runAnimation(
new LineAnimation({
duration: Math.max(elapsed, 100),
ease: easing.inOutQuad,
dataSeries: animationDS.x,
}),
);
surface.renderableSeries.getById('y').runAnimation(
surface.renderableSeries.getById('y')?.runAnimation(
new LineAnimation({
duration: Math.max(elapsed, 100),
ease: easing.inOutQuad,
dataSeries: animationDS.y,
}),
);
surface.renderableSeries.getById('z').runAnimation(
surface.renderableSeries.getById('z')?.runAnimation(
new LineAnimation({
duration: Math.max(elapsed, 100),
ease: easing.inOutQuad,
dataSeries: animationDS.z,
}),
);
surface.renderableSeries.getById('total').runAnimation(
surface.renderableSeries.getById('total')?.runAnimation(
new MountainAnimation({
duration: Math.max(elapsed, 100),
ease: easing.inOutQuad,
Expand Down
14 changes: 7 additions & 7 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-table": "^8.11.7",
"@tanstack/react-virtual": "^3.0.2",
"@tensorflow/tfjs-backend-cpu": "^4.20.0",
"@tensorflow/tfjs-backend-wasm": "^4.20.0",
"@tensorflow/tfjs-backend-webgl": "^4.20.0",
"@tensorflow/tfjs-backend-webgpu": "^4.20.0",
"@tensorflow/tfjs-core": "^4.20.0",
"@tensorflow/tfjs-data": "^4.20.0",
"@tensorflow/tfjs-backend-cpu": "^4.22.0",
"@tensorflow/tfjs-backend-wasm": "^4.22.0",
"@tensorflow/tfjs-backend-webgl": "^4.22.0",
"@tensorflow/tfjs-backend-webgpu": "^4.22.0",
"@tensorflow/tfjs-core": "^4.22.0",
"@tensorflow/tfjs-data": "^4.22.0",
"@trpc/client": "10.45.1",
"@trpc/next": "10.45.1",
"@trpc/react-query": "10.45.1",
Expand Down Expand Up @@ -130,7 +130,7 @@
"refractor": "3.6.0",
"ring-buffer-ts": "^1.2.0",
"rxjs": "^7.8.1",
"scichart": "^3.4.636",
"scichart": "^3.5.711",
"scichart-react": "^0.1.9",
"screenfull": "^6.0.2",
"semver": "^7.6.3",
Expand Down
Loading

0 comments on commit d55171d

Please sign in to comment.